cudaEvent and gettimeofday report drastically different time

271 Views Asked by At

I'm trying to time a loop by using either gettimeofday or cudaEventRecord. However, they report very different results. Here's the pseudo code:

// get time here (start) 
    while (..)
    {
.        ..
    }
// get time here (stop)
// calculate time 
// time = (stop.tv_usec-start.tv_usec)*1.0e-3 + (stop.tv_sec - start.tv_sec); or
// cudaEventElapsedTime(&time,start,stop);

I do not use both of them at the same time but use each separately and the results are not the same. I also called cudaEventSynchrosize(stop) when using cudaEvent. Thanks.

1

There are 1 best solutions below

0
On

I see problem in measuring units. I am not much of cuda programmer, but I can tell about gettimeofday function. gettimeofday expresses the time in seconds and microseconds, so the right pseudocode line would be:

// time = (stop.tv_usec-start.tv_usec)*1.0e-6 + (stop.tv_sec - start.tv_sec);

There are cuda specific solution given here: Timing CUDA operations. I hope this helped.