L1 Beginner · Module 3: The performance mental model
3.3The roofline model
One picture, two numbers. The roofline model tells you whether a kernel is waiting on memory or on math, and it explains why LLM decode leaves most of a GPU idle.
By the end you will be able to
- ✓Draw a roofline from a GPU's peak FLOP/s and memory bandwidth
- ✓Place a matmul on it using arithmetic intensity
- ✓Explain why decode is memory-bound and prefill is compute-bound, and what batching does about it
Every kernel does two things: it moves bytes between HBM and the chip, and it does math on them. Whichever takes longer sets the speed. The roofline model turns that observation into a single plot.
Two ceilings
A GPU has two hard limits:
- Peak compute : how many FLOP/s the tensor cores can do. An H100 SXM does about 989 TFLOP/s in dense BF16.
- Memory bandwidth : how many bytes/s HBM can deliver. An H100 SXM delivers about 3.35 TB/s.
A kernel’s arithmetic intensity is the work it does per byte it moves:
The best throughput it can reach is the lower of the two ceilings:
On a log-log plot that is a slanted line (bandwidth-limited) meeting a flat roof (compute-limited). They cross at the ridge point , which is about 295 FLOP/byte on an H100. Below the ridge the tensor cores sit idle waiting for data.
Placing an LLM layer on the roof
Take one linear layer, , with of size and tokens in . Everything is FP16 (2 bytes).
When , this simplifies to : arithmetic intensity is about the number of tokens processed per step.
- Decode produces one token per sequence per step, so is the batch size. At batch 1, , and the H100 runs at about 0.3% of peak.
- Prefill processes the whole prompt at once, so is the prompt length. At 2,048 tokens, , which is compute-bound at 100%.
Play with it
- intensity
- 7.97
- TFLOP/s
- 26.7
- of peak
- 2.7%
memory-bound — the tensor cores wait on HBM.
- intensity
- 1024
- TFLOP/s
- 989
- of peak
- 100%
compute-bound — HBM keeps up; math is the limit.
Model: one 4096×4096 FP16 linear layer. Drag the dots or use the sliders. Real kernels sit below the roof.
What this means for serving
This one plot explains most of the inference stack:
- Batching is the main lever for decode. Each extra sequence in a step reuses the same weight bytes, which raises . That is why serving engines do continuous batching.
- Prefill and decode want different things. Prefill wants FLOP/s. Decode wants bandwidth. That mismatch motivates chunked prefill and, at scale, disaggregated serving.
- Quantization helps decode for free. INT4 weights move a quarter of the bytes, so quadruples for the same work (see Module 12).
Lab: compute the roofline yourself 🟢
def intensity(m: int) -> float: return flops(m) / bytes_moved(m) # 2*m*d*d / 2*(m*d + d*d + m*d)
def attainable(gpu: str, ai: float) -> float: peak, bw = GPUS[gpu] return min(peak, bw * ai) # TB/s * FLOP/B = TFLOP/spython labs/m03/3.3/roofline.pyH100 SXM: peak 989 TFLOP/s, 3.35 TB/s -> ridge 295 FLOP/B
phase M AI (FLOP/B) TFLOP/s % peak bounddecode 1 1.0 3.3 0.3% memorydecode 8 8.0 26.7 2.7% memorydecode 64 62.1 207.9 21.0% memorydecode 256 227.6 762.3 77.1% memoryprefill 512 409.6 989.0 100.0% computeprefill 2048 1024.0 989.0 100.0% computeSources
Check your understanding
0 / 4 answered1.A GPU has 400 TFLOP/s of peak compute and 2 TB/s of bandwidth. Where is its ridge point?
2.For a d×d FP16 linear layer with M ≪ d, arithmetic intensity is about…
3.Why is single-user decode slow even on the most powerful GPU?
4.Which change raises the arithmetic intensity of decode weight matmuls?