Expand description
Shared default impls for the Backend Contract trait.
The Contract surface is thirty typed per-op methods
(super::Backend::add, super::Backend::matmul, …) plus
super::Backend::execute (&GraphProto, HashMap →
HashMap). Each side has a default body that calls into the
other so backend authors override whichever side is natural:
-
Override per-op methods (e.g.
CpuBackendover ndarray): each Contract method is a direct kernel call. The defaultexecutewalks the graph node-by-node and dispatches through the overridden per-op methods. -
Override
execute(e.g. a graph-compiling backend like Burn): the wholeGraphProtobody is handed to the native execution engine. The per-op defaults wrap a single-nodeGraphProtoand call back intoexecute.
Pathological case: a backend that overrides neither side
stack-overflows — every add call walks into a single-node
graph that calls add again. Document loudly on the trait.
This module also encodes the attribute conventions every
BackendSubgraph_* carrier uses for primitive ops with
attributes (ReduceSum.axes, Reshape.shape, Cast.to, …).
Per-op defaults call ints_attr / int_attr / tensor_attr
to encode; the walker calls attr_ints / attr_int /
attr_tensor to decode. ONNX-style names are preserved
(axes, keepdims, shape, perm, axis, to, value).
Enums§
- Backend
Walk Error - Failures the default walker surfaces when handed a malformed
GraphProtobody or when aBackend::executeimpl violates its output-name contract. RequiredFrombound onBackend::Errormakes the walker fail with a typed error instead ofpanic!-ing on peer-supplied or buggy input.
Functions§
- execute_
graph_ via_ per_ op - Default body for
Backend::execute— walksgraph.nodein topological order, dispatching each through the typed per-op methods onbackend. The implementation is a tight linear scan: ONNX guaranteesgraph.nodeis topologically ordered, so no petgraph / explicit ordering is needed. - execute_
multi - Default body for multi-output per-op methods (
Backend::splittoday). Builds a one-nodeGraphProtowithoutput_countpositionally-named outputs, callsBackend::execute, and extracts the outputs in declared order. - execute_
single - Default body for every per-op method on
Backend— wraps the op in a one-nodeGraphProtoand routes throughBackend::execute. Backends that overrideexecutenatively (graph-compiling backends) get the per-op surface free; backends that override the per-op methods directly bypass this helper entirely. - int_
attr - Build an
AttributeProtoof typeINT(per ONNX [AttributeType::Int]). Used by the Contract per-op defaults for scalari64attributes (axis,to,keepdims). - ints_
attr - Build an
AttributeProtoof typeINTS. Used for vector attributes (axes,shape,perm,starts,ends,steps,split). - tensor_
attr - Build an
AttributeProtoof typeTENSOR. Used forConstant’svalueattribute.