Navigation
⚡ Inference Systems· 8 min read

Roofline Analysis for Inference

Is this configuration compute-bound or bandwidth-bound, and how close to the theoretical limit?

rooflinecompute-boundbandwidth-boundarithmetic-intensityanalysis

Roofline analysis tells you how close to optimal your inference configuration is — and whether improving compute or memory bandwidth would help more.


1. The Roofline Model

Performance is limited by whichever ceiling is lower:

Attainable FLOPS=min⁡(Peak FLOPS,HBM BW×Arithmetic Intensity)\text{Attainable FLOPS} = \min(\text{Peak FLOPS}, \text{HBM BW} \times \text{Arithmetic Intensity})

Where arithmetic intensity = FLOPs per byte of memory accessed.

If AI < balance pointMemory-bandwidth-boundOptimization: reduce bytes (quantization, batching)
If AI > balance pointCompute-boundOptimization: reduce FLOPs (pruning, smaller model)

H100 balance point: 989T/3350GB/s≈295989\text{T} / 3350\text{GB/s} \approx 295 FLOP/byte.


2. Inference Workloads on the Roofline

Inference Roofline

WorkloadArithmetic intensityBoundWhy
Decode, batch=1~1 FLOP/byteMemoryLoad all weights for 1 token
Decode, batch=32~32 FLOP/byteMemoryStill below 295
Decode, batch=256~256 FLOP/byteMemory (borderline)Approaching balance
Prefill, 4K tokens~4096 FLOP/byteComputeWell above balance
Prefill, 128 tokens~128 FLOP/byteMemoryShort prompt, below balance

Key insight: Decode is almost always memory-bound. Prefill is almost always compute-bound (for reasonable prompt lengths). The optimization strategy differs completely.


3. How to Use Roofline for Configuration Decisions

Should I quantize?

ConfigurationAIBoundQuantize?
70B BF16, batch=88Memory✅ INT4 reduces bytes 4× → 4× faster
70B BF16, batch=256256Memory (borderline)✅ Still helps (moves toward compute-bound)
70B BF16, prefill 4K4096Compute❌ Won’t help (already compute-limited)

Should I add more TP?

Higher TP splits weights across GPUs → each GPU loads fewer bytes → faster decode:

  • TP=4 → each GPU: 35 GB weights → AI still ~1 FLOP/byte → still memory-bound but 4× less data per GPU

Should I batch more?

More batching → higher AI → closer to compute utilization:

  • But requires more KV cache memory → limits max batch size

4. Measuring Actual Utilization

MFU=Actual throughput (tokens/s)×FLOPs per tokenPeak GPU FLOPS\text{MFU} = \frac{\text{Actual throughput (tokens/s)} \times \text{FLOPs per token}}{\text{Peak GPU FLOPS}}
ConfigurationExpected MFUWhy
Decode, batch=1<1%Massively memory-bound
Decode, batch=32~10%Better but still memory-bound
Prefill, 4K tokens40-60%Compute-utilized
Prefill + decode mixed20-40%Depends on mix

For the prefill/decode arithmetic intensity derivation, see Prefill & Decode Phases.


Self-Check

  • Calculate arithmetic intensity for decode at batch=1 and batch=64
  • Determine if a given configuration is compute-bound or memory-bound
  • Predict whether quantization or batching would help more
  • Calculate MFU for a given throughput and hardware