pub struct ComputeGraph {
pub nodes: Vec<GraphNode>,
pub edges: HashMap<EdgeId, TensorInfo>,
pub inputs: Vec<EdgeId>,
pub outputs: Vec<EdgeId>,
/* private fields */
}Expand description
A computation graph representing a multi-operation model.
This is a DAG where nodes are operations and edges are tensors flowing between operations.
Fields§
§nodes: Vec<GraphNode>All nodes in the graph, keyed by NodeId.
edges: HashMap<EdgeId, TensorInfo>All tensor edges, keyed by EdgeId.
inputs: Vec<EdgeId>Graph-level input edge ids (model inputs).
outputs: Vec<EdgeId>Graph-level output edge ids (model outputs).
Implementations§
Source§impl ComputeGraph
impl ComputeGraph
Sourcepub fn add_edge(&mut self, info: TensorInfo) -> EdgeId
pub fn add_edge(&mut self, info: TensorInfo) -> EdgeId
Add a tensor edge to the graph and return its id.
Sourcepub fn add_node(
&mut self,
op: GraphOp,
inputs: Vec<EdgeId>,
outputs: Vec<EdgeId>,
name: impl Into<String>,
) -> Result<NodeId, IrError>
pub fn add_node( &mut self, op: GraphOp, inputs: Vec<EdgeId>, outputs: Vec<EdgeId>, name: impl Into<String>, ) -> Result<NodeId, IrError>
Add a node to the graph and return its id.
§Errors
Returns IrError::UnknownEdge if any input or output EdgeId has
not been previously registered via add_edge, or
IrError::DuplicateEdgeProducer if an output edge already has a
producer node (each edge may have at most one producer).
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Number of nodes in the graph.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Number of edges (tensors) in the graph.
Sourcepub fn topological_order(&self) -> Result<Vec<&GraphNode>, IrError>
pub fn topological_order(&self) -> Result<Vec<&GraphNode>, IrError>
Returns nodes in topological order.
The ordering is deterministic: among nodes with the same in-degree,
the one with the smaller NodeId is emitted first.
§Errors
Returns IrError::CycleDetected if the graph contains a cycle.
Sourcepub fn edge_consumers(&self, edge: EdgeId) -> Vec<&GraphNode>
pub fn edge_consumers(&self, edge: EdgeId) -> Vec<&GraphNode>
Find all nodes that consume the given edge.
Sourcepub fn edge_producer(&self, edge: EdgeId) -> Option<&GraphNode>
pub fn edge_producer(&self, edge: EdgeId) -> Option<&GraphNode>
Find the node that produces the given edge, if any.
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