使用CUDA时如何测量每个块的执行时间? [英] How to measure the execution time of every block when using CUDA?
本文介绍了使用CUDA时如何测量每个块的执行时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
clock() 不够准确.
clock() is not accurate enough.
推荐答案
使用 CUDA 事件测量内核或 CUDA 操作(memcpy 等)的时间:
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);
参见 CUDA 编程指南,第 3.2.7.6 节
See CUDA Programming Guide, section 3.2.7.6
这篇关于使用CUDA时如何测量每个块的执行时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文