Skip to content

Commit 65b1361

Browse files
ktfclaude
andauthored
[Common] Avoid zero-initialising the NN TPC PID prediction buffer (#17831)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 3736e45 commit 65b1361

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

Common/Tools/PID/pidTPCModule.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,8 @@ class pidTPCModule
443443

444444
//__________________________________________________
445445
template <typename TCCDB, typename M, typename T, typename B>
446-
std::vector<float> createNetworkPrediction(TCCDB& ccdb, soa::Join<aod::Collisions, aod::EvSels> const& collisions, M const& mults, T const& tracks, B const& bcs, const size_t size)
446+
std::unique_ptr<float[]> createNetworkPrediction(TCCDB& ccdb, soa::Join<aod::Collisions, aod::EvSels> const& collisions, M const& mults, T const& tracks, B const& bcs, const size_t size)
447447
{
448-
449-
std::vector<float> network_prediction;
450-
451448
auto start_network_total = std::chrono::high_resolution_clock::now();
452449
if (pidTPCopts.autofetchNetworks) {
453450
const auto& bc = bcs.begin();
@@ -505,7 +502,10 @@ class pidTPCModule
505502
const uint64_t track_prop_size = input_dimensions * size;
506503
const uint64_t prediction_size = output_dimensions * size;
507504

508-
network_prediction = std::vector<float>(prediction_size * 9); // For each mass hypotheses
505+
// Deliberately uninitialised: the evaluation loop below writes every element
506+
// (one block per mass hypothesis), so zero-initialising would only touch
507+
// every page of an O(100 MB) buffer twice.
508+
std::unique_ptr<float[]> network_prediction(new float[prediction_size * 9]); // For each mass hypotheses
509509
const float nNclNormalization = response->GetNClNormalization();
510510
float duration_network = 0;
511511

@@ -624,7 +624,7 @@ class pidTPCModule
624624

625625
//__________________________________________________
626626
template <typename T, typename NSF, typename NST>
627-
void makePidTables(const int flagFull, NSF& tableFull, const int flagTiny, NST& tableTiny, const o2::track::PID::ID pid, const float tpcSignal, const T& trk, const int64_t multTPC, const std::vector<float>& network_prediction, const int& count_tracks, const int& tracksForNet_size)
627+
void makePidTables(const int flagFull, NSF& tableFull, const int flagTiny, NST& tableTiny, const o2::track::PID::ID pid, const float tpcSignal, const T& trk, const int64_t multTPC, const float* network_prediction, const int& count_tracks, const int& tracksForNet_size)
628628
{
629629
if (flagFull != 1 && flagTiny != 1) {
630630
return;
@@ -750,7 +750,7 @@ class pidTPCModule
750750
reserveTable(pidTPCopts.pidTinyAl, products.tablePIDTinyAl);
751751

752752
const uint64_t tracksForNet_size = (pidTPCopts.skipTPCOnly) ? totalTPCnotStandalone : totalTPCtracks;
753-
std::vector<float> network_prediction;
753+
std::unique_ptr<float[]> network_prediction;
754754

755755
if (pidTPCopts.useNetworkCorrection) {
756756
network_prediction = createNetworkPrediction(ccdb, cols, pidmults, tracks, bcs, tracksForNet_size);
@@ -951,7 +951,7 @@ class pidTPCModule
951951
}
952952

953953
auto makePidTablesDefault = [&trk, &tpcSignalToEvaluatePID, &multTPC, &network_prediction, &count_tracks, &tracksForNet_size, this](const int flagFull, auto& tableFull, const int flagTiny, auto& tableTiny, const o2::track::PID::ID pid) {
954-
this->makePidTables(flagFull, tableFull, flagTiny, tableTiny, pid, tpcSignalToEvaluatePID, trk, multTPC, network_prediction, count_tracks, tracksForNet_size);
954+
this->makePidTables(flagFull, tableFull, flagTiny, tableTiny, pid, tpcSignalToEvaluatePID, trk, multTPC, network_prediction.get(), count_tracks, tracksForNet_size);
955955
};
956956

957957
makePidTablesDefault(pidTPCopts.pidFullEl, products.tablePIDFullEl, pidTPCopts.pidTinyEl, products.tablePIDTinyEl, o2::track::PID::Electron);

0 commit comments

Comments
 (0)