Roofline
A roofline is the two-ceiling model (peak bandwidth and peak compute) that turns a kernel's measured time into a verdict: how far from the physical limit, and which limit. On a platform whose profiler cannot run inside a scripted benchmark loop, it's the primary analysis tool, and you build it yourself; the profiler's GPU read and write bandwidth and memory limiter counters (a percentage of peak) are the cross-check on the bandwidth roof you measure.
CUDA equivalent: the roofline chart Nsight Compute draws for you automatically. Here you assemble it from two measurements:
The bandwidth ceiling: measure, don't trust the spec. A STREAM-style probe
(large buffer copies/reads swept past cache sizes) gives achievable DRAM
bandwidth. The worked example in the case-study codebase,
m5-gemm's bandwidth.metal/bandwidth.py (opens in a new tab),
measured ~516 GB/s copy on an M5 Max: ~84% of the 614 GB/s spec, a typical
achievable fraction for unified memory. Use the measured number as your roof;
using the spec quietly inflates every "% of peak" you report.
The compute ceiling: from the reverse-engineered tables. metal-benchmarks (opens in a new tab)' instruction throughput tables give per-op ceilings per core; scale by core count and clock. For matmul, a shortcut: the best measured GEMM on your chip class is a practical ceiling (13.5 TFLOPS fp32 on a 40-core M5 Max, from the case study).
Then every benchmark result gets the same two-line interrogation: achieved GFLOPS ÷ compute ceiling, achieved GB/s ÷ bandwidth ceiling. Whichever ratio is higher names your binding constraint. If both are low, the kernel is overhead-bound (dispatch, sync) or stalled (spills, occupancy); go look at what the compiler emitted.
Platform-specific hygiene, learned the hard way in the war stories:
- Thermals are part of the model. Fanless and laptop chips decay under sustained load. One project measured long-run throughput decay dropping from 50% to 6.7% just by locking fans to max. Instruments' Thermal State instrument records the device's thermal state next to the GPU timeline, which tells you whether a slow stretch was throttled. Report sustained numbers, not first-second numbers.
- The ceilings move with problem size in ways spec sheets hide: the GEMM ladder's winner flips at three different sizes because launch latency, unroll quality, and bandwidth trade dominance. A roofline claim without a size sweep is a guess.
- End-to-end or it didn't happen: a kernel at 90% of roofline that's 3% of runtime buys nothing. Amdahl kills more optimizations here than physics does.