Launch overhead and graphs: amortize a repeated dependency structure
Compare declared submission budgets, graph setup costs, and device critical paths without promising universal acceleration.
On this page
The question for today
What you’ll understand
- Distinguish host submission cost from device execution time.
- Compute a break-even replay count from hypothetical measured costs.
- Explain graph dependencies, parameter updates, and setup limitations.
For very small kernels, repeatedly submitting work can cost enough host time or device idle gaps to matter. CUDA Graphs describe a dependency structure that can be prepared and replayed with a different submission path. They do not remove the actual kernel work or guarantee a speedup for every workload. The right question is whether a repeated structure has enough avoidable submission cost to justify graph creation, instantiation, updates, and operational complexity under the selected CUDA version.
Separate submission from the device critical path
A CPU can enqueue a kernel and return before the device finishes it. Timing that host call therefore measures submission behavior and any blocking, not the kernel’s full execution. For many small dependent kernels, gaps in submission may leave the device waiting; for a large compute-bound kernel, reducing host launch cost may barely affect application latency. Use completion-aware measurements and distinguish cold initialization, compilation or loading, warm repeated submission, and steady device execution.
A graph contains nodes and dependency edges for supported operations. Instantiation prepares an executable graph, and a graph launch submits that executable structure under its documented semantics. Independent nodes expose potential overlap while dependent nodes retain order. Capture has restrictions, and graph-update support depends on which parameters or structure change. Do not assume arbitrary dynamic control flow can be captured once and replayed unchanged forever. Check CUDA12.6 graph rules for the actual node types, allocations, and stream behavior in use.
Amortize setup only when replays really occur
Graph creation and instantiation add an up-front cost. If a workload replays the same valid graph many times, a lower per-iteration cost can amortize that setup. If shapes change frequently and require updates or reconstruction, those costs belong in the comparison. A graph may also reduce some device-side scheduling overhead, but that is measured behavior, not an invariant of the API. Keep numerical outputs, buffer addresses, lifetimes, and dependency edges correct when changing parameters across replay.
Kernel fusion is a different transformation. Combining stages can remove launches and intermediate traffic but change register pressure, occupancy, and synchronization opportunities. A graph preserves a supported operation structure rather than automatically fusing all kernels into one. Compare both approaches when relevant, but do not erase the costs one approach retains. For an application, include the final output completion and any CPU work that remains on the critical path instead of reporting only the smallest enqueue measurement.
Measure graph behavior under the real change pattern
Benchmark repeated warm iterations and the actual frequency of shape or parameter changes. Record whether each update is supported, whether instantiation repeats, and whether memory allocation or synchronization sneaks into the loop. Preserve an ordinary execution path for comparison and test error handling during graph construction and launch. A graph that reuses a freed input buffer is not an optimization regardless of its timing. Focus on useful completed iterations per second and relevant latency distribution.
The queue lab illustrates repeated submission pressure only. Reset, set λ=4 and μ=3, predict backlog 4+t, then Play or Step. Reset and set λ=2 and μ=3 for drainage. This fluid work model does not build or launch graphs, measure overhead, or fuse kernels. It shows why reducing unnecessary arrivals or per-item service work can matter, but the claimed graph benefit still needs the explicit setup-and-replay measurements in the worked example.
Work it through
Break even on a declared replay cost
A controlled hypothetical workload costs 120 microseconds per completed ordinary iteration and 90 microseconds per completed graph replay. Graph setup costs 600 microseconds. Assume these costs include the required completion and remain constant.
The saving per replay is 120−90=30 microseconds. Divide setup by this saving: 600/30=20 replays exactly recover setup under the model.
At 20 iterations, ordinary cost is 2,400 microseconds, and graph cost is 600+20×90=2,400. More than 20 is needed for strictly lower total graph time.
At 30 iterations, ordinary time is 3,600 microseconds while graph time is 600+2,700=3,300. The 300-microsecond saving is conditional on valid replay and unchanged measured costs; updates or contention can alter it.
The break-even count comes from comparable completed-work measurements, not a universal CUDA launch latency or guaranteed graph speedup.
The living notebook
Explore the model
Interactive lab · queue
Repeated submissions have a rate budget
Reset, set λ=4 and μ=3, predict backlog 4+t, then Play or Step. Reset and set λ=2 and μ=3 for drainage. This fluid queue does not implement CUDA Graphs, launch overhead, graph updates, or kernel fusion.
- Fluid backlog
- 4
- Net rate · λ − μ
- −1 /s
- M/M/1 mean residence
- 1 s
Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA repeated-work optimization needs measured cost changes as well as a correct dependency structure.
Pause & reason
Check your understanding
Your turn
Try it yourself
Ordinary completed iterations take 50 microseconds, graph replays take 40, and setup costs 250. How many replays give strictly lower total graph time?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Compute equal-cost break-even first, then require a strict integer improvement.
Compare with the solution
Each replay saves ten microseconds. Twenty-five replays exactly offset the 250-microsecond setup, so at least 26 are needed for strictly lower total cost under this fixed model. Unsupported changes, reconstruction, or additional synchronization can move the actual threshold.
Keep the idea
Take it with you
- Host submission cost and device execution need separate measurement boundaries.
- Graphs preserve explicit dependencies and supported replay semantics.
- Setup amortization and update frequency determine the measured benefit.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.