Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:15:13

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
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 }