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);
96 clustererNN.
mNnClassThreshold = (float)std::log(settings.nnClassThreshold / (1.f - settings.nnClassThreshold));
100 if (settings.nnClusterizerVerbosity < 0) {
108 if (!settings.nnClusterizerUseCfRegression) {
123 void* Alloc(
size_t size);
125 const OrtMemoryInfo* Info()
const;
126 void* Reserve(
size_t size);
127 size_t NumAllocations()
const;
128 size_t NumReserveAllocations()
const;
136 std::atomic<size_t> memory_inuse{0};
137 std::atomic<size_t> num_allocations{0};
138 std::atomic<size_t> num_reserve_allocations{0};
139 OrtMemoryInfo* mMemoryInfoInternal;
145 OrtAllocator::version = ORT_API_VERSION;
151 mMemoryInfoInternal = info;
162 LOG(info) <<
"(ORT) Allocating direct memory of size " <<
size <<
" bytes";
168 LOG(info) <<
"(ORT) Reserving direct memory of size " <<
size <<
" bytes";
179 return mMemoryInfoInternal;
184 return num_allocations.load();
189 return num_reserve_allocations.load();
194 if (memory_inuse.load()) {
195 LOG(warning) <<
"memory leak!!!";
201 mMockedAlloc = std::make_shared<MockedOrtAllocator>(
rec, (OrtMemoryInfo*)(*memInfo));
203 Ort::ThrowOnError(Ort::GetApi().UnregisterAllocator((OrtEnv*)(*env), (OrtMemoryInfo*)(*memInfo)));
205 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
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"