请教大家测时问题

hanyi_2011 2011-05-04 10:08:59
我想测试整个程序的运行时间,不单单是kernel函数的时间,想问大家用什么函数?
...全文
119 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
stuqbx 2011-06-22
  • 打赏
  • 举报
回复
在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。如果记录其中任何一个事件使用了非零流,则结果不确定。



要测试整个程序的运行时间,可以用time.h中的clock函数,在程序头和程序尾clock,然后计算时间差。
希望能帮到你!
hanyi_2011 2011-06-15
  • 打赏
  • 举报
回复
想测一下整个程序运行的时间,包括主函数和KERNEL 函数。
hu123rong00 2011-05-28
  • 打赏
  • 举报
回复
可以用c中带的clock()计时,还可以用cuda中的计时函数cutCreateTimer(),后者精度略优于前者
lixingjian4 2011-05-23
  • 打赏
  • 举报
回复
很多啊,最简单的用time就行了= =
或者你搜一下计时函数,很多方案
hanyi_2011 2011-05-12
  • 打赏
  • 举报
回复
没有人知道吗?

374

社区成员

发帖
与我相关
我的任务
社区描述
CUDA on Linux
社区管理员
  • CUDA on Linux社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