CUDA graphs, part 1: how they work
Here's how CUDA graphs work on DGX Spark. Part two shows how to shrink what they cost.
Chapters
- 0:00Introduction
- 0:07Where this fits: The AI stack
- 0:14The problem: Every launch costs time
- 0:23The idea: Record once, replay often
- 0:35The rules: What must stay fixed
- 0:52The price: Memory and start-up time
- 1:05Wrap up
Read the transcript
Introduction
Here's how CUDA graphs work on DGX Spark. Part two shows how to shrink what they cost.
Where this fits: The AI stack
Start at the bottom: the machine. Its GPU runs small programs called kernels.
The problem: Every launch costs time
Normally the processor sets up each kernel launch. Then it launches it on the GPU. And it pays that cost again for the next one.
The idea: Record once, replay often
Capture records the work instead of running it. New data goes into the same memory places. One launch then replays all of it. The main saving is launch work, not the maths.
The rules: What must stay fixed
Shapes are fixed. Another size needs another graph, or padding. The processor can't wait on the GPU, or make ordinary data decisions, inside. Processor work isn't recorded, so a replay skips it. And the memory addresses must stay put.
The price: Memory and start-up time
Graphs keep memory, from the same pool as the model. Servers capture a set of sizes before serving, so starting takes longer. In vLLM, a batch with no graph big enough runs the normal way.
Wrap up
Part two shows the settings, and how to shrink graphs without guessing.
Sources
- docs.nvidia.com/cuda/cuda-programming-guide/04-special-topics/cuda-graphs.html
- docs.pytorch.org/docs/stable/notes/cuda.html
- docs.vllm.ai/en/stable/design/cuda_graphs
- docs.vllm.ai/en/stable/design/torch_compile
- github.com/vllm-project/vllm/blob/v0.34.0/vllm/config/compilation.py
- docs.sglang.io/docs/advanced_features/breakable_cuda_graph