Problem
ComputeC = A × B where:
Ais(M, K), row-majorBis(K, N), row-majorCis(M, N), row-major
Approach: tiled outer product
Each threadgroup computes one tile ofC. Threads within the threadgroup cooperate by loading shared tiles of A and B into threadgroup memory, then computing the partial dot products.
Naive kernel (no shared memory)
A simpler starting point — each thread computes one output element:Tiled kernel with layout algebra
For larger matrices, tile with layout algebra to enable shared memory reuse:Performance tips
- Tile size: 16×16 or 32×32 threadgroup tiles hit L1/L2 cache reuse sweet spots.
- vec_width=4: Vectorize loads with
float4to improve memory bandwidth. - Simdgroup matrix: On M3+ hardware, use
simdgroup_multiply_accumulatefor 8×8 hardware-accelerated matrix multiply.
See also
- Layout Algebra — tiling concepts
- Memory Model — threadgroup shared memory
- SIMD Group Operations
- API Reference: Layout Functions
