Articles

Roofline Model: Compute-Bound vs Memory-Bound Explained

The roofline model uses arithmetic intensity to show whether a workload is limited by compute or memory bandwidth, on CPUs, GPUs, and in LLM inference.

Chisato Chisato · · 5 min read
Close-up of an NVIDIA GPU circuit board

The roofline model is a simple visual performance model that tells you whether a piece of code is limited by how fast a processor can compute or by how fast it can move data from memory. It plots achievable performance against a single property of the workload — arithmetic intensity, the number of operations performed per byte of memory traffic. The answer determines which optimizations will help and which will be wasted effort, which is why the roofline model is a standard tool for reasoning about CPUs, GPUs, and AI accelerators.

The two ceilings

Every processor has two hard limits:

  • Peak compute throughput — the maximum number of floating-point operations per second (FLOP/s) the chip can execute when every arithmetic unit is busy.
  • Peak memory bandwidth — the maximum number of bytes per second it can read from and write to main memory.

A workload can never exceed either limit. Which one it hits first depends on how much computation it does for each byte it loads.

Arithmetic intensity

Arithmetic intensity (AI, sometimes called operational intensity) is defined as:

arithmetic intensity = floating-point operations ÷ bytes moved to and from memory

Consider two examples:

  • Vector addition (c[i] = a[i] + b[i]). For each element you read two numbers, write one, and do a single addition. With 4-byte floats that’s 1 operation per 12 bytes — very low intensity.
  • Large matrix multiplication. Multiplying two n×n matrices does on the order of 2n³ operations but only needs to load on the order of 3n² values. Intensity grows with n, so large matrix multiplications can reach very high intensity, as long as data is reused from caches or on-chip memory.

Drawing the roofline

On a log-log chart with arithmetic intensity on the x-axis and achievable FLOP/s on the y-axis, the model draws two lines:

  • A sloped line for memory bandwidth: performance = bandwidth × arithmetic intensity. At low intensity, performance rises linearly as you do more work per byte.
  • A flat line for peak compute. No matter how high the intensity, you can’t exceed it.

Where the two lines meet is the ridge point (or machine balance):

ridge point = peak FLOP/s ÷ peak bytes/s

The shape resembles a roof, hence the name. Any kernel can be placed on the chart by measuring its intensity and its achieved performance.

Compute-bound vs memory-bound

Memory-boundCompute-bound
Position on chartLeft of the ridge point, under the sloped roofRight of the ridge point, under the flat roof
Limiting resourceMemory bandwidthArithmetic units
Typical examplesElement-wise ops, reductions, sparse operations, LLM decodeDense matrix multiply, convolutions, LLM prefill
What helpsFewer bytes: fusion, caching, tiling, smaller data typesMore efficient math: specialized units, better instruction use
What doesn’t helpFaster arithmetic unitsFaster memory alone

The key insight is that the two regimes need opposite optimizations. Tuning arithmetic instructions in a memory-bound kernel achieves almost nothing, because the arithmetic units are already idle while they wait for data. Conversely, adding bandwidth to a compute-bound kernel leaves performance unchanged.

Why modern accelerators are often memory-bound

Over many processor generations, peak compute has tended to grow faster than memory bandwidth. Each new generation pushes the ridge point further to the right, which means a workload needs higher and higher arithmetic intensity to use all the compute it paid for. Our explainer on memory bandwidth vs latency covers the physical reasons memory struggles to keep up.

This is the motivation for high-bandwidth memory stacked next to GPUs and AI chips, and for large on-chip caches and SRAM. It’s also why specialized matrix units like tensor cores raise the flat roof dramatically for dense matrix math, while leaving element-wise operations firmly limited by memory.

The roofline applied to LLM inference

Large language model inference illustrates both regimes in a single request, a split our prefill vs decode explainer covers in depth.

Prefill processes the whole prompt at once. Each weight matrix is loaded from memory and multiplied against many tokens, so the same bytes get reused many times. Intensity is high and prefill tends to be compute-bound.

Decode generates one token at a time. For a single sequence, every weight must be loaded to produce just one token’s worth of computation. Intensity is very low, so decode is usually memory-bound: tokens per second is roughly governed by how quickly the model’s weights and KV cache can be streamed from memory.

Several common inference techniques make sense once you see them on a roofline:

  • Batching serves many sequences with each weight load, multiplying the work done per byte. Continuous batching keeps batches full so decode moves rightward toward the ridge point.
  • Quantization stores weights in fewer bits. Fewer bytes per operation means higher intensity and faster memory-bound decode, even if the arithmetic itself isn’t any faster.
  • Kernel fusion combines several element-wise operations into one pass so intermediate results stay in registers or on-chip memory instead of making a round trip to main memory.

Using the model in practice

Applying the roofline to your own code follows a few steps:

  1. Find the machine’s ceilings. Look up or measure peak FLOP/s for the data type you use, and peak memory bandwidth. The ratio gives the ridge point.
  2. Measure the kernel. Profilers on most platforms report both executed operations and bytes transferred from memory. Divide to get intensity.
  3. Plot achieved performance. If it sits well below the relevant roof, there’s headroom from better code. If it sits close to the roof, you need to change the algorithm or data layout to move the point itself.
  4. Pick the right optimization. Memory-bound: reduce traffic with tiling, caching, fusion, or narrower data types. Compute-bound: use SIMD or matrix units, reduce redundant work, and improve instruction-level parallelism.

Refinements of the basic model add additional roofs for each cache level, for different instruction types, or for interconnects between chips. The core idea stays the same: performance is capped by whichever resource runs out first.

Limitations

The roofline model is deliberately simple. It assumes perfect overlap between computation and memory access, ignores latency effects that matter for small or irregular workloads, and treats bandwidth as a single number when real systems have several levels of memory hierarchy. It tells you which wall you’re up against, not exactly how close you can get to it.

The takeaway

The roofline model reduces performance analysis to one question: how many operations does this workload perform per byte of memory traffic? Below the machine’s ridge point, it’s memory-bound and needs less data movement; above it, it’s compute-bound and needs more efficient arithmetic. That framing explains why AI chips invest so heavily in memory bandwidth, why LLM decode benefits from batching and quantization, and why optimizing the wrong resource rarely pays off.

Chisato Chisato · · 4 min read

CPU vs GPU vs TPU: What's the Difference?

CPUs excel at sequential logic, GPUs at parallel math, and TPUs at the specific matrix operations behind neural networks. Here's how they compare.

#Hardware #AI #Performance
Chisato Chisato · · 4 min read

What Is an NPU? The AI Chip Inside Your Next Laptop

An NPU is a processor built for one job: running AI models fast at very low power. What TOPS numbers actually mean and why every new laptop ships with one.

#Hardware #AI #Performance