Arithmetic Intensity and the Roofline Model in Large Language Models: Why Generation Is Memory-Bound and Prefill Is Compute-Bound
Every optimization in modern large language model (LLM) serving exists to solve a single hardware reality: running a Transformer model is not one computational problem, but two completely distinct workloads operating on opposite sides of a physical performance barrier.
When an LLM processes a prompt during the prefill phase, it saturates modern GPU Tensor Cores, operating near theoretical peak floating-point throughput. When that same model generates subsequent tokens autoregressively during the decode phase, GPU compute utilization plummets to single-digit percentages, leaving trillions of arithmetic operations per second idle while the processor waits for memory access.
Understanding this divergence requires analyzing hardware execution through the lens of the Roofline Model and arithmetic intensity.
The Roofline Model and Arithmetic Intensity
First formalized by Samuel Williams, Andrew Waterman, and David Patterson in 2009, the Roofline Model provides an intuitive visual bound relating an application's execution performance to two fundamental hardware constraints:
- Peak Computational Performance (): The maximum rate of floating-point operations the processor execution units can sustain (measured in FLOP/s or TFLOP/s).
- Peak Memory Bandwidth (): The maximum rate at which data can be transferred from high-bandwidth memory (HBM) into on-chip SRAM, registers, and execution caches (measured in Bytes/s or TB/s).
The parameter connecting an algorithm to these physical ceilings is operational intensity (commonly called arithmetic intensity), defined as the ratio of arithmetic operations performed to bytes of data moved across the memory bus:
The Roofline Model establishes that maximum attainable performance () is the minimum of these two bounds:
Performance (TFLOP/s)
^
| +--------------------------- Peak Compute Ceiling (P_peak)
| /
| / Compute-Bound Regime
| / (Tensor Cores Saturated)
| /
| /
| /
| /
| /
| / Memory-Bound Regime
| / (Memory Bandwidth Starvation)
| /
| /
| /
| /
| +
+------+------------------------------------------> Arithmetic Intensity (FLOP/Byte)
^
Ridge Point (I_ridge = P_peak / B_mem)The intersection where the memory bandwidth ceiling meets the peak compute ceiling is the ridge point ():
Any algorithm whose arithmetic intensity falls below is strictly memory bandwidth-bound. Increasing compute capability (e.g., faster Tensor Cores) yields zero speedup for memory-bound workloads because execution time is entirely dominated by data transfer latency. Conversely, workloads with arithmetic intensity above are compute-bound, where the memory bus supplies data faster than execution units can consume it.
Hardware Ridge Points on Modern Accelerators
Over the past decade, processor computational speed has scaled at a much faster rate than memory bandwidth, a dynamic widely known as the "memory wall." Consequently, modern accelerator architectures feature high ridge points.
Consider the specifications for prominent data center AI accelerators:
| Hardware Accelerator | Precision | Peak Compute () | HBM Bandwidth () | Hardware Ridge Point () | | :--- | :--- | :--- | :--- | :--- | | NVIDIA A100 SXM4 (80GB) | FP16 Dense | 312 TFLOP/s | 2.039 TB/s | 153.0 FLOP/Byte | | NVIDIA H100 SXM5 (80GB) | FP16 Dense | 989.5 TFLOP/s | 3.35 TB/s | 295.4 FLOP/Byte | | NVIDIA H100 SXM5 (80GB) | FP8 Dense | 1,979.0 TFLOP/s | 3.35 TB/s | 590.7 FLOP/Byte | | Google TPU v4 | BF16 Dense | 275 TFLOP/s | 1.20 TB/s | 229.2 FLOP/Byte | | NVIDIA B200 (Blackwell) | FP16 Dense | 2,250 TFLOP/s | 8.00 TB/s | 281.3 FLOP/Byte | | NVIDIA B200 (Blackwell) | FP8 Dense | 4,500 TFLOP/s | 8.00 TB/s | 562.5 FLOP/Byte |
On an NVIDIA H100 SXM5 GPU executing FP16 operations, any kernel requiring fewer than 295.4 FLOPs for every byte transferred from HBM is memory-bandwidth bound. For FP8 computation, the ridge point doubles to 590.7 FLOP/Byte.
The Prefill Phase: Matrix-Matrix Multiplication (GEMM)
During the initial prefill (prompt processing) phase, the model receives a prompt of length tokens. Because the entire prompt is known in advance, the model processes all tokens in parallel.

