Unit 6 of 12 · about 4 hours · explain, measure

Device synchronization, warmup, compilation and cold versus warm state

Asynchronous launch makes naive timers measure submission, not execution. Every timing in this section stands or falls on synchronization and warm state.

You'll be able to

  • Explain why host timers need device synchronization and what stream-ordered event semantics guarantee.
  • Separate warmup, compilation and graph-capture state from steady-state timing.
  • Design a cold-versus-warm comparison that fixes model, cache and workload state.

Covers

Device synchronization and CUDA event semanticsWarmup, compilation and graph-capture stateCold versus warm model and cache state
1

Read

In this order, only the parts listed

0 of 3 done

  1. Event and stream semantics with phase rangesAI Systems Performance Engineering - Chapter 16, profiling and debugging inference

    Profiling with Nsight Systems and Nsight Compute (pp. 969 to 973): per-stream naming, NVTX Prefill and Decode step ranges, and the tightest scope around encode

  2. Machine-state control before any timingTensorRT-LLM Benchmarking Guide

    Before Benchmarking: persistence mode with sudo nvidia-smi -pm 1, clock reset with sudo nvidia-smi -rgc, power limits and boost settings (page read 2026-10-05)

  3. Cache-state control for latency runsvLLM Benchmark CLI (v0.31.0)

    Online Benchmark warning on prefix-cache reuse across repeated runs, with varying the seed, restarting the server or resetting caches between runs

2

Focus on

  • Treat the Timed boundaries, asynchronous launch and event timing unit and the Warmup, compilation, allocator and cache state unit as read. This unit applies them to serving runs.
  • Kernel launches return before the work finishes. A host timer without synchronization measures queueing into the driver, and only stream-ordered events or a synchronize call bracket the device work.
  • First runs include compilation, graph capture, allocator setup and cold caches. Warm every shape you will time, then discard the warmup before recording.
  • Cold versus warm is a comparison of stated states: weights resident or not, compilation and graphs captured or not, allocator settled or not, prefix cache empty or populated, clocks settled or not. Name all five before quoting either number.
Common mistakes · 3
  • Timing a range that includes the first-ever request and calling it the baseline. Compilation and capture dominate it; it is a startup measurement, not a serving one.
  • Reusing prompts across repeated latency runs with prefix caching on. Later runs hit the cache and look faster without any real change.
  • Comparing a cold run at settled clocks with a warm run after thermal throttling started. Clocks and temperature are part of the state; record both.
3

Try it yourself

Closed-book, before checking anything

Closed-book, list the five warm states that a first vLLM request passes through before steady state, and write the synchronized timing pattern that brackets one decode step without including queue submission.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Why does an unsynchronized host timer under-report GPU work?Answer

    Launches are asynchronous, so the timer stops at submission. The device work continues after the host proceeds.

  2. 2.What does a stream-ordered event pair guarantee that a host timer does not?Answer

    It timestamps when the stream reaches each event on the device, so the interval covers the device work enqueued between them, not the host's submission time. It still includes idle gaps if the host enqueues slowly, and other streams can slow the work it brackets.

  3. 3.Which states must a warmup cover before a latency baseline?Answer

    Model weights resident, compilation and graph capture done, allocator settled, caches at their declared state, and clocks settled. Time only after all of them.

  4. 4.Two latency runs differ only in that the second reuses the first run's prompts. What explains a faster second run?Answer

    Prefix-cache hits from the first run's KV blocks, not faster execution. Vary the seed or reset the server for a clean comparison.

5

Practice

You're done when

Your warmed timings are stable across repeats, your cold-versus-warm gap names its five states, and no first-run artifact remains in the baseline.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 9 more in the section
  • AI Systems Performance Engineering - Chapter 16, profiling and debugging inferenceChris Fregly (O'Reilly) · required

    Read the first part of Chapter 16: monitoring system metrics, profiling with Nsight Systems and Nsight Compute, the troubleshooting recipes and debugging correctness. Treat every quoted speedup as a hypothesis for your own hardware.

  • vLLM Benchmark CLI (v0.31.0)vLLM Project · required

    Use vllm bench latency, vllm bench throughput and vllm bench serve for phase and endpoint baselines. Fix the dataset, lengths, request rate, warmup and sampling, and keep the raw per-request results.

  • TensorRT-LLM Benchmarking GuideNVIDIA · support

    Use Before Benchmarking and Online Serving Benchmarking as a reproducibility checklist. Borrow environment capture and startup metrics even if TensorRT-LLM is not the selected engine.

Also in this section

  • Efficiently Scaling Transformer InferenceMLSys · primary

    Read the prefill and decode cost, memory, batching and parallelism sections. Use its models to predict phase bottlenecks before measurement and record which assumptions fail on the selected model, engine and GPU.

  • AI Systems Performance Engineering companion code - Chapter 16Chris Fregly · required

    Begin with inference_profiling.py, inference_server_load_test.py, monitoring_bundle.py and runtime scheduler instrumentation. Run only hardware-compatible targets, retain raw artifacts and re-measure all bundled expectations on your own device.

  • Hands-On LLM Serving and Optimization - Chapter 5 and the Chapter 4 metrics sectionChi Wang and Peiheng Hu (O'Reilly) · required

    Read Chapter 5 on GPU specifications, model loading and arithmetic intensity in the prefill and decode phases, and "Measuring Performance in LLM Serving" in Chapter 4. Turn each claim into a prediction for one short-prompt and one long-prompt workload.

  • vLLM Metrics Design and Production MetricsvLLM Project · required

    Map scheduler and cache events to exported request, queue, TTFT, inter-token and generation metrics. The link is pinned to v0.31.0; check the definitions against the version you install.

  • Time to First Token - Measurement and Load-Testing SessionsPatchy631 · support

    Use only Week 3 and Week 5 as a practical checklist for Prometheus, Grafana and request-rate sweeps. Follow the competency gate rather than its calendar, and replace fixed concurrency goals with your hardware-safe saturation range.

  • LLM Inference Systems Laboratory - InstrumentationRoadmap-Final · support

    Complete Milestone B: correlate request, iteration, KV, scheduler, kernel and resource events, quantify observer overhead, and retain raw arrival and completion records.

  • Taming Throughput-Latency Tradeoff in LLM Inference with Sarathi-ServeAgrawal et al. · support

    Read arXiv v3, Chunked-prefills and Stall-free batching for the chunked-prefill vocabulary and the prefill-decode interference argument, and Overhead of chunked-prefills for the cost of splitting. Treat the reported capacity gains as the paper's result on its hardware.

  • py-spy - sampling profiler for PythonBen Frederick · support

    Use py-spy record to take CPU flame graphs of tokenizer and detokenizer work, and py-spy top to watch the hot functions live. Launch the profiled process under py-spy.

  • vLLM SamplingParams API (v0.31.0)vLLM Project · reference

    Look up temperature, seed, max_tokens, ignore_eos, stop and stop_token_ids defaults when you fix the output contract. The link is pinned to v0.31.0; check the fields against the version you install.