File indexing completed on 2025-01-30 09:15:13
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include <onnxruntime_cxx_api.h>
0012
0013 inline void runSessionWithIoBinding(Ort::Session& sess,
0014 std::vector<const char*>& inputNames,
0015 std::vector<Ort::Value>& inputData,
0016 std::vector<const char*>& outputNames,
0017 std::vector<Ort::Value>& outputData) {
0018 if (inputNames.size() < 1) {
0019 throw std::runtime_error("Onnxruntime input data mapping cannot be empty");
0020 }
0021 if (inputNames.size() != inputData.size()) {
0022 throw std::runtime_error("inputData size mismatch");
0023 }
0024
0025 Ort::IoBinding iobinding(sess);
0026 for (std::size_t idx = 0; idx < inputNames.size(); ++idx) {
0027 iobinding.BindInput(inputNames[idx], inputData[idx]);
0028 }
0029
0030 for (std::size_t idx = 0; idx < outputNames.size(); ++idx) {
0031 iobinding.BindOutput(outputNames[idx], outputData[idx]);
0032 }
0033
0034 sess.Run(Ort::RunOptions{nullptr}, iobinding);
0035 }