Performance Engineering Practice
Turn measurements into reproducible explanations and bounded engineering decisions
Build a versioned experiment record, follow one quantity across model and system layers, write a causal report, scope a finishable capstone, and evaluate new systems without losing workload context.
An engineer changes a normalization operation in the recurring 7-billion-parameter inference service, which runs on one 80 GiB graphics processing unit (GPU). A local CUDA-event benchmark reports a 22-microsecond improvement, but the weekly report contains no tensor shape, raw samples, correctness result, source revision, or end-to-end request measurement. Three months later, nobody can determine whether a compiler update removed the gain or whether the original comparison timed different work.
Chapter 21 turns an optimization attempt into a reproducible experiment. A laboratory record names the question, predicts a mechanism, captures the environment, stores raw timing samples, and links a separate profiler report to the ordinary benchmark. The chapter follows learned weights through general matrix multiplication (GEMM), retained attention data through the key-value (KV) cache, and host preparation on the central processing unit (CPU). High-bandwidth memory (HBM) names the large off-chip memory attached to each GPU whenever the experiment counts device-memory traffic.
The chapter also connects local results to user-visible measures. Time to first token (TTFT) runs from a declared request-entry timestamp to delivery of the first generated token. Time per output token (TPOT) measures the cadence of later generated tokens for an active request. A faster GPU program matters to the inference service only when the experiment shows how the changed interval affects TTFT, TPOT, capacity, cost, or another declared objective.
Every practice section produces artifacts that another engineer can inspect: a versioned experiment record, a cross-layer representation table, a causal report, a bounded capstone proposal, or a version-aware reproduction note. The artifacts preserve failed hypotheses and limitations as carefully as the fastest result because future decisions depend on knowing where the evidence stops.
Prerequisites
- Chapters 0–20, or documented proficiency in their prerequisites
- One completed correctness and performance investigation
- Version control, command-line tools, and basic data plotting
Learning objectives
- Create a reproducible experiment record from a prewritten prediction through archived raw evidence
- Follow one declared quantity through model semantics, software representation, GPU execution, and an end-to-end metric
- Write a causal performance report and a bounded capstone proposal with explicit limits and stop conditions
Study this chapter
- 21.1Reproducible performance experimentsBegin lesson →
Produce an experiment record that another engineer can inspect, run, and compare after a software or hardware change
- 21.2Cross-layer performance analysisBegin lesson →
Trace one named quantity with stable units from model semantics to an end-to-end service or training metric
- 21.3Performance report structureBegin lesson →
Write a report that labels direct measurement, causal inference, model-based extrapolation, and unresolved assumptions
- 21.4Capstone projectsBegin lesson →
Write and execute a capstone proposal whose evidence milestones and stop conditions fit the available hardware and schedule
- 21.5Continued technical studyBegin lesson →
Evaluate a new system with versioned primary sources, a fixed comparison contract, and the smallest experiment that distinguishes its claimed mechanism
Extended exercises
Complete these projects after the lesson-level practice tasks. Each project combines several mechanisms from the chapter.
Audit one causal claim
Choose one past optimization report and label every technical claim as direct measurement, calculation, inference, extrapolation, source-supported fact, or unresolved assumption.
Evidence: A revised one-page report that links each measured claim to raw evidence and names the smallest experiment needed for every consequential gap.
Design a cross-layer investigation
Follow one quantity such as key-value bytes per retained token through at least four layers. Fix one recurring workload and predict the observation at each interface before measuring it.
Evidence: A representation table, staged experiment plan, unit-consistent calculations, named tools, falsifiable predictions, and explicit boundary between measured and simulated scale.
Write a capstone proposal
Propose a project that adds one new integration task to a measurement workflow you have already completed. For example, add PyTorch operator registration to a verified CUDA kernel or add one collective communication operation to a measured single-GPU training step. Define decisive evidence and numerical stop conditions before implementation.
Evidence: Objective, workload, baseline, model, correctness contract, measurements, primary sources, hardware cost, milestones, stop conditions, reproducibility package, and publication plan.
Sources and further reading
The lesson explanations synthesize primary papers and official references. Follow the originals for proofs, exact APIs, architecture details, and version-sensitive behavior.
- The Rust Programming Language↗
Structural inspiration: progressive chapters, concrete examples, and explicit learning flow.
- CUDA C++ Best Practices Guide↗
- Nsight Compute Profiling Guide↗
- MLPerf Inference Rules↗
- torch.compile Programming Model↗
- PagedAttention / vLLM↗