1212// / \file GPUTPCNNClusterizerHost.cxx
1313// / \author Christian Sonnabend
1414
15- #ifdef GPUCA_HAS_SOFIE
16- #include " Rtypes.h"
17- #endif
18-
1915#include < CommonUtils/StringUtils.h>
2016
2117#include " GPUTPCNNClusterizerHost.h"
3329#endif
3430
3531#ifdef GPUCA_HAS_SOFIE
36- #include < TMVA /RGPUModel.hxx>
37- #include < TMVA /RModelParser_ONNX.hxx>
32+ #include < SOFIE /RGPUModel.hxx>
33+ #include < SOFIE /RModelParser_ONNX.hxx>
3834#endif
3935#include < array>
4036#include < limits>
@@ -44,8 +40,8 @@ using namespace o2::gpu;
4440
4541struct GPUTPCNNClusterizerHost ::SofieState {
4642#ifdef GPUCA_HAS_SOFIE
47- std::array<std::shared_ptr<TMVA ::Experimental:: SOFIE ::RGPUModel>, 3 > models;
48- std::array<std::unique_ptr<TMVA ::Experimental:: SOFIE ::RGPUModel::Session>, 3 > sessions;
43+ std::array<std::shared_ptr<SOFIE ::RGPUModel>, 3 > models;
44+ std::array<std::unique_ptr<SOFIE ::RGPUModel::Session>, 3 > sessions;
4945#endif
5046 std::array<std::string, 3 > buffers;
5147 size_t workspaceSize = 0 ;
@@ -168,7 +164,7 @@ void GPUTPCNNClusterizerHost::initClusterizer(const GPUSettingsProcessingNNclust
168164 }
169165 clustererNN.mSofieWorkspaceSize = mSofie ->workspaceSize ;
170166 for (const auto & model : mSofie ->models ) {
171- if (model && ((model->GetPrecision () == TMVA ::Experimental:: SOFIE ::RGPUModel::Precision::Float16) != (clustererNN.mNnInferenceInputDType == 1 ) || clustererNN.mNnInferenceInputDType != clustererNN.mNnInferenceOutputDType )) {
167+ if (model && ((model->GetPrecision () == SOFIE ::RGPUModel::Precision::Float16) != (clustererNN.mNnInferenceInputDType == 1 ) || clustererNN.mNnInferenceInputDType != clustererNN.mNnInferenceOutputDType )) {
172168 throw std::runtime_error (" Changing SOFIE precision requires chain reinitialization" );
173169 }
174170 if (model && model->InputSize () != static_cast <size_t >(clustererNN.mNnClusterizerElementSize )) {
@@ -328,7 +324,7 @@ MockedOrtAllocator* GPUTPCNNClusterizerHost::getMockedAllocator()
328324void GPUTPCNNClusterizerHost::initSofie (const GPUSettingsProcessingNNclusterizer& settings, void * stream, int32_t device, bool hip, const GPUTPCNNClusterizerHost* source, const std::array<std::string_view, 3 >& buffers, const GPUTPCNNClusterizerHost* previous)
329325{
330326#ifdef GPUCA_HAS_SOFIE
331- using Model = TMVA ::Experimental:: SOFIE ::RGPUModel;
327+ using Model = SOFIE ::RGPUModel;
332328 if (!settings.nnClusterizerBatchedMode || settings.nnClusterizerBatchedMode > static_cast <unsigned >(std::numeric_limits<int32_t >::max ())) {
333329 throw std::runtime_error (" SOFIE requires a positive batch capacity within int32 range" );
334330 }
@@ -339,7 +335,7 @@ void GPUTPCNNClusterizerHost::initSofie(const GPUSettingsProcessingNNclusterizer
339335 if (value == " FP16" || value == " fp16" ) {
340336 return Model::Precision::Float16;
341337 }
342- throw std::runtime_error (" SOFIE precision must be FP32 or FP16" );
338+ throw std::runtime_error (" SOFIE supports FP32 or FP16 model precision " );
343339 };
344340 const auto inputType = precision (settings.nnInferenceInputDType );
345341 if (inputType != precision (settings.nnInferenceOutputDType )) {
@@ -383,7 +379,7 @@ void GPUTPCNNClusterizerHost::initSofie(const GPUSettingsProcessingNNclusterizer
383379 paths[i + 1 ] = regression[i];
384380 }
385381 }
386- TMVA ::Experimental:: SOFIE ::RModelParser_ONNX parser;
382+ SOFIE ::RModelParser_ONNX parser;
387383 std::unordered_map<std::string, std::shared_ptr<Model>> compiled;
388384 if (settings.nnLoadFromCCDB && previous && previous->mSofie ) {
389385 for (size_t i = 0 ; i < previous->mSofie ->models .size (); i++) {
@@ -413,17 +409,16 @@ void GPUTPCNNClusterizerHost::initSofie(const GPUSettingsProcessingNNclusterizer
413409 inputType == Model::Precision::Float16 ? " FP16" : " FP32" );
414410 if (settings.nnLoadFromCCDB ) {
415411 std::istringstream input (state->buffers [i], std::ios::in | std::ios::binary);
416- model = std::make_shared<Model>(parser.ParseGPU (input));
412+ model = std::make_shared<Model>(parser.Parse (input, " clusterizer " ));
417413 } else {
418- model = std::make_shared<Model>(parser.ParseGPU (paths[i]));
414+ model = std::make_shared<Model>(parser.Parse (paths[i]));
419415 }
420416 if (model->GetPrecision () != inputType) {
421417 throw std::runtime_error (" SOFIE model precision differs from nnInferenceInputDType: " + paths[i]);
422418 }
423419 if (model->InputSize () != inputSize || model->OutputSize () > static_cast <size_t >(std::numeric_limits<int32_t >::max ()) / settings.nnClusterizerBatchedMode ) {
424420 throw std::runtime_error (" SOFIE model shape does not match the clusterizer window or index range: " + paths[i]);
425421 }
426- model->WorkspaceSize (settings.nnClusterizerBatchedMode );
427422 model->Compile ({hip ? Model::Backend::HIP : Model::Backend::CUDA , settings.sofieCompiler , settings.sofieArchitecture });
428423 GPUInfo (" SOFIE: model %zu compilation succeeded, input=%zu, output=%zu" ,
429424 i, model->InputSize (), model->OutputSize ());
@@ -471,14 +466,16 @@ void GPUTPCNNClusterizerHost::bindSofieWorkspace(void* workspace, size_t bytes)
471466 if (!mSofie ) {
472467 return ;
473468 }
474- if (!workspace || bytes < mSofie ->workspaceSize ) {
469+ if (( !workspace && mSofie -> workspaceSize ) || bytes < mSofie ->workspaceSize ) {
475470 throw std::runtime_error (" O2 supplied insufficient SOFIE workspace" );
476471 }
477472 auto * next = static_cast <char *>(workspace);
478473 for (const auto & session : mSofie ->sessions ) {
479474 if (session) {
480475 session->SetWorkspace (next, session->WorkspaceSize ());
481- next += session->WorkspaceSize ();
476+ if (session->WorkspaceSize ()) {
477+ next += session->WorkspaceSize ();
478+ }
482479 }
483480 }
484481#endif
0 commit comments