GSYNC

From Jacket Wiki

Jump to: navigation, search
Back to Jacket Function List, Jacket Basics

Block or wait until all queued GPU computation is complete

Supported Syntax

gsync % Synchronize all operations on current gpu
gsync (n) % Synchronize all operations on nth gpu
gsync ('all') % Synchronize all operations on all gpus

GFOR Compatibility?

No, do not use inside a GFOR loop.

Example

gsync % ensure GPU is ready to begin
tic
for i = 1:n
  a = a .* a; % some computation
end
geval(a) % ensure computation is evaluated
gsync % wait until GPU finishes executing
toc

The following example shows that operations may be queued up and not yet executed.

reps = 100;
n = 1000;
A = grandn(n,'single');
geval(A * A);
 
gsync, tic
  for r = 1:reps
    geval(A * A)
  end
gsync  % wait until queue is emptied
with_sync = toc  % with_sync = 8.1318
 
tic
  for r = 1:reps
    geval(A * A)
  end
% don't wait ... immediately stop timer
without_sync = toc   % without_sync = 0.0094

TIMEIT was introduced recently to hide much of these details and considerations. The code above is trivially replaced with:

n = 1000;
A = grandn(n,'single');
with_sync = timeit(@() A * A)

Multi GPU synchronization

tic;
for ii = 1:ngpu
  gselect(ii);
  a = grand(100);
  b = cos(a .* a) + sin(a .* a);
  res{ii} = all(b == 1);
end
gsync('all');
t = toc;

Notes

GSYNC is used for debugging and benchmarking only. Please remove any instances of this in real code.

See Also

GEVAL, TIC, TOC, TIMEIT

Views
Personal tools