Skip to content

Commit 83c004f

Browse files
committed
First version of CCDB implementation
1 parent 0c1cfb7 commit 83c004f

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

GPU/GPUTracking/Definitions/GPUSettingsList.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ AddOption(nnClassificationPath, std::string, "network_class.onnx", "", 0, "The c
249249
AddOption(nnClassThreshold, float, 0.5, "", 0, "The cutoff at which clusters will be accepted / rejected.")
250250
AddOption(nnRegressionPath, std::string, "network_reg.onnx", "", 0, "The regression network path")
251251
AddOption(nnSigmoidTrafoClassThreshold, int, 1, "", 0, "If true (default), then the classification threshold is transformed by an inverse sigmoid function. This depends on how the network was trained (with a sigmoid as acitvation function in the last layer or not).")
252+
// CCDB
253+
AddOption(nnLoadFromCCDB, int, 1, "", 0, "If 1 networks are fetched from ccdb, else locally")
254+
AddOption(nnCCDBURL, std::string, "http://alice-ccdb.cern.ch", "", 0, "The CCDB URL from where the network files are fetched")
255+
AddOption(nnCCDBPath, std::string, "Users/c/csonnabe/TPC/Clusterization", "", 0, "Folder path containing the networks")
256+
AddOption(nnCCDBWithMomentum, int, 1, "", 0, "Distinguishes between the network with and without momentum output for the regression")
257+
AddOption(nnCCDBLayerType, std::string, "FC", "", 0, "Distinguishes between network with different layer types. Options: FC, CNN")
258+
AddOption(nnCCDBBeamType, std::string, "", "", 0, "Distinguishes between networks trained for different beam types. Options: PbPb, pp")
259+
AddOption(nnCCDBInteractionRate, int, -1, "", 0, "Distinguishes between networks for different interaction rates [kHz].")
252260
AddHelp("help", 'h')
253261
EndConfig()
254262

GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,27 @@ int32_t GPUChainTracking::RunTPCClusterizer(bool synchronizeOutput)
615615
const GPUSettingsProcessingNNclusterizer& nn_settings = GetProcessingSettings().nn;
616616
GPUTPCNNClusterizerHost nnApplication; // potentially this needs to be GPUTPCNNClusterizerHost nnApplication[NSECTORS]; Technically ONNX ->Run() is threadsafe at inference time since its read-only
617617
if (GetProcessingSettings().nn.applyNNclusterizer) {
618+
if(nn_settings.nnLoadFromCCDB) {
619+
std::unordered_map<std::string, std::string> ccdbSettings = {
620+
{"nnCCDBPath", nn_settings.nnCCDBPath},
621+
{"inputDType", nn_settings.inputDType},
622+
{"outputDType", nn_settings.outputDType},
623+
{"nnCCDBWithMomentum", std::to_string(nn_settings.nnCCDBWithMomentum)},
624+
{"nnCCDBLayerType", nn_settings.nnCCDBLayerType},
625+
{"nnCCDBBeamType", nn_settings.nnCCDBBeamType},
626+
{"nnCCDBInteractionRate", std::to_string(nn_settings.nnCCDBInteractionRate)}
627+
};
628+
629+
std::unordered_map<std::string, std::string> networkRetrieval = ccdbSettings;
630+
631+
networkRetrieval["nnCCDBEvalType"] = "classification_c1";
632+
networkRetrieval["outputFile"] = "net_classification_c1.onnx";
633+
nnApplication.loadFromCCDB(networkRetrieval);
634+
635+
networkRetrieval["nnCCDBEvalType"] = "regression_c1";
636+
networkRetrieval["outputFile"] = "net_regression_c1.onnx";
637+
nnApplication.loadFromCCDB(networkRetrieval);
638+
}
618639
uint32_t maxClusters = 0;
619640
nnApplication.init(nn_settings);
620641
for (uint32_t iSector = 0; iSector < NSECTORS; iSector++) {

GPU/GPUTracking/TPCClusterFinder/GPUTPCNNClusterizerHost.cxx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,32 @@ GPUTPCNNClusterizerHost::GPUTPCNNClusterizerHost(const GPUSettingsProcessingNNcl
2626
init(settings);
2727
}
2828

29+
void GPUTPCNNClusterizerHost::loadFromCCDB(std::unordered_map<std::string, std::string> settings) {
30+
o2::ccdb::CcdbApi ccdbApi;
31+
ccdbApi.init(settings["nnCCDBURL"]);
32+
33+
metadata[settings["inputDType"]] = settings["inputDType"];
34+
metadata[settings["outputDType"]] = settings["outputDType"];
35+
metadata[settings["nnCCDBEvalType"]] = settings["nnCCDBEvalType"]; // classification_1C, classification_2C, regression_1C, regression_2C
36+
metadata[settings["nnCCDBWithMomentum"]] = std::stoi(settings["nnCCDBWithMomentum"]); // 0, 1 -> Only for regression model
37+
metadata[settings["nnCCDBLayerType"]] = settings["nnCCDBLayerType"]; // FC, CNN
38+
if (settings["nnCCDBInteractionRate"] != "" && std::stoi(settings["nnCCDBInteractionRate"]) > 0) {
39+
metadata[settings["nnCCDBInteractionRate"]] = settings["nnCCDBInteractionRate"];
40+
}
41+
if (settings["nnCCDBBeamType"] != "") {
42+
metadata[settings["nnCCDBBeamType"]] = settings["nnCCDBBeamType"];
43+
}
44+
45+
bool retrieveSuccess = ccdbApi.retrieveBlob(settings["nnPathCCDB"], ".", metadata, 1, false, settings["outputFile"]);
46+
// headers = ccdbApi.retrieveHeaders(nnPathCCDB, metadata, ccdbTimestamp); // potentially needed to init some local variables
47+
48+
if (retrieveSuccess) {
49+
LOG(info) << "Network " << settings["nnPathCCDB"] << " retrieved from CCDB, stored at " << settings["networkPathLocal"];
50+
} else {
51+
LOG(error) << "Failed to retrieve network from CCDB";
52+
}
53+
}
54+
2955
void GPUTPCNNClusterizerHost::init(const GPUSettingsProcessingNNclusterizer& settings)
3056
{
3157
OrtOptions = {

GPU/GPUTracking/TPCClusterFinder/GPUTPCNNClusterizerHost.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class GPUTPCNNClusterizerHost
4141

4242
void init(const GPUSettingsProcessingNNclusterizer&);
4343
void initClusterizer(const GPUSettingsProcessingNNclusterizer&, GPUTPCNNClusterizer&);
44+
void loadFromCCDB(std::unordered_map<std::string, std::string>);
4445

4546
void networkInference(o2::ml::OrtModel model, GPUTPCNNClusterizer& clusterer, size_t size, float* output, int32_t dtype);
4647

0 commit comments

Comments
 (0)