Skip to content
Search

CUDA:Event

lastmod 2024-07-22created 2024-07-206 edits

This section describes the event management functions of the CUDA runtime application programming interface.

About

Jihunlee25.tistory.com_-_cuda_event.png

Leaves a mark at a specific point in the flow of commands inside a stream (a kind of mark → marker)

Because the GPU runs separately from (in parallel with) the CPU, checking the time on the CPU is not synchronized. Therefore, Event synchronization logic that runs in a separate flow for the GPU (CUDA:Stream) is needed.

Functions

Creation and Destruction

__host__ ​cudaError_t cudaEventCreate ( cudaEvent_t* event )
Creates an event object.
__host__ ​ __device__ ​cudaError_t cudaEventCreateWithFlags ( cudaEvent_t* event, unsigned int flags )
Creates an event object with the specified flags.
__host__ ​ __device__ ​cudaError_t cudaEventDestroy ( cudaEvent_t event )
Destroys an event object.

Recording Events

__host__ ​ __device__ ​cudaError_t cudaEventRecord ( cudaEvent_t event, cudaStream_t stream = 0 )
Records an event.
  • Marks the event position in the stream
  • Information is recorded in the event when it is taken out of the stream
__host__ ​cudaError_t cudaEventRecordWithFlags ( cudaEvent_t event, cudaStream_t stream = 0, unsigned int flags = 0 )
Records an event with the specified flags.

Synchronization / Querying

__host__ ​cudaError_t cudaEventSynchronize ( cudaEvent_t event )
Waits for an event to complete.
  • Waits until the event occurs
__host__ ​cudaError_t cudaEventQuery ( cudaEvent_t event )
Queries an event's status.
  • Checks whether the event has occurred

Measure the elasped time

__host__ ​cudaError_t cudaEventElapsedTime ( float* ms, cudaEvent_t start, cudaEvent_t end )
Computes the elapsed time between events.
  • Computes the time elapsed between start and end in milliseconds

Example

Example of measuring time with Events:

//create two events
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);

cudaEventRecord(start); //record start event on the default stream

kernel <<< grid, block >>> (arguments); //execute kernel

cudaEventRecord(stop); //record stop event on the default stream
cudaEventSynchronize(stop); //wait until the stop event completes

//calculate the elapsed time between two events
float time;
cudaEventElapsedTime(&time, start, stop);

//clean up the two events
cudaEventDestroy(start);
cudaEventDestroy(stop);

See also

Favorite site

author Zer0 sitemap