How to measure GPU vs CPU performance? Which time measurement functions?

有些话、适合烂在心里 提交于 2019-12-08 19:36:29

问题


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?

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


回答1:


I'm using the following

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;

EDIT

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



来源:https://stackoverflow.com/questions/16258141/how-to-measure-gpu-vs-cpu-performance-which-time-measurement-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!