Dive into Deep Learning · §13.2
Hardware Anatomy: CPUs, GPUs, Tensor Cores, and Memory Hierarchy
memory hierarchy · wire count & shoreline · sector access · SMs & Tensor Cores · PCIe & NVLink · decode sweep time
Motivation
bf16 weights from GDDR6X at 0.9\text{ TB/s} takes 2.2\text{ ms}—nearly 200\times longer.Memory Hierarchy
Physical Bandwidth
Access Latency
Access Patterns
GPU DRAM achieves its rated bandwidth \beta only on sequential, coalesced addresses. Below, we gather a 1\text{ GiB} float32 array x[idx] using an identity permutation versus a random permutation:
identity: 4.8 ms, 0.90 TB/s at 16 B/element
random : 37.4 ms, 0.32 TB/s at 44 B/element
random / identity: 7.8x
Why random gathers lose 8\text{--}10\times in speed: Memory transactions fetch 32-byte sectors (wasting 28 of 32\text{ B} per random 4-byte read), and random addresses repeatedly miss open kilobyte-scale DRAM rows and address-translation caches.
Hockney Transfer Model
t(n) \;=\; \alpha + \frac{n}{\beta}, \qquad \beta_{\textrm{eff}}(n) \;=\; \frac{\beta}{1 + \alpha\beta / n}
Silicon Geometry
Hardware Trends
Power & Energy
fp32 multiply costs 3.7\text{ pJ}, whereas reading 64\text{ bits} from off-chip DRAM costs 1.3\text{--}2.6\text{ nJ}—roughly 500 fp32 multiplications.GPU Execution Model
\textrm{Bytes in flight} \;=\; \beta \times \textrm{latency} \;\approx\; 250\textrm{ KB}
Tensor Cores
P_{\textrm{fp32}} \;=\; 128 \times 128 \times 2 \times 2.52\textrm{ GHz} \;\approx\; 82.6\textrm{ TFLOP/s}
fp32 accumulation.tf32 reaches 82.6\text{ TFLOP/s} (1\times), bf16/fp16 doubles to 165.2\text{ TFLOP/s} (2\times), and fp8 quadruples to 330.4\text{ TFLOP/s} (4\times).Number Formats
bfloat16 replaced float16 for training: fp32, tf32, and bf16 all share an 8-bit exponent (dynamic range \sim 10^{\pm 38}), so bf16 requires no loss scaling.tf32, which is stored as 32-bit fp32 in DRAM) both halves memory bytes moved and doubles Tensor Core P. Sub-8-bit formats (fp8, fp4) require per-tensor or per-block (16–32 element) microscaling.Accelerator Comparison
Comparing two flagship data-center GPUs against two consumer cards highlights where consumer cards trade off capacity, bandwidth, and multi-GPU interconnects:
| Specification | H100 SXM | B200 | RTX 4090 (Ours) | RTX 5090 |
|---|---|---|---|---|
| Memory Capacity (C) | 80\text{ GB HBM3} | 180\text{ GB HBM3e} | 24\text{ GB GDDR6X} | 32\text{ GB GDDR7} |
| Memory Bandwidth (\beta) | 3.35\text{ TB/s} | 8.0\text{ TB/s} | 1.01\text{ TB/s} | 1.79\text{ TB/s} |
bfloat16 Tensor Core (P) |
989\text{ TFLOP/s} | 2{,}250\text{ TFLOP/s} | 165.2\text{ TFLOP/s} | 209.5\text{ TFLOP/s} |
fp8 / fp4 Tensor Core |
1{,}979 / — | 4{,}500 / 9{,}000 | 330.4 / — | 419 / 1{,}676 |
Ridge Point (I^*, bf16) |
295\text{ FLOP/B} | 281\text{ FLOP/B} | 164\text{ FLOP/B} | 117\text{ FLOP/B} |
| Inter-GPU Link (1-way) | NVLink 4 (450\text{ GB/s}) | NVLink 5 (900\text{ GB/s}) | PCIe 4.0 (\le 32\text{ GB/s}) | PCIe 5.0 (\le 64\text{ GB/s}) |
Host Data Paths
The GPU’s DMA copy engines can stream minibatches over PCIe concurrently with SM execution only if the source buffer resides in page-locked (pinned) host RAM:
pageable: 14.2 GB/s
pinned: 23.1 GB/s
pin_memory=True / 'pinned_host') and copy asynchronously (non_blocking=True).Multi-GPU Topology
nvidia-smi topo shows, every byte exchanged between GPUs on our workstation travels up one PCIe 4.0 \times 16 link, through host DRAM, and down another (\le 23\text{ GB/s}, nearly 40\times slower than NVLink 5’s 900\text{ GB/s}).fp32 gradients): One gradient transfer takes \ge 0.17\text{ s} over host-staged PCIe vs. < 5\text{ ms} over NVLink 5.Workload Analysis
Autoregressive language model serving splits into two distinct roofline regimes for a model of N parameters stored in bfloat16 (2N bytes):
\textrm{Prefill ($n$ prompt tokens): } I \approx n \;\textrm{(compute-bound)}, \qquad \textrm{Decode ($1$ token): } I \approx 1 \;\textrm{(bandwidth-bound)}
Capacity & Sweep Time
Check Your Understanding
Work out the following hardware estimates on the RTX 4090 (\beta_{\textrm{achieved}} \approx 0.9\text{ TB/s}, bf16 peak P = 165\text{ TFLOP/s}, fp8 peak 330\text{ TFLOP/s}, ridge I^* = 164\text{ FLOP/byte}):
bfloat16 to fp8 for (a) an elementwise kernel at I = 0.25\text{ FLOP/B} and (b) a large matmul at I = 1{,}000\text{ FLOP/B}. What speedup does each get, and why does neither get 4\times?bfloat16 (16\text{ GB} of weights, KV cache neglected) runs on the RTX 4090. What is the maximum token throughput for 1 stream (B = 1) and across 64 concurrent streams (B = 64)?Answers:
Key Takeaways
| Hardware Principle / Metric | Rule / Formula | RTX 4090 / Workstation | Practical Systems Consequence |
|---|---|---|---|
| Wire Bandwidth Law | \beta = \textrm{wires} \times \textrm{rate/wire} | 1.0\text{ TB/s} DRAM vs. 23\text{ GB/s} PCIe | Each hop off-die cuts wire count and bandwidth by \sim 10\text{--}40\times |
| Shoreline & Energy | Compute \propto L^2, I/O \propto L | 1\text{ DRAM read} \approx 500\text{ FLOPs} | Ridge points (117\text{--}295\text{ FLOP/B}) rise across generations |
| Sector & Row Access | t(n) = \alpha + n/\beta, 32-B sectors | Random gather \sim 10\times slower | Coalesce memory reads; shuffle disk data in \ge 1\text{ MB} blocks |
| Little’s Law (SMs) | \textrm{In-flight} = \beta \times \textrm{latency} | \approx 250\text{ KB} (128 SMs) | Kernels must expose enough warps to hide 250\text{ ns} DRAM latency |
| Precision Narrowing | \textrm{Bytes} \div 2, Tensor Core P \times 2 | tf32 83\text{ TF/s} \to bf16 165\text{ TF/s} |
Speeds up both bandwidth-bound and compute-bound kernels |
| Decode & Sweep Time | \textrm{tok/s} \lesssim \beta / (2N + \textrm{KV}) | C/\beta \approx 24\text{ ms} (\sim 42\text{ tok/s} full) | Single-stream decode is memory-bound; batching raises I \approx B |