Triton's layout heuristic is wrong by up to 19x, but fixing it barely changes performance

ML compiler eng, your job is NP-hard

Amazon's Tensor Seeks Layout paper proves layout selection is NP-hard, even for simple matmul-heavy graphs. But when I tested Triton's crude 0-or-32x rule against a proper cost model, the heuristic overestimated by 4x for fp32 and 19x for fp16—yet swapping in accurate costs changed almost nothing. Rematerialization and arbitrary-but-fine defaults mean the real bottleneck is the closed-source ptxas compiler, where instruction ordering alone can make a matmul 15–26x faster.

The finding that layout search is computationally hard in Amazon's paper is valid, and good to share with your executives. But, in reality, you don't have to check all that many options: there are generally just a few places to put a conversion in a specific kernel.
  1. saagarjha

    > in this case it moved one local_load 6 ops earlier, which caused ptxas to drop from 255 registers to 40. I don’t know why!

    This is usually because ptxas runs a very simple pass to try to calculate register usage and it has a number of heuristics that it tries to apply to decide whether to keep things in the same registers or to grab new ones. Usually I find that for very high performance code they are not useful and produce very surprising behavior that makes it hard to predict performance :(

  2. mathisfun123

    This isn't special - almost every compiler pass is a heuristic approximation of an NP-hard problem (hello register allocation, instruction scheduling).

More from this day

2026-11-28