From 0f393d46adbb286a439c8f89f31d5e8ae0f9d09a Mon Sep 17 00:00:00 2001
From: Martin Beyer <martin.beyer@physik.uni-giessen.de>
Date: Wed, 5 Jun 2024 07:47:06 +0000
Subject: [PATCH] mRich: fix ONNX Runtime crash using slurm

---
 reco/detectors/rich/mcbm/CbmRichMCbmDenoiseCnn.cxx | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/reco/detectors/rich/mcbm/CbmRichMCbmDenoiseCnn.cxx b/reco/detectors/rich/mcbm/CbmRichMCbmDenoiseCnn.cxx
index 5ecebd00b7..96f46b2c1e 100644
--- a/reco/detectors/rich/mcbm/CbmRichMCbmDenoiseCnn.cxx
+++ b/reco/detectors/rich/mcbm/CbmRichMCbmDenoiseCnn.cxx
@@ -28,13 +28,6 @@ void CbmRichMCbmDenoiseCnn::Init()
   fOrtEnv = std::make_unique<Ort::Env>(ORT_LOGGING_LEVEL_WARNING, GetName());
 
   fOrtSessionOptions = std::make_unique<Ort::SessionOptions>();
-  fOrtSession        = std::make_unique<Ort::Session>(*fOrtEnv, fOnnxFilePath.c_str(), *fOrtSessionOptions);
-
-  fOrtRunOptions    = std::make_unique<Ort::RunOptions>(nullptr);
-  fOrtAllocatorInfo = std::make_unique<Ort::MemoryInfo>(Ort::MemoryInfo::CreateCpu(OrtDeviceAllocator, OrtMemTypeCPU));
-  fOrtInput         = std::make_unique<Ort::Value>(Ort::Value::CreateTensor<float>(
-    *fOrtAllocatorInfo, fInput.data(), fInput.size(), fInputShape.data(), fInputShape.size()));
-
   // Thread numbers need to be explicitly set. With the current Ort version it can't detect
   // the numbers on the cluster, should be fixed in a later version.
   fOrtSessionOptions->SetIntraOpNumThreads(1);
@@ -42,6 +35,13 @@ void CbmRichMCbmDenoiseCnn::Init()
   fOrtSessionOptions->SetExecutionMode(ORT_SEQUENTIAL);
   fOrtSessionOptions->SetGraphOptimizationLevel(ORT_ENABLE_ALL);
 
+  fOrtSession = std::make_unique<Ort::Session>(*fOrtEnv, fOnnxFilePath.c_str(), *fOrtSessionOptions);
+
+  fOrtRunOptions    = std::make_unique<Ort::RunOptions>(nullptr);
+  fOrtAllocatorInfo = std::make_unique<Ort::MemoryInfo>(Ort::MemoryInfo::CreateCpu(OrtDeviceAllocator, OrtMemTypeCPU));
+  fOrtInput         = std::make_unique<Ort::Value>(Ort::Value::CreateTensor<float>(
+    *fOrtAllocatorInfo, fInput.data(), fInput.size(), fInputShape.data(), fInputShape.size()));
+
   fCbmRichDigiMapManager = &CbmRichDigiMapManager::GetInstance();
 }
 
-- 
GitLab