/ concept-collection / math-webgpu-sandbox
Sign in
concept-collection / math-webgpu-sandbox
math-webgpu-sandbox / examples / matmul.m
16 lines · 488 BCodeBlameHistory
02f2376Scale examples to 1-4 s of GPU work so tic/toc comparisons are meaningfulJeremy Magland 1% Tiled f32 matrix multiply (the GPU has no f64): 30 products of
2% 2048 x 2048, about half a teraflop of work.
e01ddf1MATLAB-syntax scripts on WebGPU: fused kernels, tic/toc timing, CPU comparisonJeremy Magland 3% For an apples-to-apples MATLAB run, also try single precision there:
4% A = rand(n, n, 'single'); B = rand(n, n, 'single');
6reps = 30;
8B = rand(n, n);
9C = A * B; % warm-up
10tic;
13end
14t = toc;
02f2376Scale examples to 1-4 s of GPU work so tic/toc comparisons are meaningfulJeremy Magland 15fprintf('%.1f GFLOP/s over %d multiplies of %dx%d\n', 2*n^3*reps/1e9/t, reps, n, n);
e01ddf1MATLAB-syntax scripts on WebGPU: fused kernels, tic/toc timing, CPU comparisonJeremy Magland 16fprintf('checksum %.2f\n', sum(C(:))/n^2);
moveopenescclose