ATLAS Offline Software
OnnxRuntimeSessionToolCPU.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 
19  // Create the session options.
20  // TODO: Make this configurable.
21  // other threading options: https://onnxruntime.ai/docs/performance/tune-performance/threading.html
22  // 1) SetIntraOpNumThreads( 1 );
23  // 2) SetInterOpNumThreads( 1 );
24  // 3) SetGraphOptimizationLevel( GraphOptimizationLevel::ORT_ENABLE_EXTENDED );
25 
26  Ort::SessionOptions sessionOptions;
27  sessionOptions.SetGraphOptimizationLevel( GraphOptimizationLevel::ORT_ENABLE_ALL );
28 
29  // Create the session.
30  ATH_MSG_INFO("Asking model from: " << m_modelFileName.value());
31  std::string modelFilePath = PathResolver::find_file(m_modelFileName.value(), "CALIBPATH", PathResolver::RecursiveSearch);
32  ATH_MSG_INFO("Loading model from: " << modelFilePath);
33  m_session = std::make_unique<Ort::Session>(m_onnxRuntimeSvc->env(), modelFilePath.c_str(), sessionOptions);
34 
35  return StatusCode::SUCCESS;
36 }
37 
39 {
40  return *m_session;
41 }
PathResolver::RecursiveSearch
@ RecursiveSearch
Definition: PathResolver.h:28
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
PathResolver::find_file
static std::string find_file(const std::string &logical_file_name, const std::string &search_path, SearchType search_type=LocalSearch)
Definition: PathResolver.cxx:251
asg
Definition: DataHandleTestTool.h:28
AthOnnx::OnnxRuntimeSessionToolCPU::session
virtual Ort::Session & session() const override final
Create Onnx Runtime session.
Definition: OnnxRuntimeSessionToolCPU.cxx:38
python.oracle.Session
Session
Definition: oracle.py:78
OnnxRuntimeSessionToolCPU.h
AthOnnx::OnnxRuntimeSessionToolCPU::OnnxRuntimeSessionToolCPU
OnnxRuntimeSessionToolCPU()=delete
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
PathResolver.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AthOnnx::OnnxRuntimeSessionToolCPU::initialize
virtual StatusCode initialize() override final
Initialize the tool.
Definition: OnnxRuntimeSessionToolCPU.cxx:13