ATLAS Offline Software
Loading...
Searching...
No Matches
OnnxRuntimeSessionToolCPU.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
7
9 : asg::AsgTool( name)
10{
11}
12
14{
15 // Get the Onnx Runtime service.
16 ATH_CHECK(m_onnxRuntimeSvc.retrieve());
17 ATH_MSG_INFO(" OnnxRuntime release: " << OrtGetApiBase()->GetVersionString());
18 Ort::SessionOptions sessionOptions;
19 sessionOptions.SetGraphOptimizationLevel( GraphOptimizationLevel::ORT_ENABLE_ALL );
20 sessionOptions.DisablePerSessionThreads(); // use global thread pool.
21
22 // Create the session.
23 ATH_MSG_INFO("Asking model from: " << m_modelFileName.value());
24 std::string modelFilePath = PathResolver::find_calib_file(m_modelFileName.value());
25 ATH_MSG_INFO("Loading model from: " << modelFilePath);
26 m_session = std::make_unique<Ort::Session>(m_onnxRuntimeSvc->env(), modelFilePath.c_str(), sessionOptions);
27
28 return StatusCode::SUCCESS;
29}
30
32{
33 return *m_session;
34}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
std::unique_ptr< Ort::Session > m_session
virtual Ort::Session & session() const override final
Create Onnx Runtime session.
virtual StatusCode initialize() override final
Initialize the tool.
ServiceHandle< IOnnxRuntimeSvc > m_onnxRuntimeSvc
Gaudi::Property< std::string > m_modelFileName
static std::string find_calib_file(const std::string &logical_file_name)
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58