A better way to time Jacket code

by vishy on March 30, 2011

in Benchmarks

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');
% CPU timing
for r = 1:reps
   x = rand(n,'single');
cpu_time = toc;
% GPU timing
gsync, tic
for r = 1:reps
   x = grand(n,'single');
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.

{ 1 comment }

Matt November 13, 2011 at 9:25 am

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?

Comments on this entry are closed.

Previous post:

Next post: