The roofline of LLM inference, and what it asks of our engine
Every design decision in an inference engine comes back to one question: is this step limited by arithmetic or by memory? The roofline model answers it with two numbers per GPU and one per operation. This paper walks through the roofline for language model inference, shows why prefill and decode sit on opposite sides of it, and traces each major feature of the engine we plan to build (batching, paged KV cache, quantization, speculative decoding, CUDA graphs) back to where it moves an operation on that chart.
Before building an inference engine, it helps to know what the hardware can possibly do. The roofline model is the simplest honest answer. It won't predict exact speed. It will tell you which wall you are about to hit, and that decides what is worth optimising.
Two numbers per GPU
Every GPU has a peak arithmetic rate, in floating-point operations per second, and a peak memory bandwidth, in bytes per second from its main memory. Divide the first by the second and you get the ridge point: how many operations the GPU can perform in the time it takes to fetch one byte.
On modern GPUs that ratio is large, often in the hundreds of operations per byte for low-precision tensor-core arithmetic. That single fact shapes almost everything below.
One number per operation
Every operation has an arithmetic intensity: the operations it performs divided by the bytes it has to move.
- If its intensity is below the ridge point, it is memory-bound. The arithmetic units finish early and wait for data. The best possible speed is bandwidth × intensity.
- If its intensity is above the ridge point, it is compute-bound. Memory keeps up and the arithmetic units are the limit.
The chart this gives, with performance rising along a slope and then flattening into a roof, is the roofline. The job of an inference engine is to push each operation as close to its line as possible, and where it can, to move operations to the right.
Where a language model sits
Most of the work in a transformer is matrix multiplication against weight matrices. For each weight, the model does one multiply and one add per token that uses it: two operations. In 16-bit precision, each weight is two bytes. So if a forward pass processes T tokens at once, each weight byte fetched supports roughly T operations.
That gives the central result:
The arithmetic intensity of the weight multiplies is roughly the number of tokens processed together.
Everything else follows from it.
Prefill is compute-bound
When a request arrives, its whole prompt goes through the model in one pass. A 2,000-token prompt has an intensity of about 2,000 operations per weight byte, which is far right of the ridge point. Prefill is limited by arithmetic, and it is where the tensor cores earn their keep. This is why time to first token grows with prompt length, and why fast matrix multiply kernels matter most here.
Decode is memory-bound
After the first token, each step produces one new token per sequence. With a single sequence, T is 1: the GPU reads every weight in the model to do two operations with it. Intensity is about 1, far left of the ridge point, and the arithmetic units sit mostly idle.