Expand description
§onnx-runtime-ir
The Graph intermediate representation (IR) for the ORT 2.0 runtime.
This crate is the stable contract that every downstream runtime crate
(onnx-runtime-loader, onnx-runtime-ep-api, onnx-runtime-session, …)
builds against. It is intentionally pure, safe Rust with no FFI and no
device dependencies so it compiles standalone on any target.
It is a Rust port of the design captured in docs/ORT2.md §3 (Graph IR),
§5 (Striding & Layout) and §11 (Dynamic Shape), itself inspired by the
Python onnx-ir package.
§What lives here
| Concept | Type |
|---|---|
| Element type | DataType |
| Symbolic / static shapes | Shape, Dim, SymbolConstraints |
| Physical strided layout | TensorLayout, MemoryFormat |
| Device placement | DeviceType, DeviceId |
| Graph values (SSA edges) | Value, ValueId |
| Graph operations | Node, NodeId, Attribute |
| Constant / weight storage | TensorData, SparseTensorData, WeightRef |
| The graph itself | Graph |
| Errors | IrError, GraphError |
§Design guarantees
- SSA-like: every
Valuehas at most one producerNode; node outputs are unique. - First-class layout & device: every value carries a
TensorLayoutand an optionalDeviceId, unlike upstream ONNX /onnx-ir. - Mutable during optimization: the
Graphmutation API keeps producer/consumer edges consistent so optimization passes can rewrite it, then it is shared immutably viaArconce frozen.
Deep algorithms whose full implementation belongs to a later task (e.g.
per-op shape inference) are represented here only by their data model; the
Graph operations that are cheap and foundational (topological ordering,
validation, edge rewiring, broadcasting, stride arithmetic) are fully
implemented and unit-tested so downstream crates compile against a stable,
working surface.
Structs§
- Arena
- A slot map: dense
Vecstorage withO(1)insert/remove/lookup by key. - Consumers
- The unordered internal set of input slots that consume a value.
- Device
Id - A specific device instance: a
DeviceTypeplus an ordinal index. - Graph
- A computation graph in SSA form.
- Node
- An operation in the graph.
- NodeId
- Unique identifier for a
Nodewithin aGraph. - Sparse
Tensor Data - A sparse constant tensor in COO form.
- Symbol
Constraints - Constraints on a symbolic dimension, used by shape bucketing, kernel
specialization, and tiling (see
docs/ORT2.md§11). - Symbol
Id - Unique identifier for a symbolic dimension.
- Tensor
Data - A concrete constant tensor held inline (e.g. an attribute value or a small initializer). Element bytes are stored little-endian and densely packed.
- Tensor
Layout - First-class strided layout for a value.
- Value
- A value flowing through the graph — the output of one node and the input of zero or more others (SSA form: at most one producer).
- ValueId
- Unique identifier for a
Valuewithin aGraph.
Enums§
- Attribute
- An ONNX operator attribute. Covers all attribute value kinds.
- Data
Type - Supported tensor element types.
- Device
Type - A class of compute device / execution backend.
- Dim
- A single dimension: either a concrete size or a symbol.
- Graph
Error - A single structural defect in a
Graph. - IrError
- Crate-level error for fallible IR operations.
- Memory
Format - Memory-format hint used to pick vectorized kernels.
- Type
Proto - An ONNX
TypeProto: the type of a value, which may be a tensor or a container of tensors (seedocs/ORT2.md§3.2). - Weight
Ref - A reference to initializer (weight) data.
Constants§
- AI_
ONNX_ DOMAIN - The explicit spelling of the default ONNX operator domain.
Traits§
- Arena
Key - A type usable as an arena key: a newtype around a
u32index.
Functions§
- as_
static_ shape - Returns
Some(dims)if every dimension ofshapeis static. - broadcast_
shapes - Compute the output shape of a numpy-style broadcast of
aandb. - compute_
contiguous_ strides - Compute row-major (C-order) contiguous strides, in elements, for a shape.
- is_
contiguous - Whether
stridesdescribe a row-major contiguous layout forshape. - is_
default_ domain - Whether a raw operator domain string denotes the default ONNX domain.
- is_
fully_ static - Whether every dimension of
shapeis static. - normalize_
domain - Canonicalize an operator domain to its post-load form.
- static_
shape - Convenience constructor for a fully-static shape.