What Is a CUDA Event? Synchronize Streams and Measure GPU Time
A CUDA event is a marker placed in a GPU stream. It lets you check how far work has completed, connect dependencies between streams, and measure a GPU time interval. The fact that the host-side event-record call has returned does not mean the GPU work before it has finished. Choose completion events and timing events according to their purpose, and account for work from other streams that may run between timestamps. This article covers CUDA C++ and the CUDA 13.5 documentation reviewed on 2026-11-22.
What Is a CUDA Event? Synchronize Streams and Measure GPU Time
A CUDA event is a marker placed in a GPU stream. It lets you check how far work has completed, connect dependencies between streams, and measure a GPU time interval. The fact that the host-side event-record call has returned does not mean the GPU work before it has finished. Choose completion events and timing events according to their purpose, and account for work from other streams that may run between timestamps. This article covers CUDA C++ and the CUDA 13.5 documentation reviewed on 2026-11-22.
What does an event record in a stream?
A newly created event has no recorded work. Calling cudaEventRecord(event, stream) associates the event with the work already queued in the specified stream at that point. The event does not launch a kernel or copy; it marks a point that earlier queued work must reach. If you record it after a kernel in a producer stream, completion marks a boundary after earlier work in that same stream. The host call may return asynchronously before that happens.
Producer stream: [work A] → [record event] → [independent work C]
│
Consumer stream: └→ [wait for event] → [dependent work B]
Host: query (poll) or event synchronization (wait)An event adds only the relationship needed between work in different streams. Work queued to a consumer stream after its wait is ordered after the producer work captured by the event. Because the dependency is queued before the consumer work, the CPU need not stop the whole device at every step. If the data is not ready, omitting the record or recording it in the wrong stream can make the consumer read it too soon.
The next example makes consumer work wait for producer work. It assumes the streams, buffers, grid, and block are prepared by the application; error checking and cleanup are omitted for clarity. A dependency-only event disables timing, is recorded in the producer stream, and is then waited on by the consumer stream.
// stream, buffers, grid and block are prepared by the application.
// producerKernel and consumerKernel are application-defined.
cudaEvent_t dataReady;
cudaEventCreateWithFlags(&dataReady, cudaEventDisableTiming);
producerKernel<<<grid, block, 0, producerStream>>>(data);
cudaEventRecord(dataReady, producerStream);
// Future work in consumerStream waits for the producer marker.
cudaStreamWaitEvent(consumerStream, dataReady, 0);
consumerKernel<<<grid, block, 0, consumerStream>>>(data);| Goal | API | Behavior of the calling host thread |
|---|---|---|
| Add a completion marker at a stream point | cudaEventRecord(event, stream) | Queues the marker and may return first |
| Check completion without blocking | cudaEventQuery(event) | Returns cudaSuccess if complete or cudaErrorNotReady otherwise |
| Have the CPU wait for the marker | cudaEventSynchronize(event) | Waits for work captured by that event |
| Start dependent work in another stream | cudaStreamWaitEvent(consumer, event, 0) | Queues a GPU-side wait in the consumer stream |
| Have the CPU wait for earlier work in one stream | cudaStreamSynchronize(stream) | Waits within that stream's scope |
| Have the CPU wait for earlier work on the current device | cudaDeviceSynchronize() | Can include work from multiple streams |
cudaEventSynchronize makes the CPU wait for the work represented by a recorded event. cudaStreamWaitEvent queues later GPU work to wait in a different stream. They are not interchangeable. If the CPU has no useful work to do, event synchronization can be appropriate before reading a result; to express only a dependency in a GPU pipeline, a stream wait is usually narrower. cudaStreamSynchronize waits for earlier work in a stream, while cudaDeviceSynchronize has a wider scope that can include earlier work in multiple streams. Query completion only after recording the event.
What can go wrong with querying and rerecording an event?
Before its first record, an event represents an empty set of work. Therefore, cudaEventQuery can return success, but that does not mean a newly submitted producer finished. Record the event in the producer stream first, then query or wait against that record. In a pipeline that reuses events for input/output buffers, track which record generation each slot is waiting for.
Calling cudaEventRecord again on the same event replaces the state captured by its earlier record. cudaStreamWaitEvent uses the most recently captured record at the time the wait is called; a later rerecord does not change a wait already queued. However, careless reuse while several frames or buffers are in flight can mismatch the host's “current frame” with the record the GPU is waiting for. Consider a separate event per concurrently active slot, or rerecord only after the prior use has finished.
The recorded stream and event handle must belong to the same CUDA context. The Runtime API also documents use of an event from another device with cudaStreamWaitEvent, but validate a multi-GPU path separately from a single-device example. An asynchronous CUDA error may be reported by a later query or synchronization call, so do not assume the most recent call is necessarily its cause; also inspect earlier kernels and copies.
What does CUDA event timing measure?
When timing is enabled, recording start and stop events around a measurement interval in one stream gives the difference between the times the GPU reaches the two markers, in milliseconds. The markers represent device progress in the stream, not the CPU wall-clock times when the API calls were made. This timeline shows the basic pattern for measuring work queued to that stream.
Measurement stream: [start timestamp] → [target GPU work] → [stop timestamp]
Host: submit markers (may return) → wait for stop → read elapsed timeThe example assumes the application has prepared the stream, target kernel, and input/output memory. It queues a start marker, the target work, and a stop marker in the same stream, in that order. Read elapsed time after the stop marker completes. This example explains API ordering; it has not been compiled or run on a GPU.
// stream, buffers, grid and block are prepared by the application.
// targetKernel is application-defined.
cudaEvent_t start, stop;
cudaEventCreate(&start); // timing enabled by default
cudaEventCreate(&stop);
cudaEventRecord(start, stream);
targetKernel<<<grid, block, 0, stream>>>(input, output);
cudaEventRecord(stop, stream);
// The host waits until the stop marker and earlier stream work complete.
cudaEventSynchronize(stop);
float elapsedMs = 0.0f;
cudaEventElapsedTime(&elapsedMs, start, stop);
// In production code, check every CUDA return value and clean up on all paths.
cudaEventDestroy(stop);
cudaEventDestroy(start);This value is GPU event time, not CPU API-call overhead or application end-to-end latency. Putting both markers in the same stream is a useful way to bound the target interval, but the Runtime API warns that work from other streams may execute between the timestamps when events are recorded to a non-null stream. This can happen even when both events use the same stream handle. Do not treat a single measurement with competing streams as the exact time of one kernel. Repeat measurements under isolated conditions, and use a GPU timeline if you need to see what ran between markers.
NVIDIA documents approximately 0.5 microsecond resolution, but resolution does not guarantee accuracy or repeatability. Avoid overinterpreting one run of very short work; compare the same input and concurrency conditions with warmup and repeated measurements. If you want the user-visible time from CPU submission through result use, design a separate end-to-end measurement with a CPU timer and explicit completion. Frequent device-wide synchronization stalls the pipeline, so record the purpose and scope of the measurement.
| Measurement goal | Suitable method | What it includes and caveats |
|---|---|---|
| Work interval queued to one stream | Two default timing events and cudaEventElapsedTime | Time between GPU markers; competing work in other streams can increase it |
| Time for a CPU function to return | Wrap the API call with a CPU timer | With asynchronous calls, this may show mostly submission time |
| Application wait until the result is usable | CPU timer plus explicit event/stream completion wait | Includes CPU and GPU waiting; frequent synchronization changes the pipeline |
| Check event completion frequently | cudaEventQuery | Nonblocking status check; do not mistake the initial success of an unrecorded event for completion |
How should you choose event settings and troubleshoot problems?
An event used only to order work between streams does not need timing data. Create it with cudaEventCreateWithFlags(event, cudaEventDisableTiming); NVIDIA says this provides better performance for query and stream-wait use. However, cudaEventElapsedTime cannot use such an event. Start/stop events used for timing must have timing enabled, such as with the default flags. cudaEventBlockingSync changes how the CPU waits in cudaEventSynchronize: with this flag the CPU thread blocks until device completion; without it the API may busy-wait while waiting. This choice does not change GPU data dependencies or the measured interval.
| Event setting | Suitable use | Limitation or check |
|---|---|---|
| Default event (timing enabled) | Start/stop markers and elapsed-time calculation | Interpret marker intervals carefully when work overlaps |
| cudaEventDisableTiming | Stream dependencies and completion query/wait | Cannot be used for elapsed-time calculation |
| cudaEventBlockingSync | Choose blocking rather than busy-waiting when the CPU waits | Changes host wait behavior only; it does not establish GPU ordering |
| cudaEventInterprocess with cudaEventDisableTiming | Separate designs that share events across processes | Requires shared handles/APIs and system configuration; outside the ordinary stream example |
When an event behaves unexpectedly, narrow the cause in this order:
**Check the stream that records the marker.** Confirm `cudaEventRecord` receives the intended producer stream and that the record was submitted.
**Rule out an unrecorded event.** Do not treat the initial success of a query as completion of new work; check status after recording.
**Check the record generation.** After rerecording, verify which record each wait refers to; use separate events for concurrent slots.
**Check timing mode.** Confirm that events passed to elapsed-time calculation were not created with timing disabled.
**Check the interval and concurrent work.** Look for other streams executing between timestamps, and compare GPU interval time with CPU end-to-end time separately.
To use CUDA events correctly, separate three questions: which stream work does the event mark as complete, where should other GPU work wait, and which timestamps define the interval you want to measure? Matching those questions to the event's record generation helps you design dependencies and measurements without relying on broad CPU synchronization or a misleading single timing value.
Sources
[NVIDIA CUDA Programming Guide — Asynchronous Execution](https://docs.nvidia.com/cuda/cuda-programming-guide/02-basics/asynchronous-execution.html)
[NVIDIA CUDA Runtime API 13.5 — Event Management](https://docs.nvidia.com/cuda/cuda-runtime-api/cuda_runtime_api/group__CUDART__EVENT.html)
[NVIDIA CUDA Runtime API 13.5 — Stream Management](https://docs.nvidia.com/cuda/cuda-runtime-api/cuda_runtime_api/group__CUDART__STREAM.html)
[NVIDIA CUDA C++ Best Practices Guide — Performance Metrics and Timing](https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/)