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

Launch and host overhead, streams, events and asynchronous execution

Pinned memory, streams, events and copy-compute overlap supplied the CUDA mechanics. A serving loop must hide host preparation without exposing unfinished tokens or recycling KV before its consumers finish.

You'll be able to

  • Separate host scheduling and launch supply from GPU execution on a decode timeline.
  • Preserve producer, consumer and host-read ordering with stream events and buffer lifetimes.
  • Measure a completed serving step without inserting a device-wide wait after every operator.

Covers

Kernel launch and host overheadCUDA streams, events and asynchronous execution
1

Read

In this order, only the parts listed

0 of 3 done

  1. Host work on the decode critical pathUCSD CSE 291A (Spring 2026) - Guest lecture: Engineering vLLM

    May 7, 2026 scribe notes: Sections 4.1, 4.3 and 4.4, CPU overhead, asynchronous scheduling and GPU-native input preparation

    Read the dependencies and preparation boundaries. Do not inherit lecture timing examples or treat all host work as removed by asynchronous scheduling.

  2. Sampled-token copy completionMini-SGLang - Kernel, Model Runner and Overlap Boundaries

    ForwardOutput and Engine.forward_batch: active stream, sampling, CPU copy and completion event

  3. Overlap and safe host consumptionMini-SGLang - Kernel, Model Runner and Overlap Boundaries

    overlap_loop, normal_loop, _process_last_data and shutdown

2

Focus on

  • A short GPU step can wait for host launches, scheduler work or input preparation. Locate gaps on the timeline before choosing a faster arithmetic kernel.
  • One stream orders its operations; another stream needs an explicit dependency. Event waiting establishes readiness, while retaining storage or recording its use prevents allocator reuse. These are separate obligations.
  • A nonblocking copy return is not proof that the CPU tensor is ready or that transfer overlaps compute. Wait for completion before host inspection and verify overlap in the trace.
  • Overlap can prepare work for a request that finishes or is cancelled. Discard its output and defer storage reuse until in-flight consumers finish; check this ordering in a deterministic CPU event simulation.
Common mistakes · 3
  • Timing Python enqueue duration and calling it completed decode latency.
  • Replacing an event wait with a global synchronization at every token, thereby changing the overlap being measured.
  • Freeing a cancelled request's slots while previously enqueued kernels still read them. Cancellation changes ownership, not completion of GPU work.
3

Try it yourself

Closed-book, before checking anything

On your GPU, prepare a 32-element torch.float32 vector of ones and a pinned host output. Have a producer stream add one, record a ready event, and a consumer stream wait on it before multiplying by three and copying to the host. Record completion after the copy and wait before reading; every host element must be 6. Keep all buffers alive. Capture a short timeline and identify both dependencies; overlap is an observation, not a requirement. Repeat the ownership sequence in a CPU event simulation where cancellation prevents early slot reuse.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Does a stream wait block the host until the producer finishes?Answer

    No. It orders future work on the waiting stream. A host event synchronization is needed before the CPU consumes unfinished results.

  2. 2.Why retain a buffer after adding a cross-stream event dependency?Answer

    The dependency establishes execution order, not storage lifetime. The allocator must not reuse storage while another stream still uses it.

  3. 3.What disproves a host-launch-bound hypothesis?Answer

    A timeline with sufficient queued GPU work and device execution occupying the critical path, together with no useful improvement when host launch supply is reduced.

You're done when

The two-stream result is correct, the trace shows the required ordering, and cancellation cannot return storage before its final consumer completes.

Only when you can do this without notes.

Leads to

Notes

Resources · 2 for this unit, 12 more in the section

Also in this section