pub trait Lowering<'a> {
// Required method
fn lower(
&self,
graph: &Graph,
mode: LoweringMode,
) -> Result<Dag<Box<dyn ExecutableOp>>>;
// Provided methods
fn lower_with_mapping(
&self,
graph: &Graph,
mode: LoweringMode,
) -> Result<(Dag<Box<dyn ExecutableOp>>, Vec<usize>)> { ... }
fn extra_dag_names(
&self,
_graph: &Graph,
_graph_to_dag: &[usize],
) -> Vec<(usize, String)> { ... }
fn base_lowering(&self) -> Option<&dyn Lowering<'a>> { ... }
}Expand description
Lowers a Graph into a DAG of ExecutableOps, ready to compile/execute.
Required Methods§
Sourcefn lower(
&self,
graph: &Graph,
mode: LoweringMode,
) -> Result<Dag<Box<dyn ExecutableOp>>>
fn lower( &self, graph: &Graph, mode: LoweringMode, ) -> Result<Dag<Box<dyn ExecutableOp>>>
Lowers graph for mode.
Provided Methods§
Sourcefn lower_with_mapping(
&self,
graph: &Graph,
mode: LoweringMode,
) -> Result<(Dag<Box<dyn ExecutableOp>>, Vec<usize>)>
fn lower_with_mapping( &self, graph: &Graph, mode: LoweringMode, ) -> Result<(Dag<Box<dyn ExecutableOp>>, Vec<usize>)>
Like [lower] but also returns a graph_node_idx → dag_node_idx mapping
so that graph-level metadata (e.g. names) can be propagated into the compiled DAG.
The default implementation assumes a 1-to-1 identity mapping between graph topological order and DAG node indices — valid for graphs that are already in topological order (which is always true for models built by sequential recording) and lowerings that do not reorder or split nodes. Override this method in lowerings that reorder or split nodes to return the correct mapping.
Sourcefn extra_dag_names(
&self,
_graph: &Graph,
_graph_to_dag: &[usize],
) -> Vec<(usize, String)>
fn extra_dag_names( &self, _graph: &Graph, _graph_to_dag: &[usize], ) -> Vec<(usize, String)>
Returns extra (dag_idx, name) pairs beyond those derivable from the 1-to-1 graph→dag mapping. Used for lowerings that split one graph node into multiple DAG nodes (e.g. Conv2d-with-bias → Conv2d + NchwBiasAdd); the “extra” DAG nodes would otherwise have no name and their weight parameters would not be loaded.
Sourcefn base_lowering(&self) -> Option<&dyn Lowering<'a>>
fn base_lowering(&self) -> Option<&dyn Lowering<'a>>
Returns the next lowering in a middleware chain, or None if this is
the final lowering. A custom lowering can call self.base_lowering()
to delegate ops it does not handle.