Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to measure the execution time of every block when using CUDA?

clock() is not accurate enough.

like image 837
cnhk Avatar asked Dec 05 '22 01:12

cnhk


1 Answers

Use CUDA events for measure time of kernels or CUDA operations (memcpy etc):

// Prepare
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
// Start record
cudaEventRecord(start, 0);
// Do something on GPU
MyKernel<<<dimGrid, dimBlock>>>(input_data, output_data);
// Stop event
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
float elapsedTime;
cudaEventElapsedTime(&elapsedTime, start, stop); // that's our time!
// Clean up:
cudaEventDestroy(start);
cudaEventDestroy(stop);

See CUDA Programming Guide, section 3.2.7.6

like image 128
KoppeKTop Avatar answered May 25 '23 12:05

KoppeKTop