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));
上一篇: vue中常见的问题及解决方法总结(推荐)