How the C++ libraries are split#

onnx-light is split into small C++ libraries so consumers link only the features they use. Parsing a model does not require schemas, shape inference, kernels, or backend tests.

The dependency graph below points from each library to its dependencies. It is generated from library_split.dot with dot -Tsvg.

Dependency graph between the onnx-light C++ libraries

The base dependency is lib_onnx_proto:

lib_onnx_proto
    └── lib_onnx_core
            ├── lib_onnx_op
            ├── lib_onnx_shape
            ├── lib_onnx_patterns
            ├── lib_onnx_kernels
            │       └── lib_onnx_backend_test
            ├── lib_onnx_gradient
            └── lib_onnx_manipulations
                    └── lib_onnx_lib

lib_onnx_core contains the shared mechanisms used by the extension libraries: graph helpers, symbolic expressions, the graph builder and pattern optimizer, runtime execution machinery, and empty dispatch registries. Concrete schemas, shape functions, patterns, and kernels are registered by their sibling libraries, so none needs to depend on another extension.

Summary of each library#

  • onnx_proto::lib_onnx_proto — proto-compatible message types, binary parsing and serialization, external data, and encrypted files.

  • onnx_light::lib_onnx_core — graph and symbolic-shape utilities, GraphBuilder, generic pattern optimization, runtime execution, and extension registries.

  • onnx_light::lib_onnx_op — lightweight ONNX operator schemas without full checker or shape-inference support.

  • onnx_light::lib_onnx_manipulations — text parser/printer, composition, and schema-independent model, attribute, and tensor helpers.

  • onnx_light::lib_onnx_lib — the complete ONNX-compatible schemas, checker, inliner, shape inference, and version converter.

  • onnx_light::lib_onnx_shape — concrete shape-inference and peak-memory functions.

  • onnx_light::lib_onnx_patterns — concrete ONNX graph-rewriting patterns.

  • onnx_light::lib_onnx_kernels — reference runtime kernels.

  • onnx_light::lib_onnx_backend_test — generated backend-test cases and their registry.

  • onnx_light::lib_onnx_gradient — reverse-mode gradient generation.

The last three targets are available only when ONNX_LIGHT_BUILD_KERNELS=ON. With Python enabled, the libraries are shared so all nanobind modules use the same C++ types; pure C++ builds use static libraries.

Extension registration#

The core library owns registries but does not register concrete ONNX implementations. Applications select extensions explicitly:

onnx_light::onnx_shapes::RegisterShapeFunctions();
onnx_light::onnx_kernels::RegisterKernelFunctions();
onnx_light::onnx_patterns::RegisterPatterns();

Kernel registration also registers the corresponding workspace estimators. Shape-only consumers can instead call onnx_light::onnx_kernels::RegisterPeakMemoryFunctions() when the kernel library is available. Estimator implementations live beside their kernels; neither lib_onnx_shape nor lib_onnx_core depends on lib_onnx_kernels.

This keeps linking predictable: an application that does not evaluate models, infer shapes, estimate peak memory, or optimize graphs does not pull in those implementations.

Registration is application setup, not session state. Shape, peak-memory, and built-in kernel registration populate process-wide dispatch tables explicitly; runtime sessions and analysis contexts only read those tables. Model-local functions remain owned by their model/session scope, and context-local custom functions or kernels do not modify process-wide tables. Gradient rules use a different contract: DefaultGradRegistry is immutable, while custom rules are added to a caller-owned GradRegistry passed explicitly to the gradient transformation.