In each Transformer layer, the linear projections (Query, Key, Value, Output, and MLP projections) perform general matrix-matrix multiplications (GEMM). For an input activation tensor and a weight matrix :
- Floating-point operations: Computing requires FLOPs (one multiply and one add per element).
- Memory transfers: Assuming weights are loaded once from HBM into SRAM and activations are streamed, the total bytes loaded are $(2 \times d_{\text{model}} \times d_{\text{out}}) + (2 \times B \times T_{\text{in}} \times d_{\text{model}})$ bytes for FP16 (2 bytes per element).
When is large (e.g., a batch of 8 requests with 2,048 prompt tokens each, so ), the weight loading term is amortized across thousands of token vectors:
With , the arithmetic intensity reaches thousands of FLOPs per byte, far exceeding the H100's ridge point of 295.4 FLOP/Byte.
As documented by Pope et al. (2022) and Sheng et al. (2023), prefill execution operates at or near peak Model FLOPs Utilization (MFU), typically achieving 50% to 75% of hardware maximum throughput. The execution time during prefill scales with total token count and computational complexity rather than memory bus bandwidth.
The Decode Phase: Matrix-Vector Multiplication (GEMV)
Once prompt prefill completes, autoregressive text generation begins. Autoregressive models generate tokens strictly one at a time because each new token depends causally on all preceding tokens:
In a single-request scenario (), generating token requires passing a single token activation vector through the entire network. The operations across all linear layers are no longer matrix-matrix multiplications (GEMM); they degenerate into matrix-vector multiplications (GEMV).
The Arithmetic Intensity of Batch-Size-1 Generation
Consider a model with parameters stored in FP16 (16 bits = 2 bytes per parameter). To compute a single forward pass for :
- Floating-point operations: A standard forward pass requires approximately FLOPs per token (2 FLOPs per parameter for matrix multiplications).
- Weight memory transfers: To multiply the single input vector by the weight matrices, every single weight in the model must be loaded from HBM across the memory bus into on-chip registers. This requires bytes of memory transfer.
Calculating the resulting arithmetic intensity for the model's feedforward and projection weights:
On an NVIDIA H100 GPU with a ridge point of 295.4 FLOP/Byte, an arithmetic intensity of means the hardware operates at:
More than 99.6% of the GPU's theoretical compute capacity sits completely idle, stalled waiting for HBM to stream parameters over the internal bus.
+-----------------------------------------------------------------------------+
| LLM Serving Phase Comparison (H100 SXM5, FP16) |
+-----------------------------------------------------------------------------+
| Phase | Primary Kernel | Batch Size | Arithmetic Intensity | Regime |
+----------+----------------+------------+----------------------+-------------+
| Prefill | GEMM | B * T >> 1 | > 1,000 FLOP/Byte | Compute |
| Decode | GEMV | B = 1 | ~ 1.0 FLOP/Byte | Memory-Bound|
+-----------------------------------------------------------------------------+The KV Cache Memory Bandwidth Overhead
The memory bandwidth bottleneck during token generation is not limited to model weights; it is compounded by the Key-Value (KV) cache.
To avoid recomputing keys and values for all historical tokens at every step, inference engines store the key and value projections from previous tokens in GPU memory. During each decoding step, the new query vector must attend to all previous key vectors and compute a weighted sum over all value vectors.
For a sequence of length with layers, key-value heads, and head dimension , the total KV cache size per request is:
At each decoding step :
- The GPU must read the entire accumulated KV cache from HBM into SRAM to compute multi-head attention.
- The GPU must write the newly generated key and value vectors ( bytes) back to HBM.
As sequence length grows into tens or hundreds of thousands of tokens, the bytes transferred for KV cache retrieval can surpass the bytes loaded for model weights. This further depresses effective arithmetic intensity and establishes sequence length as a primary throughput constraint.
Architectural Mechanisms to Overcome the Memory Wall
Because autoregressive decoding is constrained by memory bandwidth rather than compute limits, every major software and architectural innovation in modern LLM serving targets increasing arithmetic intensity or reducing bytes moved across the memory bus:
+---------------------------------------------------+
| Strategies for Overcoming the Memory Wall |
+---------------------------------------------------+
|
+-----------------------------------+-----------------------------------+
| |
+-------v-----------------------+ +-------v-----------------------+
| Increase Arithmetic Intensity| | Reduce Bytes Transferred |
+-------------------------------+ +-------------------------------+
| * Continuous Batching (B > 1) | | * Weight Quantization (W4A16) |
| * Speculative Decoding | | * KV Cache Quantization (FP8) |
| * Multi-Token Prediction (MTP)| | * GQA / MQA / MLA Head Sharing|
+-------------------------------+ +-------------------------------+1. Continuous and Dynamic Batching
By grouping independent user requests into a single forward pass, the model weights loaded from HBM are multiplied against token vectors simultaneously. This converts GEMV back into a small GEMM, scaling arithmetic intensity roughly linearly with batch size () until the batch size approaches the hardware ridge point (). As demonstrated by Yu et al. (2022) in Orca, iteration-level scheduling prevents request completion mismatches from causing pipeline bubbles.
2. Weight and KV Cache Quantization
Quantizing model weights from FP16 (16 bits) to INT4 or FP4 (4 bits) reduces weight data traffic by 75%. Because generation latency at small batch sizes is governed directly by memory bandwidth:
Halving the precision of model weights doubles token generation speed on memory-bound workloads, even if the dequantization overhead slightly increases arithmetic instructions.
3. Key-Value Head Compression (GQA, MQA, and MLA)
Standard Multi-Head Attention maintains separate Key and Value heads for every Query head (). Grouped-Query Attention (GQA) shares single Key and Value heads across groups of Query heads, cutting KV cache memory traffic by 4x to 8x. Multi-Head Latent Attention (MLA) compresses Key-Value projections into a low-rank latent vector, slashing KV cache memory transfers by up to 93%.
4. Speculative Decoding
Speculative decoding uses a compact, fast draft model to speculate candidate tokens. The primary target model then verifies all tokens in a single forward pass using GEMM. If multiple tokens are accepted, the target model processes tokens for the memory cost of loading its weights once, effectively boosting generation arithmetic intensity by a factor proportional to the mean acceptance rate.
5. Disaggregated Prefill and Decode Architectures
Because prefill and decode exhibit opposing resource bottlenecks, co-locating them on the same GPU creates destructive interference: compute-heavy prefill operations preempt memory-bandwidth-sensitive decode streams, introducing severe latency spikes (time-to-first-token versus inter-token latency trade-offs). Disaggregated serving architectures such as Splitwise partition GPU clusters into dedicated prefill pools (optimized for high TFLOP/s) and decode pools (optimized for maximum memory bandwidth and high interconnect speeds), transferring intermediate KV caches across high-speed networks.
Summary
The Roofline Model provides the foundational mathematical framework explaining why large language model inference behaves as two fundamentally different computational tasks:
- Prefill is Compute-Bound: Parallel processing across entire input sequences yields high arithmetic intensity (), saturating Tensor Cores and achieving high Model FLOPs Utilization.
- Decode is Memory-Bound: Sequential, token-by-token generation forces full model weight streaming per forward pass, resulting in near-unity arithmetic intensity () that leaves modern execution engines starved for data.
Understanding the roofline curve makes clear why serving system optimizations focus relentlessly on memory footprint reduction, batch consolidation, speculative verification, and phase disaggregation: until hardware memory bandwidth catches up to arithmetic capacity, generation performance will remain bounded by the memory bus.
Sources
- Williams, S., Waterman, A., & Patterson, D. (2009). Roofline: An Insightful Visual Performance Model for Multicore Architectures. Communications of the ACM, 52(4), 65–76. ACM Digital Library
- Pope, R., Douglas, S., Chowdhery, A., Devlin, J., Bradbury, J., Levskaya, A., Heek, J., Xiao, K., Agrawal, S., & Dean, J. (2022). Efficiently Scaling Transformer Inference. arXiv:2211.05102. arXiv
- Patel, P., Choukse, E., Zhang, C., Shah, A., & Goiri, Í. (2023). Splitwise: Efficient Generative LLM Serving Using Phase Splitting. arXiv:2311.18677. arXiv
- Sheng, Y., Zheng, L., Yuan, B., Li, Z., Ryabinin, M., Fu, D. Y., Xie, C. X., Chen, B., Barrett, C., & Ré, C. (2023). FlexGen: High-Throughput Generative Inference of Large Language Models with a Single GPU. arXiv:2303.06865. arXiv
- Yu, G. I., Jeong, J. S., Kim, G. W., Kim, S., & Chun, B. G. (2022). Orca: A Distributed Serving System for Transformer-Based Generative Models. USENIX OSDI '22. USENIX
- Ainslie, J., Ontanon, S., Alberti, C., Cvicek, V., Fisher, Z., Pham, P., Ravula, A., Sumbaly, S., & Yang, L. (2023). GQA: Training Generalized Multi-Query Transformer Models from Multi-Head Checkpoints. arXiv:2305.13245. arXiv
- DeepSeek-AI. (2024). DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model. arXiv:2405.04434. arXiv
- Leviathan, Y., Kalman, M., & Matias, Y. (2023). Fast Inference from Transformers via Speculative Decoding. arXiv:2211.17192. arXiv



