In this article
Grouping is a bijection over logical output tiles; replacing the actual final-group height with the preferred group size can duplicate or miss coordinates.
Separate launch identity from tile coordinates
The program_id interface identifies a program instance in the launch grid. A matrix kernel can transform that identifier into output tile coordinates in different orders. This transformation changes locality without changing the mathematical product only if it still covers every intended output tile exactly as required. A cache-oriented schedule is therefore also an indexing contract, not merely a performance annotation attached to otherwise unchanged coordinates.
Read the grouped mapping
The matrix multiplication tutorial groups tile rows and traverses columns within each group to encourage operand reuse. It computes the first row of the group and the actual number of rows remaining there. That latter quantity can be smaller than the configured preferred group height. Use it in the within-group coordinate mapping rather than assuming that the last group has the same shape as earlier groups.
Inspect the reusable implementation
The standard library source contains swizzle2d, including adjustment for a final group with fewer rows. This supports a concrete review method: compare a proposed custom mapping with the intended permutation on a small tile grid. Keep launch count, tile-grid dimensions, and group height in the same coordinate system. Matrix element dimensions and tile counts are related, but substituting one for another in the permutation changes the schedule’s domain.
Test the case divisible examples miss
Imagine all initial benchmarks use a tile-row count divisible by the group height. A simplified mapping can pass those tests and fail when another matrix leaves a partial final group. Enumerate program IDs, collect output coordinates, and check both coverage and duplicates before running arithmetic. This detects schedule mistakes independently from floating-point tolerance. Then compare complete matrix results, including edge stores, because correct tile permutation does not itself validate every boundary mask or reduction load.
Measure locality after correctness
Record tile dimensions, launch grid, grouping parameter, final-group calculation, and tested shapes. Guides to tensor axes and GPU acceptance evidence provide context. Include partial groups when validating an optimized kernel. Improved cache reuse is hardware- and workload-dependent; the invariant is the intended output coverage. A published tutorial speedup should not replace a measurement of the actual kernel after its program-ID permutation has been verified.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.