Skip to content

Commit 81c646b

Browse files
committed
Using const ref and moving CCDB calls to host initialization
1 parent ad4b22b commit 81c646b

File tree

3 files changed

+53
-51
lines changed

3 files changed

+53
-51
lines changed

GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#endif
4141

4242
#ifdef GPUCA_HAS_ONNX
43-
#include <CommonUtils/StringUtils.h>
4443
#include "GPUTPCNNClusterizerKernels.h"
4544
#include "GPUTPCNNClusterizerHost.h"
4645
#endif
@@ -613,51 +612,9 @@ int32_t GPUChainTracking::RunTPCClusterizer(bool synchronizeOutput)
613612
}
614613

615614
#ifdef GPUCA_HAS_ONNX
616-
GPUSettingsProcessingNNclusterizer nn_settings = GetProcessingSettings().nn;
615+
const GPUSettingsProcessingNNclusterizer& nn_settings = GetProcessingSettings().nn;
617616
GPUTPCNNClusterizerHost nnApplication; // potentially this needs to be GPUTPCNNClusterizerHost nnApplication[NSECTORS]; Technically ONNX ->Run() is threadsafe at inference time since its read-only
618617
if (GetProcessingSettings().nn.applyNNclusterizer) {
619-
if(nn_settings.nnLoadFromCCDB) {
620-
std::map<std::string, std::string> ccdbSettings = {
621-
{"nnCCDBURL", nn_settings.nnCCDBURL},
622-
{"nnCCDBPath", nn_settings.nnCCDBPath},
623-
{"inputDType", nn_settings.nnInferenceInputDType},
624-
{"outputDType", nn_settings.nnInferenceOutputDType},
625-
{"nnCCDBWithMomentum", std::to_string(nn_settings.nnCCDBWithMomentum)},
626-
{"nnCCDBBeamType", nn_settings.nnCCDBBeamType},
627-
{"nnCCDBInteractionRate", std::to_string(nn_settings.nnCCDBInteractionRate)}
628-
};
629-
630-
std::string nnFetchFolder = "";
631-
std::vector<std::string> fetchMode = o2::utils::Str::tokenize(nn_settings.nnCCDBFetchMode, ':');
632-
std::map<std::string, std::string> networkRetrieval = ccdbSettings;
633-
634-
if (fetchMode[0] == "c1") {
635-
networkRetrieval["nnCCDBLayerType"] = nn_settings.nnCCDBClassificationLayerType;
636-
networkRetrieval["nnCCDBEvalType"] = "classification_c1";
637-
networkRetrieval["outputFile"] = nnFetchFolder + "net_classification_c1.onnx";
638-
nnApplication.loadFromCCDB(networkRetrieval);
639-
} else if (fetchMode[0] == "c2") {
640-
networkRetrieval["nnCCDBLayerType"] = nn_settings.nnCCDBClassificationLayerType;
641-
networkRetrieval["nnCCDBEvalType"] = "classification_c2";
642-
networkRetrieval["outputFile"] = nnFetchFolder + "net_classification_c2.onnx";
643-
nnApplication.loadFromCCDB(networkRetrieval);
644-
}
645-
nn_settings.nnClassificationPath = networkRetrieval["outputFile"]; // Setting the proper path from the where the models will be initialized locally
646-
647-
networkRetrieval["nnCCDBLayerType"] = nn_settings.nnCCDBRegressionLayerType;
648-
networkRetrieval["nnCCDBEvalType"] = "regression_c1";
649-
networkRetrieval["outputFile"] = nnFetchFolder + "net_regression_c1.onnx";
650-
nnApplication.loadFromCCDB(networkRetrieval);
651-
nn_settings.nnRegressionPath = networkRetrieval["outputFile"];
652-
if (fetchMode[1] == "r2") {
653-
networkRetrieval["nnCCDBLayerType"] = nn_settings.nnCCDBRegressionLayerType;
654-
networkRetrieval["nnCCDBEvalType"] = "regression_c2";
655-
networkRetrieval["outputFile"] = nnFetchFolder + "net_regression_c2.onnx";
656-
nnApplication.loadFromCCDB(networkRetrieval);
657-
nn_settings.nnRegressionPath += ":", networkRetrieval["outputFile"];
658-
}
659-
}
660-
661618
uint32_t maxClusters = 0;
662619
nnApplication.init(nn_settings);
663620
for (uint32_t iSector = 0; iSector < NSECTORS; iSector++) {
@@ -988,7 +945,7 @@ int32_t GPUChainTracking::RunTPCClusterizer(bool synchronizeOutput)
988945
if (!clustererNN.nnClusterizerUseCfRegression) {
989946
nnApplication.networkInference(nnApplication.model_reg_1, clustererNN, iSize, clustererNN.outputDataReg1, clustererNN.nnClusterizerDtype);
990947
runKernel<GPUTPCNNClusterizerKernels, GPUTPCNNClusterizerKernels::publishClass1Regression>({GetGrid(iSize, lane), krnlRunRangeNone}, iSector, clustererNN.nnClusterizerDtype, withMC, batchStart); // Running the NN for regression class 1
991-
if (nnApplication.model_class.getNumOutputNodes()[0][1] > 1 && nnApplication.reg_model_paths.size() > 1) {
948+
if (nnApplication.model_class.getNumOutputNodes()[0][1] > 1 && nnApplication.model_reg_2.isInitialized()) {
992949
nnApplication.networkInference(nnApplication.model_reg_2, clustererNN, iSize, clustererNN.outputDataReg2, clustererNN.nnClusterizerDtype);
993950
runKernel<GPUTPCNNClusterizerKernels, GPUTPCNNClusterizerKernels::publishClass2Regression>({GetGrid(iSize, lane), krnlRunRangeNone}, iSector, clustererNN.nnClusterizerDtype, withMC, batchStart); // Running the NN for regression class 2
994951
}

GPU/GPUTracking/TPCClusterFinder/GPUTPCNNClusterizerHost.cxx

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
using namespace o2::gpu;
2424

25-
GPUTPCNNClusterizerHost::GPUTPCNNClusterizerHost(GPUSettingsProcessingNNclusterizer settings)
25+
GPUTPCNNClusterizerHost::GPUTPCNNClusterizerHost(const GPUSettingsProcessingNNclusterizer& settings)
2626
{
2727
init(settings);
2828
}
@@ -53,10 +53,55 @@ void GPUTPCNNClusterizerHost::loadFromCCDB(std::map<std::string, std::string> se
5353
}
5454
}
5555

56-
void GPUTPCNNClusterizerHost::init(GPUSettingsProcessingNNclusterizer settings)
56+
void GPUTPCNNClusterizerHost::init(const GPUSettingsProcessingNNclusterizer& settings)
5757
{
58+
std::string class_model_path = settings.nnClassificationPath, reg_model_path = settings.nnRegressionPath;
59+
std::vector<std::string> reg_model_paths;
60+
61+
if(settings.nnLoadFromCCDB) {
62+
std::map<std::string, std::string> ccdbSettings = {
63+
{"nnCCDBURL", settings.nnCCDBURL},
64+
{"nnCCDBPath", settings.nnCCDBPath},
65+
{"inputDType", settings.nnInferenceInputDType},
66+
{"outputDType", settings.nnInferenceOutputDType},
67+
{"nnCCDBWithMomentum", std::to_string(settings.nnCCDBWithMomentum)},
68+
{"nnCCDBBeamType", settings.nnCCDBBeamType},
69+
{"nnCCDBInteractionRate", std::to_string(settings.nnCCDBInteractionRate)}
70+
};
71+
72+
std::string nnFetchFolder = "";
73+
std::vector<std::string> fetchMode = o2::utils::Str::tokenize(settings.nnCCDBFetchMode, ':');
74+
std::map<std::string, std::string> networkRetrieval = ccdbSettings;
75+
76+
if (fetchMode[0] == "c1") {
77+
networkRetrieval["nnCCDBLayerType"] = settings.nnCCDBClassificationLayerType;
78+
networkRetrieval["nnCCDBEvalType"] = "classification_c1";
79+
networkRetrieval["outputFile"] = nnFetchFolder + "net_classification_c1.onnx";
80+
loadFromCCDB(networkRetrieval);
81+
} else if (fetchMode[0] == "c2") {
82+
networkRetrieval["nnCCDBLayerType"] = settings.nnCCDBClassificationLayerType;
83+
networkRetrieval["nnCCDBEvalType"] = "classification_c2";
84+
networkRetrieval["outputFile"] = nnFetchFolder + "net_classification_c2.onnx";
85+
loadFromCCDB(networkRetrieval);
86+
}
87+
class_model_path = networkRetrieval["outputFile"]; // Setting the proper path from the where the models will be initialized locally
88+
89+
networkRetrieval["nnCCDBLayerType"] = settings.nnCCDBRegressionLayerType;
90+
networkRetrieval["nnCCDBEvalType"] = "regression_c1";
91+
networkRetrieval["outputFile"] = nnFetchFolder + "net_regression_c1.onnx";
92+
loadFromCCDB(networkRetrieval);
93+
reg_model_path = networkRetrieval["outputFile"];
94+
if (fetchMode[1] == "r2") {
95+
networkRetrieval["nnCCDBLayerType"] = settings.nnCCDBRegressionLayerType;
96+
networkRetrieval["nnCCDBEvalType"] = "regression_c2";
97+
networkRetrieval["outputFile"] = nnFetchFolder + "net_regression_c2.onnx";
98+
loadFromCCDB(networkRetrieval);
99+
reg_model_path += ":", networkRetrieval["outputFile"];
100+
}
101+
}
102+
58103
OrtOptions = {
59-
{"model-path", settings.nnClassificationPath},
104+
{"model-path", class_model_path},
60105
{"device", settings.nnInferenceDevice},
61106
{"device-id", std::to_string(settings.nnInferenceDeviceId)},
62107
{"allocate-device-memory", std::to_string(settings.nnInferenceAllocateDevMem)},
@@ -70,7 +115,7 @@ void GPUTPCNNClusterizerHost::init(GPUSettingsProcessingNNclusterizer settings)
70115

71116
model_class.init(OrtOptions);
72117

73-
reg_model_paths = o2::utils::Str::tokenize(settings.nnRegressionPath, ':');
118+
reg_model_paths = o2::utils::Str::tokenize(reg_model_path, ':');
74119

75120
if (!settings.nnClusterizerUseCfRegression) {
76121
if (model_class.getNumOutputNodes()[0][1] == 1 || reg_model_paths.size() == 1) {

GPU/GPUTracking/TPCClusterFinder/GPUTPCNNClusterizerHost.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class GPUTPCNNClusterizerHost
3737
{
3838
public:
3939
GPUTPCNNClusterizerHost() = default;
40-
GPUTPCNNClusterizerHost(GPUSettingsProcessingNNclusterizer);
40+
GPUTPCNNClusterizerHost(const GPUSettingsProcessingNNclusterizer&);
4141

42-
void init(GPUSettingsProcessingNNclusterizer);
42+
void init(const GPUSettingsProcessingNNclusterizer&);
4343
void initClusterizer(const GPUSettingsProcessingNNclusterizer&, GPUTPCNNClusterizer&);
4444
void loadFromCCDB(std::map<std::string, std::string>);
4545

0 commit comments

Comments
 (0)