/ concept-collection / math-webgpu-sandbox
concept-collection / math-webgpu-sandbox
math-webgpu-sandbox / examples / reductions.m
16 lines · 447 BBlameHistoryRaw
1% Reductions with fused loaders, 300 times over 10 million elements:
2% dot, norm and max each read their operands exactly once per pass --
3% sum(a.*b) is one sweep of memory, not two.
4n = 10000000;
5reps = 300;
6a = rand(n, 1);
7b = rand(n, 1);
8tic;
9for k = 1:reps
10 d = dot(a, b);
11 nrm = norm(a - b);
12 mx = max(abs(a - b));
13end
14t = toc;
15fprintf('dot %.0f norm %.2f max %.6f\n', d, nrm, mx);
16fprintf('%.1f GB/s effective\n', reps*6*n*4/1e9/t);