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

Warmup and correct device timingFLOP, byte and launch accountingProfiler evidence for bottleneck classification
1

Read

In this order, only the parts listed

0 of 3 done

  1. 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 plus torch.cuda.synchronize after each step; Section 2.1.4 with Problem (nsys_profile) (pp. 4 to 6): GPU Kernel Summary and NVTX ranges

    Use the timing idiom and the profiler problem here; leave the full-model sweep for the baseline section.

  2. Benchmark idiom and the FLOP/byte ledgerAI Systems Performance Engineering companion code - Chapter 18

    benchmark_attention in flex_attention_native.py (warmup loop, device synchronize, one Event pair around the timed loop reported as a mean per call) and compute_paged_attention_metrics in paged_attn_common.py (FLOP, byte and roofline ledger)

    One event pair yields a mean; record per-iteration events yourself to report medians with spread.

  3. 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.

2

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.
3

Try it yourself

Closed-book, before checking anything

Closed-book, derive the ledger for 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.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 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. 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. 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. 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