How the C++ libraries are split#
onnx-light is intentionally split into several small static (or shared)
C++ libraries (also referred to as assemblies) instead of a single
monolithic archive. The goal is to let any C++ project link only
what it actually needs: a program that just parses a ModelProto does
not need operator schemas, a program that only registers schemas does
not need shape inference, a program that only evaluates models does not
need the full ONNX schema / checker stack, and so on.
Each library has a well defined responsibility and a minimal set of
dependencies on the other libraries. The full dependency graph is
shown below (arrows point from a library to the library it depends
on). The SVG below is generated from
library_split.dot with
dot -Tsvg (Graphviz); regenerate it after editing the .dot source.
The same graph as an ASCII tree (rooted at lib_onnx_proto, the
base dependency):
lib_onnx_proto
├── lib_onnx_op
│ └── lib_onnx_optim
└── lib_onnx_manipulations
├── lib_onnx_lib
└── lib_onnx_kernels
└── lib_onnx_backend_test
lib_onnx_op and lib_onnx_manipulations are independent siblings: each
links directly against lib_onnx_proto but neither depends on the other.
lib_onnx_optim depends on lib_onnx_op only (it does not pull in
lib_onnx_lib). lib_onnx_manipulations gathers the schema-independent
ModelProto manipulation helpers (text parser / printer, attribute and
tensor proto helpers, data-type name utilities and the graph-manipulation
helpers); both lib_onnx_lib (full schemas, checker, shape inference,
version converter) and lib_onnx_kernels depend publicly on it.
lib_onnx_backend_test depends publicly on lib_onnx_kernels (and
transitively on lib_onnx_manipulations / lib_onnx_proto) because every
registered test case computes its expected outputs by invoking the bundled C++
reference kernels.
When installed (cmake --install) all libraries are exported under the
onnx_light:: namespace and can be consumed individually through
find_package(onnx_light).
Summary of each library#
Library / CMake target and Sources |
What it contains |
|---|---|
|
Protobuf-compatible message types ( |
|
Lightweight |
|
Foundational |
|
Full ONNX-compatible operator schemas (with history), checker,
inliner, shape inference and version converter. This is the
target to link for the complete ONNX-light experience.
Depends publicly on |
|
Shape-inference dispatch table, expression engine for small
tensor / backward-propagation shape inference, and graph
optimization helpers. Depends publicly on |
|
C++ reference implementation of the ONNX operators used to
evaluate models in-process. Contains the runtime data model
( |
|
Backend test infrastructure ( |
What to link for a given use case#
The libraries are designed so that a downstream project links the smallest set that covers its needs. The most common scenarios are:
Read / write ONNX models, including > 2 GB files, external data or encrypted models, without any operator notion — link
onnx_light::lib_onnx_proto.Enumerate or look up ONNX operator schemas (for example to drive code generation or to validate node op types) without paying for shape inference — link
onnx_light::lib_onnx_op.Parse / print ONNX text models and manipulate ``ModelProto`` / ``GraphProto`` (attribute and tensor proto helpers, data-type name utilities, graph-input collection) without pulling in the operator schemas — link
onnx_light::onnx_manipulations.Full ONNX feature set (schemas with history, checker, inliner, shape inference, version conversion) — link
onnx_light::onnx_light.Shape inference and graph optimization passes — link
onnx_light::lib_onnx_optim(which transitively pullslib_onnx_opandlib_onnx_proto).Evaluate ONNX nodes / graphs / models in C++ using the bundled reference kernels (runtime
struct Tensor,RunGraph/RunFunction/RunModel,SplitMix64RNG, …) without pulling in any backend-test fixtures — linkonnx_light::onnx_kernels.Run backend tests / evaluate models in C++ using the built-in reference kernels — link
onnx_light::onnx_backend_test(which transitively pullslib_onnx_kernelsandlib_onnx_proto). It can be combined withonnx_light::onnx_lightwhen both schema validation and execution are needed.
The Python extensions follow the same split and each link to the
minimal C++ library that provides their feature. See
Linking onnx-light in C++ for the full discussion of the Python /
C++ packaging and of the shared lib_onnx_proto runtime.