码迷,mamicode.com
首页 > 其他好文 > 详细

cuda中时间用法

时间:2014-08-18 21:46:03      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   使用   os   strong   文件   

转载:http://blog.csdn.net/jdhanhua/article/details/4843653

因之前使用nvcc编译.cu 文件时,使用time_t及其一系列函数编译报不知名错误。

在CUDA中统计运算时间,大致有三种方法:

 

<1>使用cutil.h中的函数
unsigned int timer=0;
//创建计时器
cutCreateTimer(&timer);
//开始计时
cutStartTimer(timer);
{
  //统计的代码段
  …………
}
//停止计时
cutStopTimer(timer);
//获得从开始计时到停止之间的时间
cutGetTimerValue( timer);
//删除timer值
cutDeleteTimer( timer);
 

不知道在这种情况下,统计精度。

 

<2>time.h中的clock函数
clock_t start, finish;
float costtime;
start = clock(); 
{
  //统计的代码段
  …………
}
finish = clock();
//得到两次记录之间的时间差
costtime = (float)(finish - start) / CLOCKS_PER_SEC; 
时钟计时单元的长度为1毫秒,那么计时的精度也为1毫秒

 

<3>事件event
cudaEvent_t start,stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecend(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中时间用法,布布扣,bubuko.com

cuda中时间用法

标签:des   style   blog   http   使用   os   strong   文件   

原文地址:http://www.cnblogs.com/Anita-z/p/3920417.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!