Skip to main content

Graph

Struct Graph 

Source
pub struct Graph { /* private fields */ }
Expand description

A CUDA graph representing a DAG of GPU operations.

Nodes represent individual operations (kernel launches, memory copies, memsets, or empty barriers). Dependencies are directed edges that enforce execution ordering between nodes.

The graph can be instantiated into a GraphExec for repeated low-overhead execution.

Implementations§

Source§

impl Graph

Source

pub fn new() -> Self

Creates a new empty graph with no nodes or dependencies.

Source

pub fn add_kernel_node( &mut self, function_name: &str, grid: (u32, u32, u32), block: (u32, u32, u32), shared_mem: u32, ) -> usize

Adds a kernel launch node to the graph.

Returns the index of the newly created node, which can be used to establish dependencies via add_dependency.

§Parameters
  • function_name - Name of the kernel function.
  • grid - Grid dimensions (x, y, z).
  • block - Block dimensions (x, y, z).
  • shared_mem - Dynamic shared memory in bytes.
Source

pub fn add_memcpy_node( &mut self, direction: MemcpyDirection, size: usize, ) -> usize

Adds a memory copy node to the graph.

Returns the index of the newly created node.

§Parameters
  • direction - Direction of the memory copy.
  • size - Size of the transfer in bytes.
Source

pub fn add_memset_node(&mut self, size: usize, value: u8) -> usize

Adds a memset node to the graph.

Returns the index of the newly created node.

§Parameters
  • size - Number of bytes to set.
  • value - Byte value to fill with.
Source

pub fn add_empty_node(&mut self) -> usize

Adds an empty (no-op) node to the graph.

Empty nodes are useful as synchronisation barriers — they have no work of their own but can serve as join points for multiple dependency chains.

Returns the index of the newly created node.

Source

pub fn add_dependency(&mut self, from: usize, to: usize) -> CudaResult<()>

Adds a dependency edge from node from to node to.

This means to will not begin execution until from has completed. Both indices must refer to existing nodes.

§Errors

Returns CudaError::InvalidValue if either index is out of bounds or if from == to (self-dependency).

Source

pub fn node_count(&self) -> usize

Returns the total number of nodes in the graph.

Source

pub fn dependency_count(&self) -> usize

Returns the total number of dependency edges in the graph.

Source

pub fn nodes(&self) -> &[GraphNode]

Returns a slice of all nodes in insertion order.

Source

pub fn dependencies(&self) -> &[(usize, usize)]

Returns a slice of all dependency edges as (from, to) pairs.

Source

pub fn get_node(&self, index: usize) -> Option<&GraphNode>

Returns the node at the given index, or None if out of bounds.

Source

pub fn topological_sort(&self) -> CudaResult<Vec<usize>>

Performs a topological sort of the graph nodes.

Returns the node indices in an order that respects all dependency edges, or an error if the graph contains a cycle.

§Errors

Returns CudaError::InvalidValue if the graph contains a dependency cycle.

Source

pub fn instantiate(&self) -> CudaResult<GraphExec>

Instantiates the graph into an executable form.

The returned GraphExec can be launched on a stream with minimal CPU overhead. The graph is validated (topological sort) during instantiation.

§Errors

Returns CudaError::InvalidValue if the graph contains cycles.

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Graph

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Graph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin for Graph

§

impl UnwindSafe for Graph

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more