GFOR timing problem

[Old posts from the commercial version of ArrayFire] Discussion of ArrayFire using CUDA or OpenCL.

Moderator: pavanky

GFOR timing problem

Postby uahakan » Fri Nov 22, 2013 8:59 am


I have a code segment including GFOR structure and I want to accurately measure timing of execution :

Code: Select all

static array totalSignal = randu(65536,16,c32);
static array referenceSignal = randu(65536,c32);

static void execute () {
  gfor(array i, 16){
    array temp = totalSignal(span,i);
    for(int ind = 0 ... 100)
         fft(referenceSignal * af::conjg(shift(temp)));

I measure with two different timing format:

Code: Select all
timer t = timer.start()
double time = timer.stop(t) * 1000;

Code: Select all
double time = timeit(execute)  * 1000;

These two different timing formats give different results. Documentation states that timeit is more accurate but why is the difference so big ?

Thanks in advance.

Posts: 2
Joined: Tue Nov 19, 2013 4:49 am

Re: GFOR timing problem

Postby shehzan » Fri Nov 22, 2013 5:20 pm

Hi Hakan,

To answer your question, the times are different because timer start and stop runs the code once and return the difference of time between start and stop. Whereas timeit runs the code inside the function many times and returns an average of the result.
The reason times are different is because it is natural that GPU's are not at their fastest as soon as execution starts. There is a "warm up" period. Hence we take an average with timeit.

A few points you can take note of (based on the code you provided):
* Both timer and timeit return time in seconds. You do not need to multiply it by 1000 is you need time in seconds.
* I assume that you are doing a for loop inside the gfor to get an average time. Do not do this purely for the sake of getting average times. Use timeit instead or timer start-stop inside a for loop.
* Use array.eval() to ensure that the variable is evaluated within the section being timed. Since ArrayFire uses Just-In-Time compilation, it is not necessary that the code executes within the timer range. The eval() function ensures that the array variable is evaluated before the next statement after eval(). You can read more about eval at: ... __eval.htm

You can find out more about timing at ... ted_timing.

Let me know if you have further questions.
User avatar
Posts: 121
Joined: Tue Feb 12, 2013 7:20 pm

Return to [archive-commercial] Programming & Development with ArrayFire