{"course":{"slug":"maths-you-need","title":"The Maths You Actually Need","url":"https://addaly.com/learn/maths-you-need","level":"intermediate","track":"deep"},"lesson":{"slug":"arithmetic-intensity-and-the-roofline","title":"Why a GPU idles: memory-bound versus compute-bound","url":"https://addaly.com/learn/maths-you-need/arithmetic-intensity-and-the-roofline","position":62,"of":76,"minutes":10,"answer":"A computation runs at the slower of its compute and bandwidth limits, and its arithmetic intensity in FLOPs per byte decides which.","keyIdea":"A computation runs at the slower of its compute and bandwidth limits, and its arithmetic intensity in FLOPs per byte decides which, so single-token generation at one FLOP per byte is bandwidth-bound and takes weights ÷ bandwidth seconds regardless of how fast the chip's arithmetic is."},"body":{"format":"markdown","text":"## Two ceilings, not one\n\nA chip can only do so many floating-point operations per second: its compute ceiling. It can also only move so many bytes per second between memory and the units that do the arithmetic: its bandwidth ceiling. Every computation needs both, and it runs at the speed of whichever ceiling it hits first. FLOP counts, from three lessons ago, see only the first. Most of the surprises in ML performance come from the second.\n\nThe numbers for an A100-class GPU:\n\n```\ncompute:    312 × 10^12 FLOP/s (half precision)\nbandwidth:    2 × 10^12 bytes/s\n```\n\nFor a laptop CPU, roughly `10^11` FLOP/s and `5 × 10^10` bytes/s.\n\n## Arithmetic intensity\n\nDivide the FLOPs a computation performs by the bytes it must move, and you get its **arithmetic intensity**, in FLOPs per byte. Compare it with the chip's **ridge point**, the compute ceiling divided by the bandwidth ceiling:\n\n```\nA100 ridge:   312 × 10^12 / 2 × 10^12 = 156 FLOP/byte\nlaptop ridge: 10^11 / 5 × 10^10        =   2 FLOP/byte\n```\n\nBelow the ridge, the computation is **memory-bound**: the arithmetic units wait for data and the achieved FLOP/s is the intensity times the bandwidth. Above it, **compute-bound**: the chip is doing arithmetic as fast as it can. Plot achieved performance against intensity and you get a rising line that flattens at the ridge, shaped like a roof, which is why this is called the roofline model.\n\n## Generating one token is memory-bound\n\nA model generating text produces one token at a time, and for each token it multiplies every weight matrix by a single vector. Each weight, 2 bytes in fp16, is read from memory once and used for one multiply and one add: 2 FLOPs per 2 bytes, an intensity of 1.\n\nOn the A100 that is 156 times below the ridge. The chip is doing arithmetic less than one per cent of the time. What it is doing is streaming 14 GB of weights past the arithmetic units, and the time that takes is set by bandwidth alone:\n\n```\n14 GB / 2 TB/s = 7 ms per token  →  at most about 140 tokens per second\n```\n\nNo FLOP count predicts that. On a laptop with 50 GB/s of bandwidth and a 4 GB int4 model, the same arithmetic gives 80 ms per token, about twelve tokens a second, which is what people see running a small model locally. Quantising to int4 speeds up generation not because the arithmetic is cheaper but because there are a quarter as many bytes to stream.\n\n## Batching is how you climb the roof\n\nProcess 64 sequences at once and each weight, still read once, is used 64 times: intensity 64. Process 256 and it is 256, above the ridge, and now the chip is compute-bound and the FLOP count starts to predict the time. This is why serving systems batch requests, why throughput per GPU rises almost linearly with batch size until the ridge, and why the latency for a single user is what it is regardless of how fast the chip's arithmetic is. Training uses batches of thousands of tokens against each weight and lives well above the ridge, which is why FLOP arithmetic works for training time and fails for single-stream inference.\n\n> Figure: The roof: what a chip achieves against what the work asks of it. Line chart of Achieved throughput, trillions of FLOPs a second against Arithmetic intensity, FLOPs per byte moved: 2 TB a second of bandwidth, then a 312 TFLOP ceiling (1, 2) (10, 20) (50, 100) (100, 200) (156, 312) (300, 312) (600, 312). Generating one token at a time sits at intensity 1, at the far left: the arithmetic units idle and the speed is 14 GB divided by 2 TB a second, about seven milliseconds a token. Batching 256 sequences moves the same work past the ridge, where a FLOP count finally predicts the time.\n\n## The operations that never climb\n\nElementwise work has an intensity near a quarter: adding two tensors reads 8 bytes and writes 4 to do one FLOP. Activation functions, layer normalisation, dropout, residual additions are all like this, and all are memory-bound on every chip ever made. A transformer layer that spends 5 per cent of its FLOPs on them can spend 40 per cent of its *time* on them. The fix is fusion: combine several elementwise steps into one kernel so the data is read once and written once. Every compiled-model toolchain does this, and the reason is on this page.\n\n## Why training reaches 40 per cent of the rating\n\nThe 312 trillion is for one ideal operation running continuously. A real step alternates large matrix multiplies, which approach the rating, with attention blocks, normalisations, optimiser updates and communication between GPUs, none of which do. The average over a step is the utilisation figure, and 35 to 45 per cent is a good result. Quoting a job's cost from the rating alone underestimates it by that factor.\n\n## Measure the roof you own\n\n```python\nimport numpy as np, time\nn = 4096\nA = np.random.rand(n, n).astype(np.float32); x = np.random.rand(n, 1).astype(np.float32)\nfor cols in (1, 16, 256):\n    X = np.repeat(x, cols, axis=1)\n    t = time.perf_counter(); A @ X; dt = time.perf_counter() - t\n    print(cols, round(2 * n * n * cols / dt / 1e9), \"GFLOP/s\")\n```\n\nThe one-column case is a matrix-vector product with intensity near 0.5 and runs at bandwidth speed. The 256-column case is compute-bound. The ratio between the two lines is your machine's version of the gap this lesson is about, and it will be somewhere between ten and a hundred.\n\n## What the model leaves out\n\nThe roofline has two ceilings; real chips have more. Cache levels give a small working set a higher effective bandwidth. Communication between GPUs in a cluster is a third, lower ceiling that bounds large training runs. And the model says nothing about latency between dependent operations, which matters for small models where launching a kernel takes longer than running it. It is still the first tool to reach for, because the single most common performance mistake is counting FLOPs for a computation that was never going to be limited by them."},"check":{"question":"A team quantises a 14 GB fp16 model to 3.5 GB int4 and sees single-user generation speed rise about four-fold, though the int4 arithmetic is not faster. Why?","options":[{"text":"Quantisation reduces the FLOPs per token by four, so the compute ceiling allows more tokens.","correct":false,"tempting":"The FLOP count per token is unchanged, since every parameter still does one multiply-add; the speed-up comes from the other ceiling."},{"text":"Generation is bound by streaming the weights, and int4 has a quarter of the bytes.","correct":true},{"text":"The smaller model fits in cache, which is faster than main memory.","correct":false,"tempting":"3.5 GB fits no cache; the weights still stream from main memory each token, and it is the byte count over that link that fell."},{"text":"int4 lets the GPU process four tokens in parallel for every one it processed before.","correct":false,"tempting":"Invents a parallelism that quantisation does not provide; the batch is still one, and the gain is purely fewer bytes per token."}]},"prev":{"slug":"memory-arithmetic","title":"Bytes per parameter, and the arithmetic of what fits on a card","url":"https://addaly.com/learn/maths-you-need/memory-arithmetic"},"next":{"slug":"hashing-and-the-birthday-bound","title":"Hashing, collisions, and the square-root law behind them","url":"https://addaly.com/learn/maths-you-need/hashing-and-the-birthday-bound"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Source and assessment review continues. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 'Why a GPU idles: memory-bound versus compute-bound', in The Maths You Actually Need. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/maths-you-need/arithmetic-intensity-and-the-roofline (Accessed: 29 November 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"Why a GPU idles: memory-bound versus compute-bound","courseTitle":"The Maths You Actually Need","module":{"index":7,"slug":"cost-and-scale","title":"Counting the cost: complexity and the arithmetic of scale"},"answer":null,"keyIdea":"A computation runs at the slower of its compute and bandwidth limits, and its arithmetic intensity in FLOPs per byte decides which, so single-token generation at one FLOP per byte is bandwidth-bound and takes weights ÷ bandwidth seconds regardless of how fast the chip’s arithmetic is.","hero":{"kind":"figure","figure":{"t":"figure","label":"Figure","figure":{"caption":"Generating one token at a time sits at intensity 1, at the far left: the arithmetic units idle and the speed is 14 GB divided by 2 TB a second, about seven milliseconds a token. Batching 256 sequences moves the same work past the ridge, where a FLOP count finally predicts the time.","series":[{"label":"2 TB a second of bandwidth, then a 312 TFLOP ceiling","points":[[1,2],[10,20],[50,100],[100,200],[156,312],[300,312],[600,312]]}],"title":"The roof: what a chip achieves against what the work asks of it","type":"line","xLabel":"Arithmetic intensity, FLOPs per byte moved","yLabel":"Achieved throughput, trillions of FLOPs a second"},"alt":"Figure: The roof: what a chip achieves against what the work asks of it. Line chart of Achieved throughput, trillions of FLOPs a second against Arithmetic intensity, FLOPs per byte moved: 2 TB a second of bandwidth, then a 312 TFLOP ceiling (1, 2) (10, 20) (50, 100) (100, 200) (156, 312) (300, 312) (600, 312). Generating one token at a time sits at intensity 1, at the far left: the arithmetic units idle and the speed is 14 GB divided by 2 TB a second, about seven milliseconds a token. Batching 256 sequences moves the same work past the ridge, where a FLOP count finally predicts the time."}},"blocks":[{"t":"h2","id":"two-ceilings-not-one","runs":[{"text":"Two ceilings, not one"}]},{"t":"p","runs":[{"text":"A chip can only do so many floating-point operations per second: its compute ceiling. It can also only move so many bytes per second between memory and the units that do the arithmetic: its bandwidth ceiling. Every computation needs both, and it runs at the speed of whichever ceiling it hits first. FLOP counts, from three lessons ago, see only the first. Most of the surprises in ML performance come from the second."}]},{"t":"p","runs":[{"text":"The numbers for an A100-class GPU:"}]},{"t":"code","lang":"","label":"Text","text":"compute:    312 × 10^12 FLOP/s (half precision)\nbandwidth:    2 × 10^12 bytes/s"},{"t":"p","runs":[{"text":"For a laptop CPU, roughly "},{"text":"10^11","code":true},{"text":" FLOP/s and "},{"text":"5 × 10^10","code":true},{"text":" bytes/s."}]},{"t":"h2","id":"arithmetic-intensity","runs":[{"text":"Arithmetic intensity"}]},{"t":"p","runs":[{"text":"Divide the FLOPs a computation performs by the bytes it must move, and you get its "},{"text":"arithmetic intensity","b":true},{"text":", in FLOPs per byte. Compare it with the chip’s "},{"text":"ridge point","b":true},{"text":", the compute ceiling divided by the bandwidth ceiling:"}]},{"t":"code","lang":"","label":"Text","text":"A100 ridge:   312 × 10^12 / 2 × 10^12 = 156 FLOP/byte\nlaptop ridge: 10^11 / 5 × 10^10        =   2 FLOP/byte"},{"t":"p","runs":[{"text":"Below the ridge, the computation is "},{"text":"memory-bound","b":true},{"text":": the arithmetic units wait for data and the achieved FLOP/s is the intensity times the bandwidth. Above it, "},{"text":"compute-bound","b":true},{"text":": the chip is doing arithmetic as fast as it can. Plot achieved performance against intensity and you get a rising line that flattens at the ridge, shaped like a roof, which is why this is called the roofline model."}]},{"t":"h2","id":"generating-one-token-is-memory-bound","runs":[{"text":"Generating one token is memory-bound"}]},{"t":"p","runs":[{"text":"A model generating text produces one token at a time, and for each token it multiplies every weight matrix by a single vector. Each weight, 2 bytes in fp16, is read from memory once and used for one multiply and one add: 2 FLOPs per 2 bytes, an intensity of 1."}]},{"t":"p","runs":[{"text":"On the A100 that is 156 times below the ridge. The chip is doing arithmetic less than one per cent of the time. What it is doing is streaming 14 GB of weights past the arithmetic units, and the time that takes is set by bandwidth alone:"}]},{"t":"code","lang":"","label":"Text","text":"14 GB / 2 TB/s = 7 ms per token  →  at most about 140 tokens per second"},{"t":"p","runs":[{"text":"No FLOP count predicts that. On a laptop with 50 GB/s of bandwidth and a 4 GB int4 model, the same arithmetic gives 80 ms per token, about twelve tokens a second, which is what people see running a small model locally. Quantising to int4 speeds up generation not because the arithmetic is cheaper but because there are a quarter as many bytes to stream."}]},{"t":"h2","id":"batching-is-how-you-climb-the-roof","runs":[{"text":"Batching is how you climb the roof"}]},{"t":"p","runs":[{"text":"Process 64 sequences at once and each weight, still read once, is used 64 times: intensity 64. Process 256 and it is 256, above the ridge, and now the chip is compute-bound and the FLOP count starts to predict the time. This is why serving systems batch requests, why throughput per GPU rises almost linearly with batch size until the ridge, and why the latency for a single user is what it is regardless of how fast the chip’s arithmetic is. Training uses batches of thousands of tokens against each weight and lives well above the ridge, which is why FLOP arithmetic works for training time and fails for single-stream inference."}]},{"t":"h2","id":"the-operations-that-never-climb","runs":[{"text":"The operations that never climb"}]},{"t":"p","runs":[{"text":"Elementwise work has an intensity near a quarter: adding two tensors reads 8 bytes and writes 4 to do one FLOP. Activation functions, layer normalisation, dropout, residual additions are all like this, and all are memory-bound on every chip ever made. A transformer layer that spends 5 per cent of its FLOPs on them can spend 40 per cent of its "},{"text":"time","i":true},{"text":" on them. The fix is fusion: combine several elementwise steps into one kernel so the data is read once and written once. Every compiled-model toolchain does this, and the reason is on this page."}]},{"t":"h2","id":"why-training-reaches-40-per-cent-of-the-rating","runs":[{"text":"Why training reaches 40 per cent of the rating"}]},{"t":"p","runs":[{"text":"The 312 trillion is for one ideal operation running continuously. A real step alternates large matrix multiplies, which approach the rating, with attention blocks, normalisations, optimiser updates and communication between GPUs, none of which do. The average over a step is the utilisation figure, and 35 to 45 per cent is a good result. Quoting a job’s cost from the rating alone underestimates it by that factor."}]},{"t":"h2","id":"measure-the-roof-you-own","runs":[{"text":"Measure the roof you own"}]},{"t":"code","lang":"python","label":"Python","text":"import numpy as np, time\nn = 4096\nA = np.random.rand(n, n).astype(np.float32); x = np.random.rand(n, 1).astype(np.float32)\nfor cols in (1, 16, 256):\n    X = np.repeat(x, cols, axis=1)\n    t = time.perf_counter(); A @ X; dt = time.perf_counter() - t\n    print(cols, round(2 * n * n * cols / dt / 1e9), \"GFLOP/s\")"},{"t":"p","runs":[{"text":"The one-column case is a matrix-vector product with intensity near 0.5 and runs at bandwidth speed. The 256-column case is compute-bound. The ratio between the two lines is your machine’s version of the gap this lesson is about, and it will be somewhere between ten and a hundred."}]},{"t":"h2","id":"what-the-model-leaves-out","runs":[{"text":"What the model leaves out"}]},{"t":"p","runs":[{"text":"The roofline has two ceilings; real chips have more. Cache levels give a small working set a higher effective bandwidth. Communication between GPUs in a cluster is a third, lower ceiling that bounds large training runs. And the model says nothing about latency between dependent operations, which matters for small models where launching a kernel takes longer than running it. It is still the first tool to reach for, because the single most common performance mistake is counting FLOPs for a computation that was never going to be limited by them."}]}],"check":{"question":[{"text":"A team quantises a 14 GB fp16 model to 3.5 GB int4 and sees single-user generation speed rise about four-fold, though the int4 arithmetic is not faster. Why?"}],"options":[{"text":[{"text":"Quantisation reduces the FLOPs per token by four, so the compute ceiling allows more tokens."}],"correct":false,"tempting":[{"text":"The FLOP count per token is unchanged, since every parameter still does one multiply-add; the speed-up comes from the other ceiling."}]},{"text":[{"text":"Generation is bound by streaming the weights, and int4 has a quarter of the bytes."}],"correct":true,"tempting":null},{"text":[{"text":"The smaller model fits in cache, which is faster than main memory."}],"correct":false,"tempting":[{"text":"3.5 GB fits no cache; the weights still stream from main memory each token, and it is the byte count over that link that fell."}]},{"text":[{"text":"int4 lets the GPU process four tokens in parallel for every one it processed before."}],"correct":false,"tempting":[{"text":"Invents a parallelism that quantisation does not provide; the batch is still one, and the gain is purely fewer bytes per token."}]}],"order":[3,1,0,2],"why":null},"prev":{"slug":"memory-arithmetic","title":"Bytes per parameter, and the arithmetic of what fits on a card","minutes":9},"next":{"slug":"hashing-and-the-birthday-bound","title":"Hashing, collisions, and the square-root law behind them","minutes":9}}}