L1 Beginner · Module 3: The performance mental model
3.2Arithmetic intensity
Arithmetic intensity, FLOPs per byte moved, is the one number that tells you which side of the compute/memory line a kernel falls on. Learn to compute it on paper for the operations an LLM runs, and you can predict their speed before running anything.
By the end you will be able to
- ✓Define arithmetic intensity and compare it with a GPU's ridge point
- ✓Compute intensity for elementwise ops, GEMV, GEMM and attention
- ✓Show that a linear layer's intensity is about the number of tokens in the step
- ✓Name the three ways to raise intensity (batching, fewer bytes, and fusion)
Chapter 3.1 compared compute time with memory time. Divide one by the other and the hardware constants separate out from the kernel’s own property:
The kernel’s ratio is its arithmetic intensity, , in FLOP per byte. The GPU’s ratio is its ridge point : about 153 for an A100 and 295 for an H100 in BF16. The rule is simple:
Counting rules
- FLOPs: a multiply-add counts as 2. A matmul of is .
- Bytes: count what has to cross between HBM and the chip at least once: each input read and each output written. Data reused from shared memory or registers does not count again. Use the storage format: 2 bytes for BF16, 1 for FP8, 0.5 for INT4.
- This gives the best case, assuming perfect on-chip reuse. Real kernels move somewhat more.
The intensities that matter
| Operation (BF16 unless noted) | FLOPs | Bytes | Intensity |
|---|---|---|---|
| Vector add, FP32 | 0.08 | ||
| Elementwise SiLU | ~1 | ||
| GEMV: weights · one vector | ≈ 1 | ||
| Linear layer, tokens, weights | |||
| Square GEMM, | |||
| Decode attention, per KV head | (query heads per KV head) |
Two rows deserve a closer look.
The linear layer. Each weight is loaded once and used once per token in the step. With tokens, the intensity is about while is much smaller than . So the intensity of an LLM’s weight matmuls is set by how many tokens are processed together: 1 for single-user decode, the batch size for batched decode, and the prompt length for prefill.
Decode attention. Every sequence reads its own K and V, and batching does not share them. Each cached value is used by the query heads that share its KV head: for classic multi-head attention, for Llama-3-8B with grouped-query attention, which is one reason GQA helps decode (9.2). Either way, decode attention sits far below any ridge point.
Three ways to raise intensity
- Process more tokens per weight load. Batching in decode raises . This is the single most important lever in serving (10.1).
- Move fewer bytes per value. INT4 weights carry a quarter of the bytes of BF16, so intensity for the same FLOPs is four times higher (Module 12).
- Fuse operations. Running RMSNorm, then a matmul, then an activation as separate kernels writes and re-reads the activations to HBM between each step. Fusing them keeps the intermediates on chip, removing those bytes. FlashAttention is the famous case: it never writes the score matrix to HBM at all (8.5).
Sources
Check your understanding
0 / 4 answered1.What is the arithmetic intensity of an FP32 vector add, c[i] = a[i] + b[i]?
2.A linear layer has 4096×4096 BF16 weights and processes 32 tokens. Its intensity is about…
3.Why does batching not raise the intensity of decode attention?
4.How does kernel fusion raise arithmetic intensity?