记录运行时间
记录一个在device上运行的函数的运行时间时需要用到 事件 (event): cudaEvent_t timeStartEvent, timeEndEvent; //声明两个cudaEvent_t变量 cudaEventCreate( &timeStartEvent, 0 ); //第二个参数忘了干吗用的了************** cudaEventCreate( &timeEndEvent ); //第二个参数可以不用 cudaEventRecord( cudaStartEvent, 0 ); //第二个参数具体查看这个网址http://developer.download.nvidia.com/compute/cuda/4_2/rel/toolkit/docs/online/group__CUDART__EVENT_ga324d5ce3fbf46899b15e5e42ff9cfa5.html kernel<<<block, grid>>>(...); //要在device上运行的函数 float elapsedTime; cudaEventRecord( cudaEndEvent, 0 );
cudaEventSynchronize( cudaEndEvent );
cudaEventElapsedTime( &elapseTime, timeStartEvent, timeEndEvent ); //这个函数具体看上面那个网站
printf("%f\n", elapsedtime); cudaEventDestroy( timeStartEvent ); cudaEventDestroy( timeEndEvent );