【问题标题】:How to measure GPU vs CPU performance? Which time measurement functions?如何测量 GPU 与 CPU 的性能?哪些时间测量功能?
【发布时间】:2013-04-21 21:48:47
【问题描述】:

需要使用哪些库或函数来客观比较 CPU 和 GPU 性能?为了准确评估,应该警告哪些警告

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

【问题讨论】:

  • 获取时间?为我工作。
  • 对于计时 cuda 活动,您可能对 this 感兴趣,您应该能够找到大量有关计时 CPU 代码的参考。
  • @windfinder 它适用于 cpu 测量但 GPU 测量如何?
  • GPU 测量你可以试试nvprof:link

标签: time cuda gpu measurement


【解决方案1】:

我正在使用以下

CPU - 以 2 微秒的分辨率返回 tic 和 toc 之间的微秒数

#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 operations

【讨论】:

    猜你喜欢
    • 2019-10-20
    • 2015-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-09
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    相关资源
    最近更新 更多