Tiled matmul in NumPy, counting bytes
CPU · your Macscript60 minrequiredGoal · A Python simulation of block-tiled matmul that counts "global memory" loads for several tile sizes and shows arithmetic intensity rising with T.
- 1Write naive_matmul(A, B) with explicit triple loops over small matrices (N=64) and count every element read from A and B.
- 2Write tiled_matmul(A, B, T) that loads TxT tiles into local arrays, counts one load per tile element, and multiplies from the tiles.
- 3Verify both against numpy A @ B.
- 4Tabulate loads and FLOPs for T in 1, 4, 8, 16, 32 and compute FLOPs per byte assuming float32.
- 5Plot intensity versus T and mark the T4 ridge point from your roofline lesson; state the smallest T that would be compute-bound.
- Deliverable
- tiled_sim.py and the intensity table.
- Check
- Results match numpy within 1e-4; loads for tile size T are exactly (2 N^3 / T) elements, so intensity scales linearly with T.