Skip to content

Commit 4de0632

Browse files
authored
Merge branch 'dev' into streamline-spawner
2 parents 0f169a9 + 0c5140e commit 4de0632

File tree

33 files changed

+431
-422
lines changed

33 files changed

+431
-422
lines changed

Common/ML/include/ML/OrtInterface.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,10 @@ class OrtModel
4545

4646
public:
4747
// Constructors & destructors
48-
OrtModel() = default;
49-
OrtModel(std::unordered_map<std::string, std::string> optionsMap) { init(optionsMap); }
50-
void init(std::unordered_map<std::string, std::string> optionsMap)
51-
{
52-
initOptions(optionsMap);
53-
initEnvironment();
54-
}
55-
virtual ~OrtModel() = default;
48+
OrtModel();
49+
OrtModel(std::unordered_map<std::string, std::string> optionsMap);
50+
void init(std::unordered_map<std::string, std::string> optionsMap);
51+
virtual ~OrtModel();
5652

5753
// General purpose
5854
void initOptions(std::unordered_map<std::string, std::string> optionsMap);
@@ -113,7 +109,7 @@ class OrtModel
113109
private:
114110
// ORT variables -> need to be hidden as pImpl
115111
struct OrtVariables;
116-
OrtVariables* mPImplOrt;
112+
std::unique_ptr<OrtVariables> mPImplOrt;
117113

118114
// Input & Output specifications of the loaded network
119115
std::vector<const char*> mInputNamesChar, mOutputNamesChar;

