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_edgereturnsGraphError::CycleDetectedif 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
impl ComputeGraph
Sourcepub fn add_node(&mut self, node: GraphNode) -> NodeId
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.
Sourcepub fn node(&self, id: NodeId) -> GraphResult<&GraphNode>
pub fn node(&self, id: NodeId) -> GraphResult<&GraphNode>
Returns a reference to the node with the given ID, or an error.
Sourcepub fn node_mut(&mut self, id: NodeId) -> GraphResult<&mut GraphNode>
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.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Returns the total number of nodes.
Sourcepub fn add_buffer(&mut self, buf: BufferDescriptor) -> BufferId
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.
Sourcepub fn buffer(&self, id: BufferId) -> GraphResult<&BufferDescriptor>
pub fn buffer(&self, id: BufferId) -> GraphResult<&BufferDescriptor>
Returns a reference to the buffer descriptor, or an error.
Sourcepub fn buffers(&self) -> &[BufferDescriptor]
pub fn buffers(&self) -> &[BufferDescriptor]
Returns a slice of all buffer descriptors.
Sourcepub fn buffer_count(&self) -> usize
pub fn buffer_count(&self) -> usize
Returns the number of registered buffers.
Sourcepub fn add_edge(&mut self, from: NodeId, to: NodeId) -> GraphResult<()>
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
GraphError::NodeNotFoundif either ID is invalid.GraphError::CycleDetectedif the edge would create a cycle.
Sourcepub fn is_reachable(&self, src: NodeId, dst: NodeId) -> bool
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.
Sourcepub fn successors(&self, id: NodeId) -> GraphResult<&[NodeId]>
pub fn successors(&self, id: NodeId) -> GraphResult<&[NodeId]>
Returns successors of id (nodes that depend on it).
Sourcepub fn predecessors(&self, id: NodeId) -> GraphResult<&[NodeId]>
pub fn predecessors(&self, id: NodeId) -> GraphResult<&[NodeId]>
Returns predecessors of id (nodes it depends on).
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Returns the total number of directed edges in the graph.
Sourcepub fn sources(&self) -> Vec<NodeId>
pub fn sources(&self) -> Vec<NodeId>
Returns all nodes with no predecessors (entry points of the graph).
Sourcepub fn sinks(&self) -> Vec<NodeId>
pub fn sinks(&self) -> Vec<NodeId>
Returns all nodes with no successors (terminal nodes of the graph).
Sourcepub fn topological_order(&self) -> GraphResult<Vec<NodeId>>
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.
Sourcepub fn infer_data_edges(&mut self) -> GraphResult<()>
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.
Sourcepub fn reachable_from(&self, roots: &[NodeId]) -> HashSet<NodeId>
pub fn reachable_from(&self, roots: &[NodeId]) -> HashSet<NodeId>
Returns the set of all nodes reachable (forward) from the given roots.
Sourcepub fn reaching(&self, targets: &[NodeId]) -> HashSet<NodeId>
pub fn reaching(&self, targets: &[NodeId]) -> HashSet<NodeId>
Returns the set of all nodes that can reach any of the given targets (reverse reachability).
Sourcepub fn critical_path_length(&self) -> GraphResult<usize>
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.
Sourcepub fn max_in_degree(&self) -> usize
pub fn max_in_degree(&self) -> usize
Returns the maximum fan-in (in-degree) among all nodes.
Sourcepub fn max_out_degree(&self) -> usize
pub fn max_out_degree(&self) -> usize
Returns the maximum fan-out (out-degree) among all nodes.
Sourcepub fn parallelism_width(&self) -> GraphResult<usize>
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.
Sourcepub fn kernel_nodes(&self) -> Vec<NodeId>
pub fn kernel_nodes(&self) -> Vec<NodeId>
Returns all nodes that are kernel launches (compute nodes).
Sourcepub fn fusible_nodes(&self) -> Vec<NodeId>
pub fn fusible_nodes(&self) -> Vec<NodeId>
Returns all nodes that are fusible kernel launches.
Trait Implementations§
Source§impl Clone for ComputeGraph
impl Clone for ComputeGraph
Source§fn clone(&self) -> ComputeGraph
fn clone(&self) -> ComputeGraph
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more