Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
OnnxRuntimeSessionConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
4 from AthenaConfiguration.ComponentFactory import CompFactory
5 from AthOnnxComps.OnnxRuntimeFlags import OnnxRuntimeType
6 from typing import Optional
7 
9  model_fname: str,
10  execution_provider: Optional[OnnxRuntimeType] = None,
11  name="OnnxRuntimeSessionTool", **kwargs):
12  """"Configure OnnxRuntimeSessionTool in Control/AthOnnx/AthOnnxComps/src"""
13 
14  acc = ComponentAccumulator()
15 
16 
17  execution_provider = flags.AthOnnx.ExecutionProvider if execution_provider is None else execution_provider
18  name += execution_provider.name
19 
20  kwargs.setdefault("ModelFileName", model_fname)
21  if execution_provider is OnnxRuntimeType.CPU:
22  acc.setPrivateTools(CompFactory.AthOnnx.OnnxRuntimeSessionToolCPU(name, **kwargs))
23  elif execution_provider is OnnxRuntimeType.CUDA:
24  acc.setPrivateTools(CompFactory.AthOnnx.OnnxRuntimeSessionToolCUDA(name, **kwargs))
25  else:
26  raise ValueError("Unknown OnnxRuntime Execution Provider: %s" % execution_provider)
27 
28  return acc
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.OnnxRuntimeSessionConfig.OnnxRuntimeSessionToolCfg
def OnnxRuntimeSessionToolCfg(flags, str model_fname, Optional[OnnxRuntimeType] execution_provider=None, name="OnnxRuntimeSessionTool", **kwargs)
Definition: OnnxRuntimeSessionConfig.py:8