Inside a GPU: Warps, Tensor Cores, and the Memory Hierarchy
How a GPU hides 400-cycle memory stalls with zero-cost warp switching, why on-chip SRAM beats HBM3 by 10×, and how the roofline model explains why AI workloads starve or saturate Tensor Cores.
CPUs chase low latency; GPUs chase total throughput
A modern CPU dedicates most of its silicon to making a single thread finish fast: huge L1/L2/L3 caches, deep branch predictors, and out-of-order execution engines. A GPU makes the opposite bet. It strips away speculative control logic and packs over a hundred Streaming Multiprocessors (SMs) onto one die.
Each SM executes threads in lockstep bundles of 32 called a warp . Instead of building giant caches to avoid memory stalls, the SM keeps dozens of warps resident in its register file at once. The moment Warp 0 stalls waiting on HBM memory, the warp scheduler swaps in Warp 1 on the very next clock cycle with zero context-switch overhead.
Math is cheap; moving bytes from HBM is expensive
An H100 GPU holds 80 GB of HBM3 memory , which stores model weights and the KV cache . Yet HBM3 is still roughly 10× slower than the tiny 33 MB of on-chip L1 and Shared SRAM sitting next to the compute units.
Fast GPU kernels are built around this gap. Rather than reading an entire attention matrix from HBM, computing softmax, and writing it back to HBM, algorithms like FlashAttention pull small tiles into SRAM, finish the entire fused calculation on-chip, and write only the final result once.
Register File
Private per-thread storage sitting right next to the ALUs and Tensor Cores. Holds active accumulators during matrix multiply-accumulate instructions with zero wait states.
Tensor Cores and the arithmetic intensity roofline
Every layer of self-attention and every feed-forward block boils down to matrix multiplication. Standard CUDA cores multiply one pair of scalars per clock. Tensor Cores are dedicated systolic arrays that execute an entire matrix multiply-accumulate () in a single instruction, pushing an H100 to 989 TFLOPS in FP16 and 1,979 TFLOPS in FP8.
Whether a kernel actually hits that peak depends on its arithmetic intensity :
On an H100 in FP16, the ridge point sits at . During prompt prefill, thousands of tokens multiply against the same weights in parallel, easily clearing the ridge point. During single-token decode, the GPU streams every weight for one token (), trapping it on the memory-bandwidth slope .
Three hardware gotchas that silently halve GPU speed
Even when your math fits in memory, three microarchitectural traps can stall an otherwise clean kernel:
Warp divergence: Because all 32 threads in a warp share one instruction stream, an
if / elsesplit inside a warp forces the SM to run theifbranch while half the lanes sit masked off, then run theelsebranch afterward.Uncoalesced HBM loads: Memory controllers fetch 128-byte cache lines. When adjacent threads in a warp read contiguous addresses, one transaction feeds all 32 threads. Strided or random pointers trigger up to 32 separate transactions and waste 90% of HBM bandwidth.
Register spilling and low occupancy: If each thread hoards too many registers or shared memory, fewer warps fit on an SM. With too few active warps, the scheduler runs out of ready work to hide 400-cycle HBM stalls.
Practical takeaway: Before buying faster compute, check which side of the roofline you are on. Memory-bound kernels (like low-batch decoding) speed up from quantization (FP8/INT4), larger batches, or operator fusion in SRAM rather than more TFLOPS.