Skip to content

Commit a5bf9d0

Browse files
committed
GPU: Add debug option to create temporary MC labels for collected merged tracks
1 parent ab7a0c4 commit a5bf9d0

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
@@ -39,7 +39,7 @@ BeginNamespace(gpu)
3939

4040
// Reconstruction parameters for TPC, no bool in here !!!
4141
BeginSubConfig(GPUSettingsRecTPC, tpc, configStandalone.rec, "RECTPC", 0, "Reconstruction settings", rec_tpc)
42-
AddOptionRTC(rejectQPtB5, float, 1.f / 0.050f, "", 0, "QPt threshold to reject clusters of TPC tracks (Inverse Pt, scaled to B=0.5T!!!)")
42+
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
4343
AddOptionRTC(hitPickUpFactor, float, 1.f, "", 0, "multiplier for the combined cluster+track error during track following")
4444
AddOptionRTC(hitSearchArea2, float, 2.f, "", 0, "square of maximum search road of hits during seeding")
4545
AddOptionRTC(neighboursSearchArea, float, 3.f, "", 0, "area in cm for the search of neighbours, for z only used if searchWindowDZDR = 0")
@@ -326,6 +326,13 @@ AddOption(conservativeMemoryEstimate, bool, false, "", 0, "Use some more conserv
326326
AddHelp("help", 'h')
327327
EndConfig()
328328

329+
// Debug Settings
330+
BeginSubConfig(GPUSettingsProcessingDebug, debug, configStandalone.proc, "DEBUG", 0, "Debugging Settings", proc_debug)
331+
AddOption(memoryScalingFuzz, uint64_t, 0, "", 0, "Fuzz the memoryScalingFactor (0 disable, 1 enable, >1 set seed", def(1))
332+
AddOption(mergerMCLabels, bool, false, "", 0, "Create MC labels for merged tracks before refit for debugging")
333+
AddHelp("help", 'h')
334+
EndConfig()
335+
329336
// Settings steering the processing once the device was selected, only available on the host
330337
BeginSubConfig(GPUSettingsProcessing, proc, configStandalone, "PROC", 0, "Processing settings", proc)
331338
AddOption(deviceNum, int32_t, -1, "gpuDevice", 0, "Set GPU device to use (-1: automatic, -2: for round-robin usage in timeslice-pipeline)")
@@ -354,7 +361,6 @@ AddOption(memoryAllocationStrategy, int8_t, 0, "", 0, "Memory Allocation Strageg
354361
AddOption(forceMemoryPoolSize, uint64_t, 1, "memSize", 0, "Force size of allocated GPU / page locked host memory", min(0ul))
355362
AddOption(forceHostMemoryPoolSize, uint64_t, 0, "hostMemSize", 0, "Force size of allocated host page locked host memory (overriding memSize)", min(0ul))
356363
AddOption(memoryScalingFactor, float, 1.f, "", 0, "Factor to apply to all memory scalers")
357-
AddOption(memoryScalingFuzz, uint64_t, 0, "", 0, "Fuzz the memoryScalingFactor (0 disable, 1 enable, >1 set seed", def(1))
358364
AddOption(tpcInputWithClusterRejection, uint8_t, 0, "", 0, "Indicate whether the TPC input is CTF data with cluster rejection, to tune buffer estimations")
359365
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")
360366
AddOption(registerStandaloneInputMemory, bool, false, "registerInputMemory", 0, "Automatically register input memory buffers for the GPU")
@@ -401,7 +407,7 @@ AddOption(tpcUseOldCPUDecoding, bool, false, "", 0, "Enable old CPU-based TPC de
401407
AddOption(tpcApplyCFCutsAtDecoding, bool, false, "", 0, "Apply cluster cuts from clusterization during decoding of compressed clusters")
402408
AddOption(tpcApplyClusterFilterOnCPU, uint8_t, 0, "", 0, "Apply custom cluster filter of GPUTPCClusterFilter class, 0: off, 1: debug, 2: PbPb23")
403409
AddOption(tpcWriteClustersAfterRejection, bool, false, "", 0, "Apply TPC rejection strategy before writing clusters")
404-
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))")
410+
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
405411
AddOption(oclCompileFromSources, bool, false, "", 0, "Compile OpenCL binary from included source code instead of using included spirv code")
406412
AddOption(oclOverrideSourceBuildFlags, std::string, "", "", 0, "Override OCL build flags for compilation from source, put a space for empty options")
407413
AddOption(hipOverrideAMDEUSperCU, int32_t, -1, "", 0, "Override AMD_EUS_PER_CU setting")
@@ -422,6 +428,7 @@ AddSubConfig(GPUSettingsProcessingRTCtechnical, rtctech)
422428
AddSubConfig(GPUSettingsProcessingParam, param)
423429
AddSubConfig(GPUSettingsProcessingNNclusterizer, nn)
424430
AddSubConfig(GPUSettingsProcessingScaling, scaling)
431+
AddSubConfig(GPUSettingsProcessingDebug, debug)
425432
AddHelp("help", 'h')
426433
EndConfig()
427434
#endif // __OPENCL__

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>
@@ -278,6 +284,7 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger& GPUrestrict() merger, int32_
278284
if (param.rec.tpc.rebuildTrackInFit && !rebuilt && !(param.rec.tpc.disableRebuildAttachment & 16) && iWay >= nWays - 3 && CAMath::Abs(mP[2]) < maxSinForUpdate && lastUpdateRow != 255) {
279285
const int32_t up = ((clusters[0].row < clusters[maxN - 1].row) ^ (iWay & 1)) ? 1 : -1;
280286
int32_t sector = lastSector;
287+
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()));
281288
uint8_t rowGapActive = 0, rowGapTotal = 0, missingRowsTotal = 0;
282289
uint8_t lastGoodRow = lastPropagateRow, lastExtrapolateRow = lastPropagateRow;
283290
uint8_t consecGoodRows = param.rec.tpc.rebuildTrackExtrMinConsecGoodRows, consecGoodRowsMissing = 0;
@@ -326,6 +333,12 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger& GPUrestrict() merger, int32_
326333
auto& candidate = merger.ClusterCandidates()[(iTrk * GPUTPCGeometry::NROWS + iRow) * param.rec.tpc.rebuildTrackInFitClusterCandidates + 0];
327334
if (candidate.id >= 2) {
328335
lastExtrapolateRow = iRow;
336+
#if defined(DEBUG_REBUILD_MC) && !defined(GPUCA_GPUCODE)
337+
if (merger.MergedTrackMC() && merger.GetConstantMem()->ioPtrs.clustersNative->clustersMCTruth) {
338+
int32_t labelCorrect = GPUTPCTrkLblSearch(merger.GetConstantMem()->ioPtrs.clustersNative->clustersMCTruth->getLabels(candidate.id - 2), merger.MergedTrackMC()[iTrk]);
339+
CADEBUG(printf("\t%21sLabel correct: %d\n", "", labelCorrect));
340+
}
341+
#endif
329342
float err2Y, err2Z, xx, yy, zz;
330343
const ClusterNative& GPUrestrict() cl = merger.GetConstantMem()->ioPtrs.clustersNative->clustersLinear[candidate.id - 2];
331344
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)