什么库或函数需要使用来客观比较CPU和GPU的性能?为了准确评估,应该提醒哪些注意事项?
我正在使用一个具有计算能力 2.1
的设备和 CUDA 5 工具包的 Ubuntu 平台。
什么库或函数需要使用来客观比较CPU和GPU的性能?为了准确评估,应该提醒哪些注意事项?
我正在使用一个具有计算能力 2.1
的设备和 CUDA 5 工具包的 Ubuntu 平台。
我正在使用以下内容
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;
}
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;
编辑
如需更完整的答案,请参阅计时CUDA操作。
nvprof
:链接。 - Yu Zhou