v2.0.0
Loading...
Searching...
No Matches
ml_onnx_model.cpp File Reference

Implementation of MLLIB::MlOnnxModel including session creation, IO-binding cache and zero-copy predict. More...

#include "ml_onnx_model.h"
#include <QDebug>
#include <QFileInfo>
#include <stdexcept>
Include dependency graph for ml_onnx_model.cpp:

Go to the source code of this file.

Detailed Description

Implementation of MLLIB::MlOnnxModel including session creation, IO-binding cache and zero-copy predict.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2026 MNE-CPP Authors

Author
Christoph Dinh chris.nosp@m.toph.nosp@m..dinh.nosp@m.@mne.nosp@m.-cpp..nosp@m.org
Since
2.2.0
Date
April 2026

The translation unit isolates every direct dependency on the ONNX Runtime C++ API behind #ifdef MNE_USE_ONNXRUNTIME, so the library object is buildable even when ORT is absent. The single static Ort::Env returned by MLLIB::MlOnnxModel::ortEnv is shared by all sessions in the process; per-instance Ort::Session and Ort::MemoryInfo are held in std::unique_ptr so the destructor must live in this TU (the forward-declared Ort types are incomplete at the header).

load opens the file with GraphOptimizationLevel::ORT_ENABLE_ALL, forces a single intra-op thread for deterministic output, disables memory patterns to keep peak RSS small, and caches input/output node names and shapes once so predict only pays for the actual Session::Run call. predict builds a zero-copy Ort::Value over the MLLIB::MlTensor buffer, runs the session, and copies the first output back into an owning tensor. save is intentionally a no-op: ONNX graphs are produced by their training framework, not by this thin inference wrapper.

Definition in file ml_onnx_model.cpp.