Common/ML/src/OrtInterface.cxx

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,20 @@ namespace o2
2727
namespace ml
2828
{
2929

30+
OrtModel::OrtModel() = default;
31+
OrtModel::OrtModel(std::unordered_map<std::string, std::string> optionsMap) { init(optionsMap); }
32+
OrtModel::~OrtModel() = default;
33+
void OrtModel::init(std::unordered_map<std::string, std::string> optionsMap)
34+
{
35+
initOptions(optionsMap);
36+
initEnvironment();
37+
}
38+
3039
struct OrtModel::OrtVariables { // The actual implementation is hidden in the .cxx file
3140
// ORT runtime objects
3241
Ort::RunOptions runOptions;
33-
std::shared_ptr<Ort::Env> env = nullptr;
34-
std::shared_ptr<Ort::Session> session = nullptr; ///< ONNX session
42+
std::unique_ptr<Ort::Env> env = nullptr;
43+
std::unique_ptr<Ort::Session> session = nullptr; ///< ONNX session
3544
Ort::SessionOptions sessionOptions;
3645
Ort::AllocatorWithDefaultOptions allocator;
3746
Ort::MemoryInfo memoryInfo = Ort::MemoryInfo("Cpu", OrtAllocatorType::OrtDeviceAllocator, 0, OrtMemType::OrtMemTypeDefault);
@@ -41,7 +50,7 @@ struct OrtModel::OrtVariables { // The actual implementation is hidden in the .c
4150
// General purpose
4251
void OrtModel::initOptions(std::unordered_map<std::string, std::string> optionsMap)
4352
{
44-
mPImplOrt = new OrtVariables();
53+
mPImplOrt = std::make_unique<OrtVariables>();
4554

4655
// Load from options map
4756
if (!optionsMap.contains("model-path")) {
@@ -101,7 +110,7 @@ void OrtModel::initOptions(std::unordered_map<std::string, std::string> optionsM
101110

102111
void OrtModel::initEnvironment()
103112
{
104-
mPImplOrt->env = std::make_shared<Ort::Env>(
113+
mPImplOrt->env = std::make_unique<Ort::Env>(
105114
OrtLoggingLevel(mLoggingLevel),
106115
(mEnvName.empty() ? "ORT" : mEnvName.c_str()),
107116
// Integrate ORT logging into Fairlogger
@@ -129,7 +138,7 @@ void OrtModel::initSession()
129138
if (mAllocateDeviceMemory) {
130139
memoryOnDevice(mDeviceId);
131140
}
132-
mPImplOrt->session = std::make_shared<Ort::Session>(*mPImplOrt->env, mModelPath.c_str(), mPImplOrt->sessionOptions);
141+
mPImplOrt->session = std::make_unique<Ort::Session>(*mPImplOrt->env, mModelPath.c_str(), mPImplOrt->sessionOptions);
133142
mPImplOrt->ioBinding = std::make_unique<Ort::IoBinding>(*mPImplOrt->session);
134143

135144
setIO();
@@ -147,12 +156,12 @@ void OrtModel::memoryOnDevice(int32_t deviceIndex)
147156
(mPImplOrt->sessionOptions).AddConfigEntry("session.use_env_allocators", "1"); // This should enable to use the volatile memory allocation defined in O2/GPU/GPUTracking/TPCClusterFinder/GPUTPCNNClusterizerHost.cxx; not working yet: ONNX still assigns new memory at init time
148157
(mPImplOrt->sessionOptions).AddConfigEntry("session_options.enable_cpu_mem_arena", "0"); // This should enable to use the volatile memory allocation defined in O2/GPU/GPUTracking/TPCClusterFinder/GPUTPCNNClusterizerHost.cxx; not working yet: ONNX still assigns new memory at init time
149158
// Arena memory shrinkage comes at performance cost
150-
/// For now prefer to use single allocation, enabled by O2/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu -> SetONNXGPUStream -> rocm_options.arena_extend_strategy = 0;
151-
// (mPImplOrt->runOptions).AddConfigEntry("memory.enable_memory_arena_shrinkage", ("gpu:" + std::to_string(deviceIndex)).c_str()); // See kOrtRunOptionsConfigEnableMemoryArenaShrinkage, https://github.com/microsoft/onnxruntime/blob/90c263f471bbce724e77d8e62831d3a9fa838b2f/include/onnxruntime/core/session/onnxruntime_run_options_config_keys.h#L27
159+
// For now prefer to use single allocation, enabled by O2/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu -> SetONNXGPUStream -> rocm_options.arena_extend_strategy = 0;
160+
(mPImplOrt->runOptions).AddConfigEntry("memory.enable_memory_arena_shrinkage", ("gpu:" + std::to_string(deviceIndex)).c_str()); // See kOrtRunOptionsConfigEnableMemoryArenaShrinkage, https://github.com/microsoft/onnxruntime/blob/90c263f471bbce724e77d8e62831d3a9fa838b2f/include/onnxruntime/core/session/onnxruntime_run_options_config_keys.h#L27
152161

153162
std::string dev_mem_str = "";
154163
if (mDeviceType == "ROCM") {
155-
dev_mem_str = "Hip";
164+
dev_mem_str = "HipPinned";
156165
}
157166
if (mDeviceType == "CUDA") {
158167
dev_mem_str = "Cuda";
@@ -166,7 +175,7 @@ void OrtModel::memoryOnDevice(int32_t deviceIndex)
166175

167176
void OrtModel::resetSession()
168177
{
169-
mPImplOrt->session = std::make_shared<Ort::Session>(*(mPImplOrt->env), mModelPath.c_str(), mPImplOrt->sessionOptions);
178+
mPImplOrt->session = std::make_unique<Ort::Session>(*(mPImplOrt->env), mModelPath.c_str(), mPImplOrt->sessionOptions);
170179
}
171180

172181
// Getters
@@ -252,7 +261,7 @@ void OrtModel::setIO()
252261

253262
void OrtModel::setEnv(Ort::Env* env)
254263
{
255-
mPImplOrt->env = std::shared_ptr<Ort::Env>(env);
264+
mPImplOrt->env.reset(env);
256265
}
257266

258267
// Inference
@@ -308,6 +317,14 @@ void OrtModel::inference(I* input, int64_t input_size, O* output)
308317
(mPImplOrt->ioBinding)->BindOutput(mOutputNames[0].c_str(), outputTensor);
309318

310319
(mPImplOrt->session)->Run(mPImplOrt->runOptions, *mPImplOrt->ioBinding);
320+
// mPImplOrt->session->Run(
321+
// mPImplOrt->runOptions,
322+
// mInputNamesChar.data(),
323+
// &inputTensor,
324+
// mInputNamesChar.size(),
325+
// mOutputNamesChar.data(),
326+
// &outputTensor,
327+
// mOutputNamesChar.size());
311328
}
312329

313330
template void OrtModel::inference<OrtDataType::Float16_t, OrtDataType::Float16_t>(OrtDataType::Float16_t*, int64_t, OrtDataType::Float16_t*);
@@ -427,10 +444,7 @@ template std::vector<OrtDataType::Float16_t> OrtModel::inference<OrtDataType::Fl
427444
// Release session
428445
void OrtModel::release(bool profilingEnabled)
429446
{
430-
// if (profilingEnabled) {
431-
// mPImplOrt->session->EndProfiling();
432-
// }
433-
LOG(info) << "(ORT) Size of mPImplOrt: " << sizeof(*mPImplOrt) << " bytes";
447+
mPImplOrt.reset();
434448
}
435449

436450
// private

DataFormats/Detectors/Common/include/DetectorsCommonDataFormats/AlignParam.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ class AlignParam
3737
AlignParam(const char* symname, int algID, // volume symbolic name and its alignable ID
3838
double x, double y, double z, // delta translation
3939
double psi, double theta, double phi, // delta rotation
40-
bool global = true); // global (preferable) or local delta definition
40+
bool global = true, // global (preferable) or local delta definition
41+
bool convertLocalToGlobal = true); // if local is provided, convert it to global
4142

42-
AlignParam(const char* symname, int algID, TGeoMatrix& m, bool global = true);
43+
AlignParam(const char* symname, int algID, TGeoMatrix& m,
44+
bool global = true, // global (preferable) or local delta definition
45+
bool convertLocalToGlobal = true); // if local is provided, convert it to global
4346

4447
/// return symbolic name of the volume
4548
const std::string& getSymName() const { return mSymName; }
@@ -70,6 +73,9 @@ class AlignParam
7073
void setAlignableID(int id) { mAlignableID = id; }
7174
/// ================ methods for direct setting of delta params
7275

76+
/// set parameters
77+
void setParams(double x, double y, double z, double psi, double theta, double phi);
78+
7379
/// set parameters of global delta
7480
void setGlobalParams(double x, double y, double z, double psi, double theta, double phi);
7581

@@ -114,6 +120,9 @@ class AlignParam
114120

115121
int rectify(double zero = 1e-13);
116122

123+
bool isGlobal() const { return mIsGlobal; }
124+
void setIsGlobal(bool v) { mIsGlobal = v; }
125+
117126
protected:
118127
bool matrixToAngles(const double* rot, double& psi, double& theta, double& phi) const;
119128
void anglesToMatrix(double psi, double theta, double phi, double* rot) const;
@@ -123,8 +132,8 @@ class AlignParam
123132
private:
124133
std::string mSymName{};
125134

135+
bool mIsGlobal = true; /// is this global delta?
126136
int mAlignableID = -1; /// alignable ID (set for sensors only)
127-
128137
double mX = 0.; ///< X translation of global delta
129138
double mY = 0.; ///< Y translation of global delta
130139
double mZ = 0.; ///< Z translation of global delta
@@ -133,7 +142,7 @@ class AlignParam
133142
double mTheta = 0.; ///< "roll" : Euler angle of rotation around Y axis after 1st rotation (radians)
134143
double mPhi = 0.; ///< "yaw" : Euler angle of rotation around Z axis (radians)
135144

136-
ClassDefNV(AlignParam, 1);
145+
ClassDefNV(AlignParam, 2);
137146
};
138147

139148
} // namespace detectors

DataFormats/Detectors/Common/src/AlignParam.cxx

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,32 @@ using namespace o2::detectors;
2626
AlignParam::AlignParam(const char* symname, int algID, // volume symbolic name and its alignable ID
2727
double x, double y, double z, // delta translation
2828
double psi, double theta, double phi, // delta rotation
29-
bool global) // global (preferable) or local delta definition
30-
: mSymName(symname), mAlignableID(algID)
29+
bool global, // global (preferable) or local delta definition
30+
bool convertLocalToGlobal) // if local is provided, convert it to global
31+
: mSymName(symname), mIsGlobal(global || convertLocalToGlobal), mAlignableID(algID)
3132
{
3233
/// standard constructor with 3 translation + 3 rotation parameters
3334
/// If the user explicitly sets the global variable to false then the
3435
/// parameters are interpreted as giving the local transformation.
3536
/// This requires to have a gGeoMenager active instance, otherwise the
3637
/// constructor will fail (no object created)
3738

38-
if (global) {
39-
setGlobalParams(x, y, z, psi, theta, phi);
40-
} else {
39+
setParams(x, y, z, psi, theta, phi);
40+
if (!global && convertLocalToGlobal) {
4141
setLocalParams(x, y, z, psi, theta, phi);
4242
}
4343
}
4444

4545
//___________________________________________________
46-
AlignParam::AlignParam(const char* symname, int algID, TGeoMatrix& m, bool global)
47-
: mSymName(symname), mAlignableID(algID)
46+
AlignParam::AlignParam(const char* symname, int algID, TGeoMatrix& m, bool global, bool convertLocalToGlobal)
47+
: mSymName(symname), mIsGlobal(global || convertLocalToGlobal), mAlignableID(algID)
4848
{
4949
setTranslation(m);
5050
if (!setRotation(m)) {
5151
const double* rot = m.GetRotationMatrix();
5252
throw std::runtime_error(fmt::format("Failed to extract roll-pitch-yall angles from [[{},{},{}], [{},{},{}], [{},{},{}] for {}", rot[0], rot[1], rot[2], rot[3], rot[4], rot[5], rot[6], rot[7], rot[8], symname));
5353
}
54-
if (!global && !setLocalParams(mX, mY, mZ, mPsi, mTheta, mPhi)) {
54+
if (!global && convertLocalToGlobal && !setLocalParams(mX, mY, mZ, mPsi, mTheta, mPhi)) {
5555
throw std::runtime_error(fmt::format("Alignment creation for {} failed: geomManager is absent", symname));
5656
}
5757
}
@@ -223,6 +223,10 @@ bool AlignParam::createLocalMatrix(TGeoHMatrix& m) const
223223
// In case that the TGeo was not initialized or not closed,
224224
// returns false and the object parameters are not set.
225225
//
226+
m = createMatrix();
227+
if (!mIsGlobal) {
228+
return true;
229+
}
226230
if (!gGeoManager || !gGeoManager->IsClosed()) {
227231
LOG(error) << "Can't get the local alignment object parameters! gGeoManager doesn't exist or it is still open!";
228232
return false;
@@ -247,7 +251,6 @@ bool AlignParam::createLocalMatrix(TGeoHMatrix& m) const
247251
LOG(error) << "Volume name or path " << symname << " is not valid!";
248252
return false;
249253
}
250-
m = createMatrix();
251254
TGeoHMatrix gprime, gprimeinv;
252255
gprime = *node->GetMatrix();
253256
gprimeinv = gprime.Inverse();
@@ -302,18 +305,15 @@ bool AlignParam::applyToGeometry() const
302305
}
303306

304307
// double threshold = 0.001;
305-
306-
TGeoHMatrix gprime = *node->GetMatrix();
307-
TGeoHMatrix align = createMatrix();
308-
gprime.MultiplyLeft(&align);
309-
TGeoHMatrix* ginv = new TGeoHMatrix; // TGeoPhysicalNode takes and manages raw pointer, need naked new!
310-
TGeoHMatrix* g = node->GetMatrix(node->GetLevel() - 1);
311-
*ginv = g->Inverse();
312-
*ginv *= gprime;
313-
308+
TGeoHMatrix* align = new TGeoHMatrix(createMatrix());
309+
if (mIsGlobal) {
310+
align->Multiply(node->GetMatrix());
311+
TGeoHMatrix* g = node->GetMatrix(node->GetLevel() - 1);
312+
align->MultiplyLeft(node->GetMatrix(node->GetLevel() - 1)->Inverse());
313+
}
314314
LOG(debug) << "Aligning volume " << symname;
315315

316-
node->Align(ginv);
316+
node->Align(align);
317317

318318
return true;
319319
}
@@ -359,6 +359,14 @@ void AlignParam::setGlobalParams(double x, double y, double z, double psi, doubl
359359
setRotation(psi, theta, phi);
360360
}
361361

362+
//_____________________________________________________________________________
363+
void AlignParam::setParams(double x, double y, double z, double psi, double theta, double phi)
364+
{
365+
/// set parameters of global delta
366+
setTranslation(x, y, z);
367+
setRotation(psi, theta, phi);
368+
}
369+
362370
//_____________________________________________________________________________
363371
void AlignParam::setRotation(double psi, double theta, double phi)
364372
{

Detectors/ITSMFT/common/reconstruction/src/RUDecodeData.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ bool RUDecodeData::checkLinkInSync(int icab, const o2::InteractionRecord ir)
125125
link->statistics.errorCounts[GBTLinkDecodingStat::ErrOldROF]++;
126126
linkHBFToDump[(uint64_t(link->subSpec) << 32) + link->hbfEntry] = link->irHBF.orbit;
127127
if (link->needToPrintError(link->statistics.errorCounts[GBTLinkDecodingStat::ErrOldROF]) && !ROFRampUpStage) {
128-
LOGP(error, "{} (cable {}) has IR={} for current majority IR={} -> {}", link->describe(),
128+
LOGP(critical, "{} (cable {}) has IR={} for current majority IR={} -> {}", link->describe(),
129129
cableHWID[icab], link->ir.asString(), ir.asString(), link->statistics.ErrNames[GBTLinkDecodingStat::ErrOldROF]);
130130
}
131131
#endif

Detectors/ITSMFT/common/workflow/src/STFDecoderSpec.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ void STFDecoder<Mapping>::run(ProcessingContext& pc)
202202
if ((expectedTFSize != nTriggersProcessed) && mROFErrRepIntervalMS > 0 && mTFCounter > 1 && nTriggersProcessed > 0) {
203203
long currTS = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now()).time_since_epoch().count();
204204
if (currTS - lastErrReportTS > mROFErrRepIntervalMS) {
205-
LOGP(error, "Inconsistent number of ROF per TF. From parameters: {} from readout: {} (muting further reporting for {} ms)", expectedTFSize, nTriggersProcessed, mROFErrRepIntervalMS);
205+
LOGP(critical, "Inconsistent number of ROF per TF. From parameters: {} from readout: {} (muting further reporting for {} ms)", expectedTFSize, nTriggersProcessed, mROFErrRepIntervalMS);
206206
lastErrReportTS = currTS;
207207
}
208208
}

Detectors/Vertexing/include/DetectorsVertexing/SVertexHypothesis.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class SVertexHypothesis
6060

6161
bool check(float p2Pos, float p2Neg, float p2V0, float ptV0) const
6262
{ // check if given mass and pt is matching to hypothesis
63-
return check(calcMass(p2Pos, p2Neg, p2V0), ptV0);
63+
return mPars[SigmaM] > 0 && check(calcMass(p2Pos, p2Neg, p2V0), ptV0);
6464
}
6565
bool check(float mass, float pt) const
6666
{ // check if given mass and pt is matching to hypothesis
@@ -151,7 +151,7 @@ class SVertex3Hypothesis
151151

152152
bool check(float p2Pos, float p2Neg, float p2Bach, float p2Tot, float ptV0) const
153153
{ // check if given mass and pt is matching to hypothesis
154-
return check(calcMass(p2Pos, p2Neg, p2Bach, p2Tot), ptV0);
154+
return mPars[SigmaM] > 0 && check(calcMass(p2Pos, p2Neg, p2Bach, p2Tot), ptV0);
155155
}
156156

157157
bool check(float mass, float pt) const

0 commit comments

Comments
 (0)