Memory Hierarchy

The memory hierarchy explains why the same algorithm can be fast or slow depending on where its working set lives. Small memory close to compute is fast. Large memory far from compute is slower.

Approximate public mental model:

Exact values vary by CPU, GPU, memory generation, interconnect, workload, and access pattern. Use the table for order of magnitude, not as a benchmark claim.

Latency and Capacity Ladder

LayerTypical RoleRough Latency ClassCapacity ClassMain Failure Mode
CPU registercurrent scalar/vector operandssub-nsbytes to KB per coretoo little reuse in tight loops
L1 cachehottest CPU data/instructionsabout 1 nstens of KB per corerandom access misses
L2 cacheper-core working setfew nshundreds of KB to MB per coreworking set too large
L3 cacheshared CPU cachetens of nsMB to tens of MBcross-core contention
CPU RAM / DRAMhost tensors, dataloader buffers, OS page cachetens to hundreds of nsGB to TBbandwidth or capacity pressure
GPU SRAM / shared memoryon-chip tile reuse inside kernelsvery lowKB to MB per SM/blockpoor tiling or occupancy
GPU VRAM / HBMmodel weights, activations, KV cachehundreds of ns class, very high bandwidthGB to tens of GB per GPUOOM, bandwidth-bound kernels
NVMe SSDlocal dataset cache, checkpointsmicroseconds to millisecondsTBsmall-file metadata and queue depth
Network storageshared datasets, artifacts, checkpointsmilliseconds classTB to PBcontention, metadata, mount issues
Remote serviceobject store, API, databasemilliseconds to secondselasticnetwork latency and request limits

Bandwidth Ladder

Latency is delay for one access. Bandwidth is how much data can move per second once transfer is underway.

PathUseful ForBottleneck Pattern
CPU cache to coretight loops, preprocessing, tokenizationcache miss rate
DRAM to CPUdataloading, decompression, preprocessingmemory bandwidth saturation
CPU RAM to GPU VRAMhost-device transferPCIe or interconnect copy time
GPU HBM to tensor corestraining/inference kernelsmemory-bound kernels
GPU to GPUdistributed training, tensor parallelismall-reduce or peer-copy overhead
SSD to CPU RAMdataset cache, checkpoint load/savesmall files, queue depth, compression
network storage to nodeshared dataset or outputmetadata storms, shared bandwidth

Why This Matters for AI

Modern AI workloads are often limited by data movement:

If is small but the rest is large, adding a faster GPU may not help.

Common Diagnoses

SymptomCheck
CPU preprocessing is slowcache locality, vectorization, batch size, process count
GPU is idle between batchesdataloader timing, CPU RAM, storage path, host-device copy
OOM during trainingparameters, activations, gradients, optimizer state, temporary buffers
OOM during LLM inferenceweights plus KV cache, context length, concurrency, precision
checkpoint save stalls joblocal vs network storage, checkpoint size, save frequency
distributed training slows downGPU-GPU interconnect, all-reduce size, batch size, topology

Checks

  • What data must be reused in the innermost loop?
  • Does the working set fit in cache, RAM, VRAM, or only disk?
  • Is the workload latency-bound, bandwidth-bound, compute-bound, or capacity-bound?
  • Is the measured bottleneck local to one node, or caused by shared network/storage?
  • Is a cache, memory format, batch size, precision, or checkpoint interval the simplest fix?