A better way to time Jacket code

ArrayFire Benchmarks 1 Comment

Whether you are a new Jacket programmer or a GPU maestro, you are bound to speed-test Jacket at some point. There are many factors to keep in mind while benchmarking Jacket code – a simple tic-func()-toc won’t do. For example, this is some typical benchmarking code:

% warm up
x = rand(n,'single');
x = grand(n, 'single');
geval(x);
% CPU timing
tic
for r = 1:reps
   x = rand(n,'single');
end
cpu_time = toc;
% GPU timing
gsync, tic
for r = 1:reps
   x = grand(n,'single');
   geval(x);
end
gsync, gpu_time = toc

With Jacket 1.7, this entire code chunk is now replaced by two lines:

cpu_time = timeit(@()  rand(n,'single'));
gpu_time = timeit(@() grand(n,'single'));

With TIMEIT, you get a fast and easy way to bench functions. This function takes as its input a function handle, that could be a Jacket function you want to benchmark:

timeit(@() grand(512))

Or it could be a function of your own:

A = grand(30);                     
B = grand(30);
timeit(@() (A.*B).^2)

TIMEIT takes care of all the factors involved in benchmarking GPU code. No longer do you have to worry about warmup: TIMEIT does that before executing GPU functions. Also, it times each function for a sufficient number of iterations by default, so you needn’t call timeit() in a loop.

The addition of this feature is bound to make timing Jacket functions much simpler.  With this feature, Jacket programmers can concentrate on optimizing code, rather than writing helper timing functions.

Comments 1

  1. Great, but where do I learn more about what’s going on with this? What exactly is the role of GSYNC and GEVAL? What if I run the test using GSYNC but not GEVAL or vice versa?

Leave a Reply

Your email address will not be published.