如何在使用CUDA时测量每个块的执行时间? [英] How to measure the execution time of every block when using CUDA?

查看:97
本文介绍了如何在使用CUDA时测量每个块的执行时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

clock()不够准确。

clock() is not accurate enough.

推荐答案

使用CUDA事件来测量内核或CUDA操作):

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 Programming Guide,第3.2.7.6节

See CUDA Programming Guide, section 3.2.7.6

这篇关于如何在使用CUDA时测量每个块的执行时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