ero*_*gol 6 time cuda measurement gpu-programming
需要使用哪些库或函数来客观地比较CPU和GPU性能?为了准确评估,应该警告什么警告?
我使用Ubuntu平台和具有计算能力的设备2.1
并使用CUDA 5工具包.
我正在使用以下内容
CPU - 在tic和toc之间返回微秒,分辨率为2微秒
#include <sys/time.h>
#include <time.h>
struct timespec init;
struct timespec after;
void tic() { clock_gettime(CLOCK_MONOTONIC,&init); }
double toc() {
clock_gettime(CLOCK_MONOTONIC,&after);
double us = (after.tv_sec-init.tv_sec)*1000000.0f;
return us+(after.tv_nsec- init.tv_nsec)/1000.0f;
}
Run Code Online (Sandbox Code Playgroud)
GPU
float time;
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start, 0);
// Instructions
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
cudaEventElapsedTime(&time, start, stop);
cout << setprecision (10) << "GPU Time [ms] " << time << endl;
Run Code Online (Sandbox Code Playgroud)
编辑
有关更完整的答案,请参阅Timing CUDA操作.
归档时间: |
|
查看次数: |
2924 次 |
最近记录: |