欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

cuda计时方式

程序员文章站 2024-01-23 18:09:10
...

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));

 

相关标签: 计时