include <cuda_runtime.h>
//CREATE
cudaEvent_t start,stop;
checkCudaErrors(cudaEventCreate(&start));
checkCudaErrors(cudaEventCreate(&stop));
StopWatchInterface *timer=NULL;
sdkCreateTimer(&timer);
sdkResetTimer(&timer);
//TIMING
sdkStartTimer(&timer);
cudaEventRecord(start,0); //cudaEventRecord(cuda_Event_t, cudaStream_t)
//working
cudaEventRecord(stop,0);
sdkStopTimer(&timer);
//GET TIME
printf("time spent executing by the GPU: %.2f\n", gpu_time);
printf("time spent by CPU in CUDA calls: %.2f\n", sdkGetTimerValue(&timer));
//DELETE
checkCudaErrors(cudaEventDestroy(start));
checkCudaErrors(cudaEventDestroy(stop));
两种计时器
cudaEvent_t类型来定义时间记录节点
//cudaEventCreate(&event)
//cudaEventRecord(event,stream)
//cudaEventElapsedTime(&time,event,event)
//cudaEventDestroy(event)
专门的时间记录 StopWatchInterface *timer=NULL
//sdkCreateTimer(&timer)
//sdkResetTimer(&timer)
//sdkStartTimer(&timer)
//sdkStopTimer(&timer)
//sdkDeleteTimer(&timer)
//sdkGetTimerValue(&timer)