0Pricing
CUDA Academy · Lección

Eventos para medir y sincronizar

Use cudaEvent para medir y ordenar el trabajo.

Eventos para medir y sincronizar es una lección gratuita de CUDA Academy en CoddyKit. Esta es la lección 3 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de CUDA Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de CUDA Academy incluye 4 lecciones en total.

Partes de esta lección aún no han sido traducidas y se muestran en inglés.

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. 🎯

Preguntas frecuentes

¿La lección «Eventos para medir y sincronizar» es gratis?

Sí — el texto completo de «Eventos para medir y sincronizar» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de CUDA Academy, actualiza a CoddyKit PRO. El curso de CUDA Academy incluye 4 lecciones en total.

¿Qué aprenderé en «Eventos para medir y sincronizar»?

Use cudaEvent para medir y ordenar el trabajo. Practicas CUDA Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.

¿Necesito experiencia previa para empezar CUDA Academy?

No se requiere experiencia previa. CUDA Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 3 de 4.

¿Cuánto tiempo toma la lección «Eventos para medir y sincronizar»?

La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.

¿Puedo escribir y ejecutar código en esta lección de CUDA Academy?

Sí. Cada lección de CUDA Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.

Todas las lecciones de este curso

  1. La trampa del stream predeterminado
  2. Crear y usar streams
  3. Eventos para medir y sincronizar
  4. Solapar copias y cálculos
← Volver a CUDA Academy