Unit 11 of 12 · about 4 hours · derive, measure
Device timing, FLOP, byte and launch accounting, and profiler classification
Timed boundaries, asynchronous launch and event timing and Warp stalls, resource evidence and bottleneck classification taught generic timing and classification. Serving adds phase-shaped inputs, short-decode launch pressure and machine-state controls that decide whether a rerun reproduces.
You'll be able to
- Time a serving kernel with warmup, device synchronization and repeated trials, reporting medians with the exact timed boundary.
- Derive FLOP, byte and launch counts for the measured shape and place the point against stated ceilings without calling position a bottleneck.
- Confirm or reject the predicted regime with profiler evidence: kernel summaries, NVTX ranges and the counters your GPU exposes.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Warmup, synchronization and profiler problemsCS336 Assignment 2 - FlashAttention and Triton Sections
Section 2.1.3 with Problem (
benchmarking_script) (pp. 3 to 4): warmup steps plustorch.cuda.synchronizeafter each step; Section 2.1.4 with Problem (nsys_profile) (pp. 4 to 6): GPU Kernel Summary and NVTX rangesUse the timing idiom and the profiler problem here; leave the full-model sweep for the baseline section.
- Benchmark idiom and the FLOP/byte ledgerAI Systems Performance Engineering companion code - Chapter 18
benchmark_attentioninflex_attention_native.py(warmup loop, device synchronize, oneEventpair around the timed loop reported as a mean per call) andcompute_paged_attention_metricsinpaged_attn_common.py(FLOP, byte and roofline ledger)One event pair yields a mean; record per-iteration events yourself to report medians with spread.
- Machine state and benchmark methodTensorRT-LLM Architecture Overview
TensorRT LLM Benchmarking: Before Benchmarking (persistence mode, clock reset, power limits) and Throughput Benchmarking (page read 2026-10-14)
Apply the machine-state controls or label the run uncontrolled. Leave dataset preparation and LoRA sections for later.
Focus on
- Declare the timed boundary first: kernel, operator, step or request. Warmup must cover capture and autotune caches; the first iteration after a shape change measures a different regime.
- Report medians over repeated synchronized trials, with spread. Best-of hides the launch-supply variance that serving pays every step.
- Separate useful work from executed work. Padded buckets, masked lanes and reloaded tiles execute without serving; label modeled traffic as modeled and measure DRAM only with counters.
- Pin machine state or label the run uncontrolled. A drifting clock moves every ceiling the point is plotted against.
Common mistakes · 3
- Timing the enqueue call and reporting it as kernel time. Record events around the work and synchronize before reading.
- Comparing a replay median with an eager median taken under different warmup or synchronization. Interleave the two series instead.
- Placing a modeled-bytes point and reading the bottleneck off its position. Position proposes; stall and counter evidence dispose.
Try it yourself
Closed-book, before checking anything
y = torch.relu(x @ weight + bias) with input shape [8, 64], weight shape [64, 64], bias shape [64] and torch.float32 storage. Counting a multiply-add as two gives 65,536 dense-product FLOPs. Reading inputs, weights and bias once and writing output once gives 20,736 ideal bytes, about 3.2 FLOP/byte; materializing the matmul output before a fused bias and ReLU stage adds 4,096 bytes (24,832, about 2.6 FLOP/byte). These exclude activation arithmetic, reloads and cache effects. Generate standard-normal inputs with seed 0. On your GPU, run 20 warmup and 200 completed event-timed trials, validate against a CPU double-precision reference with a predeclared tolerance, and report the median with spread. Predict launch sensitivity, then confirm or reject it with a timeline rather than declaring this shape launch-bound.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Why warm up 20 before timing 200?Answer
Warmup separates first-use setup from repeated execution. Twenty is an illustrative count, not proof of stable caches or clocks; inspect convergence and extend warmup if needed.
2.Median or best-of for the report?Answer
Median with spread. Best-of hides the variance serving pays; a tail-sensitive SLO needs the distribution.
3.The point sits below the bandwidth ceiling. Is it bandwidth-bound?Answer
Not established. Launch, occupancy or latency can dominate below the ceiling. Test with a launch-scaling sweep or stall evidence.
4.Clocks drift mid-sweep. What breaks?Answer
Ceilings move, so reruns stop reproducing. Pin machine state per the benchmarking page or label the run uncontrolled.
You're done when
Your ledger states the predicted regime before you profile, the timeline confirms or rejects it, timings cover completed work and report spread, and a rerun under recorded machine state falls within that spread.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 11 more in the section
- AI Systems Performance Engineering companion code - Chapter 18Chris Fregly · required
Start with paged_attn_common.py, the dense versus paged layout pair, CUDA graph bucketing and the vLLM integration pair. Run correctness tests first, then a hardware-compatible benchmark with newly captured artifacts.
- CS336 Assignment 2 - FlashAttention and Triton SectionsStanford University · required
Complete the relevant derivation, PyTorch reference and Triton sections using your own code. Follow assignment integrity: use external help for concepts, invariants, tests and profiling, not copied solutions or edited answer code.
- TensorRT-LLM Architecture OverviewNVIDIA · support
Use the runtime-optimization section to compare graph replay, overlap scheduling and backend dispatch with your selected engine. Record current version and hardware support before treating a path as available.
Also in this section
- FlashInfer: Efficient and Customizable Attention Engine for LLM Inference ServingFlashInfer Project · primary
Read the storage heterogeneity, plan and run separation, load-balanced scheduling, customization, CUDA Graph compatibility and end-to-end evaluation. Use it to connect serving-shaped attention kernels to dynamic workloads and dispatch constraints.
- AI Systems Performance Engineering - Chapters 18 and 19, decode kernels and engine optimizationsChris Fregly (O'Reilly) · required
Read "Optimized Decode Kernels" in Chapter 18 (FlashMLA, ThunderMLA, FlexDecoding), then the Chapter 19 sections on kernel autotuning, occupancy-aware kernel selection, hot-swappable kernels and CUDA-graph prewarming. Choose one bounded critical path to verify.
- FlashAttention-2: Faster Attention with Better Parallelism and Work PartitioningTri Dao · required
Derive online-softmax state, memory traffic and work partitioning. Implement only a small oracle-backed version or use the CS336 assignment; production kernel tuning belongs to the GPU track.
- FlashInfer DocumentationFlashInfer Project · required
Use the current attention, PageAttention, sampling, JIT and CUDA Graph interfaces while implementing. Pin the version and supported GPU architecture, and validate dispatch and fallback over the real workload shape distribution.
- Mini-SGLang - Kernel, Model Runner and Overlap BoundariesSGLang Project · support
Trace how FlashAttention or FlashInfer, KV layouts, tensor parallel communication and overlap scheduling meet the model runner. Identify the fallback and state-reset boundary before attempting a change.
- UCSD CSE 291A (Spring 2026) - Guest lecture: Engineering vLLMUC San Diego · support
Read the scribe notes, Sections 4 and 5: CPU overhead, the API server and renderer, synchronous and asynchronous engine-core scheduling, GPU-side input preparation, piecewise CUDA graphs and the hybrid kernel strategy.
- vLLM CUDA Graphs design (v0.31.0)vLLM Project · support
Use the capture modes, batch-size buckets and piecewise splitting around attention to explain what a graph replay can and cannot include.
- LLM Inference: From scratch, one token at a time - Module 07Tushar Amrit · support
Work the Attention Kernels module for the decode-attention memory traffic and the paged-attention gather before the matching units.
- AI Performance Engineering - Kernel Optimization, Profiling and AttentionWafer · reference
A curated index. Use Sections 2 and 3 only to find a kernel or profiler source the other entries lack.
- vLLM structured outputs (v0.31.0)vLLM Project · required
Read Offline Inference and the API-field migration warning; trace grammar bitmask application before sampling in the versioned model-runner API.
- PyTorch compiler troubleshooting guide (2.14)PyTorch · reference
Read Graph break, Guards, Recompilation and Dynamic Shapes; run
TORCH_LOGSset tograph_breaksandrecompileson a small serving-shaped function.