Skip to content

Commit 404a2a4

Browse files
committed
GPU: Add debug option to create temporary MC labels for collected merged tracks
1 parent 2c2967e commit 404a2a4

8 files changed

Lines changed: 76 additions & 6 deletions

File tree

‎GPU/GPUTracking/Base/GPUReconstructionCPU.cxx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ int32_t GPUReconstructionCPU::ExitDevice()
216216
int32_t GPUReconstructionCPU::RunChains()
217217
{
218218
mMemoryScalers->temporaryFactor = 1.;
219-
if (GetProcessingSettings().memoryScalingFuzz) {
219+
if (GetProcessingSettings().debug.memoryScalingFuzz) {
220220
static std::mt19937 rng;
221221
static std::uniform_int_distribution<uint64_t> dist(0, 1000000);
222-
uint64_t fuzzFactor = GetProcessingSettings().memoryScalingFuzz == 1 ? dist(rng) : GetProcessingSettings().memoryScalingFuzz;
222+
uint64_t fuzzFactor = GetProcessingSettings().debug.memoryScalingFuzz == 1 ? dist(rng) : GetProcessingSettings().debug.memoryScalingFuzz;
223223
GPUInfo("Fuzzing memory scaling factor with %lu", fuzzFactor);
224224
mMemoryScalers->fuzzScalingFactor(fuzzFactor);
225225
}

‎GPU/GPUTracking/Definitions/GPUSettingsList.h‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ BeginNamespace(o2::gpu)
3232

3333
// Reconstruction parameters for TPC, no bool in here !!!
3434
BeginSubConfig(GPUSettingsRecTPC, tpc, configStandalone.rec, "RECTPC", 0, "Reconstruction settings", rec_tpc)
35-
AddOptionRTC(rejectQPtB5, float, 1.f / 0.050f, "", 0, "QPt threshold to reject clusters of TPC tracks (Inverse Pt, scaled to B=0.5T!!!)")
35+
AddOptionRTC(rejectQPtB5, float, 1.f / 0.050f, "", 0, "QPt threshold to reject clusters of TPC tracks (Inverse Pt, scaled to B=0.5T!!!)") // TODO: Sort these options automatically for parameter size
3636
AddOptionRTC(hitPickUpFactor, float, 1.f, "", 0, "multiplier for the combined cluster+track error during track following")
3737
AddOptionRTC(hitSearchArea2, float, 2.f, "", 0, "square of maximum search road of hits during seeding")
3838
AddOptionRTC(neighboursSearchArea, float, 3.f, "", 0, "area in cm for the search of neighbours, for z only used if searchWindowDZDR = 0")
@@ -330,6 +330,13 @@ AddOption(tpcDecodingSafetyBuffer, uint16_t, 1000, "", 0, "Scaling Factor: safet
330330
AddHelp("help", 'h')
331331
EndConfig()
332332

333+
// Debug Settings
334+
BeginSubConfig(GPUSettingsProcessingDebug, debug, configStandalone.proc, "DEBUG", 0, "Debugging Settings", proc_debug)
335+
AddOption(memoryScalingFuzz, uint64_t, 0, "", 0, "Fuzz the memoryScalingFactor (0 disable, 1 enable, >1 set seed", def(1))
336+
AddOption(mergerMCLabels, bool, false, "", 0, "Create MC labels for merged tracks before refit for debugging")
337+
AddHelp("help", 'h')
338+
EndConfig()
339+
333340
// Settings steering the processing once the device was selected, only available on the host
334341
BeginSubConfig(GPUSettingsProcessing, proc, configStandalone, "PROC", 0, "Processing settings", proc)
335342
AddOption(deviceNum, int32_t, -1, "gpuDevice", 0, "Set GPU device to use (-1: automatic, -2: for round-robin usage in timeslice-pipeline)")
@@ -359,7 +366,6 @@ AddOption(memoryAllocationStrategy, int8_t, 0, "", 0, "Memory Allocation Strateg
359366
AddOption(forceMemoryPoolSize, uint64_t, 1, "memSize", 0, "Force size of allocated GPU / page locked host memory (0 = disable, 1 / 2 = auto, other values set the size of the memory pool)", min(0ul))
360367
AddOption(forceHostMemoryPoolSize, uint64_t, 0, "hostMemSize", 0, "Force size of allocated host page locked host memory (overriding memSize)", min(0ul))
361368
AddOption(memoryScalingFactor, float, 1.f, "", 0, "Factor to apply to all memory scalers")
362-
AddOption(memoryScalingFuzz, uint64_t, 0, "", 0, "Fuzz the memoryScalingFactor (0 disable, 1 enable, >1 set seed", def(1))
363369
AddOption(tpcInputWithClusterRejection, uint8_t, 0, "", 0, "Indicate whether the TPC input is CTF data with cluster rejection, to tune buffer estimations")
364370
AddOption(forceMaxMemScalers, uint64_t, 0, "", 0, "Force using the maximum values for all buffers, Set a value n > 1 to rescale all maximums to a memory size of n")
365371
AddOption(registerStandaloneInputMemory, bool, false, "registerInputMemory", 0, "Automatically register input memory buffers for the GPU")
@@ -406,7 +412,7 @@ AddOption(tpcUseOldCPUDecoding, bool, false, "", 0, "Enable old CPU-based TPC de
406412
AddOption(tpcApplyCFCutsAtDecoding, bool, false, "", 0, "Apply cluster cuts from clusterization during decoding of compressed clusters")
407413
AddOption(tpcApplyClusterFilterOnCPU, uint8_t, 0, "", 0, "Apply custom cluster filter of GPUTPCClusterFilter class, 0: off, 1: debug, 2: PbPb23")
408414
AddOption(tpcWriteClustersAfterRejection, bool, false, "", 0, "Apply TPC rejection strategy before writing clusters")
409-
AddOption(oclPlatformNum, int32_t, -1, "", 0, "Platform to use, in case the backend provides multiple platforms (OpenCL only, -1 = auto-select, -2 query all platforms (also incompatible))")
415+
AddOption(oclPlatformNum, int32_t, -1, "", 0, "Platform to use, in case the backend provides multiple platforms (OpenCL only, -1 = auto-select, -2 query all platforms (also incompatible))") // TODO: Create some backend-specific options
410416
AddOption(oclCompileFromSources, bool, false, "", 0, "Compile OpenCL binary from included source code instead of using included spirv code")
411417
AddOption(oclOverrideSourceBuildFlags, std::string, "", "", 0, "Override OCL build flags for compilation from source, put a space for empty options")
412418
AddOption(metalOverrideSourceBuildFlags, std::string, "", "", 0, "Override Metal build flags for compilation from source, put a space for empty options")
@@ -430,6 +436,7 @@ AddSubConfig(GPUSettingsProcessingRTCtechnical, rtctech)
430436
AddSubConfig(GPUSettingsProcessingParam, param)
431437
AddSubConfig(GPUSettingsProcessingNNclusterizer, nn)
432438
AddSubConfig(GPUSettingsProcessingScaling, scaling)
439+
AddSubConfig(GPUSettingsProcessingDebug, debug)
433440
AddHelp("help", 'h')
434441
EndConfig()
435442
#endif // !__OPENCL__ && !__METAL__

‎GPU/GPUTracking/GPUTrackingLinkDef_O2_DataTypes.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#pragma link C++ class o2::gpu::internal::GPUConfigurableParamGPUSettingsProcessingRTCtechnical + ;
3434
#pragma link C++ class o2::gpu::internal::GPUConfigurableParamGPUSettingsProcessingNNclusterizer + ;
3535
#pragma link C++ class o2::gpu::internal::GPUConfigurableParamGPUSettingsProcessingScaling + ;
36+
#pragma link C++ class o2::gpu::internal::GPUConfigurableParamGPUSettingsProcessingDebug + ;
3637
#pragma link C++ class o2::gpu::internal::GPUConfigurableParamGPUSettingsDisplay + ;
3738
#pragma link C++ class o2::gpu::internal::GPUConfigurableParamGPUSettingsDisplayLight + ;
3839
#pragma link C++ class o2::gpu::internal::GPUConfigurableParamGPUSettingsDisplayHeavy + ;

‎GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ int32_t GPUChainTracking::RunTPCTrackingMerger(bool synchronizeOutput)
176176
runKernel<GPUTPCGlobalDebugSortKernels, GPUTPCGlobalDebugSortKernels::mergedTracks1>({{1, -WarpSize(), 0, deviceType}}, 1);
177177
runKernel<GPUTPCGlobalDebugSortKernels, GPUTPCGlobalDebugSortKernels::mergedTracks2>({{1, -WarpSize(), 0, deviceType}}, 1);
178178
}
179+
if (!doGPU && GetProcessingSettings().debug.mergerMCLabels) {
180+
Merger.CreateMCLabels(1, 1, 0, 0);
181+
}
179182
DoDebugAndDump(RecoStep::TPCMerging, GPUChainTrackingDebugFlags::TPCMergingCollectedTracks, doGPU, Merger, &GPUTPCGMMerger::DumpCollected, *mDebugFile);
180183

181184
if (param().rec.tpc.mergeCE) {

‎GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ using namespace o2::gpu::internal;
148148

149149
#include "GPUQA.h"
150150
#include "GPUMemorySizeScalers.h"
151+
#include "GPUQAHelper.h"
151152

152153
GPUTPCGMMerger::GPUTPCGMMerger()
153154
{
@@ -164,7 +165,7 @@ GPUTPCGMMerger::GPUTPCGMMerger()
164165
}
165166

166167
// DEBUG CODE
167-
#if !defined(GPUCA_GPUCODE) && (defined(GPUCA_MERGER_BY_MC_LABEL) || defined(GPUCA_CADEBUG_ENABLED) || GPUCA_MERGE_LOOPER_MC)
168+
#if defined(GPUCA_MERGER_BY_MC_LABEL) || defined(GPUCA_CADEBUG_ENABLED) || GPUCA_MERGE_LOOPER_MC
168169
#include "GPUQAHelper.h"
169170

170171
template <class T>
@@ -438,6 +439,9 @@ void* GPUTPCGMMerger::SetPointersRefitScratch(void* mem)
438439
void* GPUTPCGMMerger::SetPointersOutput(void* mem)
439440
{
440441
computePointerWithAlignment(mem, mMergedTracks, mNMaxTracks);
442+
if (mRec->GetProcessingSettings().debug.mergerMCLabels) {
443+
computePointerWithAlignment(mem, mMergedTrackMC, mNMaxTracks);
444+
}
441445
if (mRec->GetParam().dodEdxEnabled) {
442446
computePointerWithAlignment(mem, mMergedTracksdEdx, mNMaxTracks);
443447
if (mRec->GetParam().rec.tpc.dEdxClusterRejectionFlagMask != mRec->GetParam().rec.tpc.dEdxClusterRejectionFlagMaskAlt) {
@@ -547,6 +551,34 @@ int32_t GPUTPCGMMerger::CheckSectors()
547551
return 0;
548552
}
549553

554+
void GPUTPCGMMerger::CreateMCLabels(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread)
555+
{
556+
const o2::tpc::ClusterNativeAccess* GPUrestrict() clusters = GetConstantMem()->ioPtrs.clustersNative;
557+
if (clusters == nullptr || clusters->clustersMCTruth == nullptr) {
558+
return;
559+
}
560+
if (mMergedTrackMC == nullptr) {
561+
return;
562+
}
563+
564+
auto labelAssigner = GPUTPCTrkLbl(clusters->clustersMCTruth, 0.1f);
565+
for (int32_t i = get_global_id(0); i < NMergedTracks(); i += get_global_size(0)) {
566+
const auto& trk = mMergedTracks[i];
567+
if (!trk.OK()) {
568+
continue;
569+
}
570+
labelAssigner.reset();
571+
for (uint32_t j = 0; j < trk.NClusters(); j++) {
572+
const auto& cl = mClusters[trk.FirstClusterRef() + j];
573+
if (cl.state & GPUTPCGMMergedTrackHit::flagReject) {
574+
continue;
575+
}
576+
labelAssigner.addLabel(cl.num);
577+
}
578+
mMergedTrackMC[i] = labelAssigner.computeLabel();
579+
}
580+
}
581+
550582
#endif // GPUCA_GPUCODE
551583

552584
GPUd() void GPUTPCGMMerger::ClearTrackLinks(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, bool output)

‎GPU/GPUTracking/Merger/GPUTPCGMMerger.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class GPUTPCGMMerger : public GPUProcessor
123123

124124
GPUhdi() int32_t NMergedTracks() const { return mMemory->nMergedTracks; }
125125
GPUhdi() const GPUTPCGMMergedTrack* MergedTracks() const { return mMergedTracks; }
126+
GPUhdi() const o2::MCCompLabel* MergedTrackMC() const { return mMergedTrackMC; }
126127
GPUhdi() GPUTPCGMMergedTrack* MergedTracks() { return mMergedTracks; }
127128
GPUhdi() const GPUdEdxInfo* MergedTracksdEdx() const { return mMergedTracksdEdx; }
128129
GPUhdi() GPUdEdxInfo* MergedTracksdEdx() { return mMergedTracksdEdx; }
@@ -214,6 +215,7 @@ class GPUTPCGMMerger : public GPUProcessor
214215
GPUd() void ResolveHitWeights1(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, int32_t iteration);
215216
GPUd() void ResolveHitWeights2(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread);
216217
GPUd() void ResolveHitWeightsShared(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread);
218+
GPUd() void CreateMCLabels(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread);
217219

218220
#ifndef GPUCA_GPUCODE
219221
void DumpSectorTracks(std::ostream& out) const;
@@ -294,6 +296,7 @@ class GPUTPCGMMerger : public GPUProcessor
294296

295297
int32_t mNSectorHits = 0; // Total number of incoming clusters (from sector tracks)
296298
GPUTPCGMMergedTrack* mMergedTracks = nullptr; //* array of output merged tracks
299+
o2::MCCompLabel* mMergedTrackMC = nullptr;
297300
trackCluster* mClusterCandidates = nullptr;
298301
trackRebuildHelper* mTrackRebuildHelper = nullptr;
299302
int32_t* mHitWeights = nullptr;

‎GPU/GPUTracking/Merger/GPUTPCGMTrackParam.cxx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#define GPUCA_CADEBUG 0
1616
#define DEBUG_SINGLE_TRACK -1
17+
// #define DEBUG_REBUILD_MC
1718

1819
#include "GPUTPCDef.h"
1920
#include "GPUTPCGMTrackParam.h"
@@ -39,6 +40,11 @@
3940
#include "AliHLTTPCClusterMCData.h"
4041
#endif
4142

43+
#ifndef GPUCA_GPUCODE
44+
#include "SimulationDataFormat/ConstMCTruthContainer.h"
45+
#include "SimulationDataFormat/MCCompLabel.h"
46+
#endif
47+
4248
#ifndef GPUCA_GPUCODE_DEVICE
4349
#include <cmath>
4450
#include <cstdlib>
@@ -277,6 +283,7 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger& GPUrestrict() merger, int32_
277283
if (param.rec.tpc.rebuildTrackInFit && !rebuilt && !(param.rec.tpc.disableRebuildAttachment & 16) && iWay >= nWays - 3 && CAMath::Abs(mP[2]) < maxSinForUpdate && lastUpdateRow != 255) {
278284
const int32_t up = ((clusters[0].row < clusters[maxN - 1].row) ^ (iWay & 1)) ? 1 : -1;
279285
int32_t sector = lastSector;
286+
CADEBUG(merger.MergedTrackMC() printf("Extrapolate Start Track %d - sector %2d row %3d %s - fake %d\n", iTrk, sector, (int32_t)lastPropagateRow, up == 1 ? "upwards" : "downwards", (int)merger.MergedTrackMC()[iTrk].isFake()));
280287
uint8_t rowGapActive = 0, rowGapTotal = 0, missingRowsTotal = 0;
281288
uint8_t lastGoodRow = lastPropagateRow, lastExtrapolateRow = lastPropagateRow;
282289
uint8_t consecGoodRows = param.rec.tpc.rebuildTrackExtrMinConsecGoodRows, consecGoodRowsMissing = 0;
@@ -325,6 +332,12 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger& GPUrestrict() merger, int32_
325332
auto& candidate = merger.ClusterCandidates()[(iTrk * GPUTPCGeometry::NROWS + iRow) * param.rec.tpc.rebuildTrackInFitClusterCandidates + 0];
326333
if (candidate.id >= 2) {
327334
lastExtrapolateRow = iRow;
335+
#if defined(DEBUG_REBUILD_MC) && !defined(GPUCA_GPUCODE)
336+
if (merger.MergedTrackMC() && merger.GetConstantMem()->ioPtrs.clustersNative->clustersMCTruth) {
337+
int32_t labelCorrect = GPUTPCTrkLblSearch(merger.GetConstantMem()->ioPtrs.clustersNative->clustersMCTruth->getLabels(candidate.id - 2), merger.MergedTrackMC()[iTrk]);
338+
CADEBUG(printf("\t%21sLabel correct: %d\n", "", labelCorrect));
339+
}
340+
#endif
328341
float err2Y, err2Z, xx, yy, zz;
329342
const ClusterNative& GPUrestrict() cl = merger.GetConstantMem()->ioPtrs.clustersNative->clustersLinear[candidate.id - 2];
330343
merger.GetConstantMem()->calibObjects.fastTransform->Transform(sector, iRow, cl.getPad(), cl.getTime(), xx, yy, zz, mTOffset);

‎GPU/GPUTracking/qa/GPUQAHelper.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,17 @@ static inline auto GPUTPCTrkLbl(const AliHLTTPCClusterMCLabel* x, Args... args)
162162
}
163163
}
164164

165+
template <class T>
166+
static inline bool GPUTPCTrkLblSearch(const T& clusterLabels, const MCCompLabel& trkLabel)
167+
{
168+
for (const auto& clLabel : clusterLabels) {
169+
if (trkLabel.compare(clLabel) >= 0) {
170+
return true;
171+
}
172+
}
173+
return false;
174+
}
175+
165176
} // namespace gpu
166177
} // namespace o2
167178

0 commit comments

Comments
 (0)