Skip to content

CUDA:Event

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

About

Jihunlee25.tistory.com_-_cuda_event.png

Stream 내부 명령에 흐름 중, 특정 지점에 표시를 남기는 것 (일종의 표시 → marker)

GPU는 CPU 와 별개로(병렬적) 작동하기 때문에 CPU 에서 time을 확인하는 건 동기화가 안된다. 따라서 GPU 를 위한 별개의 흐름 (CUDA:Stream) 에서 작동하는 Event 동기화 로직이 필요하게 된다.

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.
  • stream에 event 발생 위치를 표시함
  • stream에서 꺼내질 때 정보가 event에 기록됨
__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.
  • 해당 event 발생까지 대기
__host__ ​cudaError_t cudaEventQuery ( cudaEvent_t event )
Queries an event's status.
  • 해당 event 발생 여부 확인

Measure the elasped time

__host__ ​cudaError_t cudaEventElapsedTime ( float* ms, cudaEvent_t start, cudaEvent_t end )
Computes the elapsed time between events.
  • start와 end 사이에 소요된 시간을 milliseconds 단위로 계산

Example

Event를 사용한 시간 측정 사용 예시:

//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