Skip to main content

ComputeGraph

Struct ComputeGraph 

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

A directed acyclic graph (DAG) of GPU operations.

Nodes represent individual GPU operations (GraphNode). Directed edges express execution-order dependencies: an edge a → b means b cannot begin until a has completed. Buffers referenced by nodes are registered separately via add_buffer.

§Guarantees

  • The graph is always a DAG — add_edge returns GraphError::CycleDetected if adding the edge would create a cycle.
  • Node IDs are unique and stable: nodes are never moved or re-indexed.
  • Buffer IDs are unique and stable.

Implementations§

Source§

impl ComputeGraph

Source

pub fn new() -> Self

Creates an empty computation graph.

Source

pub fn add_node(&mut self, node: GraphNode) -> NodeId

Adds a node to the graph and returns its assigned NodeId.

The node’s id field will be overwritten with the allocated ID.

Source

pub fn node(&self, id: NodeId) -> GraphResult<&GraphNode>

Returns a reference to the node with the given ID, or an error.

Source

pub fn node_mut(&mut self, id: NodeId) -> GraphResult<&mut GraphNode>

Returns a mutable reference to the node with the given ID, or an error.

Source

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

Returns a slice of all nodes in insertion order.

Source

pub fn node_count(&self) -> usize

Returns the total number of nodes.

Source

pub fn add_buffer(&mut self, buf: BufferDescriptor) -> BufferId

Registers a buffer and returns its assigned BufferId.

The buffer’s id field will be overwritten with the allocated ID.

Source

pub fn buffer(&self, id: BufferId) -> GraphResult<&BufferDescriptor>

Returns a reference to the buffer descriptor, or an error.

Source

pub fn buffers(&self) -> &[BufferDescriptor]

Returns a slice of all buffer descriptors.

Source

pub fn buffer_count(&self) -> usize

Returns the number of registered buffers.

Source

pub fn add_edge(&mut self, from: NodeId, to: NodeId) -> GraphResult<()>

Adds a directed dependency edge from → to.

This means to will not begin execution until from has completed.

§Errors
Source

pub fn is_reachable(&self, src: NodeId, dst: NodeId) -> bool

Returns whether node src can reach node dst via directed edges.

Uses iterative BFS to avoid stack overflow on deep graphs.

Source

pub fn successors(&self, id: NodeId) -> GraphResult<&[NodeId]>

Returns successors of id (nodes that depend on it).

Source

pub fn predecessors(&self, id: NodeId) -> GraphResult<&[NodeId]>

Returns predecessors of id (nodes it depends on).

Source

pub fn edge_count(&self) -> usize

Returns the total number of directed edges in the graph.

Source

pub fn edges(&self) -> Vec<(NodeId, NodeId)>

Returns all edges as (from, to) pairs.

Source

pub fn sources(&self) -> Vec<NodeId>

Returns all nodes with no predecessors (entry points of the graph).

Source

pub fn sinks(&self) -> Vec<NodeId>

Returns all nodes with no successors (terminal nodes of the graph).

Source

pub fn topological_order(&self) -> GraphResult<Vec<NodeId>>

Returns nodes in topological order (all predecessors before successors).

Uses Kahn’s BFS algorithm. Because the graph is guaranteed to be a DAG after successful add_edge calls, this will always succeed unless the graph is empty.

§Errors

Returns GraphError::EmptyGraph if there are no nodes.

Source

pub fn infer_data_edges(&mut self) -> GraphResult<()>

Infers and adds control edges from buffer data-flow.

For every buffer b, if node a writes b (has b in outputs) and node c reads b (has b in inputs), adds the dependency edge a → c.

§Errors

Returns GraphError::CycleDetected if any inferred edge creates a cycle.

Source

pub fn reachable_from(&self, roots: &[NodeId]) -> HashSet<NodeId>

Returns the set of all nodes reachable (forward) from the given roots.

Source

pub fn reaching(&self, targets: &[NodeId]) -> HashSet<NodeId>

Returns the set of all nodes that can reach any of the given targets (reverse reachability).

Source

pub fn is_empty(&self) -> bool

Returns true if the graph has no nodes.

Source

pub fn critical_path_length(&self) -> GraphResult<usize>

Returns the longest path length (in edges) from any source to any sink.

This is the critical path length — a lower bound on the sequential execution depth of the graph.

§Errors

Returns GraphError::EmptyGraph if the graph is empty.

Source

pub fn max_in_degree(&self) -> usize

Returns the maximum fan-in (in-degree) among all nodes.

Source

pub fn max_out_degree(&self) -> usize

Returns the maximum fan-out (out-degree) among all nodes.

Source

pub fn parallelism_width(&self) -> GraphResult<usize>

Returns the number of parallel chains (independent execution paths).

This is an upper bound on the number of streams that can be usefully exploited for concurrent execution.

Source

pub fn kernel_nodes(&self) -> Vec<NodeId>

Returns all nodes that are kernel launches (compute nodes).

Source

pub fn fusible_nodes(&self) -> Vec<NodeId>

Returns all nodes that are fusible kernel launches.

Source

pub fn to_dot(&self) -> String

Renders the graph in Graphviz DOT format for visualisation.

Trait Implementations§

Source§

impl Clone for ComputeGraph

Source§

fn clone(&self) -> ComputeGraph

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 ComputeGraph

Source§

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

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

impl Default for ComputeGraph

Source§

fn default() -> Self

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

impl Display for ComputeGraph

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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