0Pricing
CUDA Academy · Lesson

Events for Timing and Sync

cudaEvent to measure and order work.

Events for Timing and Sync is a free CUDA Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CUDA Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Is an Event?

A CUDA event is a marker you drop into a stream. The GPU records when it reaches that point, letting you time and order work. ⏱️

The Event Handle

Events use a cudaEvent_t handle, just like streams. You create it, record it, query it, and destroy it when finished.

cudaEvent_t start, stop;

Creating Events

Call cudaEventCreate for each event you need. Timing usually wants two: one before the work and one after.

cudaEventCreate(&start);
cudaEventCreate(&stop);

Recording an Event

cudaEventRecord places the event into a stream. The GPU stamps it the moment it finishes everything queued before it.

cudaEventRecord(start, stream);

Timing a Kernel

Record start, launch your kernel, then record stop, all in the same stream. The gap between them is the real GPU execution time.

cudaEventRecord(start, s);
kernel<<<g, b, 0, s>>>(d);
cudaEventRecord(stop, s);

Waiting for an Event

Events are async, so the host must wait. cudaEventSynchronize blocks until the given event has actually been recorded on the GPU.

cudaEventSynchronize(stop);

Measuring Elapsed Time

cudaEventElapsedTime returns the milliseconds between two recorded events. This is far more accurate than a host-side CPU clock.

float ms;
cudaEventElapsedTime(&ms, start, stop);

Why Not the CPU Clock?

Host timers include launch overhead and miss true GPU timing. Events sit inside the stream, so they capture exactly what the device did.

Cross-Stream Ordering

Events also synchronize streams. cudaStreamWaitEvent makes one stream pause until an event recorded in another has happened.

cudaStreamWaitEvent(streamB, eventA, 0);

Building Dependencies

With stream-wait-event you express a dependency: streamB starts its work only after streamA reaches its event, without blocking the host.

Cleaning Up Events

Free events you no longer need with cudaEventDestroy. Like streams, they are cheap but should not be leaked in long-running apps.

cudaEventDestroy(start);
cudaEventDestroy(stop);

Quick Check

Which function gives you the time between two events?

Recap

Events let you time GPU work precisely and order one stream after another. They are your tool for measuring and coordinating overlap. 🎯

Frequently asked questions

Is the “Events for Timing and Sync” lesson free?

Yes — the full text of “Events for Timing and Sync” is free to read here on the web, and the CUDA Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CUDA Academy course, upgrade to CoddyKit PRO.

What will I learn in “Events for Timing and Sync”?

cudaEvent to measure and order work. You practise CUDA Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start CUDA Academy?

No prior experience is required. CUDA Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Events for Timing and Sync” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this CUDA Academy lesson?

Yes. Every CUDA Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. The Default Stream Trap
  2. Creating and Using Streams
  3. Events for Timing and Sync
  4. Overlapping Copy and Compute
← Back to CUDA Academy