Module 3 · Lesson 2 of 5
Memory and movement
A GPU cannot compute with bytes that have not arrived. Track the path, scope and reuse of one operand.
Where an operand lives
A value stored in global memory must reach an execution unit before it contributes to a dot product. Storage capacity tells you what fits; traffic tells you how many bytes cross a boundary. They answer different questions.
The storage names in the path
- Registers: working values for an individual thread, such as a running sum, stored on the SM.
- Shared memory: storage on the SM that threads in one block explicitly fill and reuse.
- L1 and L2 caches: hardware-managed stores of recently used data. L1 is associated with an SM; L2 is shared across the device. A cache hit can avoid fetching data from device memory.
- Device DRAM (dynamic random-access memory): the GPU’s main memory for allocations such as inputs and weights. HBM means high-bandwidth memory, one DRAM technology used by many datacenter GPUs. Global memory names the address space used to access these allocations.
The transformer KV cache is a software data structure, usually allocated in global memory. It is different from the hardware L1/L2 caches. A load reads a value; a store writes one. A multiply-add multiplies two operands and adds their product to a running sum.
How big and how fast: one real GPU
The levels form a hierarchy: the closer to the math units, the smaller (and faster) the storage; the farther, the larger and slower. Real sizes for one GPU generation, the NVIDIA H100 SXM5 (Hopper), taken from NVIDIA’s published pages:
| Level | Scope | Size | Bandwidth |
|---|---|---|---|
| Registers | per thread, on the SM | 256 KB per SM; 132 SMs, about 33 MB in total | not given in the sources |
| Shared memory + L1 | per SM | 256 KB combined per SM; up to 228 KB of it configurable as shared memory | not given in the sources |
| L2 cache | whole GPU | 50 MB | not given in the sources |
| HBM3 (device DRAM) | whole GPU | 80 GB | about 3 TB/s (the product page lists 3.35 TB/s) |
Read it as orders of magnitude: tens of megabytes on chip against tens of gigabytes in HBM, roughly 1,600× more (80 GB ÷ 50 MB, a derived ratio). Only HBM bandwidth is published in these sources, so the on-chip bandwidths and every latency are left out rather than guessed; NVIDIA gives no cycle latency for any level on these pages. The rule that holds regardless is the direction: faster is smaller, so the course keeps asking how many bytes must cross the slow boundary.
Sources, read 2026-11-26: NVIDIA, “NVIDIA Hopper Architecture In-Depth” (register file, shared memory + L1, L2, SM count, HBM3; the blog says its figures were preliminary when published) and the NVIDIA H100 product page (80 GB, 3.35 TB/s). Rounded; “about 33 MB” is 132 × 256 KB. The toy SM in lesson 3.1 is not this chip: it copies its limits of 2,048 threads (64 warps) and 65,536 registers per SM (= 256 KB), but uses 64 KiB of shared memory (H100: up to 228 KB) and at most 8 blocks (H100: 32), and its numbers are for teaching.
One operand: storage scopes and optional staging
Compare a global load used directly by a thread with a tiled kernel that explicitly stages operands in shared memory. These are storage scopes, not a mandatory hardware route. Exact cache and instruction paths vary by hardware.
Global load
Inputs and weights occupy global allocations backed by device DRAM, often HBM on datacenter GPUs. Hardware caches such as device-wide L2 and SM-local L1 can serve loads: a cache hit can avoid a DRAM fetch.
Optional shared-memory staging
A tiled kernel can cooperatively load operands into block-local shared memory for reuse. A block barrier makes the staged values safe to consume; another barrier is needed before overwriting values still in use. A direct per-thread load can skip this staging.
Per-thread computation
Threads use operands in registers and update their multiply-add accumulators. In the tiled example, threads read the staged shared-memory values first. Registers are per-thread working storage, not shared addressable storage.
Output store
Completed results are stored to global memory through the applicable store/cache path.
Choose a memory boundary before counting traffic. Shared memory is explicitly managed block-local storage; hardware caches are managed by hardware. Reuse can reduce global-load demand. Capacity, logical requests and actual DRAM traffic remain different quantities.
Neighboring lanes, neighboring addresses
If adjacent lanes request nearby addresses, hardware can service them with fewer memory sectors. Change the address stride before predicting how much useful data each sector carries.
Stride is the distance between neighboring lanes’ addresses, measured here in 4-byte elements: stride 1 steps 4 bytes, stride 8 steps 32 bytes. A sector is a 32-byte address region in this teaching model: bytes 0–31, then 32–63, and so on.
Alignment describes where the first address falls relative to a sector boundary. Starting byte offset 0 begins on a boundary; offset 4 begins four bytes later. Coalescing means combining a warp’s nearby memory requests into fewer transactions. Here we count touched sectors, not measured DRAM traffic.
Walk through lane addresses → memory sectors — reveal which requests share a sector before counting bytes.
Inspect a warp’s memory requests
Toy transaction model: 32 lanes each load one distinct 4-byte number; 32-byte aligned sectors, no cache reuse. Stride 1 from byte 0 touches 4 sectors (128 bytes); stride 8 touches 32 sectors (1,024 bytes) for the same 128 useful bytes. Teaching numbers, not measurements.
Predict: Contiguous loads start 4 bytes past a sector boundary. Still exactly 4 sectors?
Reusing bytes takes coordination
Several threads can reuse an operand loaded into shared memory. They must wait until the cooperative loads finish, then wait again before overwriting a tile still in use. Faster memory without correct synchronization is a race, not an optimization.
A tile is a small portion of a matrix loaded for reuse. A block barrier is a synchronization point: participating threads wait until the block has reached it and prior shared-memory writes are available to them. This makes a cooperative load safe to reuse. It coordinates threads within a block, not separate blocks.
Ordinary block barriers must be reached by all participating threads consistently. Guard out-of-range loads and stores, not the barrier itself. Separate blocks cannot use an ordinary block barrier to communicate.
Capacity, traffic, bandwidth, latency
Capacity uses bytes; bandwidth uses bytes/second; latency uses seconds per dependent access. A 1 GiB tensor read ten times can create about 10 GiB of logical reads while occupying only 1 GiB. Hardware caches may reduce HBM reads. Shared-memory reuse can reduce global-load demand while consuming scarce on-chip storage. Lower HBM traffic does not guarantee lower time when another resource becomes limiting.
Model boundaries
Cache and DRAM paths. Not every instruction uses every cache, and a store does not imply an immediate HBM write. Exact cache paths and capacities vary by architecture. A software KV cache need not fit in hardware L2. Apple unified memory changes the physical organization; the capacity/traffic distinctions still help, while CUDA block and warp details do not transfer verbatim.
Spills and banks. Excess register demand can spill into thread-local memory backed by device memory. Shared-memory bank conflicts (competing accesses to the same storage bank) and synchronization affect access cost.
Sector counts. The coalescing explorer counts distinct 32-byte sectors touched by one warp instruction. It does not predict HBM transactions, cache hit rate, latency or speedup. Real transaction rules depend on instruction width, alignment and GPU architecture. Stride is measured in elements, not bytes; the requested addresses stay distinct in this example.
Next: count exactly what a tiled matrix product reuses.