
350 Accelerating MATLAB
®
Performance
gatherTimes = inf(size(sizes));
gpu = gpuDevice; % get the current GPU device
for ii = 1 : numel(sizes)
data = randi([0 255], sizes(ii), 1, 'uint8');
for rr = 1 : repeats
timer = tic();
gdata = gpuArray(data);
wait(gpu); % wait until memory operations are finished
sendTimes(ii) = min(sendTimes(ii), toc(timer));
timer = tic();
data2 = gather(gdata);
gatherTimes(ii) = min(gatherTimes(ii), toc(timer));
end
end
sendBandwidth = (sizes./sendTimes)/2^30;
[maxSendBandwidth,maxSendIdx] = max(sendBandwidth);
fprintf('Peak send speed is%g GB/s\n', maxSendBandwidth)
gatherBandwidth = (sizes./gatherTimes)/2^30; ...