pub struct Graph { /* private fields */ }Expand description
A graph definition with exclusive host access to native graph operations.
Move it between threads or share it through external synchronization. Native graph objects cannot be queried or modified concurrently.
Implementations§
Source§impl Graph
impl Graph
Sourcepub unsafe fn add_memory_operations_node(
&mut self,
dependencies: &[GraphNode],
operations: &[MemoryOperation],
) -> Result<GraphNode>
pub unsafe fn add_memory_operations_node( &mut self, dependencies: &[GraphNode], operations: &[MemoryOperation], ) -> Result<GraphNode>
Adds a batch memory-operation node to this graph.
§Safety
Follow crate::stream::Stream::memory_operations’s address and progress contracts for every replay.
§Errors
Returns Error::OutOfRange for 256 or more operations, Error::NullPointer for null wait or write addresses, or Error::Misaligned for misaligned ones.
Also returns an error for a dependency from another graph, an unrepresentable dependency count, or CUDA rejecting batch-node creation.
Sourcepub unsafe fn set_memory_operations_node(
&mut self,
node: &GraphNode,
operations: &[MemoryOperation],
) -> Result<()>
pub unsafe fn set_memory_operations_node( &mut self, node: &GraphNode, operations: &[MemoryOperation], ) -> Result<()>
Replaces an existing batch node’s operations.
§Safety
The new addresses and synchronization must satisfy the replay contract of Self::add_memory_operations_node.
§Errors
Returns Error::OutOfRange for 256 or more operations, Error::NullPointer for null wait or write addresses, or Error::Misaligned for misaligned ones.
Also returns an error if the node belongs to another graph or CUDA rejects the new batch parameters.
Source§impl Graph
impl Graph
Sourcepub fn create_buffer_uninit<T>(
&mut self,
length: usize,
) -> Result<GraphBuffer<MaybeUninit<T>>>where
T: DeviceRepr,
pub fn create_buffer_uninit<T>(
&mut self,
length: usize,
) -> Result<GraphBuffer<MaybeUninit<T>>>where
T: DeviceRepr,
Allocates graph-retained device memory.
The returned buffer can be used with graph-buffer node APIs. Any graph or executable graph that records the buffer retains the underlying device allocation for replay.
§Errors
Returns an error if CUDA cannot allocate device memory, the requested byte count overflows, or CUDA reports runtime initialization diagnostics.
Sourcepub fn zeroed_buffer<T>(&mut self, length: usize) -> Result<GraphBuffer<T>>where
T: ZeroableDeviceRepr,
pub fn zeroed_buffer<T>(&mut self, length: usize) -> Result<GraphBuffer<T>>where
T: ZeroableDeviceRepr,
Allocates graph-retained device memory initialized to zero bytes.
§Errors
Returns an error if CUDA cannot allocate or initialize device memory, the requested byte count overflows, or CUDA reports runtime initialization diagnostics.
Sourcepub fn buffer_from_slice<T>(&mut self, values: &[T]) -> Result<GraphBuffer<T>>where
T: DeviceRepr,
pub fn buffer_from_slice<T>(&mut self, values: &[T]) -> Result<GraphBuffer<T>>where
T: DeviceRepr,
Allocates graph-retained device memory initialized from a host slice.
§Errors
Returns an error if CUDA cannot allocate or copy device memory, the requested byte count overflows, or CUDA reports runtime initialization diagnostics.
Sourcepub fn instantiate(
&self,
flags: GraphInstantiateFlags,
) -> Result<ExecutableGraph>
pub fn instantiate( &self, flags: GraphInstantiateFlags, ) -> Result<ExecutableGraph>
Instantiates graph as an executable graph. The graph is validated for any structural constraints or intra-node constraints which were not previously validated. If instantiation is successful, returns an instantiated executable graph.
flags controls the behavior of instantiation and subsequent graph launches.
Valid flags are:
-
GraphInstantiateFlags::AUTO_FREE_ON_LAUNCH, which configures a graph containing memory allocation nodes to automatically free any unfreed memory allocations before the graph is relaunched. -
GraphInstantiateFlags::DEVICE_LAUNCH, which configures the graph for launch from the device. If this flag is passed, the executable graph handle returned can be used to launch the graph from both the host and device. This flag can only be used on platforms which support unified addressing. This flag cannot be used in conjunction withGraphInstantiateFlags::AUTO_FREE_ON_LAUNCH. -
GraphInstantiateFlags::USE_NODE_PRIORITY, which causes the graph to use the priorities from the per-node attributes rather than the priority of the launch stream during execution. Priorities are only available on kernel nodes and are copied from stream priority during stream capture.
If the graph contains any allocation or free nodes, there can be at most one executable graph in existence for that graph at a time. An attempt to instantiate a second executable graph before dropping the first results in an error. The same also applies if the graph contains any device-updatable kernel nodes.
If the graph contains kernels which call device-side ExecutableGraph::launch_async from multiple devices, this results in an error.
Graphs instantiated for launch on the device have additional restrictions which do not apply to host graphs:
- The graph’s nodes must reside on a single device.
- The graph can only contain kernel nodes, memcpy nodes, memset nodes, and child graph nodes.
- The graph cannot be empty and must contain at least one kernel, memcpy, or memset node. Operation-specific restrictions are outlined below.
- Kernel nodes:
- Use of CUDA Dynamic Parallelism is not permitted.
- Cooperative launches are permitted as long as MPS is not in use.
- Memcpy nodes:
- Only copies involving device memory and/or pinned device-mapped host memory are permitted.
- Copies involving CUDA arrays are not permitted.
- Both operands must be accessible from the current device, and the current device must match the device of other nodes in the graph.
Graph objects are not threadsafe.
§Errors
Returns an error if the context cannot be bound or CUDA rejects instantiation, including for invalid graph structure, unsupported node parameters or flags, or native restrictions on simultaneous executable instances. CUDA may also report errors from previous asynchronous launches or runtime initialization diagnostics.
Sourcepub fn try_clone(&self) -> Result<Self>
pub fn try_clone(&self) -> Result<Self>
Creates a copy of original_graph.
All parameters are copied into the cloned graph.
The original graph may be modified after this call without affecting the clone.
Child graph nodes in the original graph are recursively copied into the clone.
Cloning is not supported for graphs that contain memory allocation nodes, memory free nodes, or conditional nodes.
Graph objects are not threadsafe.
§Errors
Returns an error if CUDA rejects the graph operation, if a previous asynchronous launch reported an error, or if CUDA reports runtime initialization diagnostics.
Callbacks must not call CUDA functions; see Stream::add_callback.
Sourcepub fn add_dependency(&mut self, from: GraphNode, to: GraphNode) -> Result<()>
pub fn add_dependency(&mut self, from: GraphNode, to: GraphNode) -> Result<()>
Adds a default dependency from from to to.
§Errors
Returns an error if any node belongs to another graph or context binding fails. Also propagates CUDA dependency-update errors.
Sourcepub fn add_dependencies(
&mut self,
from: &[GraphNode],
to: &[GraphNode],
) -> Result<()>
pub fn add_dependencies( &mut self, from: &[GraphNode], to: &[GraphNode], ) -> Result<()>
Adds default dependencies between corresponding entries in from and to.
§Errors
Returns an error if any node belongs to another graph or context binding fails. Also propagates CUDA dependency-update errors. Source and destination slices must have equal lengths.
Sourcepub fn remove_dependency(
&mut self,
from: GraphNode,
to: GraphNode,
) -> Result<()>
pub fn remove_dependency( &mut self, from: GraphNode, to: GraphNode, ) -> Result<()>
Removes the default dependency from from to to.
§Errors
Returns an error if any node belongs to another graph or context binding fails. Also propagates CUDA dependency-update errors.
Sourcepub fn remove_dependencies(
&mut self,
from: &[GraphNode],
to: &[GraphNode],
) -> Result<()>
pub fn remove_dependencies( &mut self, from: &[GraphNode], to: &[GraphNode], ) -> Result<()>
Removes default dependencies between corresponding entries in from and to.
§Errors
Returns an error if any node belongs to another graph or context binding fails. Also propagates CUDA dependency-update errors. Source and destination slices must have equal lengths.
Sourcepub fn add_edges(&mut self, edges: &[GraphEdge]) -> Result<()>
pub fn add_edges(&mut self, edges: &[GraphEdge]) -> Result<()>
Adds directed edges with explicit port and dependency attributes.
§Errors
Returns an error if any node belongs to another graph or context binding fails. Also propagates CUDA dependency-update errors.
Sourcepub fn remove_edges(&mut self, edges: &[GraphEdge]) -> Result<()>
pub fn remove_edges(&mut self, edges: &[GraphEdge]) -> Result<()>
Removes directed edges matching the supplied nodes and attributes.
§Errors
Returns an error if any node belongs to another graph or context binding fails. Also propagates CUDA dependency-update errors.
Sourcepub fn add_empty_node(
&mut self,
dependencies: &[GraphNode],
) -> Result<GraphNode>
pub fn add_empty_node( &mut self, dependencies: &[GraphNode], ) -> Result<GraphNode>
Creates a node that performs no operation and adds it to the graph with the given dependencies. The dependency list may be empty, in which case the node is placed at the graph root. It may not contain duplicate entries.
An empty node performs no operation during execution, but can be used for transitive ordering. For example, a phased execution graph with 2 groups of n nodes with a barrier between them can be represented using an empty node and 2*n dependency edges, rather than no empty node and n^2 dependency edges.
Graph objects are not threadsafe.
§Errors
Returns an error if CUDA rejects the graph operation or reports runtime initialization diagnostics.
Callbacks must not call CUDA functions; see Stream::add_callback.
Sourcepub fn add_event_record_node(
&mut self,
dependencies: &[GraphNode],
event: &Arc<Event>,
) -> Result<GraphNode>
pub fn add_event_record_node( &mut self, dependencies: &[GraphNode], event: &Arc<Event>, ) -> Result<GraphNode>
Creates an event record node and adds it to the graph with the given dependencies and event. The dependency list may be empty, in which case the node is placed at the graph root. It may not contain duplicate entries.
Each graph launch records event to capture execution of the node’s dependencies.
The graph and executables instantiated from it retain event.
These nodes may not be used in loops or conditionals.
Graph objects are not threadsafe.
§Errors
Returns an error if CUDA rejects the graph operation, if a previous asynchronous launch reported an error, or if CUDA reports runtime initialization diagnostics.
Callbacks must not call CUDA functions; see Stream::add_callback.
Sourcepub fn add_event_wait_node(
&mut self,
dependencies: &[GraphNode],
event: &Arc<Event>,
) -> Result<GraphNode>
pub fn add_event_wait_node( &mut self, dependencies: &[GraphNode], event: &Arc<Event>, ) -> Result<GraphNode>
Creates an event wait node and adds it to the graph with the given dependencies and event. The dependency list may be empty, in which case the node is placed at the graph root. It may not contain duplicate entries.
The graph node waits for all work captured in event.
See Event::record for what an event captures.
Synchronization is performed efficiently on the device when applicable.
event may come from a different context or device than the launch stream.
The graph and executables instantiated from it retain event.
These nodes may not be used in loops or conditionals.
Graph objects are not threadsafe.
§Errors
Returns an error if CUDA rejects the graph operation, if a previous asynchronous launch reported an error, or if CUDA reports runtime initialization diagnostics.
Callbacks must not call CUDA functions; see Stream::add_callback.
Sourcepub unsafe fn add_host_node(
&mut self,
dependencies: &[GraphNode],
params: &HostNodeParams,
) -> Result<GraphNode>
pub unsafe fn add_host_node( &mut self, dependencies: &[GraphNode], params: &HostNodeParams, ) -> Result<GraphNode>
Creates a CPU execution node and adds it to the graph with the given dependencies and host-node parameters. The dependency list may be empty, in which case the node is placed at the graph root. It may not contain duplicate entries.
When the graph is launched, the node invokes the specified CPU function. Host nodes are not supported under MPS with pre-Volta GPUs.
Graph objects are not threadsafe.
§Safety
CUDA stores the raw callback function and user-data pointer in the graph node for later replay.
The caller must ensure params remains valid according to HostNodeParams::new for every graph instantiation and launch that can execute this node.
§Errors
Returns an error if CUDA rejects the graph operation, if a previous asynchronous launch reported an error, or if CUDA reports runtime initialization diagnostics.
Callbacks must not call CUDA functions; see Stream::add_callback.
Sourcepub unsafe fn add_kernel_node<'a, P>(
&mut self,
dependencies: &[GraphNode],
function: DeviceFunction,
config: &LaunchConfig,
params: P,
) -> Result<GraphNode>where
P: KernelLaunchArgs<'a>,
pub unsafe fn add_kernel_node<'a, P>(
&mut self,
dependencies: &[GraphNode],
function: DeviceFunction,
config: &LaunchConfig,
params: P,
) -> Result<GraphNode>where
P: KernelLaunchArgs<'a>,
Creates a kernel execution node and adds it to the graph with the given dependencies, launch configuration, and kernel parameters. The dependency list may be empty, in which case the node is placed at the graph root. It may not contain duplicate entries.
When the graph is launched, the node invokes the kernel on the grid and blocks specified by LaunchConfig.
LaunchConfig::shared_memory_bytes sets the amount of dynamic shared memory available to each thread block.
Kernel parameters are passed with KernelParameters or tuples of shared or mutable references.
Kernels launched using graphs must not use texture and surface references. Reading or writing through any texture or surface reference is undefined behavior. This restriction does not apply to texture and surface objects.
A runtime kernel handle passed as a raw function must come from the same CUDA Runtime instance. Passing a symbol that belongs to a different runtime instance results in undefined behavior.
Graph objects are not threadsafe.
§Safety
Arguments must match function’s ABI and satisfy its value and access requirements.
The function must belong to the node’s execution context.
Keep its code owner alive until every queued graph execution completes.
CUDA copies the kernel argument values during this call and stores those copied values in the graph node for later replay.
If an argument value is itself a pointer, only the pointer address is copied.
The caller must ensure every copied pointer value remains valid for every graph instantiation, update, and launch that can execute this node.
Mutable pointer arguments must also remain exclusive for the work ordered by those launches.
§Errors
Returns an error if CUDA rejects the graph operation, if a previous asynchronous launch reported an error, or if CUDA reports runtime initialization diagnostics.
Callbacks must not call CUDA functions; see Stream::add_callback.
Sourcepub unsafe fn add_memory_copy_node_1d(
&mut self,
dependencies: &[GraphNode],
params: &MemoryCopy1DNodeParams,
) -> Result<GraphNode>
pub unsafe fn add_memory_copy_node_1d( &mut self, dependencies: &[GraphNode], params: &MemoryCopy1DNodeParams, ) -> Result<GraphNode>
Creates a new 1D memcpy node and adds it to the graph with the given dependencies. The dependency list may be empty, in which case the node is placed at the root of the graph, and it may not contain duplicate entries.
When the graph is launched, the node copies count bytes from src to dst.
The transfer direction is described by MemoryCopyKind.
MemoryCopyKind::Default is recommended when unified virtual addressing is available, in which case the transfer direction is inferred from the pointer values.
Launching a memcpy node with dst and src pointers that do not match the direction of the copy results in undefined behavior.
Memcpy nodes have additional restrictions for managed memory if any device in the system does not support concurrent managed access.
Graph objects are not threadsafe.
§Safety
CUDA stores the raw source and destination addresses in the graph node for later replay.
The caller must ensure params remains valid according to MemoryCopy1DNodeParams::new for every graph instantiation and launch that can execute this node.
§Errors
Returns an error if CUDA rejects the graph operation, if a previous asynchronous launch reported an error, or if CUDA reports runtime initialization diagnostics.
Callbacks must not call CUDA functions; see Stream::add_callback.
Sourcepub unsafe fn add_memory_copy_node_1d_device_to_device<D, S>(
&mut self,
dependencies: &[GraphNode],
dst: &mut D,
src: &S,
) -> Result<GraphNode>
pub unsafe fn add_memory_copy_node_1d_device_to_device<D, S>( &mut self, dependencies: &[GraphNode], dst: &mut D, src: &S, ) -> Result<GraphNode>
Creates a device-to-device memcpy node between byte slices.
The node copies src.len() bytes.
dst must have at least that many bytes.
§Safety
CUDA stores the raw source and destination addresses in the graph node for later replay.
The caller must ensure dst and src remain valid for every graph instantiation and launch that can execute this node.
dst must not be accessed through another mutable path while graph launches using this node can write it.
§Errors
Returns an error if dst is smaller than src, if CUDA rejects the graph operation, if a previous asynchronous launch reported an error, or if CUDA reports runtime initialization diagnostics.
Sourcepub unsafe fn add_buffer_memory_copy_node_1d_device_to_device<T, D>(
&mut self,
dependencies: &[GraphNode],
dst: &mut GraphBuffer<D>,
src: &GraphBuffer<T>,
) -> Result<GraphNode>
pub unsafe fn add_buffer_memory_copy_node_1d_device_to_device<T, D>( &mut self, dependencies: &[GraphNode], dst: &mut GraphBuffer<D>, src: &GraphBuffer<T>, ) -> Result<GraphNode>
Creates a device-to-device memcpy node between graph-retained buffers.
The node copies src.byte_len() bytes.
dst must have at least that many bytes.
The graph retains both allocations so the baked CUDA graph pointers remain live for future instantiation and replay.
§Safety
Keep source elements valid for every launch, and order their producers before replay. Keep destination accesses exclusive through completion, including failed submissions. Allocation retention preserves addresses; initialization and access ordering remain caller obligations.
§Errors
Returns an error if dst is smaller than src, if CUDA rejects the graph operation, if a previous asynchronous launch reported an error, or if CUDA reports runtime initialization diagnostics.
Sourcepub unsafe fn add_memory_copy_node(
&mut self,
dependencies: &[GraphNode],
params: &MemoryCopy3DNodeParams,
) -> Result<GraphNode>
pub unsafe fn add_memory_copy_node( &mut self, dependencies: &[GraphNode], params: &MemoryCopy3DNodeParams, ) -> Result<GraphNode>
Creates a memcpy node and adds it to the graph with the given dependencies. The dependency list may be empty, in which case the node is placed at the graph root. It may not contain duplicate entries.
When the graph is launched, the node performs the memcpy described by params.
MemoryCopy3DNodeParams describes the copy and its restrictions.
Memcpy nodes have additional restrictions for managed memory if any device in the system does not support concurrent managed access.
Graph objects are not threadsafe.
§Safety
CUDA stores the raw source and destination addresses in the graph node for later replay.
The caller must ensure params remains valid according to MemoryCopy3DNodeParams for every graph instantiation and launch that can execute this node.
§Errors
Returns an error if CUDA rejects the graph operation, if a previous asynchronous launch reported an error, or if CUDA reports runtime initialization diagnostics.
Callbacks must not call CUDA functions; see Stream::add_callback.
Sourcepub unsafe fn add_memory_copy_node_to_symbol(
&mut self,
dependencies: &[GraphNode],
params: &MemoryCopyToSymbolNodeParams,
) -> Result<GraphNode>
pub unsafe fn add_memory_copy_node_to_symbol( &mut self, dependencies: &[GraphNode], params: &MemoryCopyToSymbolNodeParams, ) -> Result<GraphNode>
Adds a node that copies host or device memory into a module symbol, as described by params.
§Safety
CUDA stores the raw symbol and source pointer in the graph node for later replay.
The caller must ensure params remains valid according to MemoryCopyToSymbolNodeParams::new for every graph instantiation and launch that can execute this node.
§Errors
Returns an error if a dependency belongs to another graph, context binding fails, or CUDA rejects the symbol, pointers, copy range, or node dependencies.
Sourcepub unsafe fn add_memory_copy_node_from_symbol(
&mut self,
dependencies: &[GraphNode],
params: &MemoryCopyFromSymbolNodeParams,
) -> Result<GraphNode>
pub unsafe fn add_memory_copy_node_from_symbol( &mut self, dependencies: &[GraphNode], params: &MemoryCopyFromSymbolNodeParams, ) -> Result<GraphNode>
Adds a node that copies a module symbol into host or device memory, as described by params.
§Safety
CUDA stores the raw destination and symbol pointer in the graph node for later replay.
The caller must ensure params remains valid according to MemoryCopyFromSymbolNodeParams::new for every graph instantiation and launch that can execute this node.
§Errors
Returns an error if a dependency belongs to another graph, context binding fails, or CUDA rejects the symbol, pointers, copy range, or node dependencies.
Sourcepub unsafe fn add_memory_set_node(
&mut self,
dependencies: &[GraphNode],
params: &MemorySetNodeParams,
) -> Result<GraphNode>
pub unsafe fn add_memory_set_node( &mut self, dependencies: &[GraphNode], params: &MemorySetNodeParams, ) -> Result<GraphNode>
Creates a new memset node and adds it to the graph with the given dependencies. The dependency list may be empty, in which case the node is placed at the root of the graph, and it may not contain duplicate entries.
The element size must be 1, 2, or 4 bytes.
When the graph is launched, the node performs the memset described by params.
Graph objects are not threadsafe.
§Safety
CUDA stores the destination address in the graph node for later replay.
The caller must ensure params remains valid according to MemorySetNodeParams::new for every graph instantiation and launch that can execute this node.
§Errors
Returns an error if CUDA rejects the graph operation, if a previous asynchronous launch reported an error, or if CUDA reports runtime initialization diagnostics.
Callbacks must not call CUDA functions; see Stream::add_callback.
Sourcepub fn add_child_graph_node(
&mut self,
dependencies: &[GraphNode],
child_graph: &Self,
) -> Result<GraphNode>
pub fn add_child_graph_node( &mut self, dependencies: &[GraphNode], child_graph: &Self, ) -> Result<GraphNode>
Creates a new node which executes an embedded graph, and adds it to the graph with the given dependencies. The dependency list may be empty, in which case the node is placed at the root of the graph, and it may not contain duplicate entries.
If child_graph contains allocation nodes, free nodes, or conditional nodes, this call returns an error.
The node executes an embedded child graph. The child graph is cloned in this call.
Graph objects are not threadsafe.
§Errors
Returns an error if CUDA rejects the graph operation, if a previous asynchronous launch reported an error, or if CUDA reports runtime initialization diagnostics.
Callbacks must not call CUDA functions; see Stream::add_callback.
Sourcepub fn add_memory_free_node(
&mut self,
dependencies: &[GraphNode],
allocation: &MemoryAllocationNodeInfo,
) -> Result<GraphNode>
pub fn add_memory_free_node( &mut self, dependencies: &[GraphNode], allocation: &MemoryAllocationNodeInfo, ) -> Result<GraphNode>
Creates a new memory free node for a graph allocation and adds it to the graph. The dependency list may be empty, in which case the node is placed at the root of the graph, and it may not contain duplicate entries.
Graph::add_memory_free_node returns crate::error::Status::InvalidValue if the caller attempts to free:
- an allocation twice in the same graph.
- an address that was not returned by an allocation node.
- an invalid address.
The following restrictions apply to graphs which contain allocation and/or memory free nodes:
- Nodes and edges of the graph cannot be deleted.
- The graph can only be used in a child node if the ownership is moved to the parent.
- Only one instantiation of the graph may exist at any point in time.
- The graph cannot be cloned.
Graph objects are not threadsafe.
§Errors
Returns Error::GraphNodeMismatch if allocation did not come from this graph.
Returns an error if CUDA rejects the graph operation or if a previous asynchronous launch reported an error.
Sourcepub unsafe fn add_memory_free_node_raw(
&mut self,
dependencies: &[GraphNode],
ptr: DevicePtr,
) -> Result<GraphNode>
pub unsafe fn add_memory_free_node_raw( &mut self, dependencies: &[GraphNode], ptr: DevicePtr, ) -> Result<GraphNode>
Creates a new memory free node from a raw device address.
§Safety
CUDA stores the raw address in the graph.
The caller must ensure ptr is a graph allocation that may be freed by this graph, is ordered after the allocation node, and is not freed more than once or by another graph in a way that violates CUDA graph allocation ownership rules.
§Errors
Returns an error if a dependency belongs to another graph, context binding fails, or CUDA rejects the free node or its allocation pointer.
Sourcepub fn add_memory_allocation_node(
&mut self,
dependencies: &[GraphNode],
params: &MemoryAllocationNodeParams<'_>,
) -> Result<(GraphNode, MemoryAllocationNodeInfo)>
pub fn add_memory_allocation_node( &mut self, dependencies: &[GraphNode], params: &MemoryAllocationNodeParams<'_>, ) -> Result<(GraphNode, MemoryAllocationNodeInfo)>
Creates a new allocation node and adds it to the graph with the given dependencies and allocation parameters. The dependency list may be empty, in which case the node is placed at the root of the graph, and it may not contain duplicate entries.
When Graph::add_memory_allocation_node creates an allocation node, it returns the allocation metadata in MemoryAllocationNodeInfo.
The allocation’s address remains fixed across instantiations and launches.
If the allocation is freed in the same graph, by creating a free node using Graph::add_memory_free_node, the allocation can be accessed by nodes ordered after the allocation node but before the free node.
These allocations cannot be freed outside the owning graph, and they can only be freed once in the owning graph.
If the allocation is not freed in the same graph, then it can be accessed not only by nodes in the graph which are ordered after the allocation node, but also by stream operations ordered after the graph’s execution but before the allocation is freed.
Allocations which are not freed in the same graph can be freed by:
- passing the allocation to
DeviceMemory::free_asyncorDeviceMemory::free; - launching a graph with a free node for that allocation; or
- specifying
GraphInstantiateFlags::AUTO_FREE_ON_LAUNCHduring instantiation, which makes each launch behave as though it calledDeviceMemory::free_asyncfor every unfreed allocation.
It is not possible to free an allocation in both the owning graph and another graph. If the allocation is freed in the same graph, a free node cannot be added to another graph. If the allocation is freed in another graph, a free node can no longer be added to the owning graph.
The following restrictions apply to graphs which contain allocation and/or memory free nodes:
- Nodes and edges of the graph cannot be deleted.
- The graph can only be used in a child node if the ownership is moved to the parent.
- Only one instantiation of the graph may exist at any point in time.
- The graph cannot be cloned.
Graph objects are not threadsafe.
§Errors
Returns an error if CUDA rejects the graph operation or if a previous asynchronous launch reported an error.
Sourcepub fn nodes(&self) -> Result<Vec<GraphNode>>
pub fn nodes(&self) -> Result<Vec<GraphNode>>
Returns this graph’s nodes.
Graph objects are not threadsafe.
§Errors
Returns an error if CUDA rejects the graph operation, if a previous asynchronous launch reported an error, or if CUDA reports runtime initialization diagnostics.
Callbacks must not call CUDA functions; see Stream::add_callback.
Sourcepub fn root_nodes(&self) -> Result<Vec<GraphNode>>
pub fn root_nodes(&self) -> Result<Vec<GraphNode>>
Returns this graph’s root nodes.
Graph objects are not threadsafe.
§Errors
Returns an error if CUDA rejects the graph operation, if a previous asynchronous launch reported an error, or if CUDA reports runtime initialization diagnostics.
Callbacks must not call CUDA functions; see Stream::add_callback.
Sourcepub fn edges(&self) -> Result<Vec<GraphEdge>>
pub fn edges(&self) -> Result<Vec<GraphEdge>>
Returns this graph’s dependency edges.
Graph objects are not threadsafe.
§Errors
Returns an error if CUDA rejects the graph operation, if a previous asynchronous launch reported an error, or if CUDA reports runtime initialization diagnostics.
Callbacks must not call CUDA functions; see Stream::add_callback.
Sourcepub fn topology_summary(&self) -> Result<GraphTopologySummary>
pub fn topology_summary(&self) -> Result<GraphTopologySummary>
Returns a compact summary of this graph’s native CUDA topology.
The summary is computed from CUDA graph introspection APIs and counts node kinds, root nodes, and dependency edges in this graph.
Child graph nodes are counted as child nodes here; callers that need recursive details can query the child graph returned by Graph::child_graph.
Graph objects are not threadsafe.
§Errors
Returns an error if CUDA rejects a topology query, if a previous asynchronous launch reported an error, or if CUDA reports runtime initialization diagnostics.
Sourcepub fn write_dot(&self, path: &str, flags: GraphDebugDotFlags) -> Result<()>
pub fn write_dot(&self, path: &str, flags: GraphDebugDotFlags) -> Result<()>
Writes a DOT-formatted description of the graph to path.
By default this includes the graph topology, node types, node ID, kernel names, and memcpy direction.
flags can request more detailed information about each node type, such as parameter values, kernel attributes, node handles, and function handles.
§Errors
Returns an error if path contains an interior NUL byte or if CUDA Runtime cannot write the DOT file.
Sourcepub fn as_raw(&self) -> cudaGraph_t
pub fn as_raw(&self) -> cudaGraph_t
Returns the native graph handle without transferring ownership.
Sourcepub fn into_raw(self) -> StdResult<RawGraph, Self>
pub fn into_raw(self) -> StdResult<RawGraph, Self>
Transfers the native graph, context, and retained resources without destruction.
Returns the unchanged graph if a node or executable still shares its native owner. Keep the returned parts alive through completed native work and handle destruction, or re-adopt them.
§Errors
Returns the original graph if a node, executable, child view, or another owner still retains its native graph storage.
Source§impl Graph
impl Graph
Sourcepub fn node_type(&self, node: &GraphNode) -> Result<GraphNodeType>
pub fn node_type(&self, node: &GraphNode) -> Result<GraphNodeType>
Returns the type of node.
§Errors
Returns Error::GraphNodeMismatch if node belongs to another graph, and Error::UnknownEnumValue if CUDA reports a node type this crate does not know.
Also returns an error if CUDA cannot query the node type or a previous asynchronous launch reported an error.
Sourcepub fn node_dependencies(
&self,
node: &GraphNode,
) -> Result<Vec<GraphDependency>>
pub fn node_dependencies( &self, node: &GraphNode, ) -> Result<Vec<GraphDependency>>
Returns the dependencies of node.
§Errors
Returns Error::GraphNodeMismatch if node belongs to another graph.
Also returns an error if CUDA cannot query the dependencies or a previous asynchronous launch reports an error.
Sourcepub fn node_dependents(&self, node: &GraphNode) -> Result<Vec<GraphDependency>>
pub fn node_dependents(&self, node: &GraphNode) -> Result<Vec<GraphDependency>>
Returns the nodes that depend on node.
§Errors
Returns Error::GraphNodeMismatch if node belongs to another graph.
Also returns an error if CUDA cannot query the dependent nodes or a previous asynchronous launch reports an error.
Sourcepub fn child_graph(&self, node: &GraphNode) -> Result<BorrowedGraph<'_>>
pub fn child_graph(&self, node: &GraphNode) -> Result<BorrowedGraph<'_>>
Borrows the graph embedded in the child graph node node without cloning it.
The returned BorrowedGraph borrows this graph, so this graph cannot change while it lives, and it does not destroy the embedded graph when dropped.
Allocation and free nodes cannot be added to the returned graph.
§Errors
Returns Error::GraphNodeMismatch if node belongs to another graph.
Also returns an error if node is not a child graph node, CUDA cannot query the child graph, CUDA returns a null graph handle, or a previous asynchronous launch reports an error.
§Panics
Panics if the newly constructed borrowed graph unexpectedly has multiple owners.
Sourcepub fn memory_allocation_node_info(
&self,
node: &GraphNode,
) -> Result<MemoryAllocationNodeInfo>
pub fn memory_allocation_node_info( &self, node: &GraphNode, ) -> Result<MemoryAllocationNodeInfo>
Returns the address and size of the memory allocation node node.
§Errors
Returns Error::GraphNodeMismatch if node belongs to another graph.
Also returns an error if node is not a memory allocation node, CUDA cannot query the parameters, or a previous asynchronous launch reports an error.
Sourcepub unsafe fn memory_free_node_ptr(&self, node: &GraphNode) -> Result<DevicePtr>
pub unsafe fn memory_free_node_ptr(&self, node: &GraphNode) -> Result<DevicePtr>
Returns the address that the memory free node node frees.
§Safety
The returned pointer must not be used after the graph frees it.
§Errors
Returns Error::GraphNodeMismatch if node belongs to another graph.
Also returns an error if node is not a memory free node, CUDA cannot query the pointer, or a previous asynchronous launch reports an error.
Sourcepub fn kernel_node_attribute(
&self,
node: &GraphNode,
id: GraphKernelNodeAttributeId,
) -> Result<GraphKernelNodeAttribute>
pub fn kernel_node_attribute( &self, node: &GraphNode, id: GraphKernelNodeAttributeId, ) -> Result<GraphKernelNodeAttribute>
Returns the attribute id of the kernel node node.
§Errors
Returns Error::GraphNodeMismatch if node belongs to another graph.
Also returns an error if node is not a kernel node, CUDA cannot query the attribute, or a previous asynchronous launch reports an error.
Returns the shared memory configuration of the kernel node node.
§Errors
Returns Error::GraphNodeMismatch if node belongs to another graph.
Also propagates CUDA kernel-node attribute errors, including an incompatible node type or unsupported attribute.
Sourcepub fn kernel_node_cluster_scheduling_policy(
&self,
node: &GraphNode,
) -> Result<ClusterSchedulingPolicy>
pub fn kernel_node_cluster_scheduling_policy( &self, node: &GraphNode, ) -> Result<ClusterSchedulingPolicy>
Returns the cluster scheduling policy preference of the kernel node node.
§Errors
Returns Error::GraphNodeMismatch if node belongs to another graph.
Also propagates CUDA kernel-node attribute errors, including an incompatible node type or unsupported attribute.
Sourcepub unsafe fn set_memory_copy_node_1d_params(
&mut self,
node: &GraphNode,
params: &MemoryCopy1DNodeParams,
) -> Result<()>
pub unsafe fn set_memory_copy_node_1d_params( &mut self, node: &GraphNode, params: &MemoryCopy1DNodeParams, ) -> Result<()>
Changes the one-dimensional copy node node in the graph definition.
Existing executable graphs keep their previous parameters until explicitly updated.
§Safety
Source and destination must uphold MemoryCopy1DNodeParams::new for every affected replay.
Retain old sources for existing executables.
§Errors
Returns Error::GraphNodeMismatch if node belongs to another graph.
Also propagates context-binding and CUDA node-parameter update errors, including a node that is not a memory-copy node or invalid copy parameters.
Sourcepub fn set_child_graph(
&mut self,
node: &GraphNode,
child_graph: &Self,
) -> Result<()>
pub fn set_child_graph( &mut self, node: &GraphNode, child_graph: &Self, ) -> Result<()>
Replaces the graph embedded in the child graph node node with an independent snapshot of child_graph.
Existing executable graphs retain their previous parameters until explicitly updated.
The node identity and its incoming and outgoing dependencies are preserved.
§Errors
Returns Error::GraphNodeMismatch if node belongs to another graph, Error::ContextMismatch if child_graph has another context, or an error if CUDA rejects the replacement.
CUDA validates the replacement before changing the node.
Sourcepub unsafe fn set_memory_set_node_params(
&mut self,
node: &GraphNode,
params: &MemorySetNodeParams,
) -> Result<()>
pub unsafe fn set_memory_set_node_params( &mut self, node: &GraphNode, params: &MemorySetNodeParams, ) -> Result<()>
Changes the memset node node in the graph definition.
Existing executables keep their previous parameters until explicitly updated.
§Safety
The destination must uphold MemorySetNodeParams::new for every affected replay.
Retain previous destinations through existing executable launches.
§Errors
Returns Error::GraphNodeMismatch if node belongs to another graph, or an error if the context cannot bind or CUDA rejects the node parameters.
Sourcepub fn set_kernel_node_attribute(
&mut self,
node: &GraphNode,
attribute: GraphKernelNodeAttribute,
) -> Result<()>
pub fn set_kernel_node_attribute( &mut self, node: &GraphNode, attribute: GraphKernelNodeAttribute, ) -> Result<()>
Sets an attribute of the kernel node node.
§Errors
Returns Error::GraphNodeMismatch if node belongs to another graph.
Also returns an error if node is not a kernel node, CUDA rejects the attribute update, or a previous asynchronous launch reports an error.
Sourcepub fn copy_kernel_node_attributes(
&mut self,
dst: &GraphNode,
src: &GraphNode,
) -> Result<()>
pub fn copy_kernel_node_attributes( &mut self, dst: &GraphNode, src: &GraphNode, ) -> Result<()>
Copies the kernel attributes of src to dst, both kernel nodes of this graph.
§Errors
Returns Error::GraphNodeMismatch if either node belongs to another graph.
Also returns an error if CUDA rejects the attribute copy or a previous asynchronous launch reported an error.
Sourcepub fn set_launch_attribute(
&mut self,
node: &GraphNode,
attribute: LaunchAttribute,
) -> Result<()>
pub fn set_launch_attribute( &mut self, node: &GraphNode, attribute: LaunchAttribute, ) -> Result<()>
Sets an attribute of the kernel node node using the extended launch attribute representation.
§Errors
Returns Error::GraphNodeMismatch if node belongs to another graph.
Also propagates context-binding and CUDA kernel-node attribute errors, including an incompatible node type or unsupported attribute.