cudaEventElapsedTime计时:
#include <cuda_runtime.h>
#include <helper_cuda.h>
#include <helper_functions.h> // helper utility functions
float gpu_time = 0.0f;
cudaEvent_t start, stop;
checkCudaErrors(cudaEventCreate(&start));
checkCudaErrors(cudaEventCreate(&stop));
cudaEventRecord(start, 0);
//do something....
cudaEventRecord(stop, 0);
checkCudaErrors(cudaEventElapsedTime(&gpu_time, start, stop));
//gpu_time就是计时用时
//销毁事件
checkCudaErrors(cudaEventDestroy(start));
checkCudaErrors(cudaEventDestroy(stop));
sdkGetTimerValue计时:
#include <cuda_runtime.h>
#include <helper_cuda.h>
#include <helper_functions.h>
StopWatchInterface *timer = NULL;
sdkCreateTimer(&timer);
sdkResetTimer(&timer);
sdkStartTimer(&timer);
//do ...
sdkStopTimer(&timer);
printf("time spent by CPU in CUDA calls: %.2f\n", sdkGetTimerValue(&timer));