Skip to main content

Crate onnx_runtime_ir

Crate onnx_runtime_ir 

Source
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

ConceptType
Element typeDataType
Symbolic / static shapesShape, Dim, SymbolConstraints
Physical strided layoutTensorLayout, MemoryFormat
Device placementDeviceType, DeviceId
Graph values (SSA edges)Value, ValueId
Graph operationsNode, NodeId, Attribute
Constant / weight storageTensorData, SparseTensorData, WeightRef
The graph itselfGraph
ErrorsIrError, GraphError

§Design guarantees

  • SSA-like: every Value has at most one producer Node; node outputs are unique.
  • First-class layout & device: every value carries a TensorLayout and an optional DeviceId, unlike upstream ONNX / onnx-ir.
  • Mutable during optimization: the Graph mutation API keeps producer/consumer edges consistent so optimization passes can rewrite it, then it is shared immutably via Arc once 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 Vec storage with O(1) insert/remove/lookup by key.
Consumers
The unordered internal set of input slots that consume a value.
DeviceId
A specific device instance: a DeviceType plus an ordinal index.
Graph
A computation graph in SSA form.
Node
An operation in the graph.
NodeId
Unique identifier for a Node within a Graph.
SparseTensorData
A sparse constant tensor in COO form.
SymbolConstraints
Constraints on a symbolic dimension, used by shape bucketing, kernel specialization, and tiling (see docs/ORT2.md §11).
SymbolId
Unique identifier for a symbolic dimension.
TensorData
A concrete constant tensor held inline (e.g. an attribute value or a small initializer). Element bytes are stored little-endian and densely packed.
TensorLayout
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 Value within a Graph.

Enums§

Attribute
An ONNX operator attribute. Covers all attribute value kinds.
DataType
Supported tensor element types.
DeviceType
A class of compute device / execution backend.
Dim
A single dimension: either a concrete size or a symbol.
GraphError
A single structural defect in a Graph.
IrError
Crate-level error for fallible IR operations.
MemoryFormat
Memory-format hint used to pick vectorized kernels.
TypeProto
An ONNX TypeProto: the type of a value, which may be a tensor or a container of tensors (see docs/ORT2.md §3.2).
WeightRef
A reference to initializer (weight) data.

Constants§

AI_ONNX_DOMAIN
The explicit spelling of the default ONNX operator domain.

Traits§

ArenaKey
A type usable as an arena key: a newtype around a u32 index.

Functions§

as_static_shape
Returns Some(dims) if every dimension of shape is static.
broadcast_shapes
Compute the output shape of a numpy-style broadcast of a and b.
compute_contiguous_strides
Compute row-major (C-order) contiguous strides, in elements, for a shape.
is_contiguous
Whether strides describe a row-major contiguous layout for shape.
is_default_domain
Whether a raw operator domain string denotes the default ONNX domain.
is_fully_static
Whether every dimension of shape is static.
normalize_domain
Canonicalize an operator domain to its post-load form.
static_shape
Convenience constructor for a fully-static shape.

Type Aliases§

Result
A convenience Result alias for IR operations.
Shape
A tensor shape: an ordered list of Dims.
Usage
A node input slot that uses a value.