Volume 1 / Part 3 Mechanics — What Happens Inside / Chapter 37
What's Happening Inside the GPU — A Sea of Matrix Math
Last time we talked about how AI doesn't actually learn anything new the moment it answers you. So what is happening inside the GPU during that moment? The answer is almost anticlimactic: it's just huge matrix multiplications, over and over. Let's take a look at this "sea of matrix math."
Attention and FFN Are Both Just Matrix Multiplication
Self-attention and the feed-forward network (FFN) are the two core pieces of a Transformer, and underneath the fancy names, both of them are built from matrix multiplication. There's the transformation into the three vector groups called Q, K, and V. There's the dot product between Q and K that produces a score. There's the softmax step that turns those scores into weights and multiplies them against V. All of these are the same basic operation: matrix multiplication. The FFN side works the same way — multiply the input by a weight matrix W1, add a bias, pass it through ReLU, then multiply by another weight matrix W2 and add again. It's matrix multiplication all the way down.
Picture two spreadsheets, each 1,000 rows by 1,000 columns. You take a row from one sheet, a column from the other, multiply them element by element, and sum the result. Now repeat that for every single cell in the output. That's essentially what Attention and FFN are doing. In real models, these "spreadsheets" aren't just thousands by thousands — the parameter counts run into the billions, even hundreds of billions. Research into dedicated chips like FPGAs and ASICs for Transformers takes this matrix-multiplication foundation as a given starting point.
Behind the intimidating names, Attention and FFN both boil down to matrix multiplication.
The GPU: A Factory of Parallel Computation
Knowing that matrix multiplication is the bread and butter of this computation still leaves one question: who actually does the math, and how? That's where the GPU comes in. GPUs were originally built for image processing — performing the same simple calculation across huge numbers of pixels, all at once. That "do the same calculation on a massive scale, simultaneously" nature turned out to be a perfect match for matrix multiplication.
Here's the key insight: in a matrix multiplication, the calculation for each output cell is almost entirely independent of the others. If you have 10,000 cells to fill in, in principle you could have 10,000 workers computing them all at the same time. A GPU packs in a huge number of small computing units designed to do exactly this, bundled into groups called streaming multiprocessors. If a CPU is a handful of highly skilled craftsmen working through tasks one after another, a GPU is a factory floor packed with workers, all moving their hands at once.
This parallel design lets GPUs chew through matrix multiplication at remarkable speed, which is exactly why deep learning has run on GPUs rather than CPUs for all these years. But making the raw computation faster doesn't solve everything. There's another wall waiting right behind it: memory bandwidth.
Fast Compute, Slow Results — The Memory Bandwidth Wall
Before a GPU's compute units can do any math, they first need to pull the data out of memory. No matter how fast the computation itself is, if the data can't arrive fast enough — if memory bandwidth can't keep up — those compute units just sit there waiting. There's a framework for figuring out whether a given task is limited by raw compute speed or by data-transfer speed: the roofline model.
The roofline model works by calculating arithmetic intensity for a given task — how many calculations you get per byte of data moved — and comparing it against the hardware's ridge point, which is peak compute performance divided by peak memory bandwidth. If arithmetic intensity falls below the ridge point, the task is memory-bandwidth-bound. If it's above, the task is compute-bound. Put simply: tasks that load data once and reuse it many times tend to be compute-bound, while tasks that load data and use it only once tend to be memory-bandwidth-bound.
Prefill and Decode: Two Different Faces
LLM inference splits broadly into two phases: prefill, where the entire input prompt is processed at once, and decode, where the model generates the answer one word at a time. Prefill runs the whole prompt through matrix multiplication in a single batch, which gives it high arithmetic intensity — so it tends to be compute-bound. Decode is a different story. Every single new word requires reading the entire set of model weights from memory, and those weights don't get reused afterward. Because of this "load it, use it once" pattern, the decode phase is often reported to be memory-bandwidth-bound.
If inference feels slow, the bottleneck might not be raw compute power — it might be memory bandwidth.
Another Sea Inside the GPU — HBM and SRAM
Let's dig one level deeper into memory bandwidth. A GPU doesn't have just one kind of memory — it has layers of memory running at different speeds. There's HBM (high-bandwidth memory), which has large capacity but is comparatively slow, and there's on-chip SRAM, which has small capacity but is extremely fast. The FlashAttention-2 paper, published in 2023, reports that on an A100 GPU, HBM bandwidth runs around 1.5 to 2.0 TB/s, while SRAM bandwidth reaches roughly 19 TB/s — nearly an order of magnitude faster.
FlashAttention, a technique introduced in 2022, made the case that the real bottleneck in attention computation wasn't the arithmetic itself — it was the back-and-forth of reading and writing data between HBM and SRAM. In conventional implementations, the large intermediate matrices generated mid-calculation get written out to HBM and then read back in, over and over. FlashAttention uses a technique called tiling to cut down on that round-tripping, keeping more of the computation self-contained within SRAM and boosting speed as a result.
NVIDIA's official spec for the H100 GPU lists 3 TB/s of memory bandwidth per GPU. As of October 2026, depending on the product form factor, real-world figures range from roughly 2.0 to 3.9 TB/s. Those numbers sound plenty fast, but compute performance has also grown enormously with each hardware generation, so the balance between computation and data transfer is never a settled question.
Next Time — Understanding Hardware Reveals AI's "Quirks"
As we've seen, what's really happening inside a GPU is a quiet but surprisingly deep tug-of-war: matrix multiplication on one side, and the memory bandwidth needed to feed it on the other. Once you have this picture in mind, questions like "why does this AI service feel slow when it's the same model?" or "why is batching requests together so much more efficient?" start to have answers you can work out for yourself.
This tension between compute and memory bandwidth is actually a theme we'll dig into much further in the hardware-focused second season of this series. The design philosophy behind GPUs, and the reasons dedicated AI chips keep showing up, all trace back to the roofline model we talked about today. It's worth holding onto.
Today we looked at what matrix multiplication actually is, how GPUs parallelize it, and the memory bandwidth wall that stands in the way. Next time, we'll shift angle and ask something different: how does a system built around the simple task of "predict the next word" end up capable of translation and summarization? Now that you understand the machinery underneath, that mystery should feel even more interesting.
FAQ
Why is AI computation done on GPUs instead of CPUs?
Attention and FFN are both built from huge matrix multiplications, and matrix multiplication breaks down into a massive number of independent calculations. GPUs are optimized for running the same calculation across many units at once in parallel, which makes them a natural fit for this kind of math.
What does "memory-bandwidth-bound" mean?
It describes a situation where the limiting factor isn't the calculation itself, but how fast data can be pulled from memory — the compute units end up sitting idle, waiting for data. In LLM inference, the decode phase, where tokens are generated one at a time, is often reported to run into this limit.
What is FlashAttention?
It's a technique for speeding up attention computation, introduced in 2022. It improves efficiency by reducing how much data gets read from and written to the two memory tiers inside a GPU, HBM and SRAM.
Next time, we'll ask how a mechanism built on nothing more than "predict the next word" ends up handling translation and summarization too.
Primary sources
- Design and Implementation of an FPGA-Based Tiled Matrix Multiplication Accelerator for Transformer Self-Attention — Basis for Attention and FFN being matrix multiplication
- KernelSight-LM: A Kernel-Level LLM Inference Simulator — Definition of the roofline model and ridge point
- AI Hardware Accelerators for Large Language Models: Architectures and the Memory Wall — Distinction between compute-bound prefill and memory-bound decode
- RooflineBench: A Benchmarking Framework for On-Device LLMs via Roofline Analysis — Basis for decode tending to be memory-bound
- FlashAttention-2: Faster Attention with Better Parallelism and Work Partitioning — Specific HBM/SRAM bandwidth figures
- H100 GPU | NVIDIA — Official H100 memory bandwidth spec
- Designing Hardware-Aware Algorithms: FlashAttention — Explanation of FlashAttention's goals and mechanism
This article organizes general knowledge based on our experience and public sources. Product specs, prices, and regulations reflect the time of writing (October 9, 2026) and may change.