如何衡量GPU与CPU的性能?哪些时间测量功能? [英] How to measure GPU vs CPU performance? Which time measurement functions?

查看:277
本文介绍了如何衡量GPU与CPU的性能?哪些时间测量功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What libraries or functions need to be used for an objective comparison of CPU and GPU performance? What caveat should be warned for the sake of an accurate evaluation?

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

I using an Ubuntu platform with a device having compute capability 2.1 and working with the CUDA 5 toolkit.

推荐答案

我正在使用以下

CPU -返回tic和toc之间的微秒,分辨率为2毫秒

CPU - return microseconds between tic and toc with 2 microseconds of resolution

#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操作计时

For a more complete answer, please see Timing CUDA operations.

这篇关于如何衡量GPU与CPU的性能?哪些时间测量功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