Skip to content

Commit 2b03a37

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

File tree

7 files changed

+76
-6
lines changed

7 files changed

+76
-6
lines changed

GPU/GPUTracking/Base/GPUReconstructionCPU.cxx

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

GPU/GPUTracking/Definitions/GPUSettingsList.h

Lines changed: 11 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")
@@ -304,6 +304,14 @@ AddOption(nnCCDBInteractionRate, std::string, "500", "", 0, "Distinguishes betwe
304304
AddHelp("help", 'h')
305305
EndConfig()
306306

307+
// Debug Settings
308+
BeginSubConfig(GPUSettingsProcessingDebug, debug, configStandalone.proc, "DEBUG", 0, "Debugging Settings", proc_debug)
309+
AddOption(memoryScalingFuzz, uint64_t, 0, "", 0, "Fuzz the memoryScalingFactor (0 disable, 1 enable, >1 set seed", def(1))
310+
AddOption(mergerMCLabels, bool, false, "", 0, "Create MC labels for merged tracks before refit for debugging")
311+
AddHelp("help", 'h')
312+
EndConfig()
313+
314+
307315
// Settings steering the processing once the device was selected, only available on the host
308316
BeginSubConfig(GPUSettingsProcessing, proc, configStandalone, "PROC", 0, "Processing settings", proc)
309317
AddOption(deviceNum, int32_t, -1, "gpuDevice", 0, "Set GPU device to use (-1: automatic, -2: for round-robin usage in timeslice-pipeline)")
@@ -329,7 +337,6 @@ AddOption(memoryAllocationStrategy, int8_t, 0, "", 0, "Memory Allocation Strageg
329337
AddOption(forceMemoryPoolSize, uint64_t, 1, "memSize", 0, "Force size of allocated GPU / page locked host memory", min(0ul))
330338
AddOption(forceHostMemoryPoolSize, uint64_t, 0, "hostMemSize", 0, "Force size of allocated host page locked host memory (overriding memSize)", min(0ul))
331339
AddOption(memoryScalingFactor, float, 1.f, "", 0, "Factor to apply to all memory scalers")
332-
AddOption(memoryScalingFuzz, uint64_t, 0, "", 0, "Fuzz the memoryScalingFactor (0 disable, 1 enable, >1 set seed", def(1))
333340
AddOption(conservativeMemoryEstimate, bool, false, "", 0, "Use some more conservative defaults for larger buffers during TPC processing")
334341
AddOption(tpcInputWithClusterRejection, uint8_t, 0, "", 0, "Indicate whether the TPC input is CTF data with cluster rejection, to tune buffer estimations")
335342
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")
@@ -377,7 +384,7 @@ AddOption(tpcUseOldCPUDecoding, bool, false, "", 0, "Enable old CPU-based TPC de
377384
AddOption(tpcApplyCFCutsAtDecoding, bool, false, "", 0, "Apply cluster cuts from clusterization during decoding of compressed clusters")
378385
AddOption(tpcApplyClusterFilterOnCPU, uint8_t, 0, "", 0, "Apply custom cluster filter of GPUTPCClusterFilter class, 0: off, 1: debug, 2: PbPb23")
379386
AddOption(tpcWriteClustersAfterRejection, bool, false, "", 0, "Apply TPC rejection strategy before writing clusters")
380-
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))")
387+
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
381388
AddOption(oclCompileFromSources, bool, false, "", 0, "Compile OpenCL binary from included source code instead of using included spirv code")
382389
AddOption(oclOverrideSourceBuildFlags, std::string, "", "", 0, "Override OCL build flags for compilation from source, put a space for empty options")
383390
AddOption(printSettings, bool, false, "", 0, "Print all settings when initializing")
@@ -396,6 +403,7 @@ AddSubConfig(GPUSettingsProcessingRTC, rtc)
396403
AddSubConfig(GPUSettingsProcessingRTCtechnical, rtctech)
397404
AddSubConfig(GPUSettingsProcessingParam, param)
398405
AddSubConfig(GPUSettingsProcessingNNclusterizer, nn)
406+
AddSubConfig(GPUSettingsProcessingDebug, debug)
399407
AddHelp("help", 'h')
400408
EndConfig()
401409
#endif // __OPENCL__

GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ int32_t GPUChainTracking::RunTPCTrackingMerger(bool synchronizeOutput)
170170
runKernel<GPUTPCGlobalDebugSortKernels, GPUTPCGlobalDebugSortKernels::mergedTracks1>({{1, -WarpSize(), 0, deviceType}}, 1);
171171
runKernel<GPUTPCGlobalDebugSortKernels, GPUTPCGlobalDebugSortKernels::mergedTracks2>({{1, -WarpSize(), 0, deviceType}}, 1);
172172
}
173+
if (!doGPU && GetProcessingSettings().debug.mergerMCLabels) {
174+
Merger.CreateMCLabels(1, 1, 0, 0);
175+
}
173176
DoDebugAndDump(RecoStep::TPCMerging, GPUChainTrackingDebugFlags::TPCMergingCollectedTracks, doGPU, Merger, &GPUTPCGMMerger::DumpCollected, *mDebugFile);
174177

