如何衡量GPU与CPU的性能?使用哪些时间测量函数?

7

什么库或函数需要使用来客观比较CPU和GPU的性能?为了准确评估,应该提醒哪些注意事项?

我正在使用一个具有计算能力 2.1 的设备和 CUDA 5 工具包的 Ubuntu 平台。


获取当前时间?对我来说没问题。 - Alex
如果您想计时CUDA活动,您可能会对这个感兴趣。您应该能够找到大量关于计时仅CPU代码的参考资料。 - Robert Crovella
@windfinder它适用于CPU测量,但GPU测量呢? - erogol
针对GPU测量,您可以尝试使用nvprof链接 - Yu Zhou
1个回答

6

我正在使用以下内容

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操作


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接