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 [
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 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.