/ concept-collection / math-webgpu-sandbox
concept-collection / math-webgpu-sandbox
math-webgpu-sandbox / examples / matmul.m
16 lines · 488 BBlameHistoryRaw
1% Tiled f32 matrix multiply (the GPU has no f64): 30 products of
2% 2048 x 2048, about half a teraflop of work.
3% For an apples-to-apples MATLAB run, also try single precision there:
4% A = rand(n, n, 'single'); B = rand(n, n, 'single');
5n = 2048;
6reps = 30;
7A = rand(n, n);
8B = rand(n, n);
9C = A * B; % warm-up
10tic;
11for k = 1:reps
12 C = A * B;
13end
14t = toc;
15fprintf('%.1f GFLOP/s over %d multiplies of %dx%d\n', 2*n^3*reps/1e9/t, reps, n, n);
16fprintf('checksum %.2f\n', sum(C(:))/n^2);