Task 3 of 5
Square matrices hide a trap: every dimension is 16, so any loop bound "works".
Real matmuls are rectangular — here rectA is 8×32 (8 rows, 32 columns) and
rectB is 32×12, so the product is 8×12. Suddenly there are
three different sizes and each belongs somewhere specific.
Two of them shape the launch: output: [width, height] = [columns of B,
rows of A] = [12, 8] — already set up below. The third, 32, is the
shared dimension: A's columns must equal B's rows, and that's the only
dimension the loop is allowed to run over.
rectA × rectB — fix the
inner loop so it covers the full shared dimension of 32.output: [12, 8] — columns of B across, rows of A downk over the shared dimension: all 32 of ita[this.thread.y][k] * b[k][this.thread.x] as beforeThe loop walks across a row of A (32 long) and down a column of B (also 32 long — that's why the shapes are compatible). Neither 8 nor 12 appears in the loop at all.
The starter loop stops at 12 — it sums only the first 12 of 32 terms. Change
the bound: for (let k = 0; k < 32; k++).
sgemm(M, N, K, …) in cuBLAS and rocBLAS
keeps the three sizes as separate parameters for exactly this reason. Mixing them up is
the classic GEMM bug on every platform, not just here.
This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.