事件event
cudaEvent_t start,stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start,0);
{
//统计的代码段
…………
}
cudaEventRecord(stop,0);
float costtime;
cudaEventElapsedTime(&costtime,start,stop);

cudaError_t cudaEventCreate( cudaEvent_t* event )---创建事件对象;
cudaError_t cudaEventRecord( cudaEvent_t event,CUstream stream )--- 记录事件;
cudaError_t cudaEventElapsedTime( float* time,cudaEvent_t start,cudaEvent_t end )---计算两次事件之间相差的时间;
cudaError_t cudaEventDestroy( cudaEvent_t event )---销毁事件对象。
计算两次事件之间相差的时间(以毫秒为单位,精度为0.5微秒)。如果尚未记录其中任何一个事件,此函数将返回cudaErrorInvalidValue。如果记录其中任何一个事件使用了非零流,则结果不确定。

该例子是CUDA_C_Best_Practices_Guide中的例子:
cudaEvent_t start, stop;
float time;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord( start, 0 );
kernel<<>> ( d_odata, d_idata, size_x, size_y, NUM_REPS);
cudaEventRecord( stop, 0 );
cudaEventSynchronize( stop );
cudaEventElapsedTime( &time, start, stop );
cudaEventDestroy( start );
cudaEventDestroy( stop );

需要注意的是函数cudaEventSynchronize() 不可或缺,因为CUDA的kernel函数是以异步方式执行的,调用后立刻返回,这会导致计时不准确。cudaEventSynchronize(stop)会使得直到GPU执行完cudaEventRecord(stop, 0)之前的所有语句时,事件stop才会被记录下来,即起到同步的作用。

最新文章

  1. 【noip】noip201503求和(市赛后公布)
  2. C#设计模式之桥接
  3. PostgreSQL 在centos 7下的安装配置
  4. Excel导入数据库脚本
  5. ABAP ole方式对EXCEL进行操作
  6. OXM
  7. python 补充-decode和encode
  8. PHP使用缓存生成静态页面
  9. 标准库bind函数中使用占位符placeholders
  10. [SCOI 2009]windy数
  11. Ubuntu下编译SqlCipher以及解密微信数据库EnMicroMsg.db过程和坑
  12. vs问题--------------标记为系统必备组建...
  13. hive使用动态分区时如果动态分区的字段存在空值的问题
  14. #10 Python字符串
  15. ubuntu下tensorflow 报错 libcusolver.so.8.0: cannot open shared object file: No such file or directory
  16. linux下部署git服务器
  17. TZOJ 2546 Electricity(去掉割点后形成的最大连通图数)
  18. POJ3186(KB12-O DP)
  19. Gold Point Game~~
  20. Lintcode: Lowest Common Ancestor

热门文章

  1. mongodb you can&#39;t add a second
  2. Educational Codeforces Round 48 (Rated for Div. 2) D 1016D Vasya And The Matrix (构造)
  3. jenkins 12
  4. xcode8.3 shell 自动打包脚本
  5. ch8 -- directMethod
  6. 省选九省联考T2 IIIDX(线段树)
  7. chapter06
  8. python 用turtle 画小猪佩奇
  9. QT源码解析笔记
  10. CQRS之旅——旅程2(分解领域)