ClikaRT::io::OnnxModel
class
Header: ClikaRT/io/onnx_model.h
An ONNX model, opened from disk or built from scratch. Move-only.
Static member functions
open()
static OnnxModel open(std::string_view path, OnnxModelOptions options = {})
Open a .onnx file. The graph structure loads into memory (memory-mapped parse); initializer payloads referenced as external data stay on disk beside the model until something consumes them. No compute graph is built and nothing is validated beyond the wire format; compile is where operator support is decided.
Declared in ClikaRT/io/onnx_model.h, line 99
create()
static OnnxModel create(
std::string_view graph_name,
std::int64_t opset_version = 0,
OnnxModelOptions options = {}
)
Create an empty model: a named graph at the given ai.onnx opset version (and OnnxModelOptions::ir_version). A version <= 0 means "solve it": both unset → the library defaults; only the opset given → the minimum IR that supports it; only the IR given → the highest opset it supports. A fully-specified pair is validated against the official ONNX version table; an unsupported combination is an error, so a saved model is version-valid by construction. Build the graph up with add_input / add_initializer / add_node / add_output.
Declared in ClikaRT/io/onnx_model.h, line 113
Member functions
OnnxModel(OnnxModel)
OnnxModel(OnnxModel&&) noexcept
Move-only: transfers the model.
Declared in ClikaRT/io/onnx_model.h, line 120
operator=(OnnxModel)
Move-assign: transfers the model.
Declared in ClikaRT/io/onnx_model.h, line 122
OnnxModel(OnnxModel)
OnnxModel(const OnnxModel&) =delete
Declared in ClikaRT/io/onnx_model.h, line 123
operator=(OnnxModel)
Declared in ClikaRT/io/onnx_model.h, line 124
~OnnxModel()
~OnnxModel()
Releases the parsed model.
Declared in ClikaRT/io/onnx_model.h, line 126
num_nodes()
std::size_t num_nodes() const noexcept
graph node count
Declared in ClikaRT/io/onnx_model.h, line 129
num_initializers()
std::size_t num_initializers() const noexcept
initializer (weight) count
Declared in ClikaRT/io/onnx_model.h, line 130
opset()
std::int64_t opset() const noexcept
The default (ai.onnx) opset version / the model IR version.
Declared in ClikaRT/io/onnx_model.h, line 132
ir_version()
std::int64_t ir_version() const noexcept
the file's ONNX IR version
Declared in ClikaRT/io/onnx_model.h, line 133
inputs()
std::vector<spec::TensorSpec> inputs() const
Graph inputs / outputs as (name, dtype, dims) specs, declaration order. A dynamic dimension reads as spec::TensorSpec::kDynamicDim.
Declared in ClikaRT/io/onnx_model.h, line 138
outputs()
std::vector<spec::TensorSpec> outputs() const
Graph outputs: the same (name, dtype, dims) spec shape as inputs(), declaration order.
Throws
ClikaRT::Error: when the specs cannot be read.
Declared in ClikaRT/io/onnx_model.h, line 142
add_opset_domain()
void add_opset_domain(std::string_view domain, std::int64_t version)
Declare an additional opset import (e.g. ("com.microsoft", 1)) for nodes added under a non-standard domain.
Declared in ClikaRT/io/onnx_model.h, line 147
add_input(string_view, DataType, vector<spec::DimOrInt>)
std::string add_input(
std::string_view name,
DataType dtype,
const std::vector<spec::DimOrInt>& shape
)
Register a graph input / output; returns the tensor name. The shape mixes all three dim spellings (see spec::DimOrInt): a concrete extent, an anonymous dynamic dim (any value <= 0, each occurrence its own), and a spec::Dim object, named or identity-tied, so the SAME spec::Dim passed to several declarations ties those dims (an anonymous spec::Dim gets a systematic model-assigned name: "dim_0", "dim_1", …). The spec::TensorSpec overload takes back exactly what inputs() / outputs() (here and on graph::ModelGraph) hand out: one IO-slot vocabulary across the library.
Declared in ClikaRT/io/onnx_model.h, line 160
add_input(spec::TensorSpec)
std::string add_input(const spec::TensorSpec& spec)
Register a graph input / output; returns the tensor name. The shape mixes all three dim spellings (see spec::DimOrInt): a concrete extent, an anonymous dynamic dim (any value <= 0, each occurrence its own), and a spec::Dim object, named or identity-tied, so the SAME spec::Dim passed to several declarations ties those dims (an anonymous spec::Dim gets a systematic model-assigned name: "dim_0", "dim_1", …). The spec::TensorSpec overload takes back exactly what inputs() / outputs() (here and on graph::ModelGraph) hand out: one IO-slot vocabulary across the library.
Declared in ClikaRT/io/onnx_model.h, line 164
add_output(string_view, DataType, vector<spec::DimOrInt>)
std::string add_output(
std::string_view name,
DataType dtype,
const std::vector<spec::DimOrInt>& shape
)
Declared in ClikaRT/io/onnx_model.h, line 169
add_output(spec::TensorSpec)
std::string add_output(const spec::TensorSpec& spec)
Declared in ClikaRT/io/onnx_model.h, line 173
add_initializer()
std::string add_initializer(const Tensor& value)
Create an initializer (a graph constant) from a materialized tensor's bytes. Returns the generated initializer name.
Declared in ClikaRT/io/onnx_model.h, line 180
add_node()
std::vector<std::string> add_node(
std::string_view op_type,
const std::vector<std::string>& inputs,
int num_outputs,
const std::vector<OnnxAttr>& attrs = {},
std::string_view domain = {},
const std::vector<std::string>& output_names = {}
)
Append a node of any op type. inputs are tensor names in the op's positional input slots (an empty string is an omitted interior optional); each of the num_outputs outputs gets a generated name, returned in node output order, or, with a non-empty output_names (one per output), the caller's exact names (an in-use name is an error). domain empty = the standard ai.onnx domain (declare a custom domain via add_opset_domain first).
Declared in ClikaRT/io/onnx_model.h, line 197
remove_node()
void remove_node(std::string_view name)
Remove the node named name (an error if absent).
Declared in ClikaRT/io/onnx_model.h, line 206
optimize()
int optimize()
Run the ONNX graph-rewrite pipeline to a fixed point: collapse double casts, drop redundant quantize/dequantize pairs, fuse shape movement, fold constants, eliminate dead nodes. Returns the number of pipeline passes executed.
Declared in ClikaRT/io/onnx_model.h, line 213
merge()
void merge(OnnxModel second, const std::vector<std::pair<std::string, std::string>>& io_map)
Combine second into this model (consuming it): each io_map entry (this_output, second_input) connects one of THIS model's outputs to one of second's inputs; the connected outputs stop being graph outputs and the connected inputs stop being graph inputs; everything unconnected remains, so the combined model's inputs are this model's plus second's unconnected ones, and its outputs are second's plus this model's unconnected ones. Name collisions between the two graphs are resolved automatically (the second model's colliding names are renamed); opset imports merge to the max version per domain.
Declared in ClikaRT/io/onnx_model.h, line 226
save()
void save(std::string_view path) const
Assemble the model and write it to path. Initializer payloads ride inline or in a <stem>_data sidecar per OnnxModelOptions::save_as_external_data. A model opened with external-data references saves those references verbatim; keep its sidecar beside the saved file.
Declared in ClikaRT/io/onnx_model.h, line 238
compile()
graph::ModelGraph compile(const graph::CompileOptions& options = {}) const
Build the executable form: parse every node into its runtime operator (an unsupported op fails here, naming it), bind the weights, resolve shapes per options (see graph::CompileOptions), optimize, and return the runnable graph::ModelGraph. The OnnxModel is unchanged and reusable.
Declared in ClikaRT/io/onnx_model.h, line 246