Skip to content

Commit d767ed1

Browse files
committed
Working CCDB API calls (tested with test-ccdb)
1 parent 83c004f commit d767ed1

File tree

4 files changed

+34
-23
lines changed

4 files changed

+34
-23
lines changed

GPU/GPUTracking/Definitions/GPUSettingsList.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ AddOption(nnInferenceDevice, std::string, "CPU", "", 0, "(std::string) Specify i
229229
AddOption(nnInferenceDeviceId, unsigned int, 0, "", 0, "(unsigned int) Specify inference device id")
230230
AddOption(nnInferenceAllocateDevMem, int, 0, "", 0, "(bool, default = 0), if the device memory should be allocated for inference")
231231
AddOption(nnInferenceDtype, std::string, "fp32", "", 0, "(std::string) Specify the datatype for which inference is performed (fp32: default, fp16)") // fp32 or fp16
232+
AddOption(nnInferenceInputDType, std::string, "FP32", "", 0, "(std::string) Specify the datatype for which inference is performed (FP32: default, fp16)") // fp32 or fp16
233+
AddOption(nnInferenceOutputDType, std::string, "FP32", "", 0, "(std::string) Specify the datatype for which inference is performed (fp32: default, fp16)") // fp32 or fp16
232234
AddOption(nnInferenceIntraOpNumThreads, int, 1, "", 0, "Number of threads used to evaluate one neural network (ONNX: SetIntraOpNumThreads). 0 = auto-detect, can lead to problems on SLURM systems.")
233235
AddOption(nnInferenceInterOpNumThreads, int, 1, "", 0, "Number of threads used to evaluate one neural network (ONNX: SetInterOpNumThreads). 0 = auto-detect, can lead to problems on SLURM systems.")
234236
AddOption(nnInferenceEnableOrtOptimization, unsigned int, 99, "", 0, "Enables graph optimizations in ONNX Runtime. Can be [0, 1, 2, 99] -> see https://github.com/microsoft/onnxruntime/blob/3f71d637a83dc3540753a8bb06740f67e926dc13/include/onnxruntime/core/session/onnxruntime_c_api.h#L347")
@@ -251,12 +253,13 @@ AddOption(nnRegressionPath, std::string, "network_reg.onnx", "", 0, "The regress
251253
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).")
252254
// CCDB
253255
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")
256+
AddOption(nnCCDBURL, std::string, "http://ccdb-test.cern.ch:8080", "", 0, "The CCDB URL from where the network files are fetched")
255257
AddOption(nnCCDBPath, std::string, "Users/c/csonnabe/TPC/Clusterization", "", 0, "Folder path containing the networks")
256258
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].")
259+
AddOption(nnCCDBClassificationLayerType, std::string, "FC", "", 0, "Distinguishes between network with different layer types. Options: FC, CNN")
260+
AddOption(nnCCDBRegressionLayerType, std::string, "CNN", "", 0, "Distinguishes between network with different layer types. Options: FC, CNN")
261+
AddOption(nnCCDBBeamType, std::string, "PbPb", "", 0, "Distinguishes between networks trained for different beam types. Options: PbPb, pp")
262+
AddOption(nnCCDBInteractionRate, int, 50, "", 0, "Distinguishes between networks for different interaction rates [kHz].")
260263
AddHelp("help", 'h')
261264
EndConfig()
262265

GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -616,26 +616,29 @@ int32_t GPUChainTracking::RunTPCClusterizer(bool synchronizeOutput)
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) {
618618
if(nn_settings.nnLoadFromCCDB) {
619-
std::unordered_map<std::string, std::string> ccdbSettings = {
619+
std::map<std::string, std::string> ccdbSettings = {
620+
{"nnCCDBURL", nn_settings.nnCCDBURL},
620621
{"nnCCDBPath", nn_settings.nnCCDBPath},
621-
{"inputDType", nn_settings.inputDType},
622-
{"outputDType", nn_settings.outputDType},
622+
{"inputDType", nn_settings.nnInferenceInputDType},
623+
{"outputDType", nn_settings.nnInferenceOutputDType},
623624
{"nnCCDBWithMomentum", std::to_string(nn_settings.nnCCDBWithMomentum)},
624-
{"nnCCDBLayerType", nn_settings.nnCCDBLayerType},
625625
{"nnCCDBBeamType", nn_settings.nnCCDBBeamType},
626626
{"nnCCDBInteractionRate", std::to_string(nn_settings.nnCCDBInteractionRate)}
627627
};
628628

629-
std::unordered_map<std::string, std::string> networkRetrieval = ccdbSettings;
629+
std::map<std::string, std::string> networkRetrieval = ccdbSettings;
630630

631+
networkRetrieval["nnCCDBLayerType"] = nn_settings.nnCCDBClassificationLayerType;
631632
networkRetrieval["nnCCDBEvalType"] = "classification_c1";
632633
networkRetrieval["outputFile"] = "net_classification_c1.onnx";
633634
nnApplication.loadFromCCDB(networkRetrieval);
634635

636+
networkRetrieval["nnCCDBLayerType"] = nn_settings.nnCCDBRegressionLayerType;
635637
networkRetrieval["nnCCDBEvalType"] = "regression_c1";
636638
networkRetrieval["outputFile"] = "net_regression_c1.onnx";
637639
nnApplication.loadFromCCDB(networkRetrieval);
638640
}
641+
639642
uint32_t maxClusters = 0;
640643
nnApplication.init(nn_settings);
641644
for (uint32_t iSector = 0; iSector < NSECTORS; iSector++) {

GPU/GPUTracking/TPCClusterFinder/GPUTPCNNClusterizerHost.cxx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "GPUTPCNNClusterizerHost.h"
1818
#include "GPUTPCNNClusterizer.h"
19+
#include "CCDB/CcdbApi.h"
1920
#include "GPUSettings.h"
2021
#include "ML/3rdparty/GPUORTFloat16.h"
2122

@@ -26,27 +27,27 @@ GPUTPCNNClusterizerHost::GPUTPCNNClusterizerHost(const GPUSettingsProcessingNNcl
2627
init(settings);
2728
}
2829

29-
void GPUTPCNNClusterizerHost::loadFromCCDB(std::unordered_map<std::string, std::string> settings) {
30+
void GPUTPCNNClusterizerHost::loadFromCCDB(std::map<std::string, std::string> settings) {
3031
o2::ccdb::CcdbApi ccdbApi;
3132
ccdbApi.init(settings["nnCCDBURL"]);
3233

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
34+
metadata["inputDType"] = settings["inputDType"];
35+
metadata["outputDType"] = settings["outputDType"];
36+
metadata["nnCCDBEvalType"] = settings["nnCCDBEvalType"]; // classification_1C, classification_2C, regression_1C, regression_2C
37+
metadata["nnCCDBWithMomentum"] = settings["nnCCDBWithMomentum"]; // 0, 1 -> Only for regression model
38+
metadata["nnCCDBLayerType"] = settings["nnCCDBLayerType"]; // FC, CNN
3839
if (settings["nnCCDBInteractionRate"] != "" && std::stoi(settings["nnCCDBInteractionRate"]) > 0) {
39-
metadata[settings["nnCCDBInteractionRate"]] = settings["nnCCDBInteractionRate"];
40+
metadata["nnCCDBInteractionRate"] = settings["nnCCDBInteractionRate"];
4041
}
4142
if (settings["nnCCDBBeamType"] != "") {
42-
metadata[settings["nnCCDBBeamType"]] = settings["nnCCDBBeamType"];
43+
metadata["nnCCDBBeamType"] = settings["nnCCDBBeamType"];
4344
}
4445

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
46+
bool retrieveSuccess = ccdbApi.retrieveBlob(settings["nnCCDBPath"], ".", metadata, 1, false, settings["outputFile"]);
47+
// headers = ccdbApi.retrieveHeaders(settings["nnPathCCDB"], metadata, 1); // potentially needed to init some local variables
4748

4849
if (retrieveSuccess) {
49-
LOG(info) << "Network " << settings["nnPathCCDB"] << " retrieved from CCDB, stored at " << settings["networkPathLocal"];
50+
LOG(info) << "Network " << settings["nnCCDBPath"] << " retrieved from CCDB, stored at " << settings["outputFile"];
5051
} else {
5152
LOG(error) << "Failed to retrieve network from CCDB";
5253
}
@@ -69,7 +70,7 @@ void GPUTPCNNClusterizerHost::init(const GPUSettingsProcessingNNclusterizer& set
6970

7071
model_class.init(OrtOptions);
7172

72-
reg_model_paths = splitString(settings.nnRegressionPath, ":");
73+
reg_model_paths = o2::utils::Str::tokenize(settings.nnRegressionPath, ':');
7374

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

GPU/GPUTracking/TPCClusterFinder/GPUTPCNNClusterizerHost.h

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

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

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

4848
std::unordered_map<std::string, std::string> OrtOptions;
4949
o2::ml::OrtModel model_class, model_reg_1, model_reg_2; // For splitting clusters
5050
std::vector<std::string> reg_model_paths;
51+
52+
private:
53+
std::map<std::string, std::string> metadata;
54+
std::map<std::string, std::string> headers;
5155
}; // class GPUTPCNNClusterizerHost
5256

5357
} // namespace o2::gpu

0 commit comments

Comments
 (0)