< Will Bosler

GPU Storage ยท

If you're looking to optimise model speed or run local models, it's worth having at least a cursory understanding of GPU architecture and its storage hierarchy. Here we use the NVIDIA B200 as the example.

0:06 / 0:07

Pulled apart, the B200 is two compute dies with eight stacks of high bandwidth memory beside them. Each die carries half of the L2 cache and 74 of the GPU's 148 streaming multiprocessors (SMs), the units that perform the computation. Inside every SM sit its registers and its L1 cache and shared memory. Those are the four tiers where a byte can live, and the further each one is from the math, the slower it is, the more data it holds for each owner and the more widely it is shared.

We start at the largest source of memory, high bandwidth memory (HBM). This is where the model weights, the activations and the KV cache all live, until the SMs call in the slices they need to perform computation. HBM belongs to the whole GPU: every SM can reach it, as can other GPUs over NVLink and the host CPU over PCIe. On the B200 it holds 180 GB and moves about 8 TB/s, yet a single read still takes hundreds of cycles to come back.

0:04 / 0:10

Going back to HBM is slow, so in general we want to bring data as close as we can to where the compute is occurring. This is the purpose of the L2 cache. It is available to all the SMs, and recently used data stays in it so that the next request can avoid going back to HBM. The hardware manages it: programs address HBM, and the L2 keeps copies, so it can't be addressed directly. On the B200 it is 126 MB, split across the two dies.

0:03 / 0:07

We then move into shared memory, inside the SM itself, which is available to all the threads in a single thread block. On Hopper and newer GPUs, blocks grouped into a cluster can also read and write each other's shared memory. A block stages data here so that its threads can reuse it without going back to HBM. Shared memory uses the same physical storage as the SM's L1 cache, which the hardware fills automatically: 256 KB per SM on the B200, of which up to 228 KB can be shared memory. Again, we are moving data closer to compute.

0:03 / 0:07

Finally, we have the registers, each belonging to a single thread in a block. The one exception is a warp, a group of 32 threads, whose threads can swap register values directly with shuffle instructions. This is where the values for the computation taking place actually sit: most instructions read their operands from registers and write their results back to them. Each SM has 65,536 32-bit registers, 256 KB in total, handed out to its threads as their blocks launch, up to 255 per thread. Reading one costs no extra cycles.

0:03 / 0:07

The key principle is that we want to bring data close to compute to reduce latency, but there is a trade-off with how much data each tier can store. HBM keeps all of it, and on demand we bring data closer through the L2 cache, shared memory and registers to complete the computation. This is also why generating text one token at a time is often limited by memory rather than math: every new token needs the model's weights to be read from HBM again.

0:02 / 0:06