Project
Loading...
Searching...
No Matches
OrtInterface.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
16#include "ML/OrtInterface.h"
18
19// ONNX includes
20#include <onnxruntime_cxx_api.h>
21
22#include <sstream>
23
24namespace o2
25{
26
27namespace ml
28{
29
30OrtModel::OrtModel() = default;
31OrtModel::OrtModel(std::unordered_map<std::string, std::string> optionsMap) { init(optionsMap); }
32OrtModel::~OrtModel() = default;
33void OrtModel::init(std::unordered_map<std::string, std::string> optionsMap)
34{
35 initOptions(optionsMap);
37}
38
39struct OrtModel::OrtVariables { // The actual implementation is hidden in the .cxx file
40 // ORT runtime objects
41 Ort::RunOptions runOptions;
42 std::unique_ptr<Ort::Env> env = nullptr;
43 std::unique_ptr<Ort::Session> session = nullptr;
44 Ort::SessionOptions sessionOptions;
45 Ort::AllocatorWithDefaultOptions allocator;
46 Ort::MemoryInfo memoryInfo = Ort::MemoryInfo("Cpu", OrtAllocatorType::OrtDeviceAllocator, 0, OrtMemType::OrtMemTypeDefault);
47 std::unique_ptr<Ort::IoBinding> ioBinding = nullptr;
48};
49
50// General purpose
51void OrtModel::initOptions(std::unordered_map<std::string, std::string> optionsMap)
52{
53 mPImplOrt = std::make_unique<OrtVariables>();
54
55 // Load from options map
56 if (!optionsMap.contains("model-path")) {
57 LOG(fatal) << "(ORT) Model path must be contained in options map!";
58 }
59
60 if (!optionsMap["model-path"].empty()) {
61 mModelPath = optionsMap["model-path"];
62 mDeviceType = (optionsMap.contains("device-type") ? optionsMap["device-type"] : "CPU");
63 mDeviceId = (optionsMap.contains("device-id") ? std::stoi(optionsMap["device-id"]) : -1);
64 mAllocateDeviceMemory = (optionsMap.contains("allocate-device-memory") ? std::stoi(optionsMap["allocate-device-memory"]) : 0);
65 mIntraOpNumThreads = (optionsMap.contains("intra-op-num-threads") ? std::stoi(optionsMap["intra-op-num-threads"]) : 0);
66 mInterOpNumThreads = (optionsMap.contains("inter-op-num-threads") ? std::stoi(optionsMap["inter-op-num-threads"]) : 0);
67 mLoggingLevel = (optionsMap.contains("logging-level") ? std::stoi(optionsMap["logging-level"]) : 0);
68 mEnableProfiling = (optionsMap.contains("enable-profiling") ? std::stoi(optionsMap["enable-profiling"]) : 0);
69 mEnableOptimizations = (optionsMap.contains("enable-optimizations") ? std::stoi(optionsMap["enable-optimizations"]) : 0);
70 mEnvName = (optionsMap.contains("onnx-environment-name") ? optionsMap["onnx-environment-name"] : "onnx_model_inference");
71 mDeterministicMode = (optionsMap.contains("deterministic-compute") ? std::stoi(optionsMap["deterministic-compute"]) : 0);
72
73 if (mDeviceType == "CPU") {
74 (mPImplOrt->sessionOptions).SetIntraOpNumThreads(mIntraOpNumThreads);
75 (mPImplOrt->sessionOptions).SetInterOpNumThreads(mInterOpNumThreads);
76 if (mIntraOpNumThreads > 1 || mInterOpNumThreads > 1) {
77 (mPImplOrt->sessionOptions).SetExecutionMode(ExecutionMode::ORT_PARALLEL);
78 } else if (mIntraOpNumThreads == 1) {
79 (mPImplOrt->sessionOptions).SetExecutionMode(ExecutionMode::ORT_SEQUENTIAL);
80 }
81 if (mLoggingLevel < 2) {
82 LOG(info) << "(ORT) CPU execution provider set with " << mIntraOpNumThreads << " (mIntraOpNumThreads) and " << mInterOpNumThreads << " (mInterOpNumThreads) threads";
83 }
84 }
85
86 // OrtROCMProviderOptions rocm_options{};
87 // (mPImplOrt->sessionOptions).AppendExecutionProvider_ROCM(rocm_options);
88
89 (mPImplOrt->sessionOptions).DisableMemPattern();
90 (mPImplOrt->sessionOptions).DisableCpuMemArena();
91
92 if (mEnableProfiling) {
93 if (optionsMap.contains("profiling-output-path")) {
94 (mPImplOrt->sessionOptions).EnableProfiling((optionsMap["profiling-output-path"] + "/ORT_LOG_").c_str());
95 } else {
96 LOG(warning) << "(ORT) If profiling is enabled, optionsMap[\"profiling-output-path\"] should be set. Disabling profiling for now.";
97 (mPImplOrt->sessionOptions).DisableProfiling();
98 }
99 } else {
100 (mPImplOrt->sessionOptions).DisableProfiling();
101 }
102
103 if (mDeterministicMode > 0) {
104 (mPImplOrt->sessionOptions).AddConfigEntry("session_options.use_deterministic_compute", "1");
105 }
106
107 (mPImplOrt->sessionOptions).SetGraphOptimizationLevel(GraphOptimizationLevel(mEnableOptimizations));
108 (mPImplOrt->sessionOptions).SetLogSeverityLevel(OrtLoggingLevel(mLoggingLevel));
109
110 mInitialized = true;
111 } else {
112 LOG(fatal) << "(ORT) Model path cannot be empty!";
113 }
114}
115
117{
118 mPImplOrt->env = std::make_unique<Ort::Env>(
119 OrtLoggingLevel(mLoggingLevel),
120 (mEnvName.empty() ? "ORT" : mEnvName.c_str()),
121 // Integrate ORT logging into Fairlogger
122 [](void* param, OrtLoggingLevel severity, const char* category, const char* logid, const char* code_location, const char* message) {
123 if (severity == ORT_LOGGING_LEVEL_VERBOSE) {
124 LOG(debug) << "(ORT) [" << logid << "|" << category << "|" << code_location << "]: " << message;
125 } else if (severity == ORT_LOGGING_LEVEL_INFO) {
126 LOG(info) << "(ORT) [" << logid << "|" << category << "|" << code_location << "]: " << message;
127 } else if (severity == ORT_LOGGING_LEVEL_WARNING) {
128 LOG(warning) << "(ORT) [" << logid << "|" << category << "|" << code_location << "]: " << message;
129 } else if (severity == ORT_LOGGING_LEVEL_ERROR) {
130 LOG(error) << "(ORT) [" << logid << "|" << category << "|" << code_location << "]: " << message;
131 } else if (severity == ORT_LOGGING_LEVEL_FATAL) {
132 LOG(fatal) << "(ORT) [" << logid << "|" << category << "|" << code_location << "]: " << message;
133 } else {
134 LOG(info) << "(ORT) [" << logid << "|" << category << "|" << code_location << "]: " << message;
135 }
136 },
137 (void*)3);
138 (mPImplOrt->env)->DisableTelemetryEvents(); // Disable telemetry events
139}
140
141void OrtModel::initSessionFromBuffer(const char* buffer, size_t bufferSize)
142{
143 if (mAllocateDeviceMemory) {
144 memoryOnDevice(mDeviceId);
145 }
146 mPImplOrt->sessionOptions.AddConfigEntry("session.load_model_format", "ONNX");
147 mPImplOrt->sessionOptions.AddConfigEntry("session.use_ort_model_bytes_directly", "1");
148
149 mPImplOrt->session = std::make_unique<Ort::Session>(*mPImplOrt->env,
150 buffer,
151 bufferSize,
152 mPImplOrt->sessionOptions);
153 mPImplOrt->ioBinding = std::make_unique<Ort::IoBinding>(*mPImplOrt->session);
154
155 setIO();
156
157 if (mLoggingLevel < 2) {
158 LOG(info) << "(ORT) Model loaded successfully from buffer! (inputs: " << printShape(mInputShapes, mInputNames) << ", outputs: " << printShape(mOutputShapes, mInputNames) << ")";
159 }
160}
161
163{
164 if (mAllocateDeviceMemory) {
165 memoryOnDevice(mDeviceId);
166 }
167 mPImplOrt->session = std::make_unique<Ort::Session>(*mPImplOrt->env, mModelPath.c_str(), mPImplOrt->sessionOptions);
168 mPImplOrt->ioBinding = std::make_unique<Ort::IoBinding>(*mPImplOrt->session);
169
170 setIO();
171
172 if (mLoggingLevel < 2) {
173 LOG(info) << "(ORT) Model loaded successfully! (inputs: " << printShape(mInputShapes, mInputNames) << ", outputs: " << printShape(mOutputShapes, mInputNames) << ")";
174 }
175}
176
178{
179 if (deviceIndex >= 0) {
180 (mPImplOrt->runOptions).AddConfigEntry("disable_synchronize_execution_providers", "1");
181 (mPImplOrt->sessionOptions).AddConfigEntry("session.use_device_allocator_for_initializers", "1"); // See kOrtSessionOptionsUseDeviceAllocatorForInitializers, https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/session/onnxruntime_session_options_config_keys.h
182 (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
183 (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
184 // Arena memory shrinkage comes at performance cost
185 // For now prefer to use single allocation, enabled by O2/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu -> SetONNXGPUStream -> rocm_options.arena_extend_strategy = 0;
186 (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
187
188 std::string dev_mem_str = "";
189 if (mDeviceType == "ROCM") {
190 dev_mem_str = "HipPinned";
191 }
192 if (mDeviceType == "CUDA") {
193 dev_mem_str = "Cuda";
194 }
195 mPImplOrt->memoryInfo = Ort::MemoryInfo(dev_mem_str.c_str(), OrtAllocatorType::OrtDeviceAllocator, deviceIndex, OrtMemType::OrtMemTypeDefault);
196 if (mLoggingLevel < 2) {
197 LOG(info) << "(ORT) Memory info set to on-device memory for device type " << mDeviceType << " with ID " << deviceIndex << " and mPImplOrt pointer " << mPImplOrt;
198 }
199 }
200}
201
203{
204 mPImplOrt->session = std::make_unique<Ort::Session>(*(mPImplOrt->env), mModelPath.c_str(), mPImplOrt->sessionOptions);
205}
206
207// Getters
208Ort::SessionOptions* OrtModel::getSessionOptions()
209{
210 return &mPImplOrt->sessionOptions;
211}
212
213Ort::MemoryInfo* OrtModel::getMemoryInfo()
214{
215 return &mPImplOrt->memoryInfo;
216}
217
219{
220 return (mPImplOrt->env).get();
221}
222
223template <class I, class O>
224std::vector<O> OrtModel::v2v(std::vector<I>& input, bool clearInput)
225{
226 if constexpr (std::is_same_v<I, O>) {
227 return input;
228 } else {
229 std::vector<O> output(input.size());
230 std::transform(std::begin(input), std::end(input), std::begin(output), [](I f) { return O(f); });
231 if (clearInput) {
232 input.clear();
233 }
234 return output;
235 }
236}
237
239{
240 for (size_t i = 0; i < (mPImplOrt->session)->GetInputCount(); ++i) {
241 mInputNames.push_back((mPImplOrt->session)->GetInputNameAllocated(i, mPImplOrt->allocator).get());
242 }
243 for (size_t i = 0; i < (mPImplOrt->session)->GetInputCount(); ++i) {
244 mInputShapes.emplace_back((mPImplOrt->session)->GetInputTypeInfo(i).GetTensorTypeAndShapeInfo().GetShape());
245 }
246 for (size_t i = 0; i < (mPImplOrt->session)->GetOutputCount(); ++i) {
247 mOutputNames.push_back((mPImplOrt->session)->GetOutputNameAllocated(i, mPImplOrt->allocator).get());
248 }
249 for (size_t i = 0; i < (mPImplOrt->session)->GetOutputCount(); ++i) {
250 mOutputShapes.emplace_back((mPImplOrt->session)->GetOutputTypeInfo(i).GetTensorTypeAndShapeInfo().GetShape());
251 }
252
253 mInputNamesChar.resize(mInputNames.size(), nullptr);
254 std::transform(std::begin(mInputNames), std::end(mInputNames), std::begin(mInputNamesChar),
255 [&](const std::string& str) { return str.c_str(); });
256 mOutputNamesChar.resize(mOutputNames.size(), nullptr);
257 std::transform(std::begin(mOutputNames), std::end(mOutputNames), std::begin(mOutputNamesChar),
258 [&](const std::string& str) { return str.c_str(); });
259
260 mInputShapesCopy = mInputShapes;
261 mOutputShapesCopy = mOutputShapes;
262 mInputSizePerNode.resize(mInputShapes.size(), 1);
263 mOutputSizePerNode.resize(mOutputShapes.size(), 1);
264 mInputsTotal = 1;
265 for (size_t i = 0; i < mInputShapes.size(); ++i) {
266 if (mInputShapes[i].size() > 0) {
267 for (size_t j = 1; j < mInputShapes[i].size(); ++j) {
268 if (mInputShapes[i][j] > 0) {
269 mInputsTotal *= mInputShapes[i][j];
270 mInputSizePerNode[i] *= mInputShapes[i][j];
271 }
272 }
273 }
274 }
275 mOutputsTotal = 1;
276 for (size_t i = 0; i < mOutputShapes.size(); ++i) {
277 if (mOutputShapes[i].size() > 0) {
278 for (size_t j = 1; j < mOutputShapes[i].size(); ++j) {
279 if (mOutputShapes[i][j] > 0) {
280 mOutputsTotal *= mOutputShapes[i][j];
281 mOutputSizePerNode[i] *= mOutputShapes[i][j];
282 }
283 }
284 }
285 }
286}
287
288void OrtModel::setEnv(Ort::Env* env)
289{
290 mPImplOrt->env.reset(env);
291}
292
293// Inference
294template <class I, class O>
295std::vector<O> OrtModel::inference(std::vector<I>& input)
296{
297 std::vector<int64_t> inputShape = mInputShapes[0];
298 inputShape[0] = input.size();
299 for (size_t i = 1; i < mInputShapes[0].size(); ++i) {
300 inputShape[0] /= mInputShapes[0][i];
301 }
302 std::vector<Ort::Value> inputTensor;
303 if constexpr (std::is_same_v<I, OrtDataType::Float16_t>) {
304 inputTensor.emplace_back(Ort::Value::CreateTensor<Ort::Float16_t>(mPImplOrt->memoryInfo, reinterpret_cast<Ort::Float16_t*>(input.data()), input.size(), inputShape.data(), inputShape.size()));
305 } else {
306 inputTensor.emplace_back(Ort::Value::CreateTensor<I>(mPImplOrt->memoryInfo, input.data(), input.size(), inputShape.data(), inputShape.size()));
307 }
308 // input.clear();
309 auto outputTensors = (mPImplOrt->session)->Run(mPImplOrt->runOptions, mInputNamesChar.data(), inputTensor.data(), inputTensor.size(), mOutputNamesChar.data(), mOutputNamesChar.size());
310 O* outputValues = outputTensors[0].template GetTensorMutableData<O>();
311 std::vector<O> outputValuesVec{outputValues, outputValues + inputShape[0] * mOutputShapes[0][1]};
312 outputTensors.clear();
313 return outputValuesVec;
314}
315
316template std::vector<float> o2::ml::OrtModel::inference<float, float>(std::vector<float>&);
317template std::vector<float> o2::ml::OrtModel::inference<OrtDataType::Float16_t, float>(std::vector<OrtDataType::Float16_t>&);
318template std::vector<OrtDataType::Float16_t> o2::ml::OrtModel::inference<OrtDataType::Float16_t, OrtDataType::Float16_t>(std::vector<OrtDataType::Float16_t>&);
319
320template <class I, class O>
321void OrtModel::inference(I* input, int64_t input_size, O* output)
322{
323 // std::vector<std::string> providers = Ort::GetAvailableProviders();
324 // for (const auto& provider : providers) {
325 // LOG(info) << "Available Execution Provider: " << provider;
326 // }
327 std::vector<int64_t> inputShape{input_size, (int64_t)mInputShapes[0][1]};
328 Ort::Value inputTensor = Ort::Value(nullptr);
329 if constexpr (std::is_same_v<I, OrtDataType::Float16_t>) {
330 inputTensor = Ort::Value::CreateTensor<Ort::Float16_t>(mPImplOrt->memoryInfo, reinterpret_cast<Ort::Float16_t*>(input), input_size * mInputShapes[0][1], inputShape.data(), inputShape.size());
331 } else {
332 inputTensor = Ort::Value::CreateTensor<I>(mPImplOrt->memoryInfo, input, input_size * mInputShapes[0][1], inputShape.data(), inputShape.size());
333 }
334 (mPImplOrt->ioBinding)->BindInput(mInputNames[0].c_str(), inputTensor);
335
336 std::vector<int64_t> outputShape{input_size, mOutputShapes[0][1]};
337 Ort::Value outputTensor = Ort::Value(nullptr);
338 if constexpr (std::is_same_v<O, OrtDataType::Float16_t>) {
339 outputTensor = Ort::Value::CreateTensor<Ort::Float16_t>(mPImplOrt->memoryInfo, reinterpret_cast<Ort::Float16_t*>(output), input_size * mOutputShapes[0][1], outputShape.data(), outputShape.size());
340 } else {
341 outputTensor = Ort::Value::CreateTensor<O>(mPImplOrt->memoryInfo, output, input_size * mOutputShapes[0][1], outputShape.data(), outputShape.size());
342 }
343 (mPImplOrt->ioBinding)->BindOutput(mOutputNames[0].c_str(), outputTensor);
344
345 (mPImplOrt->session)->Run(mPImplOrt->runOptions, *mPImplOrt->ioBinding);
346 // mPImplOrt->session->Run(
347 // mPImplOrt->runOptions,
348 // mInputNamesChar.data(),
349 // &inputTensor,
350 // mInputNamesChar.size(),
351 // mOutputNamesChar.data(),
352 // &outputTensor,
353 // mOutputNamesChar.size());
354}
355
356template void OrtModel::inference<OrtDataType::Float16_t, OrtDataType::Float16_t>(OrtDataType::Float16_t*, int64_t, OrtDataType::Float16_t*);
357template void OrtModel::inference<OrtDataType::Float16_t, float>(OrtDataType::Float16_t*, int64_t, float*);
358template void OrtModel::inference<float, OrtDataType::Float16_t>(float*, int64_t, OrtDataType::Float16_t*);
359template void OrtModel::inference<float, float>(float*, int64_t, float*);
360
361template <class I, class O>
362void OrtModel::inference(I** input, int64_t input_size, O* output)
363{
364 std::vector<Ort::Value> inputTensors(mInputShapesCopy.size());
365
366 for (size_t i = 0; i < mInputShapesCopy.size(); ++i) {
367
368 mInputShapesCopy[i][0] = input_size; // batch-size
369 mOutputShapesCopy[i][0] = input_size; // batch-size
370
371 if constexpr (std::is_same_v<I, OrtDataType::Float16_t>) {
372 inputTensors[i] = Ort::Value::CreateTensor<Ort::Float16_t>(
373 mPImplOrt->memoryInfo,
374 reinterpret_cast<Ort::Float16_t*>(input[i]),
375 mInputSizePerNode[i] * input_size,
376 mInputShapesCopy[i].data(),
377 mInputShapesCopy[i].size());
378 } else {
379 inputTensors[i] = Ort::Value::CreateTensor<I>(
380 mPImplOrt->memoryInfo,
381 input[i],
382 mInputSizePerNode[i] * input_size,
383 mInputShapesCopy[i].data(),
384 mInputShapesCopy[i].size());
385 }
386 }
387
388 Ort::Value outputTensor = Ort::Value(nullptr);
389 if constexpr (std::is_same_v<O, OrtDataType::Float16_t>) {
390 outputTensor = Ort::Value::CreateTensor<Ort::Float16_t>(
391 mPImplOrt->memoryInfo,
392 reinterpret_cast<Ort::Float16_t*>(output),
393 mOutputSizePerNode[0] * input_size, // assumes that there is only one output node
394 mOutputShapesCopy[0].data(),
395 mOutputShapesCopy[0].size());
396 } else {
397 outputTensor = Ort::Value::CreateTensor<O>(
398 mPImplOrt->memoryInfo,
399 output,
400 mOutputSizePerNode[0] * input_size, // assumes that there is only one output node
401 mOutputShapesCopy[0].data(),
402 mOutputShapesCopy[0].size());
403 }
404
405 // === Run inference ===
406 mPImplOrt->session->Run(
407 mPImplOrt->runOptions,
408 mInputNamesChar.data(),
409 inputTensors.data(),
410 mInputNamesChar.size(),
411 mOutputNamesChar.data(),
412 &outputTensor,
413 mOutputNamesChar.size());
414}
415
416template void OrtModel::inference<OrtDataType::Float16_t, OrtDataType::Float16_t>(OrtDataType::Float16_t**, int64_t, OrtDataType::Float16_t*);
417template void OrtModel::inference<OrtDataType::Float16_t, float>(OrtDataType::Float16_t**, int64_t, float*);
418template void OrtModel::inference<float, OrtDataType::Float16_t>(float**, int64_t, OrtDataType::Float16_t*);
419template void OrtModel::inference<float, float>(float**, int64_t, float*);
420
421template <class I, class O>
422std::vector<O> OrtModel::inference(std::vector<std::vector<I>>& inputs)
423{
424 std::vector<Ort::Value> input_tensors;
425
426 for (size_t i = 0; i < inputs.size(); ++i) {
427
428 mInputShapesCopy[i][0] = inputs[i].size() / mInputSizePerNode[i]; // batch-size
429
430 if constexpr (std::is_same_v<I, OrtDataType::Float16_t>) {
431 input_tensors.emplace_back(
432 Ort::Value::CreateTensor<Ort::Float16_t>(
433 mPImplOrt->memoryInfo,
434 reinterpret_cast<Ort::Float16_t*>(inputs[i].data()),
435 mInputSizePerNode[i] * mInputShapesCopy[i][0],
436 mInputShapesCopy[i].data(),
437 mInputShapesCopy[i].size()));
438 } else {
439 input_tensors.emplace_back(
440 Ort::Value::CreateTensor<I>(
441 mPImplOrt->memoryInfo,
442 inputs[i].data(),
443 mInputSizePerNode[i] * mInputShapesCopy[i][0],
444 mInputShapesCopy[i].data(),
445 mInputShapesCopy[i].size()));
446 }
447 }
448
449 int32_t totalOutputSize = mOutputsTotal * mInputShapesCopy[0][0];
450
451 // === Run inference ===
452 auto output_tensors = mPImplOrt->session->Run(
453 mPImplOrt->runOptions,
454 mInputNamesChar.data(),
455 input_tensors.data(),
456 input_tensors.size(),
457 mOutputNamesChar.data(),
458 mOutputNamesChar.size());
459
460 // === Extract output values ===
461 O* output_data = output_tensors[0].template GetTensorMutableData<O>();
462 std::vector<O> output_vec(output_data, output_data + totalOutputSize);
463 output_tensors.clear();
464 return output_vec;
465}
466
467template std::vector<float> OrtModel::inference<float, float>(std::vector<std::vector<float>>&);
468template std::vector<OrtDataType::Float16_t> OrtModel::inference<OrtDataType::Float16_t, OrtDataType::Float16_t>(std::vector<std::vector<OrtDataType::Float16_t>>&);
469
470// Release session
471void OrtModel::release(bool profilingEnabled)
472{
473 mPImplOrt.reset();
474}
475
476// private
477std::string OrtModel::printShape(const std::vector<int64_t>& v)
478{
479 std::stringstream ss("");
480 for (size_t i = 0; i < v.size() - 1; i++) {
481 ss << v[i] << "x";
482 }
483 ss << v[v.size() - 1];
484 return ss.str();
485}
486
487std::string OrtModel::printShape(const std::vector<std::vector<int64_t>>& v, std::vector<std::string>& n)
488{
489 std::stringstream ss("");
490 for (size_t i = 0; i < v.size(); i++) {
491 ss << n[i] << " -> (";
492 for (size_t j = 0; j < v[i].size() - 1; j++) {
493 ss << v[i][j] << "x";
494 }
495 ss << v[i][v[i].size() - 1] << "); ";
496 }
497 return ss.str();
498}
499
500} // namespace ml
501
502} // namespace o2
std::ostringstream debug
int32_t i
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
char error[CURL_ERROR_SIZE]
void output(const std::map< std::string, ChannelStat > &channels)
Definition rawdump.cxx:197
A header library for loading ONNX models and inferencing them on CPU and GPU.
uint32_t j
Definition RawData.h:0
void initOptions(std::unordered_map< std::string, std::string > optionsMap)
void memoryOnDevice(int32_t=0)
Ort::Env * getEnv()
void release(bool=false)
void setEnv(Ort::Env *)
std::vector< O > v2v(std::vector< I > &, bool=true)
void initSessionFromBuffer(const char *buffer, size_t bufferSize)
Ort::MemoryInfo * getMemoryInfo()
std::vector< O > inference(std::vector< I > &)
virtual ~OrtModel()
void init(std::unordered_map< std::string, std::string > optionsMap)
Ort::SessionOptions * getSessionOptions()
GLdouble n
Definition glcorearb.h:1982
GLsizeiptr size
Definition glcorearb.h:659
const GLdouble * v
Definition glcorearb.h:832
GLdouble f
Definition glcorearb.h:310
GLuint GLsizei const GLchar * message
Definition glcorearb.h:2517
GLenum GLfloat param
Definition glcorearb.h:271
GLenum GLenum severity
Definition glcorearb.h:2513
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
void empty(int)
Ort::AllocatorWithDefaultOptions allocator
std::unique_ptr< Ort::Session > session
ONNX session.
Ort::SessionOptions sessionOptions
std::unique_ptr< Ort::IoBinding > ioBinding
std::unique_ptr< Ort::Env > env
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
const std::string str