175178
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
@@ -113,6 +113,7 @@ class GPUTPCGMMerger : public GPUProcessor
113113

114114
GPUhdi() int32_t NMergedTracks() const { return mMemory->nMergedTracks; }
115115
GPUhdi() const GPUTPCGMMergedTrack* MergedTracks() const { return mMergedTracks; }
116+
GPUhdi() const o2::MCCompLabel* MergedTrackMC() const { return mMergedTrackMC; }
116117
GPUhdi() GPUTPCGMMergedTrack* MergedTracks() { return mMergedTracks; }
117118
GPUhdi() const GPUdEdxInfo* MergedTracksdEdx() const { return mMergedTracksdEdx; }
118119
GPUhdi() GPUdEdxInfo* MergedTracksdEdx() { return mMergedTracksdEdx; }
@@ -204,6 +205,7 @@ class GPUTPCGMMerger : public GPUProcessor
204205
GPUd() void ResolveHitWeights1(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, int32_t iteration);
205206
GPUd() void ResolveHitWeights2(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread);
206207
GPUd() void ResolveHitWeightsShared(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread);
208+
GPUd() void CreateMCLabels(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread);
207209

208210
#ifndef GPUCA_GPUCODE
209211
void DumpSectorTracks(std::ostream& out) const;
@@ -284,6 +286,7 @@ class GPUTPCGMMerger : public GPUProcessor
284286

285287
int32_t mNSectorHits = 0; // Total number of incoming clusters (from sector tracks)
286288
GPUTPCGMMergedTrack* mMergedTracks = nullptr; //* array of output merged tracks
289+
o2::MCCompLabel* mMergedTrackMC = nullptr;
287290
trackCluster* mClusterCandidates = nullptr;
288291
trackRebuildHelper* mTrackRebuildHelper = nullptr;
289292
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"
@@ -40,6 +41,11 @@
4041
#include "AliHLTTPCClusterMCData.h"
4142
#endif
4243

44+
#ifndef GPUCA_GPUCODE
45+
#include "SimulationDataFormat/ConstMCTruthContainer.h"
46+
#include "SimulationDataFormat/MCCompLabel.h"
47+
#endif
48+
4349
#ifndef GPUCA_GPUCODE_DEVICE
4450
#include <cmath>
4551
#include <cstdlib>
@@ -279,6 +285,7 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger& GPUrestrict() merger, int32_
279285
if (param.rec.tpc.rebuildTrackInFit && !rebuilt && !(param.rec.tpc.disableRebuildAttachment & 16) && iWay >= nWays - 3 && CAMath::Abs(mP[2]) < maxSinForUpdate && lastUpdateRow != 255) {
280286
const int32_t up = ((clusters[0].row < clusters[maxN - 1].row) ^ (iWay & 1)) ? 1 : -1;
281287
int32_t sector = lastSector;
288+
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()));
282289
uint8_t rowGapActive = 0, rowGapTotal = 0, missingRowsTotal = 0;
283290
uint8_t lastGoodRow = lastPropagateRow, lastExtrapolateRow = lastPropagateRow;
284291
uint8_t consecGoodRows = param.rec.tpc.rebuildTrackExtrMinConsecGoodRows, consecGoodRowsMissing = 0;
@@ -327,6 +334,12 @@ GPUd() bool GPUTPCGMTrackParam::Fit(GPUTPCGMMerger& GPUrestrict() merger, int32_
327334
auto& candidate = merger.ClusterCandidates()[(iTrk * GPUCA_ROW_COUNT + iRow) * param.rec.tpc.rebuildTrackInFitClusterCandidates + 0];
328335
if (candidate.id >= 2) {
329336
lastExtrapolateRow = iRow;
337+
#if defined(DEBUG_REBUILD_MC) && !defined(GPUCA_GPUCODE)
338+
if (merger.MergedTrackMC() && merger.GetConstantMem()->ioPtrs.clustersNative->clustersMCTruth) {
339+
int32_t labelCorrect = GPUTPCTrkLblSearch(merger.GetConstantMem()->ioPtrs.clustersNative->clustersMCTruth->getLabels(candidate.id - 2), merger.MergedTrackMC()[iTrk]);
340+
CADEBUG(printf("\t%21sLabel correct: %d\n", "", labelCorrect));
341+
}
342+
#endif
330343
float err2Y, err2Z, xx, yy, zz;
331344
const ClusterNative& GPUrestrict() cl = merger.GetConstantMem()->ioPtrs.clustersNative->clustersLinear[candidate.id - 2];
332345
merger.GetConstantMem()->calibObjects.fastTransformHelper->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)