[英]How to measure GPU vs CPU performance? Which time measurement functions?
需要使用哪些库或函数来客观地比较CPU和GPU性能? 为了准确评估,应该警告什么警告 ?
我使用具有计算能力2.1
的设备的Ubuntu平台并使用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;
}
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;
编辑
有关更完整的答案,请参阅Timing CUDA操作 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.