Computational Performance

Dive into Deep Learning · §13

Computational Performance: Roofline Models, Hardware, Compilers, and Multi-GPU Scaling
arithmetic intensity · roofline & dispatch bounds · memory & precision · fusion & CUDA graphs · collectives & FSDP

Four Bottlenecks Govern Training Time and Capacity

The Central Problem

  • Compute (P) vs. Bandwidth (\beta): Large 8192^2 bf16 GEMMs saturate Tensor Cores near 165\text{ TFLOP/s}, while elementwise adds (I = 0.25) stall at 0.25\text{ TFLOP/s}.
  • Host Dispatch (h): Launching eager kernels from Python costs 10\text{--}100\,\mu\text{s} per op, leaving the GPU idle between microsecond calls.
  • Memory Capacity (C): A 1B GPT with fp32 Adam consumes 16N \approx 15.1\text{ GiB} of a 24\text{ GiB} card before storing a single token’s activations.

The Three-Floor Time Model and the Roofline Ridge

Unifying Analytical Model

t \;\gtrsim\; \max\!\left(h,\; \frac{\textrm{FLOPs}}{P},\; \frac{\textrm{bytes}}{\beta}\right)

  • Arithmetic Intensity (I = \textrm{FLOPs}/\textrm{bytes}): Counts operations performed per byte moved between off-chip DRAM and on-chip registers/SRAM.
  • The Ridge Point (I^* = P/\beta): Where the bandwidth roof I\beta meets the compute roof P (I^* \approx 164\text{ FLOP/B} in bf16 on RTX 4090; \sim 295 on H100).
  • Multi-GPU Scaling: Distributing across k GPUs adds collective latency and transfer time \alpha + \frac{2(k-1)}{k}S\beta_{\textrm{link}}.

Five Hardware Constants Characterize Our Benchmark Host

Reference Machine

  • Compute & Bandwidth (P, \beta, I^*): Four 24\text{ GiB} RTX 4090s deliver P = 165.2\text{ TFLOP/s} (bf16) and \beta = 1.01\text{ TB/s} DRAM bandwidth (I^* \approx 164\text{ FLOP/B}).
  • Host Launch (h): Single-op dispatch costs \sim 13\,\mu\text{s}.
  • Inter-GPU Link (\beta_{\textrm{link}}): Host-staged PCIe 4.0 allreduces run at \sim 2.4\text{ GB/s} bus bandwidth (0.42\text{ ns/B}).

Architectural Roadmap of Chapter 13

Chapter Structure

  • §13.1–13.2 Roofline & Hardware: Arithmetic intensity, synchronized timing, memory hierarchy, SMs, Tensor Cores, and the 20\text{ ms} sweep invariant.
  • §13.3–13.4 Compilers & Memory: Symbolic tracing, operator fusion (9\times), CUDA graphs, 16N Adam state, bf16, rematerialization, and accumulation.
  • §13.5–13.8 Multi-GPU & Case Study: Ring allreduce, DDP bucketing, ZeRO/FSDP sharding, and a 6\times step-by-step GPT speedup.

How to Study This Chapter

Study Guide

  • Always predict before measuring: Before running any benchmark cell, write down the FLOPs, bytes moved, and predicted floor \max(h, \textrm{FLOPs}/P, \textrm{bytes}/\beta). When a measurement disagrees with your paper estimate, the discrepancy reveals an uncounted memory transfer, hidden host barrier, or SM contention.
  • Verify numerical equivalence first: An optimization that silently alters gradients, batch-norm statistics, or causal masking is a bug, not a speedup. Every section pairs timing benchmarks with one-step gradient checks (allclose) and end-to-end validation loss gates.

Up next (§13.1 The Performance Model): Defining arithmetic intensity, constructing the roofline bound, avoiding asynchronous timing traps, and profiling a complete MLP training step.