Task 2 of 5
On the CPU, C = A × B is the classic triple loop: over rows, over
columns, over k. On the GPU the outer two loops vanish into the
launch — output: [16, 16] starts 256 threads, one per cell of
C, and only the innermost loop survives inside the kernel.
Cell C[y][x] is the dot product of row y of A with
column x of B: walk k across the row
a[y][k] and down the column b[k][x]. Same loop as task 1 —
now every thread aims it at its own row/column pair.
matA × matB — each
thread returns the dot product of its row of a with its column of
b.output: [16, 16] — one thread per cell of Ck over the 16 shared elementsa[this.thread.y][k] * b[k][this.thread.x] and return the sumthis.thread.y picks the row of a,
this.thread.x picks the column of b, and k is
the only index that moves during the loop.
let sum = 0;
for (let k = 0; k < 16; k++) {
sum += a[this.thread.y][k] * b[k][this.thread.x];
}
return sum;This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.