1. clock()
//计算GPU时钟主频
int get_GPU_Rate()
{
cudaDeviceProp deviceProp;//CUDA定义的存储GPU属性的结构体
cudaGetDeviceProperties(&deviceProp,0);//CUDA定义函数
return deviceProp.clockRate;
}
clock_t start,end,timeused;
start=clock();
{
//要计时部分
}
end=clock();
int rate=get_GPU_rate();
timeused=(end-start)/rate;
2. event
cudaEvent_t start,stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecend(start,0);
{
//统计的代码段
}
cudaEventRecord(stop,0);
cudaEventSynchronize(stop);
float timeused;
cudaEventElapsedTime(&timeused,start,stop);
cudaEventDestroy( start );
cudaEventDestroy( stop );