Skip to main content

Module graph

Module graph 

Source
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

Since the actual CUDA Graph driver functions (cuGraphCreate, cuGraphLaunch, etc.) are not available on macOS and require driver support, this module implements a Rust-side graph representation that records operations as nodes with explicit dependencies. On systems with a real CUDA driver, this would translate to the native graph API.

§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.
GraphExec
An instantiated, executable graph.
StreamCapture
Records GPU operations submitted to a stream into a Graph.

Enums§

GraphNode
A single operation node within a Graph.
MemcpyDirection
Direction of a memory copy operation within a graph node.