24#include <onnxruntime_cxx_api.h>
31 std::string class_model_path = settings.nnClassificationPath, reg_model_path = settings.nnRegressionPath;
32 std::vector<std::string> reg_model_paths_local;
35 if (settings.nnLoadFromCCDB) {
36 reg_model_path = settings.nnLocalFolder +
"/net_regression_c1.onnx";
37 if (evalMode[0] ==
"c1") {
38 class_model_path = settings.nnLocalFolder +
"/net_classification_c1.onnx";
39 }
else if (evalMode[0] ==
"c2") {
40 class_model_path = settings.nnLocalFolder +
"/net_classification_c2.onnx";
43 if (evalMode[1] ==
"r2") {
44 reg_model_path +=
":" + settings.nnLocalFolder +
"/net_regression_c2.onnx";
49 {
"model-path", class_model_path},
50 {
"device-type", settings.nnInferenceDevice},
51 {
"allocate-device-memory",
std::to_string(settings.nnInferenceAllocateDevMem)},
52 {
"intra-op-num-threads",
std::to_string(settings.nnInferenceIntraOpNumThreads)},
53 {
"inter-op-num-threads",
std::to_string(settings.nnInferenceInterOpNumThreads)},
54 {
"enable-optimizations",
std::to_string(settings.nnInferenceEnableOrtOptimization)},
55 {
"enable-profiling",
std::to_string(settings.nnInferenceOrtProfiling)},
56 {
"profiling-output-path", settings.nnInferenceOrtProfilingPath},
58 {
"onnx-environment-name",
"c1"}};
65 if (!settings.nnClusterizerUseCfRegression) {
66 if (reg_model_paths_local.size() == 1) {
67 mOrtOptions[
"model-path"] = reg_model_paths_local[0];
72 mOrtOptions[
"model-path"] = reg_model_paths_local[0];
76 mOrtOptions[
"model-path"] = reg_model_paths_local[1];
91 clustererNN.
mNnClusterizerElementSize = ((2 * settings.nnClusterizerSizeInputRow + 1) * (2 * settings.nnClusterizerSizeInputPad + 1) * (2 * settings.nnClusterizerSizeInputTime + 1)) + (settings.nnClusterizerAddIndexData ? 3 : 0);
97 clustererNN.
mNnClassThreshold = (float)std::log(settings.nnClassThreshold / (1.f - settings.nnClassThreshold));
101 if (settings.nnClusterizerVerbosity < 0) {
109 if (!settings.nnClusterizerUseCfRegression) {
124 void* Alloc(
size_t size);
126 const OrtMemoryInfo* Info()
const;
127 void* Reserve(
size_t size);
128 size_t NumAllocations()
const;
129 size_t NumReserveAllocations()
const;
137 std::atomic<size_t> memory_inuse{0};
138 std::atomic<size_t> num_allocations{0};
139 std::atomic<size_t> num_reserve_allocations{0};
140 OrtMemoryInfo* mMemoryInfoInternal;
146 OrtAllocator::version = ORT_API_VERSION;
152 mMemoryInfoInternal = info;
163 LOG(info) <<
"(ORT) Allocating direct memory of size " <<
size <<
" bytes";
169 LOG(info) <<
"(ORT) Reserving direct memory of size " <<
size <<
" bytes";
180 return mMemoryInfoInternal;
185 return num_allocations.load();
190 return num_reserve_allocations.load();
195 if (memory_inuse.load()) {
196 LOG(warning) <<
"memory leak!!!";
202 mMockedAlloc = std::make_shared<MockedOrtAllocator>(
rec, (OrtMemoryInfo*)(*memInfo));
204 Ort::ThrowOnError(Ort::GetApi().UnregisterAllocator((OrtEnv*)(*env), (OrtMemoryInfo*)(*memInfo)));
206 Ort::ThrowOnError(Ort::GetApi().RegisterAllocator((OrtEnv*)(*env),
mMockedAlloc.get()));
o2::ml::OrtModel mModelReg1
o2::ml::OrtModel mModelClass
const OrtMemoryInfo * getMockedMemoryInfo()
o2::ml::OrtModel mModelReg2
std::unordered_map< std::string, std::string > mOrtOptions
void initClusterizer(const GPUSettingsProcessingNNclusterizer &, GPUTPCNNClusterizer &)
MockedOrtAllocator * getMockedAllocator()
std::shared_ptr< MockedOrtAllocator > mMockedAlloc
std::vector< bool > mModelsUsed
void directOrtAllocator(Ort::Env *, Ort::MemoryInfo *, GPUReconstruction *, bool=false)
void init(const GPUSettingsProcessingNNclusterizer &)
int mNnClusterizerSizeInputPad
int mNnClusterizerBatchedMode
int mNnClusterizerModelReg1NumOutputNodes
int mNnInferenceOutputDType
int mNnInferenceInputDType
bool mNnClusterizerSetDeconvolutionFlags
int mNnClusterizerElementSize
int mNnClusterizerModelClassNumOutputNodes
bool mNnClusterizerAddIndexData
int mNnClusterizerModelReg2NumOutputNodes
int mNnClusterizerSizeInputRow
int mNnClusterizerUseCfRegression
int mNnClusterizerVerbosity
bool mNnSigmoidTrafoClassThreshold
int mNnClusterizerSizeInputTime
int mNnClusterizerBoundaryFillValue
void initOptions(std::unordered_map< std::string, std::string > optionsMap)
std::vector< std::vector< int64_t > > getNumOutputNodes() const
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
std::string to_string(gsl::span< T, Size > span)
void * Alloc(size_t size)
size_t NumAllocations() const
const OrtMemoryInfo * Info() const
MockedOrtAllocator(GPUReconstruction *=nullptr, OrtMemoryInfo *=nullptr)
void * Reserve(size_t size)
size_t NumReserveAllocations() const
static std::vector< std::string > tokenize(const std::string &src, char delim, bool trimToken=true, bool skipEmpty=true)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"