Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 893
erogol Avatar asked Apr 27 '13 23:04

erogol


People also ask

How is GPU performance measured?

To monitor the overall GPU resource usage, click the Performance tab, scroll down the left pane, and find the “GPU” option. Here you can watch real-time usage. It displays different graphs for what is happening with your system — like encoding videos or gameplay.

How can measure the computational time of an application developed in Cuda?

You can use this: timer = 0; cutCreateTimer(&timer);


1 Answers

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.

like image 126
Vitality Avatar answered Jun 01 '23 14:06

Vitality