Expand description
CUDA Graph API for recording and replaying sequences of GPU operations.
CUDA Graphs allow capturing a sequence of operations (kernel launches, memory copies, memsets) into a graph data structure that can be instantiated and launched repeatedly with minimal CPU overhead.
§Architecture
This module exposes a Rust-side graph representation that records
operations as nodes with explicit dependency edges. Graph::instantiate
translates that representation into the native CUDA Graph API
(cuGraphCreate + cuGraphInstantiate) whenever a CUDA driver is
available, and GraphExec::launch issues a real cuGraphLaunch. On macOS
(or any host without a driver) the graph is still built and validated
CPU-side, and launching reports CudaError::NotInitialized.
§Node lowering (important)
A GraphNode stores only an operation specification — a kernel name,
copy direction/size, or memset size/value — and carries no resolved
CUfunction or device pointers. Kernel / memcpy / memset nodes therefore
cannot yet be lowered to their real cuGraphAddKernelNode /
cuGraphAddMemcpyNode / cuGraphAddMemsetNode form: they are added as
cuGraphAddEmptyNode barriers. The instantiated graph faithfully
reproduces the node count and dependency topology, but a cuGraphLaunch
performs none of those operations’ work (instantiate logs a
tracing::warn! when any such node is lowered). Only genuine
GraphNode::Empty barriers are represented exactly.
§Example
let mut graph = Graph::new();
let n0 = graph.add_memcpy_node(MemcpyDirection::HostToDevice, 4096);
let n1 = graph.add_kernel_node(
"vector_add",
(4, 1, 1),
(256, 1, 1),
0,
);
let n2 = graph.add_memcpy_node(MemcpyDirection::DeviceToHost, 4096);
graph.add_dependency(n0, n1).ok();
graph.add_dependency(n1, n2).ok();
assert_eq!(graph.node_count(), 3);
assert_eq!(graph.dependency_count(), 2);Structs§
- Graph
- A CUDA graph representing a DAG of GPU operations.
- Graph
Exec - An instantiated, executable graph.
- Stream
Capture - Records GPU operations submitted to a stream into a
Graph. - Stream
Graph Capture - Driver-backed CUDA stream capture.
Enums§
- Graph
Node - A single operation node within a
Graph. - Memcpy
Direction - Direction of a memory copy operation within a graph node.