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.

01

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.

Latency Hiding: CPU Core vs GPU Warp Scheduler
ALU BUSY: 92%
Cycle 12 / 12 Issued ops: 11
Active ALU Compute Waiting on HBM Memory Ready (Queued)
When Warp 0 stalls waiting for HBM memory, the GPU scheduler switches to Warp 1, 2, or 3 in zero cycles, keeping the math units fed.
02

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.

GPU Memory Pyramid & SRAM Tiling (H100 SXM)
SRAM-TILED KERNEL
ON-CHIP · FASTEST

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.

Capacity 256 KB / SM
Bandwidth >100 TB/s
Access Cost ~1 cycle
Kernel Strategy (4096×4096 FP16 MatMul)
HBM Traffic
0.20 GB
Est. Speed
14.2× faster
03

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 (D=A×B+CD = A \times B + C) 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 II:

Throughput≤min⁡ ⁣(Peak FLOPs,  I×HBM Bandwidth)\text{Throughput} \le \min\!\Big(\text{Peak FLOPs},\; I \times \text{HBM Bandwidth}\Big)

On an H100 in FP16, the ridge point sits at 989/3.35≈295 FLOPs/byte989 / 3.35 \approx 295\text{ FLOPs/byte}. 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 (I≈1I \approx 1), trapping it on the memory-bandwidth slope .

H100 SXM Roofline & Arithmetic Intensity Explorer
MEMORY-BOUND
Ridge: 295 FLOPs/B Achieved TFLOPS (log scale) Arithmetic Intensity (FLOPs / Byte, log scale) Compute Ceiling: 989 TFLOPS HBM3 Slope (3.35 TB/s)
Arithmetic Intensity 1.0 FLOPs/B
Achieved Throughput 3.4 TFLOPS
Tensor Core Utilization 0.3%
At batch = 1, every weight byte read from HBM performs only 1 multiply-add. The Tensor Cores sit 99.7% idle waiting for the memory bus.
04

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 / else split inside a warp forces the SM to run the if branch while half the lanes sit masked off, then run the else branch 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.