From 7e7880b07be15d70a7e02587ef275dc1cce11831 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Fri, 4 Dec 2026 21:53:41 +0100 Subject: [PATCH 1/5] GPU: Fix incorrect namespace usage --- .../TPCClusterDecompressionCore.inc | 40 +++++++++---------- .../display/helpers/GPUDisplayColors.inc | 34 ++++++++-------- 2 files changed, 35 insertions(+), 39 deletions(-) diff --git a/GPU/GPUTracking/DataCompression/TPCClusterDecompressionCore.inc b/GPU/GPUTracking/DataCompression/TPCClusterDecompressionCore.inc index cf11d8d9ee808..e715bb097b3b1 100644 --- a/GPU/GPUTracking/DataCompression/TPCClusterDecompressionCore.inc +++ b/GPU/GPUTracking/DataCompression/TPCClusterDecompressionCore.inc @@ -9,7 +9,7 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// \file TPCCLusterDecompressionCore.inc +/// \file TPCClusterDecompressionCore.inc /// \author Gabriele Cimador #ifndef TPCCLUSTERDECOMPRESSOR_INC @@ -26,8 +26,6 @@ #include #endif -using namespace o2::tpc; - namespace o2::gpu { @@ -35,36 +33,36 @@ class TPCClusterDecompressionCore { public: #ifndef GPUCA_GPUCODE - GPUhi() static auto decompressTrackStore(const CompressedClusters& clustersCompressed, const uint32_t offset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, std::function func) + GPUhi() static auto decompressTrackStore(const o2::tpc::CompressedClusters& clustersCompressed, const uint32_t offset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, std::function func) { - const auto cluster = ClusterNative(time, clustersCompressed.flagsA[offset], pad, clustersCompressed.sigmaTimeA[offset], clustersCompressed.sigmaPadA[offset], clustersCompressed.qMaxA[offset], clustersCompressed.qTotA[offset]); + const auto cluster = o2::tpc::ClusterNative(time, clustersCompressed.flagsA[offset], pad, clustersCompressed.sigmaTimeA[offset], clustersCompressed.sigmaPadA[offset], clustersCompressed.qMaxA[offset], clustersCompressed.qTotA[offset]); func(cluster, offset); return cluster; } - GPUhi() static const auto& decompressTrackStore(const CompressedClusters& clustersCompressed, const uint32_t offset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, std::vector& clusterVector) + GPUhi() static const auto& decompressTrackStore(const o2::tpc::CompressedClusters& clustersCompressed, const uint32_t offset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, std::vector& clusterVector) { clusterVector.emplace_back(time, clustersCompressed.flagsA[offset], pad, clustersCompressed.sigmaTimeA[offset], clustersCompressed.sigmaPadA[offset], clustersCompressed.qMaxA[offset], clustersCompressed.qTotA[offset]); return clusterVector.back(); } - GPUhi() static auto decompressTrackStore(const CompressedClusters& clustersCompressed, const uint32_t offset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, std::vector (&clusters)[GPUTPCGeometry::NSECTORS][GPUTPCGeometry::NROWS], std::atomic_flag (&locks)[GPUTPCGeometry::NSECTORS][GPUTPCGeometry::NROWS]) + GPUhi() static auto decompressTrackStore(const o2::tpc::CompressedClusters& clustersCompressed, const uint32_t offset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, std::vector (&clusters)[GPUTPCGeometry::NSECTORS][GPUTPCGeometry::NROWS], std::atomic_flag (&locks)[GPUTPCGeometry::NSECTORS][GPUTPCGeometry::NROWS]) { - std::vector& clusterVector = clusters[slice][row]; + std::vector& clusterVector = clusters[slice][row]; auto& lock = locks[slice][row]; while (lock.test_and_set(std::memory_order_acquire)) { } - ClusterNative retVal = decompressTrackStore(clustersCompressed, offset, slice, row, pad, time, clusterVector); + o2::tpc::ClusterNative retVal = decompressTrackStore(clustersCompressed, offset, slice, row, pad, time, clusterVector); lock.clear(std::memory_order_release); return retVal; } #endif - GPUdi() static ClusterNative decompressTrackStore(const CompressedClusters& cmprClusters, const uint32_t clusterOffset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, GPUTPCDecompression& decompressor) + GPUdi() static o2::tpc::ClusterNative decompressTrackStore(const o2::tpc::CompressedClusters& cmprClusters, const uint32_t clusterOffset, uint32_t slice, uint32_t row, uint32_t pad, uint32_t time, GPUTPCDecompression& decompressor) { uint32_t tmpBufferIndex = slice * (GPUTPCGeometry::NROWS * decompressor.mMaxNativeClustersPerBuffer) + row * decompressor.mMaxNativeClustersPerBuffer; uint32_t currentClusterIndex = CAMath::AtomicAdd(decompressor.mNativeClustersIndex + (slice * GPUTPCGeometry::NROWS + row), 1u); - const ClusterNative c(time, cmprClusters.flagsA[clusterOffset], pad, cmprClusters.sigmaTimeA[clusterOffset], cmprClusters.sigmaPadA[clusterOffset], cmprClusters.qMaxA[clusterOffset], cmprClusters.qTotA[clusterOffset]); + const o2::tpc::ClusterNative c(time, cmprClusters.flagsA[clusterOffset], pad, cmprClusters.sigmaTimeA[clusterOffset], cmprClusters.sigmaPadA[clusterOffset], cmprClusters.qMaxA[clusterOffset], cmprClusters.qTotA[clusterOffset]); if (currentClusterIndex < decompressor.mMaxNativeClustersPerBuffer) { decompressor.mTmpNativeClusters[tmpBufferIndex + currentClusterIndex] = c; } else { @@ -75,7 +73,7 @@ class TPCClusterDecompressionCore } template - GPUdi() static void decompressTrack(const CompressedClusters& cmprClusters, const GPUParam& param, const uint32_t maxTime, const uint32_t& trackIndex, uint32_t& clusterOffset, Args&... args) + GPUdi() static void decompressTrack(const o2::tpc::CompressedClusters& cmprClusters, const GPUParam& param, const uint32_t maxTime, const uint32_t& trackIndex, uint32_t& clusterOffset, Args&... args) { float zOffset = 0; uint32_t slice = cmprClusters.sliceA[trackIndex]; @@ -114,16 +112,16 @@ class TPCClusterDecompressionCore if (timeTmp & 0x800000) { timeTmp |= 0xFF000000; } - time = timeTmp + ClusterNative::packTime(CAMath::Max(0.f, geo.LinearZ2Time(slice, track.Z() + zOffset))); + time = timeTmp + o2::tpc::ClusterNative::packTime(CAMath::Max(0.f, geo.LinearZ2Time(slice, track.Z() + zOffset))); float tmpPad = CAMath::Max(0.f, CAMath::Min((float)geo.NPads(GPUTPCGeometry::NROWS - 1), track.LinearY2Pad(slice, track.Y(), geo.PadWidth(row), geo.NPads(row)))); - pad = cmprClusters.padResA[clusterOffset - trackIndex - 1] + ClusterNative::packPad(tmpPad); + pad = cmprClusters.padResA[clusterOffset - trackIndex - 1] + o2::tpc::ClusterNative::packPad(tmpPad); time = time & 0xFFFFFF; pad = (uint16_t)pad; - if (pad >= geo.NPads(row) * ClusterNative::scalePadPacked) { + if (pad >= geo.NPads(row) * o2::tpc::ClusterNative::scalePadPacked) { if (pad >= 0xFFFF - 11968) { // Constant 11968 = (2^15 - MAX_PADS(138) * scalePadPacked(64)) / 2 pad = 0; } else { - pad = geo.NPads(row) * ClusterNative::scalePadPacked - 1; + pad = geo.NPads(row) * o2::tpc::ClusterNative::scalePadPacked - 1; } } if (param.continuousMaxTimeBin > 0 && time >= maxTime) { @@ -152,22 +150,22 @@ class TPCClusterDecompressionCore clusterOffset += cmprClusters.nTrackClusters[trackIndex] - clusterIndex; } - GPUdi() static const auto& decompressHitsStore(const CompressedClusters& cmprClusters, uint32_t k, uint32_t time, uint16_t pad, ClusterNative*& clusterBuffer) + GPUdi() static const auto& decompressHitsStore(const o2::tpc::CompressedClusters& cmprClusters, uint32_t k, uint32_t time, uint16_t pad, o2::tpc::ClusterNative*& clusterBuffer) { - return ((*(clusterBuffer++) = ClusterNative(time, cmprClusters.flagsU[k], pad, cmprClusters.sigmaTimeU[k], cmprClusters.sigmaPadU[k], cmprClusters.qMaxU[k], cmprClusters.qTotU[k]))); + return ((*(clusterBuffer++) = o2::tpc::ClusterNative(time, cmprClusters.flagsU[k], pad, cmprClusters.sigmaTimeU[k], cmprClusters.sigmaPadU[k], cmprClusters.qMaxU[k], cmprClusters.qTotU[k]))); } #ifndef GPUCA_GPUCODE - GPUhi() static auto decompressHitsStore(const CompressedClusters& cmprClusters, uint32_t k, uint32_t time, uint16_t pad, std::function func) + GPUhi() static auto decompressHitsStore(const o2::tpc::CompressedClusters& cmprClusters, uint32_t k, uint32_t time, uint16_t pad, std::function func) { - const auto cluster = ClusterNative(time, cmprClusters.flagsU[k], pad, cmprClusters.sigmaTimeU[k], cmprClusters.sigmaPadU[k], cmprClusters.qMaxU[k], cmprClusters.qTotU[k]); + const auto cluster = o2::tpc::ClusterNative(time, cmprClusters.flagsU[k], pad, cmprClusters.sigmaTimeU[k], cmprClusters.sigmaPadU[k], cmprClusters.qMaxU[k], cmprClusters.qTotU[k]); func(cluster, k); return cluster; } #endif template - GPUdi() static void decompressHits(const CompressedClusters& cmprClusters, const uint32_t start, const uint32_t end, Args&... args) + GPUdi() static void decompressHits(const o2::tpc::CompressedClusters& cmprClusters, const uint32_t start, const uint32_t end, Args&... args) { uint32_t time = 0; uint16_t pad = 0; diff --git a/GPU/GPUTracking/display/helpers/GPUDisplayColors.inc b/GPU/GPUTracking/display/helpers/GPUDisplayColors.inc index e9ab881e4f369..1b9baf8b4375b 100644 --- a/GPU/GPUTracking/display/helpers/GPUDisplayColors.inc +++ b/GPU/GPUTracking/display/helpers/GPUDisplayColors.inc @@ -14,14 +14,12 @@ #include "GPUDisplay.h" -using namespace o2::gpu; - -inline void GPUDisplay::ActivateColor() +inline void o2::gpu::GPUDisplay::ActivateColor() { mBackend->ActivateColor(mDrawColor); } -inline void GPUDisplay::SetColorClusters() +inline void o2::gpu::GPUDisplay::SetColorClusters() { if (mCfgL.colorCollisions) { return; @@ -33,7 +31,7 @@ inline void GPUDisplay::SetColorClusters() } ActivateColor(); } -inline void GPUDisplay::SetColorTRD() +inline void o2::gpu::GPUDisplay::SetColorTRD() { if (mCfgL.colorCollisions) { return; @@ -45,7 +43,7 @@ inline void GPUDisplay::SetColorTRD() } ActivateColor(); } -inline void GPUDisplay::SetColorITS() +inline void o2::gpu::GPUDisplay::SetColorITS() { if (mCfgL.colorCollisions) { return; @@ -57,7 +55,7 @@ inline void GPUDisplay::SetColorITS() } ActivateColor(); } -inline void GPUDisplay::SetColorTOF() +inline void o2::gpu::GPUDisplay::SetColorTOF() { if (mCfgL.colorCollisions) { return; @@ -69,7 +67,7 @@ inline void GPUDisplay::SetColorTOF() } ActivateColor(); } -inline void GPUDisplay::SetColorInitLinks() +inline void o2::gpu::GPUDisplay::SetColorInitLinks() { if (mCfgL.invertColors) { mDrawColor = {0.42, 0.4, 0.1, 1.f}; @@ -78,7 +76,7 @@ inline void GPUDisplay::SetColorInitLinks() } ActivateColor(); } -inline void GPUDisplay::SetColorLinks() +inline void o2::gpu::GPUDisplay::SetColorLinks() { if (mCfgL.invertColors) { mDrawColor = {0.6, 0.1, 0.1, 1.f}; @@ -87,7 +85,7 @@ inline void GPUDisplay::SetColorLinks() } ActivateColor(); } -inline void GPUDisplay::SetColorSeeds() +inline void o2::gpu::GPUDisplay::SetColorSeeds() { if (mCfgL.invertColors) { mDrawColor = {0.6, 0.0, 0.65, 1.f}; @@ -96,7 +94,7 @@ inline void GPUDisplay::SetColorSeeds() } ActivateColor(); } -inline void GPUDisplay::SetColorTracklets() +inline void o2::gpu::GPUDisplay::SetColorTracklets() { if (mCfgL.invertColors) { mDrawColor = {0, 0, 0, 1.f}; @@ -105,7 +103,7 @@ inline void GPUDisplay::SetColorTracklets() } ActivateColor(); } -inline void GPUDisplay::SetColorTracks() +inline void o2::gpu::GPUDisplay::SetColorTracks() { if (mCfgL.invertColors) { mDrawColor = {0.6, 0, 0.1, 1.f}; @@ -114,7 +112,7 @@ inline void GPUDisplay::SetColorTracks() } ActivateColor(); } -inline void GPUDisplay::SetColorExtrapolatedTracks() +inline void o2::gpu::GPUDisplay::SetColorExtrapolatedTracks() { if (mCfgL.invertColors) { mDrawColor = {0.8, 0.2, 0, 1.f}; @@ -123,7 +121,7 @@ inline void GPUDisplay::SetColorExtrapolatedTracks() } ActivateColor(); } -inline void GPUDisplay::SetColorFinal() +inline void o2::gpu::GPUDisplay::SetColorFinal() { if (mCfgL.colorCollisions) { return; @@ -135,7 +133,7 @@ inline void GPUDisplay::SetColorFinal() } ActivateColor(); } -inline void GPUDisplay::SetColorGrid() +inline void o2::gpu::GPUDisplay::SetColorGrid() { if (mCfgL.invertColors) { mDrawColor = {0.5, 0.5, 0.0, 1.f}; @@ -144,7 +142,7 @@ inline void GPUDisplay::SetColorGrid() } ActivateColor(); } -inline void GPUDisplay::SetColorGridTRD() +inline void o2::gpu::GPUDisplay::SetColorGridTRD() { if (mCfgL.invertColors) { mDrawColor = {0.5, 0.5, 0.5, 1.f}; @@ -153,7 +151,7 @@ inline void GPUDisplay::SetColorGridTRD() } ActivateColor(); } -inline void GPUDisplay::SetColorMarked() +inline void o2::gpu::GPUDisplay::SetColorMarked() { if (mCfgL.invertColors) { mDrawColor = {0.8, 0, 0, 1.f}; @@ -162,7 +160,7 @@ inline void GPUDisplay::SetColorMarked() } ActivateColor(); } -inline void GPUDisplay::SetCollisionColor(int32_t col) +inline void o2::gpu::GPUDisplay::SetCollisionColor(int32_t col) { int32_t red = (col * 2) % 5; int32_t blue = (2 + col * 3) % 7; From 6308b19823c4a6240f67bb8ae14ee22b29806713 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Fri, 4 Dec 2026 23:47:15 +0100 Subject: [PATCH 2/5] GPU: Simplify TPCClusterDecompressor --- .../Detectors/TPC/src/CompressedClusters.cxx | 16 ++++--- .../GPUTPCClusterStatistics.cxx | 2 +- .../TPCClusterDecompressor.cxx | 43 +++++++------------ .../DataCompression/TPCClusterDecompressor.h | 3 +- .../Global/GPUChainTrackingCompression.cxx | 2 +- 5 files changed, 28 insertions(+), 38 deletions(-) diff --git a/DataFormats/Detectors/TPC/src/CompressedClusters.cxx b/DataFormats/Detectors/TPC/src/CompressedClusters.cxx index 400eed3848c64..10855108b97cb 100644 --- a/DataFormats/Detectors/TPC/src/CompressedClusters.cxx +++ b/DataFormats/Detectors/TPC/src/CompressedClusters.cxx @@ -27,12 +27,16 @@ namespace o2::tpc CompressedClusters::CompressedClusters(const CompressedClustersFlat& c) { - CompressedClustersCounters& cc = *this; - CompressedClustersPtrs& cp = *this; - const CompressedClustersOffsets& offsets = c; - cc = c; - for (unsigned int i = 0; i < sizeof(cp) / sizeof(size_t); i++) { - reinterpret_cast(&cp)[i] = reinterpret_cast(reinterpret_cast(&offsets)[i] + reinterpret_cast(&c)); // Restore pointers from offsets + if (c.ptrForward) { + *this = *c.ptrForward; + } else { + CompressedClustersCounters& cc = *this; + CompressedClustersPtrs& cp = *this; + const CompressedClustersOffsets& offsets = c; + cc = c; + for (unsigned int i = 0; i < sizeof(cp) / sizeof(size_t); i++) { + reinterpret_cast(&cp)[i] = reinterpret_cast(reinterpret_cast(&offsets)[i] + reinterpret_cast(&c)); // Restore pointers from offsets + } } }; diff --git a/GPU/GPUTracking/DataCompression/GPUTPCClusterStatistics.cxx b/GPU/GPUTracking/DataCompression/GPUTPCClusterStatistics.cxx index 1cc7d0403879c..4ec1fb15aac51 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCClusterStatistics.cxx +++ b/GPU/GPUTracking/DataCompression/GPUTPCClusterStatistics.cxx @@ -114,7 +114,7 @@ void GPUTPCClusterStatistics::RunStatistics(const o2::tpc::ClusterNativeAccess* std::vector clusterBuffer; GPUInfo("Compression statistics, decoding: %d attached (%d tracks), %d unattached", clustersCompressed->nAttachedClusters, clustersCompressed->nTracks, clustersCompressed->nUnattachedClusters); auto allocator = [&clusterBuffer](size_t size) {clusterBuffer.resize(size); return clusterBuffer.data(); }; - mDecoder.decompress(clustersCompressed, clustersNativeDecoded, allocator, param, true); + mDecoder.decompress(*clustersCompressed, clustersNativeDecoded, allocator, param, true); std::vector tmpClusters; if (param.rec.tpc.rejectionStrategy == GPUSettings::RejectionNone) { // verification does not make sense if we reject clusters during compression for (uint32_t i = 0; i < NSECTORS; i++) { diff --git a/GPU/GPUTracking/DataCompression/TPCClusterDecompressor.cxx b/GPU/GPUTracking/DataCompression/TPCClusterDecompressor.cxx index 528b4b3b902b9..1f414fbcbf664 100644 --- a/GPU/GPUTracking/DataCompression/TPCClusterDecompressor.cxx +++ b/GPU/GPUTracking/DataCompression/TPCClusterDecompressor.cxx @@ -28,26 +28,13 @@ using namespace o2::gpu; using namespace o2::tpc; -int32_t TPCClusterDecompressor::decompress(const CompressedClustersFlat* clustersCompressed, o2::tpc::ClusterNativeAccess& clustersNative, const std::function& allocator, const GPUParam& param, bool deterministicRec) +int32_t TPCClusterDecompressor::decompress(const CompressedClusters& clustersCompressed, o2::tpc::ClusterNativeAccess& clustersNative, const std::function& allocator, const GPUParam& param, bool deterministicRec) { - CompressedClusters c; - const CompressedClusters* p; - if (clustersCompressed->ptrForward) { - p = clustersCompressed->ptrForward; - } else { - c = *clustersCompressed; - p = &c; + if (clustersCompressed.nTracks && clustersCompressed.solenoidBz != -1e6f && clustersCompressed.solenoidBz != param.bzkG) { + throw std::runtime_error(std::format("Configured solenoid Bz {:f} does not match value used for track model encoding {:f}", param.bzkG, clustersCompressed.solenoidBz)); } - return decompress(p, clustersNative, allocator, param, deterministicRec); -} - -int32_t TPCClusterDecompressor::decompress(const CompressedClusters* clustersCompressed, o2::tpc::ClusterNativeAccess& clustersNative, const std::function& allocator, const GPUParam& param, bool deterministicRec) -{ - if (clustersCompressed->nTracks && clustersCompressed->solenoidBz != -1e6f && clustersCompressed->solenoidBz != param.bzkG) { - throw std::runtime_error(std::format("Configured solenoid Bz {:f} does not match value used for track model encoding {:f}", param.bzkG, clustersCompressed->solenoidBz)); - } - if (clustersCompressed->nTracks && clustersCompressed->maxTimeBin != -1e6 && clustersCompressed->maxTimeBin != param.continuousMaxTimeBin) { - throw std::runtime_error(std::format("Configured max time bin {} does not match value used for track model encoding {}", param.continuousMaxTimeBin, clustersCompressed->maxTimeBin)); + if (clustersCompressed.nTracks && clustersCompressed.maxTimeBin != -1e6 && clustersCompressed.maxTimeBin != param.continuousMaxTimeBin) { + throw std::runtime_error(std::format("Configured max time bin {} does not match value used for track model encoding {}", param.continuousMaxTimeBin, clustersCompressed.maxTimeBin)); } std::vector clusters[NSECTORS][GPUTPCGeometry::NROWS]; std::atomic_flag locks[NSECTORS][GPUTPCGeometry::NROWS]; @@ -55,34 +42,34 @@ int32_t TPCClusterDecompressor::decompress(const CompressedClusters* clustersCom (&locks[0][0])[i].clear(); } const uint32_t maxTime = param.continuousMaxTimeBin > 0 ? ((param.continuousMaxTimeBin + 1) * ClusterNative::scaleTimePacked - 1) : constants::TPC_MAX_TIME_BIN_TRIGGERED; - tbb::parallel_for(tbb::blocked_range(0, clustersCompressed->nTracks), [&](const tbb::blocked_range& range) { + tbb::parallel_for(tbb::blocked_range(0, clustersCompressed.nTracks), [&](const tbb::blocked_range& range) { uint32_t offset = 0, lasti = 0; for (uint32_t i = range.begin(); i < range.end(); i++) { if (i < lasti) { offset = lasti = 0; // dynamic scheduling order, need to reinitialize offset } while (lasti < i) { - offset += clustersCompressed->nTrackClusters[lasti++]; + offset += clustersCompressed.nTrackClusters[lasti++]; } lasti++; - TPCClusterDecompressionCore::decompressTrack(*clustersCompressed, param, maxTime, i, offset, clusters, locks); + TPCClusterDecompressionCore::decompressTrack(clustersCompressed, param, maxTime, i, offset, clusters, locks); } }); - size_t nTotalClusters = clustersCompressed->nAttachedClusters + clustersCompressed->nUnattachedClusters; + size_t nTotalClusters = clustersCompressed.nAttachedClusters + clustersCompressed.nUnattachedClusters; ClusterNative* clusterBuffer = allocator(nTotalClusters); uint32_t offsets[NSECTORS][GPUTPCGeometry::NROWS]; uint32_t offset = 0; uint32_t decodedAttachedClusters = 0; for (uint32_t i = 0; i < NSECTORS; i++) { for (uint32_t j = 0; j < GPUTPCGeometry::NROWS; j++) { - clustersNative.nClusters[i][j] = clusters[i][j].size() + ((i * GPUTPCGeometry::NROWS + j >= clustersCompressed->nSliceRows) ? 0 : clustersCompressed->nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]); + clustersNative.nClusters[i][j] = clusters[i][j].size() + ((i * GPUTPCGeometry::NROWS + j >= clustersCompressed.nSliceRows) ? 0 : clustersCompressed.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]); offsets[i][j] = offset; - offset += (i * GPUTPCGeometry::NROWS + j >= clustersCompressed->nSliceRows) ? 0 : clustersCompressed->nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]; + offset += (i * GPUTPCGeometry::NROWS + j >= clustersCompressed.nSliceRows) ? 0 : clustersCompressed.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]; decodedAttachedClusters += clusters[i][j].size(); } } - if (decodedAttachedClusters != clustersCompressed->nAttachedClusters) { - GPUWarning("%u / %u clusters failed track model decoding (%f %%)", clustersCompressed->nAttachedClusters - decodedAttachedClusters, clustersCompressed->nAttachedClusters, 100.f * (float)(clustersCompressed->nAttachedClusters - decodedAttachedClusters) / (float)clustersCompressed->nAttachedClusters); + if (decodedAttachedClusters != clustersCompressed.nAttachedClusters) { + GPUWarning("%u / %u clusters failed track model decoding (%f %%)", clustersCompressed.nAttachedClusters - decodedAttachedClusters, clustersCompressed.nAttachedClusters, 100.f * (float)(clustersCompressed.nAttachedClusters - decodedAttachedClusters) / (float)clustersCompressed.nAttachedClusters); } clustersNative.clustersLinear = clusterBuffer; clustersNative.setOffsetPtrs(); @@ -93,8 +80,8 @@ int32_t TPCClusterDecompressor::decompress(const CompressedClusters* clustersCom memcpy((void*)buffer, (const void*)clusters[i][j].data(), clusters[i][j].size() * sizeof(clusterBuffer[0])); } ClusterNative* clout = buffer + clusters[i][j].size(); - uint32_t end = offsets[i][j] + ((i * GPUTPCGeometry::NROWS + j >= clustersCompressed->nSliceRows) ? 0 : clustersCompressed->nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]); - TPCClusterDecompressionCore::decompressHits(*clustersCompressed, offsets[i][j], end, clout); + uint32_t end = offsets[i][j] + ((i * GPUTPCGeometry::NROWS + j >= clustersCompressed.nSliceRows) ? 0 : clustersCompressed.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]); + TPCClusterDecompressionCore::decompressHits(clustersCompressed, offsets[i][j], end, clout); if (param.rec.tpc.clustersEdgeFixDistance > 0.f) { constexpr GPUTPCGeometry geo; for (uint32_t k = 0; k < clustersNative.nClusters[i][j]; k++) { diff --git a/GPU/GPUTracking/DataCompression/TPCClusterDecompressor.h b/GPU/GPUTracking/DataCompression/TPCClusterDecompressor.h index 47c235d3567cb..14dd1c123607c 100644 --- a/GPU/GPUTracking/DataCompression/TPCClusterDecompressor.h +++ b/GPU/GPUTracking/DataCompression/TPCClusterDecompressor.h @@ -33,8 +33,7 @@ class TPCClusterDecompressor { public: static constexpr uint32_t NSECTORS = GPUTPCGeometry::NSECTORS; - static int32_t decompress(const o2::tpc::CompressedClustersFlat* clustersCompressed, o2::tpc::ClusterNativeAccess& clustersNative, const std::function& allocator, const GPUParam& param, bool deterministicRec); - static int32_t decompress(const o2::tpc::CompressedClusters* clustersCompressed, o2::tpc::ClusterNativeAccess& clustersNative, const std::function& allocator, const GPUParam& param, bool deterministicRec); + static int32_t decompress(const o2::tpc::CompressedClusters& clustersCompressed, o2::tpc::ClusterNativeAccess& clustersNative, const std::function& allocator, const GPUParam& param, bool deterministicRec); }; } // namespace o2::gpu diff --git a/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx b/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx index 9d77b66845f87..f3a326dc44bc7 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx @@ -255,7 +255,7 @@ int32_t GPUChainTracking::RunTPCDecompression() auto& decompressTimer = getTimer("TPCDecompression", 0); auto allocatorUse = runFiltering ? std::function{allocatorTmp} : std::function{allocatorFinal}; decompressTimer.Start(); - if (decomp.decompress(mIOPtrs.tpcCompressedClusters, *mClusterNativeAccess, allocatorUse, param(), GetProcessingSettings().deterministicGPUReconstruction || GetProcessingSettings().debugLevel >= 4 || GetProcessingSettings().tpcSortClusters)) { + if (decomp.decompress(*mIOPtrs.tpcCompressedClusters, *mClusterNativeAccess, allocatorUse, param(), GetProcessingSettings().deterministicGPUReconstruction || GetProcessingSettings().debugLevel >= 4 || GetProcessingSettings().tpcSortClusters)) { GPUError("Error decompressing clusters"); return 1; } From 6496c8f746610a0919a70092735a64ca1b8f2ee8 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Fri, 4 Dec 2026 21:54:48 +0100 Subject: [PATCH 3/5] GPU / TPC: Move TPC CTF filtering into a header function to be used in multiple places --- .../TPC/workflow/src/EntropyEncoderSpec.cxx | 127 +------------- GPU/GPUTracking/CMakeLists.txt | 1 + .../GPUTPCCompressionKernels.inc | 4 +- .../TPCClusterDecompressionCore.inc | 2 + .../TPCClusterDecompressionFilter.inc | 164 ++++++++++++++++++ GPU/GPUTracking/Global/GPUChainTracking.h | 7 + .../Global/GPUChainTrackingCompression.cxx | 3 +- .../GPUChainTrackingDebugAndProfiling.cxx | 21 +++ GPU/GPUTracking/Merger/GPUTPCGMPropagator.inc | 2 +- 9 files changed, 204 insertions(+), 127 deletions(-) create mode 100644 GPU/GPUTracking/DataCompression/TPCClusterDecompressionFilter.inc diff --git a/Detectors/TPC/workflow/src/EntropyEncoderSpec.cxx b/Detectors/TPC/workflow/src/EntropyEncoderSpec.cxx index 4de5665f1b9a0..6277146d18678 100644 --- a/Detectors/TPC/workflow/src/EntropyEncoderSpec.cxx +++ b/Detectors/TPC/workflow/src/EntropyEncoderSpec.cxx @@ -25,8 +25,7 @@ #include "GPUO2InterfaceUtils.h" #include "GPUParam.h" #include "DataFormatsTPC/ClusterNative.h" -#include "TPCClusterDecompressionCore.inc" -#include "GPUTPCCompressionKernels.inc" +#include "TPCClusterDecompressionFilter.inc" #include "TPCCalibration/VDriftHelper.h" #include "DetectorsBase/GRPGeomHelper.h" @@ -127,7 +126,7 @@ void EntropyEncoderSpec::run(ProcessingContext& pc) auto& buffer = pc.outputs().make>(Output{"TPC", "CTFDATA", 0}); std::vector rejectHits, rejectTracks, rejectTrackHits, rejectTrackHitsReduced; CompressedClusters clustersFiltered = clusters; - std::vector, std::vector>> tmpBuffer(std::max(mNThreads, 1)); + std::vector, std::vector>> tmpBuffer; // prepare trigger info trigComp.clear(); @@ -144,128 +143,10 @@ void EntropyEncoderSpec::run(ProcessingContext& pc) } if (mSelIR) { - if (clusters.nTracks && clusters.solenoidBz != -1e6f && clusters.solenoidBz != mParam->bzkG) { - throw std::runtime_error("Configured solenoid Bz does not match value used for track model encoding"); - } - if (clusters.nTracks && clusters.maxTimeBin != -1e6 && clusters.maxTimeBin != mParam->continuousMaxTimeBin) { - throw std::runtime_error("Configured max time bin does not match value used for track model encoding"); - } mCTFCoder.setSelectedIRFrames(pc.inputs().get>("selIRFrames")); - rejectHits.resize(clusters.nUnattachedClusters); - rejectTracks.resize(clusters.nTracks); - rejectTrackHits.resize(clusters.nAttachedClusters); - rejectTrackHitsReduced.resize(clusters.nAttachedClustersReduced); - + auto chkFunc = [&](const o2::InteractionRecord& chkVal, float chkExt) { return mCTFCoder.getIRFramesSelector().check(o2::dataformats::IRFrame(chkVal, chkVal + 1), chkExt, 0) < 0; }; const auto& tinfo = pc.services().get(); - const auto firstIR = o2::InteractionRecord(0, tinfo.firstTForbit); - const float totalT = std::max(mFastTransform->getMaxDriftTime(0), mFastTransform->getMaxDriftTime(GPUTPCGeometry::NSECTORS / 2)); - - unsigned int offset = 0, lasti = 0; - const unsigned int maxTime = (mParam->continuousMaxTimeBin + 1) * o2::tpc::ClusterNative::scaleTimePacked - 1; -#ifdef WITH_OPENMP -#pragma omp parallel for firstprivate(offset, lasti) num_threads(mNThreads) -#endif - for (unsigned int i = 0; i < clusters.nTracks; i++) { - unsigned int tMinP = maxTime, tMaxP = 0; - auto checker = [&tMinP, &tMaxP](const o2::tpc::ClusterNative& cl, unsigned int offset) { - if (cl.getTimePacked() > tMaxP) { - tMaxP = cl.getTimePacked(); - } - if (cl.getTimePacked() < tMinP) { - tMinP = cl.getTimePacked(); - } - }; - if (i < lasti) { - offset = lasti = 0; // dynamic OMP scheduling, need to reinitialize offset - } - while (lasti < i) { - offset += clusters.nTrackClusters[lasti++]; - } - lasti++; - o2::gpu::TPCClusterDecompressionCore::decompressTrack(clusters, *mParam, maxTime, i, offset, checker); - const float tMin = o2::tpc::ClusterNative::unpackTime(tMinP), tMax = o2::tpc::ClusterNative::unpackTime(tMaxP); - const auto chkVal = firstIR + (tMin * constants::LHCBCPERTIMEBIN); - const auto chkExt = totalT > tMax - tMin ? ((totalT - (tMax - tMin)) * constants::LHCBCPERTIMEBIN + 1) : 0; - const bool reject = mCTFCoder.getIRFramesSelector().check(o2::dataformats::IRFrame(chkVal, chkVal + 1), chkExt, 0) < 0; - if (reject) { - for (unsigned int k = offset - clusters.nTrackClusters[i]; k < offset; k++) { - rejectTrackHits[k] = true; - } - for (unsigned int k = offset - clusters.nTrackClusters[i] - i; k < offset - i - 1; k++) { - rejectTrackHitsReduced[k] = true; - } - rejectTracks[i] = true; - static std::atomic_flag lock = ATOMIC_FLAG_INIT; - while (lock.test_and_set(std::memory_order_acquire)) { - } - clustersFiltered.nTracks--; - clustersFiltered.nAttachedClusters -= clusters.nTrackClusters[i]; - clustersFiltered.nAttachedClustersReduced -= clusters.nTrackClusters[i] - 1; - lock.clear(std::memory_order_release); - } - } - offset = 0; - unsigned int offsets[GPUTPCGeometry::NSECTORS][GPUTPCGeometry::NROWS]; - for (unsigned int i = 0; i < GPUTPCGeometry::NSECTORS; i++) { - for (unsigned int j = 0; j < GPUTPCGeometry::NROWS; j++) { - if (i * GPUTPCGeometry::NROWS + j >= clusters.nSliceRows) { - break; - } - offsets[i][j] = offset; - offset += (i * GPUTPCGeometry::NROWS + j >= clusters.nSliceRows) ? 0 : clusters.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]; - } - } - -#ifdef WITH_OPENMP -#pragma omp parallel for num_threads(mNThreads) schedule(static, (GPUTPCGeometry::NSECTORS + mNThreads - 1) / mNThreads) // Static round-robin scheduling with one chunk per thread to ensure correct order of the final vector -#endif - for (unsigned int ii = 0; ii < clusters.nSliceRows; ii++) { - unsigned int i = ii / GPUTPCGeometry::NROWS; - unsigned int j = ii % GPUTPCGeometry::NROWS; - o2::tpc::ClusterNative preCl; -#ifdef WITH_OPENMP - int myThread = omp_get_thread_num(); -#else - int myThread = 0; -#endif - unsigned int count = 0; - const float x = GPUTPCGeometry::Row2X(j); - auto checker = [i, j, firstIR, totalT, x, this, &preCl, &count, &outBuffer = tmpBuffer[myThread], &rejectHits, &clustersFiltered](const o2::tpc::ClusterNative& cl, unsigned int k) { - const float y = GPUTPCGeometry::LinearPad2Y(i, j, cl.getPad()); - const float r = sqrtf(x * x + y * y); - const float maxz = r * mEtaFactor + mMaxZ; - const unsigned int deltaBC = std::max(0.f, totalT - mFastTransform->convDeltaZtoDeltaTimeInTimeFrameAbs(maxz)) * constants::LHCBCPERTIMEBIN; - const auto chkVal = firstIR + (cl.getTime() * constants::LHCBCPERTIMEBIN) - deltaBC; - const auto chkExt = totalT * constants::LHCBCPERTIMEBIN - deltaBC; - const bool reject = mCTFCoder.getIRFramesSelector().check(o2::dataformats::IRFrame(chkVal, chkVal + 1), chkExt, 0) < 0; - if (reject) { - rejectHits[k] = true; - clustersFiltered.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]--; - static std::atomic_flag lock = ATOMIC_FLAG_INIT; - while (lock.test_and_set(std::memory_order_acquire)) { - } - clustersFiltered.nUnattachedClusters--; - lock.clear(std::memory_order_release); - } else { - outBuffer.first.emplace_back(0); - outBuffer.second.emplace_back(0); - GPUTPCCompression_EncodeUnattached(clustersFiltered.nComppressionModes, cl, outBuffer.first.back(), outBuffer.second.back(), count++ ? &preCl : nullptr); - preCl = cl; - } - }; - unsigned int end = offsets[i][j] + clusters.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]; - o2::gpu::TPCClusterDecompressionCore::decompressHits(clusters, offsets[i][j], end, checker); - } - tmpBuffer[0].first.reserve(clustersFiltered.nUnattachedClusters); - tmpBuffer[0].second.reserve(clustersFiltered.nUnattachedClusters); - for (int i = 1; i < mNThreads; i++) { - tmpBuffer[0].first.insert(tmpBuffer[0].first.end(), tmpBuffer[i].first.begin(), tmpBuffer[i].first.end()); - tmpBuffer[i].first.clear(); - tmpBuffer[0].second.insert(tmpBuffer[0].second.end(), tmpBuffer[i].second.begin(), tmpBuffer[i].second.end()); - tmpBuffer[i].second.clear(); - } - clustersFiltered.timeDiffU = tmpBuffer[0].first.data(); - clustersFiltered.padDiffU = tmpBuffer[0].second.data(); + o2::gpu::TPCClusterDecompressionFilter::runFilter(*mParam, *mFastTransform, clusters, clustersFiltered, rejectHits, rejectTracks, rejectTrackHits, rejectTrackHitsReduced, tmpBuffer, mNThreads, tinfo.firstTForbit, chkFunc, mEtaFactor, mMaxZ); } // transform trigger info to differential form diff --git a/GPU/GPUTracking/CMakeLists.txt b/GPU/GPUTracking/CMakeLists.txt index 874493f5c3f27..d2f4c6a421ac2 100644 --- a/GPU/GPUTracking/CMakeLists.txt +++ b/GPU/GPUTracking/CMakeLists.txt @@ -135,6 +135,7 @@ set(HDRS_INSTALL DataCompression/GPUTPCClusterRejection.h DataCompression/GPUTPCCompressionKernels.inc DataCompression/TPCClusterDecompressionCore.inc + DataCompression/TPCClusterDecompressionFilter.inc DataTypes/GPUdEdxInfo.h DataTypes/GPUHostDataTypes.h DataTypes/GPUO2DataTypes.h diff --git a/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.inc b/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.inc index 3a644925bdd37..d900759c0cfe1 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.inc +++ b/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.inc @@ -9,7 +9,7 @@ // granted to it by virtue of its status as an Intergovernmental Organization // or submit itself to any jurisdiction. -/// \file GPUTPCCompressionKernels.cxx +/// \file GPUTPCCompressionKernels.inc /// \author David Rohr #include "GPUO2DataTypes.h" @@ -20,7 +20,7 @@ namespace o2::gpu { -GPUdii() void GPUTPCCompression_EncodeUnattached(uint8_t nComppressionModes, const o2::tpc::ClusterNative& orgCl, uint32_t& outTime, uint16_t& outPad, const o2::tpc::ClusterNative* orgClPre = nullptr) +GPUdi() GPUAlwaysInline() void GPUTPCCompression_EncodeUnattached(uint8_t nComppressionModes, const o2::tpc::ClusterNative& orgCl, uint32_t& outTime, uint16_t& outPad, const o2::tpc::ClusterNative* orgClPre = nullptr) { if (nComppressionModes & GPUSettings::CompressionDifferences) { uint32_t lastTime = 0, lastPad = 0; diff --git a/GPU/GPUTracking/DataCompression/TPCClusterDecompressionCore.inc b/GPU/GPUTracking/DataCompression/TPCClusterDecompressionCore.inc index e715bb097b3b1..b05a372364f0f 100644 --- a/GPU/GPUTracking/DataCompression/TPCClusterDecompressionCore.inc +++ b/GPU/GPUTracking/DataCompression/TPCClusterDecompressionCore.inc @@ -21,6 +21,8 @@ #include "GPUCommonAlgorithm.h" #include "GPUO2DataTypes.h" #include "GPUTPCGeometry.h" +#include "DataFormatsTPC/ClusterNative.h" +#include "DataFormatsTPC/CompressedClusters.h" #ifndef GPUCA_GPUCODE #include diff --git a/GPU/GPUTracking/DataCompression/TPCClusterDecompressionFilter.inc b/GPU/GPUTracking/DataCompression/TPCClusterDecompressionFilter.inc new file mode 100644 index 0000000000000..f73826ea34de5 --- /dev/null +++ b/GPU/GPUTracking/DataCompression/TPCClusterDecompressionFilter.inc @@ -0,0 +1,164 @@ +// Copyright 2024-2025 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// \file TPCClusterDecompressionFilter.inc +/// \author David Rohr + +#ifndef TPCCLUSTERDECOMPRESSION_FILTER_INC +#define TPCCLUSTERDECOMPRESSION_FILTER_INC + +#include "TPCClusterDecompressionCore.inc" +#include "GPUTPCCompressionKernels.inc" +#include "CommonDataFormat/InteractionRecord.h" +#include +#include +#include +#include +#include +#include +#ifdef WITH_OPENMP +#include +#endif + +namespace o2::gpu +{ + +struct TPCClusterDecompressionFilter { + template + static inline void runFilter(const GPUParam& param, const T& fastTransform, const o2::tpc::CompressedClusters& clusters, o2::tpc::CompressedClusters& clustersFiltered, std::vector& rejectHits, std::vector& rejectTracks, std::vector& rejectTrackHits, std::vector& rejectTrackHitsReduced, + std::vector, std::vector>>& tmpBuffer, int32_t nThreads, uint32_t firstTForbit, F&& chkFunc, float etaFactor, float maxZ) + { + tmpBuffer.resize(std::max(nThreads, 1)); + if (clusters.nTracks && clusters.solenoidBz != -1e6f && clusters.solenoidBz != param.bzkG) { + throw std::runtime_error("Configured solenoid Bz does not match value used for track model encoding"); + } + if (clusters.nTracks && clusters.maxTimeBin != -1e6 && clusters.maxTimeBin != param.continuousMaxTimeBin) { + throw std::runtime_error("Configured max time bin does not match value used for track model encoding"); + } + rejectHits.resize(clusters.nUnattachedClusters); + rejectTracks.resize(clusters.nTracks); + rejectTrackHits.resize(clusters.nAttachedClusters); + rejectTrackHitsReduced.resize(clusters.nAttachedClustersReduced); + + const auto firstIR = o2::InteractionRecord(0, firstTForbit); + const float totalT = std::max(fastTransform.getMaxDriftTime(0), fastTransform.getMaxDriftTime(GPUTPCGeometry::NSECTORS / 2)); + + uint32_t offset = 0, lasti = 0; + const uint32_t maxTime = (param.continuousMaxTimeBin + 1) * o2::tpc::ClusterNative::scaleTimePacked - 1; +#ifdef WITH_OPENMP +#pragma omp parallel for firstprivate(offset, lasti) num_threads(nThreads) +#endif + for (uint32_t i = 0; i < clusters.nTracks; i++) { + uint32_t tMinP = maxTime, tMaxP = 0; + auto checker = [&tMinP, &tMaxP](const o2::tpc::ClusterNative& cl, uint32_t off) { + if (cl.getTimePacked() > tMaxP) { + tMaxP = cl.getTimePacked(); + } + if (cl.getTimePacked() < tMinP) { + tMinP = cl.getTimePacked(); + } + }; + if (i < lasti) { + offset = lasti = 0; // dynamic OMP scheduling, need to reinitialize offset + } + while (lasti < i) { + offset += clusters.nTrackClusters[lasti++]; + } + lasti++; + o2::gpu::TPCClusterDecompressionCore::decompressTrack(clusters, param, maxTime, i, offset, checker); + const float tMin = o2::tpc::ClusterNative::unpackTime(tMinP), tMax = o2::tpc::ClusterNative::unpackTime(tMaxP); + const auto chkVal = firstIR + (tMin * o2::tpc::constants::LHCBCPERTIMEBIN); + const auto chkExt = totalT > tMax - tMin ? ((totalT - (tMax - tMin)) * o2::tpc::constants::LHCBCPERTIMEBIN + 1) : 0; + const bool reject = chkFunc(chkVal, chkExt); + if (reject) { + for (uint32_t k = offset - clusters.nTrackClusters[i]; k < offset; k++) { + rejectTrackHits[k] = true; + } + for (uint32_t k = offset - clusters.nTrackClusters[i] - i; k < offset - i - 1; k++) { + rejectTrackHitsReduced[k] = true; + } + rejectTracks[i] = true; + static std::atomic_flag lock = ATOMIC_FLAG_INIT; + while (lock.test_and_set(std::memory_order_acquire)) { + } + clustersFiltered.nTracks--; + clustersFiltered.nAttachedClusters -= clusters.nTrackClusters[i]; + clustersFiltered.nAttachedClustersReduced -= clusters.nTrackClusters[i] - 1; + lock.clear(std::memory_order_release); + } + } + offset = 0; + uint32_t offsets[GPUTPCGeometry::NSECTORS][GPUTPCGeometry::NROWS]; + for (uint32_t i = 0; i < GPUTPCGeometry::NSECTORS; i++) { + for (uint32_t j = 0; j < GPUTPCGeometry::NROWS; j++) { + if (i * GPUTPCGeometry::NROWS + j >= clusters.nSliceRows) { + break; + } + offsets[i][j] = offset; + offset += (i * GPUTPCGeometry::NROWS + j >= clusters.nSliceRows) ? 0 : clusters.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]; + } + } + +#ifdef WITH_OPENMP +#pragma omp parallel for num_threads(nThreads) schedule(static, (GPUTPCGeometry::NSECTORS + nThreads - 1) / nThreads) // Static round-robin scheduling with one chunk per thread to ensure correct order of the final vector +#endif + for (uint32_t ii = 0; ii < clusters.nSliceRows; ii++) { + uint32_t i = ii / GPUTPCGeometry::NROWS; + uint32_t j = ii % GPUTPCGeometry::NROWS; + o2::tpc::ClusterNative preCl; +#ifdef WITH_OPENMP + int32_t myThread = omp_get_thread_num(); +#else + int32_t myThread = 0; +#endif + uint32_t count = 0; + const float x = GPUTPCGeometry::Row2X(j); + auto checker = [i, j, firstIR, totalT, x, etaFactor, maxZ, &fastTransform, &preCl, &count, &outBuffer = tmpBuffer[myThread], &rejectHits, &clustersFiltered, &chkFunc](const o2::tpc::ClusterNative& cl, uint32_t k) { + const float y = GPUTPCGeometry::LinearPad2Y(i, j, cl.getPad()); + const float r = sqrtf(x * x + y * y); + const float maxz = r * etaFactor + maxZ; + const uint32_t deltaBC = std::max(0.f, totalT - fastTransform.convDeltaZtoDeltaTimeInTimeFrameAbs(maxz)) * o2::tpc::constants::LHCBCPERTIMEBIN; + const auto chkVal = firstIR + (cl.getTime() * o2::tpc::constants::LHCBCPERTIMEBIN) - deltaBC; + const auto chkExt = totalT * o2::tpc::constants::LHCBCPERTIMEBIN - deltaBC; + const bool reject = chkFunc(chkVal, chkExt); + if (reject) { + rejectHits[k] = true; + clustersFiltered.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]--; + static std::atomic_flag lock = ATOMIC_FLAG_INIT; + while (lock.test_and_set(std::memory_order_acquire)) { + } + clustersFiltered.nUnattachedClusters--; + lock.clear(std::memory_order_release); + } else { + outBuffer.first.emplace_back(0); + outBuffer.second.emplace_back(0); + GPUTPCCompression_EncodeUnattached(clustersFiltered.nComppressionModes, cl, outBuffer.first.back(), outBuffer.second.back(), count++ ? &preCl : nullptr); + preCl = cl; + } + }; + uint32_t end = offsets[i][j] + clusters.nSliceRowClusters[i * GPUTPCGeometry::NROWS + j]; + o2::gpu::TPCClusterDecompressionCore::decompressHits(clusters, offsets[i][j], end, checker); + } + tmpBuffer[0].first.reserve(clustersFiltered.nUnattachedClusters); + tmpBuffer[0].second.reserve(clustersFiltered.nUnattachedClusters); + for (int32_t i = 1; i < nThreads; i++) { + tmpBuffer[0].first.insert(tmpBuffer[0].first.end(), tmpBuffer[i].first.begin(), tmpBuffer[i].first.end()); + tmpBuffer[i].first.clear(); + tmpBuffer[0].second.insert(tmpBuffer[0].second.end(), tmpBuffer[i].second.begin(), tmpBuffer[i].second.end()); + tmpBuffer[i].second.clear(); + } + clustersFiltered.timeDiffU = tmpBuffer[0].first.data(); + clustersFiltered.padDiffU = tmpBuffer[0].second.data(); + } +}; +} // namespace o2::gpu + +#endif diff --git a/GPU/GPUTracking/Global/GPUChainTracking.h b/GPU/GPUTracking/Global/GPUChainTracking.h index b23b4ab5fcb11..52cc59d88ed4f 100644 --- a/GPU/GPUTracking/Global/GPUChainTracking.h +++ b/GPU/GPUTracking/Global/GPUChainTracking.h @@ -23,10 +23,16 @@ #include #include #include +#include #include #include #include +namespace o2 +{ +struct InteractionRecord; +} // namespace o2 + namespace o2::dataformats { template @@ -316,6 +322,7 @@ class GPUChainTracking : public GPUChain void RunTPCTrackingMerger_MergeBorderTracks(uint8_t mergeMode, GPUReconstruction::krnlDeviceType deviceType); void RunTPCTrackingMerger_Resolve(int8_t useOrigTrackParam, int8_t mergeAll, GPUReconstruction::krnlDeviceType deviceType); void RunTPCClusterFilter(o2::tpc::ClusterNativeAccess* clusters, std::function allocator, bool applyClusterCuts); + std::shared_ptr RunTPCClusterFilterInput(const o2::tpc::CompressedClustersFlat* input, std::function chkFunction); bool NeedTPCClustersOnGPU(); void WriteReducedClusters(); void SortClusters(bool buildNativeGPU, bool propagateMCLabels, o2::tpc::ClusterNativeAccess* clusterAccess, o2::tpc::ClusterNative* clusters); diff --git a/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx b/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx index f3a326dc44bc7..d37a464a04787 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx @@ -254,8 +254,9 @@ int32_t GPUChainTracking::RunTPCDecompression() }; auto& decompressTimer = getTimer("TPCDecompression", 0); auto allocatorUse = runFiltering ? std::function{allocatorTmp} : std::function{allocatorFinal}; + const auto& filteredInput = RunTPCClusterFilterInput(mIOPtrs.tpcCompressedClusters, nullptr); decompressTimer.Start(); - if (decomp.decompress(*mIOPtrs.tpcCompressedClusters, *mClusterNativeAccess, allocatorUse, param(), GetProcessingSettings().deterministicGPUReconstruction || GetProcessingSettings().debugLevel >= 4 || GetProcessingSettings().tpcSortClusters)) { + if (decomp.decompress(filteredInput ? *filteredInput : *mIOPtrs.tpcCompressedClusters, *mClusterNativeAccess, allocatorUse, param(), GetProcessingSettings().deterministicGPUReconstruction || GetProcessingSettings().debugLevel >= 4 || GetProcessingSettings().tpcSortClusters)) { GPUError("Error decompressing clusters"); return 1; } diff --git a/GPU/GPUTracking/Global/GPUChainTrackingDebugAndProfiling.cxx b/GPU/GPUTracking/Global/GPUChainTrackingDebugAndProfiling.cxx index d9787dfdb9137..7a15fedec0b21 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingDebugAndProfiling.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingDebugAndProfiling.cxx @@ -17,6 +17,8 @@ #include "GPUMemorySizeScalers.h" #include "GPUConstantMem.h" #include "GPUTPCClusterFilter.h" +#include "TPCClusterDecompressionFilter.inc" +#include "TPCFastTransformPOD.h" #include "utils/unique_file.h" #include #include @@ -390,6 +392,25 @@ void GPUChainTracking::RunTPCClusterFilter(o2::tpc::ClusterNativeAccess* cluster } } +std::shared_ptr GPUChainTracking::RunTPCClusterFilterInput(const o2::tpc::CompressedClustersFlat* input, std::function chkFunction) +{ + if (!chkFunction) { + return nullptr; + } + std::vector rejectHits, rejectTracks, rejectTrackHits, rejectTrackHitsReduced; + std::vector, std::vector>> tmpBuffer; + const float etaFactor = 0, maxZ = 0; + + struct Holder { + o2::tpc::CompressedClusters clusters; + }; + auto holder = std::make_shared(); + const auto firstOrbit = mIOPtrs.settingsTF && mIOPtrs.settingsTF->hasTfStartOrbit ? mIOPtrs.settingsTF->tfStartOrbit : 0u; + o2::gpu::TPCClusterDecompressionFilter::runFilter(param(), *processors()->calibObjects.fastTransform, *input, holder->clusters, rejectHits, rejectTracks, rejectTrackHits, rejectTrackHitsReduced, tmpBuffer, 1, firstOrbit, chkFunction, etaFactor, maxZ); + + return {holder, &holder->clusters}; +} + void GPUChainTracking::DumpClusters(std::ostream& out, const o2::tpc::ClusterNativeAccess* clusters) { out << "\nTPC Clusters:\n"; diff --git a/GPU/GPUTracking/Merger/GPUTPCGMPropagator.inc b/GPU/GPUTracking/Merger/GPUTPCGMPropagator.inc index 77d16a6547615..4e1c58b6351af 100644 --- a/GPU/GPUTracking/Merger/GPUTPCGMPropagator.inc +++ b/GPU/GPUTracking/Merger/GPUTPCGMPropagator.inc @@ -29,7 +29,7 @@ GPUdi() GPUAlwaysInline() int32_t GPUTPCGMPropagator::RejectCluster(float chi2Y, if (chi2Z > param.rec.tpc.maxChi2ZSplitSharedEdgeSingle && (clusterState & (GPUTPCGMMergedTrackHit::flagSplit | GPUTPCGMMergedTrackHit::flagShared | GPUTPCGMMergedTrackHit::flagEdge | GPUTPCGMMergedTrackHit::flagSingle))) { return 2; } - if (chi2Y >param.rec.tpc.maxChi2YSplitShared && (clusterState & (GPUTPCGMMergedTrackHit::flagSplit | GPUTPCGMMergedTrackHit::flagShared))) { + if (chi2Y > param.rec.tpc.maxChi2YSplitShared && (clusterState & (GPUTPCGMMergedTrackHit::flagSplit | GPUTPCGMMergedTrackHit::flagShared))) { return 2; } if (chi2Y > param.rec.tpc.maxChi2YEdge && (clusterState & GPUTPCGMMergedTrackHit::flagEdge)) { From b76bc63840702a5829e1fe0c5f466c9a4ae01f23 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Sat, 5 Dec 2026 01:01:42 +0100 Subject: [PATCH 4/5] GPU Standalone: Add option to measure build times to CMake --- GPU/GPUTracking/Standalone/CMakeLists.txt | 6 ++++++ GPU/GPUTracking/Standalone/cmake/buildTiming.sh | 14 ++++++++++++++ GPU/GPUTracking/Standalone/cmake/config.cmake | 1 + 3 files changed, 21 insertions(+) create mode 100755 GPU/GPUTracking/Standalone/cmake/buildTiming.sh diff --git a/GPU/GPUTracking/Standalone/CMakeLists.txt b/GPU/GPUTracking/Standalone/CMakeLists.txt index 2d1bae68f480a..df8aa1eed37e0 100644 --- a/GPU/GPUTracking/Standalone/CMakeLists.txt +++ b/GPU/GPUTracking/Standalone/CMakeLists.txt @@ -31,6 +31,12 @@ if(NOT EXISTS "${CMAKE_BINARY_DIR}/config.cmake") file(COPY "${CMAKE_SOURCE_DIR}/cmake/config.cmake" DESTINATION "${CMAKE_BINARY_DIR}") endif() include("${CMAKE_BINARY_DIR}/config.cmake") +if(GPUCA_BUILD_TIMING) # Wrap all build steps to log their time, see cmake/buildTiming.sh + set(TMP_TIMING "${CMAKE_SOURCE_DIR}/cmake/buildTiming.sh ${CMAKE_BINARY_DIR}/build_times.log") + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${TMP_TIMING} compile --") + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${TMP_TIMING} link --") + set_property(GLOBAL PROPERTY RULE_LAUNCH_CUSTOM "${TMP_TIMING} custom - - - --") +endif() if(DEFINED GPUCA_CONFIG_COMPILER) if(GPUCA_CONFIG_COMPILER STREQUAL "clang") set(CMAKE_C_COMPILER "clang") diff --git a/GPU/GPUTracking/Standalone/cmake/buildTiming.sh b/GPU/GPUTracking/Standalone/cmake/buildTiming.sh new file mode 100755 index 0000000000000..f4761562b4ed1 --- /dev/null +++ b/GPU/GPUTracking/Standalone/cmake/buildTiming.sh @@ -0,0 +1,14 @@ +#!/bin/bash +# Launcher for the build steps of the standalone build when GPUCA_BUILD_TIMING is set in config.cmake: runs the command and appends +# "real [s], user [s], sys [s], max RSS [kB], step, language, target, file / command" (tab-separated) to the log. Slowest steps: sort -rn | head +# usage: buildTiming.sh -- command... +log=$1; step=$2; lang=$3; tgt=$4; file=$5; shift 6 +[ "$step" = custom ] && file=$(echo "$*" | tr '\t\n\\' ' /' | cut -c1-400) +fmt="%e\t%U\t%S\t%M\t$step\t$lang\t$tgt\t${file//%/%%}" +if [ "$1" = "!" ]; then # Shell negation in a custom command + shift + /usr/bin/time -q -a -o "$log" -f "$fmt" "$@" + [ $? -ne 0 ] + exit $? +fi +exec /usr/bin/time -q -a -o "$log" -f "$fmt" "$@" diff --git a/GPU/GPUTracking/Standalone/cmake/config.cmake b/GPU/GPUTracking/Standalone/cmake/config.cmake index 8a008245745cb..ed4403231c5b5 100644 --- a/GPU/GPUTracking/Standalone/cmake/config.cmake +++ b/GPU/GPUTracking/Standalone/cmake/config.cmake @@ -42,5 +42,6 @@ set(CUDA_COMPUTETARGET "default") # Set NVIDIA GPU targets to compil #set(GPUCA_KERNEL_RESOURCE_USAGE_VERBOSE 1) # Verbose resource usage output during kernel compilation #set(GPUCA_CONFIG_COMPILER gcc) # Compiler to use for standalone compilation: gcc / clang #set(GPUCA_CONFIG_WERROR 1) # Enforce Werror +#set(GPUCA_BUILD_TIMING 1) # Log the time of each compile / link / custom build step to build_times.log in the build folder #add_definitions(-DGPUCA_GPU_DEBUG_PRINT) # Enable LOG(...) macros and GPUInfo(...) etc. in GPU code #set(GPUCA_OVERRIDE_PARAMETER_FILE "foo.csv") # Override the CSV or JSON file that contains GPU parameters From 5ffc3bc200df703d2dc009dfec05086ebc556f1c Mon Sep 17 00:00:00 2001 From: David Rohr Date: Sat, 5 Dec 2026 01:02:17 +0100 Subject: [PATCH 5/5] GPU Workflow: Copy options from CTFEntropyEncoderSpec to GPUWorkflow, and forward filter function to GPUChainTrackingDecompression --- .../TPCClusterDecompressionFilter.inc | 6 ++ GPU/GPUTracking/DataTypes/GPUSettingsTypes.h | 1 + .../Definitions/GPUSettingsList.template | 1 + .../Global/GPUChainTrackingCompression.cxx | 3 +- .../GPUChainTrackingDebugAndProfiling.cxx | 31 +++++++--- GPU/Workflow/CMakeLists.txt | 1 + .../include/GPUWorkflow/GPUWorkflowSpec.h | 5 ++ GPU/Workflow/src/GPUWorkflowCTF.cxx | 56 +++++++++++++++++++ GPU/Workflow/src/GPUWorkflowSpec.cxx | 18 ++++++ GPU/Workflow/src/gpu-reco-workflow.cxx | 2 + 10 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 GPU/Workflow/src/GPUWorkflowCTF.cxx diff --git a/GPU/GPUTracking/DataCompression/TPCClusterDecompressionFilter.inc b/GPU/GPUTracking/DataCompression/TPCClusterDecompressionFilter.inc index f73826ea34de5..6922607d36ebb 100644 --- a/GPU/GPUTracking/DataCompression/TPCClusterDecompressionFilter.inc +++ b/GPU/GPUTracking/DataCompression/TPCClusterDecompressionFilter.inc @@ -20,6 +20,7 @@ #include "CommonDataFormat/InteractionRecord.h" #include #include +#include #include #include #include @@ -31,6 +32,11 @@ namespace o2::gpu { +struct GPUTPCClusterInputFilter { // Filter for the TPC compressed clusters input, forwarded via GPUSettingsProcessing::tpcInputFilter + std::function chkFunction; // Returns true if the object at the given time with the given extent (in BC) is to be rejected + float etaFactor = 0.f, maxZ = 0.f; // Cut for unattached clusters +}; + struct TPCClusterDecompressionFilter { template static inline void runFilter(const GPUParam& param, const T& fastTransform, const o2::tpc::CompressedClusters& clusters, o2::tpc::CompressedClusters& clustersFiltered, std::vector& rejectHits, std::vector& rejectTracks, std::vector& rejectTrackHits, std::vector& rejectTrackHitsReduced, diff --git a/GPU/GPUTracking/DataTypes/GPUSettingsTypes.h b/GPU/GPUTracking/DataTypes/GPUSettingsTypes.h index cefbf5b8d4f01..5574d85c6dc23 100644 --- a/GPU/GPUTracking/DataTypes/GPUSettingsTypes.h +++ b/GPU/GPUTracking/DataTypes/GPUSettingsTypes.h @@ -26,6 +26,7 @@ namespace o2::gpu { class GPUDisplayFrontendInterface; +struct GPUTPCClusterInputFilter; class GPUReconstruction; class GPUSettings diff --git a/GPU/GPUTracking/Definitions/GPUSettingsList.template b/GPU/GPUTracking/Definitions/GPUSettingsList.template index a3ea2f77519c6..1448915c45b64 100644 --- a/GPU/GPUTracking/Definitions/GPUSettingsList.template +++ b/GPU/GPUTracking/Definitions/GPUSettingsList.template @@ -468,6 +468,7 @@ AddOption(memoryStat, bool, false, "", 0, "Print memory statistics") AddOption(queryHostMemoryUSS, int8_t, 0, "", 0, "Query the unique set size (private resident memory) of the process after every kernel and after every pop of the non-persistent memory stack, and print the maximum (2: print every query). Slow, Linux only", def(1)) AddVariable(runsStandalone, bool, false) AddVariable(eventDisplay, o2::gpu::GPUDisplayFrontendInterface*, nullptr) +AddVariable(tpcInputFilter, o2::gpu::GPUTPCClusterInputFilter*, nullptr) AddSubConfig(GPUSettingsProcessingRTC, rtc) AddSubConfig(GPUSettingsProcessingRTCtechnical, rtctech) AddSubConfig(GPUSettingsProcessingParam, param) diff --git a/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx b/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx index d37a464a04787..af01125ab75e4 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx @@ -27,6 +27,7 @@ #include "SimulationDataFormat/ConstMCTruthContainer.h" #include "SimulationDataFormat/MCCompLabel.h" #include "utils/strtag.h" +#include "TPCClusterDecompressionFilter.inc" #include #include @@ -254,7 +255,7 @@ int32_t GPUChainTracking::RunTPCDecompression() }; auto& decompressTimer = getTimer("TPCDecompression", 0); auto allocatorUse = runFiltering ? std::function{allocatorTmp} : std::function{allocatorFinal}; - const auto& filteredInput = RunTPCClusterFilterInput(mIOPtrs.tpcCompressedClusters, nullptr); + const auto& filteredInput = RunTPCClusterFilterInput(mIOPtrs.tpcCompressedClusters, GetProcessingSettings().tpcInputFilter ? GetProcessingSettings().tpcInputFilter->chkFunction : nullptr); decompressTimer.Start(); if (decomp.decompress(filteredInput ? *filteredInput : *mIOPtrs.tpcCompressedClusters, *mClusterNativeAccess, allocatorUse, param(), GetProcessingSettings().deterministicGPUReconstruction || GetProcessingSettings().debugLevel >= 4 || GetProcessingSettings().tpcSortClusters)) { GPUError("Error decompressing clusters"); diff --git a/GPU/GPUTracking/Global/GPUChainTrackingDebugAndProfiling.cxx b/GPU/GPUTracking/Global/GPUChainTrackingDebugAndProfiling.cxx index 7a15fedec0b21..de0cadf2f14d6 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingDebugAndProfiling.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingDebugAndProfiling.cxx @@ -397,17 +397,34 @@ std::shared_ptr GPUChainTracking::RunTPCClust if (!chkFunction) { return nullptr; } - std::vector rejectHits, rejectTracks, rejectTrackHits, rejectTrackHitsReduced; - std::vector, std::vector>> tmpBuffer; - const float etaFactor = 0, maxZ = 0; - - struct Holder { + struct Holder { // Owns the filtered clusters and all arrays they point to o2::tpc::CompressedClusters clusters; + std::vector, std::vector>> tmpBuffer; // Reencoded padDiffU / timeDiffU + std::vector> buffers; // All other filtered arrays }; auto holder = std::make_shared(); + const o2::tpc::CompressedClusters c = *input; + auto& f = holder->clusters = c; + std::vector rejectHits, rejectTracks, rejectTrackHits, rejectTrackHitsReduced; + const auto filter = [&holder](uint32_t n, const std::vector* reject, auto*&... ptrs) { // Replace the arrays of n entries by copies owned by the holder without the rejected entries + const auto filterOne = [&](auto*& ptr) { + auto* out = (std::remove_reference_t*)holder->buffers.emplace_back(new char[n * sizeof(*ptr)]).get(); + for (uint32_t i = 0, j = 0; i < n; i++) { + if (!reject || !(*reject)[i]) { + out[j++] = ptr[i]; + } + } + ptr = out; + }; + (filterOne(ptrs), ...); + }; + filter(c.nSliceRows, nullptr, f.nSliceRowClusters); // Modified in place by runFilter const auto firstOrbit = mIOPtrs.settingsTF && mIOPtrs.settingsTF->hasTfStartOrbit ? mIOPtrs.settingsTF->tfStartOrbit : 0u; - o2::gpu::TPCClusterDecompressionFilter::runFilter(param(), *processors()->calibObjects.fastTransform, *input, holder->clusters, rejectHits, rejectTracks, rejectTrackHits, rejectTrackHitsReduced, tmpBuffer, 1, firstOrbit, chkFunction, etaFactor, maxZ); - + o2::gpu::TPCClusterDecompressionFilter::runFilter(param(), *processors()->calibObjects.fastTransform, c, f, rejectHits, rejectTracks, rejectTrackHits, rejectTrackHitsReduced, holder->tmpBuffer, 1, firstOrbit, chkFunction, GetProcessingSettings().tpcInputFilter->etaFactor, GetProcessingSettings().tpcInputFilter->maxZ); + filter(c.nAttachedClusters, &rejectTrackHits, f.qTotA, f.qMaxA, f.flagsA, f.sigmaPadA, f.sigmaTimeA); // Same assignment of the reject vectors as in o2::tpc::CTFCoder::encode + filter(c.nAttachedClustersReduced, &rejectTrackHitsReduced, f.rowDiffA, f.sliceLegDiffA, f.padResA, f.timeResA); + filter(c.nTracks, &rejectTracks, f.qPtA, f.rowA, f.sliceA, f.timeA, f.padA, f.nTrackClusters); + filter(c.nUnattachedClusters, &rejectHits, f.qTotU, f.qMaxU, f.flagsU, f.sigmaPadU, f.sigmaTimeU); return {holder, &holder->clusters}; } diff --git a/GPU/Workflow/CMakeLists.txt b/GPU/Workflow/CMakeLists.txt index db8d22dda1bae..f697c2d3710cb 100644 --- a/GPU/Workflow/CMakeLists.txt +++ b/GPU/Workflow/CMakeLists.txt @@ -13,6 +13,7 @@ o2_add_library(GPUWorkflow SOURCES src/GPUWorkflowSpec.cxx src/GPUWorkflowTPC.cxx src/GPUWorkflowITS.cxx + src/GPUWorkflowCTF.cxx src/GPUWorkflowPipeline.cxx TARGETVARNAME targetName PUBLIC_LINK_LIBRARIES O2::Framework diff --git a/GPU/Workflow/include/GPUWorkflow/GPUWorkflowSpec.h b/GPU/Workflow/include/GPUWorkflow/GPUWorkflowSpec.h index 978c5f312cfe7..a16591176f197 100644 --- a/GPU/Workflow/include/GPUWorkflow/GPUWorkflowSpec.h +++ b/GPU/Workflow/include/GPUWorkflow/GPUWorkflowSpec.h @@ -95,6 +95,7 @@ namespace gpurecoworkflow_internals { struct GPURecoWorkflowSpec_TPCZSBuffers; struct GPURecoWorkflowSpec_PipelineInternals; +struct GPURecoWorkflowSpec_CTFFilter; struct GPURecoWorkflow_QueueObject; } // namespace gpurecoworkflow_internals @@ -111,6 +112,7 @@ class GPURecoWorkflowSpec : public o2::framework::Task bool tpcUseMCTimeGain = false; // use time gain calibration for MC (true) or from data (false) bool decompressTPC = false; bool decompressTPCFromROOT = false; + bool tpcSelIRFrames = false; // filter the TPC compressed clusters input by the selected IR frames bool caClusterer = false; bool zsDecoder = false; bool zsOnTheFly = false; @@ -167,6 +169,8 @@ class GPURecoWorkflowSpec : public o2::framework::Task /// initialize TPC options from command line void initFunctionTPCCalib(o2::framework::InitContext& ic); void initFunctionITS(o2::framework::InitContext& ic); + void initFunctionCTFFilter(o2::framework::InitContext& ic); + void setCTFFilterIRFrames(o2::framework::ProcessingContext* pc); // nullptr to clear /// storing new calib objects in buffer void finaliseCCDBTPC(o2::framework::ConcreteDataMatcher& matcher, void* obj); void finaliseCCDBITS(o2::framework::ConcreteDataMatcher& matcher, void* obj); @@ -202,6 +206,7 @@ class GPURecoWorkflowSpec : public o2::framework::Task std::function mPolicyOrder; std::unique_ptr mGPUReco; std::unique_ptr mDisplayFrontend; + std::shared_ptr mCTFFilter; calibObjectStruct mCalibObjects; std::unique_ptr mTPCDeadChannelMapCreator; diff --git a/GPU/Workflow/src/GPUWorkflowCTF.cxx b/GPU/Workflow/src/GPUWorkflowCTF.cxx new file mode 100644 index 0000000000000..d3b52f425c47b --- /dev/null +++ b/GPU/Workflow/src/GPUWorkflowCTF.cxx @@ -0,0 +1,56 @@ +// Copyright 2019-2026 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// @file GPUWorkflowCTF.cxx +/// @author David Rohr +/// @brief Filtering of the TPC compressed clusters input by selected IR frames, as in the TPC entropy encoder + +#include "GPUWorkflow/GPUWorkflowSpec.h" +#include "GPUO2InterfaceConfiguration.h" +#include "TPCClusterDecompressionFilter.inc" +#include "Framework/ConfigParamRegistry.h" +#include "Framework/InputRecord.h" +#include "CommonUtils/IRFrameSelector.h" +#include "CommonDataFormat/IRFrame.h" +#include + +namespace o2::gpu +{ +namespace gpurecoworkflow_internals +{ +struct GPURecoWorkflowSpec_CTFFilter { + o2::utils::IRFrameSelector selector; + GPUTPCClusterInputFilter filter; + size_t marginBwd = 0, marginFwd = 0; +}; +} // namespace gpurecoworkflow_internals + +void GPURecoWorkflowSpec::initFunctionCTFFilter(o2::framework::InitContext& ic) +{ + mCTFFilter = std::make_shared(); + mCTFFilter->marginBwd = ic.options().get("irframe-margin-bwd"); + mCTFFilter->marginFwd = ic.options().get("irframe-margin-fwd"); + mCTFFilter->filter.maxZ = ic.options().get("irframe-clusters-maxz"); + mCTFFilter->filter.etaFactor = 1.f / (tanf(2 * atanf(expf(-ic.options().get("irframe-clusters-maxeta"))))); + mCTFFilter->filter.chkFunction = [selector = &mCTFFilter->selector](const o2::InteractionRecord& chkVal, float chkExt) { return selector->check(o2::dataformats::IRFrame(chkVal, chkVal + 1), chkExt, 0) < 0; }; + mConfig->configProcessing.tpcInputFilter = &mCTFFilter->filter; +} + +void GPURecoWorkflowSpec::setCTFFilterIRFrames(o2::framework::ProcessingContext* pc) +{ + if (pc) { + mCTFFilter->selector.setSelectedIRFrames(pc->inputs().get>("selIRFrames"), mCTFFilter->marginBwd, mCTFFilter->marginFwd, 0, true); + } else { + mCTFFilter->selector.clear(); + } +} + +} // namespace o2::gpu diff --git a/GPU/Workflow/src/GPUWorkflowSpec.cxx b/GPU/Workflow/src/GPUWorkflowSpec.cxx index 8926a3750abf8..7944e58e21c1e 100644 --- a/GPU/Workflow/src/GPUWorkflowSpec.cxx +++ b/GPU/Workflow/src/GPUWorkflowSpec.cxx @@ -157,6 +157,9 @@ void GPURecoWorkflowSpec::init(InitContext& ic) throw std::runtime_error("GPU Event Display frontend could not be created!"); } } + if (mSpecConfig.decompressTPC && mSpecConfig.tpcSelIRFrames) { + initFunctionCTFFilter(ic); + } if (mSpecConfig.enableDoublePipeline) { mConfig->configProcessing.doublePipeline = 1; } @@ -615,6 +618,9 @@ void GPURecoWorkflowSpec::run(ProcessingContext& pc) bool doInputDigits = false, doInputDigitsMC = false; if (mSpecConfig.decompressTPC) { ptrs.tpcCompressedClusters = pCompClustersFlat; + if (mSpecConfig.tpcSelIRFrames) { + setCTFFilterIRFrames(&pc); + } } else if (mSpecConfig.zsOnTheFly) { const uint64_t* buffer = reinterpret_cast(inputZS.data()); o2::gpu::GPUReconstructionConvert::RunZSEncoderCreateMeta(buffer, tpcZSonTheFlySizes.data(), *&ptrEp, &tpcZS); @@ -841,6 +847,9 @@ void GPURecoWorkflowSpec::run(ProcessingContext& pc) debugTFDump = true; } cleanOldCalibsTPCPtrs(oldCalibObjects); + if (mSpecConfig.decompressTPC && mSpecConfig.tpcSelIRFrames) { + setCTFFilterIRFrames(nullptr); + } o2::utils::DebugStreamer::instance()->flush(); // flushing debug output to file @@ -1162,6 +1171,12 @@ Options GPURecoWorkflowSpec::options() if (mSpecConfig.enableDoublePipeline == 2) { return opts; } + if (mSpecConfig.decompressTPC && mSpecConfig.tpcSelIRFrames) { // Same options as the TPC entropy encoder + opts.emplace_back(ConfigParamSpec{"irframe-margin-bwd", VariantType::UInt32, 0u, {"margin in BC to add to the IRFrame lower boundary when selection is requested"}}); + opts.emplace_back(ConfigParamSpec{"irframe-margin-fwd", VariantType::UInt32, 0u, {"margin in BC to add to the IRFrame upper boundary when selection is requested"}}); + opts.emplace_back(ConfigParamSpec{"irframe-clusters-maxeta", VariantType::Float, 1.5f, {"Max eta for non-assigned clusters"}}); + opts.emplace_back(ConfigParamSpec{"irframe-clusters-maxz", VariantType::Float, 25.f, {"Max z for non assigned clusters (combined with maxeta)"}}); + } return opts; } @@ -1216,6 +1231,9 @@ Inputs GPURecoWorkflowSpec::inputs() inputs.emplace_back("lumiCTP", o2::header::gDataOriginCTP, "LUMICTP", 0, Lifetime::Timeframe); } } + if (mSpecConfig.decompressTPC && mSpecConfig.tpcSelIRFrames) { + inputs.emplace_back("selIRFrames", "CTF", "SELIRFRAMES", 0, Lifetime::Timeframe); + } if (mSpecConfig.decompressTPC) { inputs.emplace_back(InputSpec{"input", ConcreteDataTypeMatcher{gDataOriginTPC, mSpecConfig.decompressTPCFromROOT ? o2::header::DataDescription("COMPCLUSTERS") : o2::header::DataDescription("COMPCLUSTERSFLAT")}, Lifetime::Timeframe}); } else if (mSpecConfig.caClusterer) { diff --git a/GPU/Workflow/src/gpu-reco-workflow.cxx b/GPU/Workflow/src/gpu-reco-workflow.cxx index bcde8c9b5889b..e3883d5dce42f 100644 --- a/GPU/Workflow/src/gpu-reco-workflow.cxx +++ b/GPU/Workflow/src/gpu-reco-workflow.cxx @@ -61,6 +61,7 @@ void customize(std::vector& workflowOptions) {"enableDoublePipeline", VariantType::Bool, false, {"enable GPU double pipeline mode"}}, {"tpc-deadMap-sources", VariantType::Int, -1, {"Sources to consider for TPC dead channel map creation; -1=all, 0=deactivated"}}, {"tpc-mc-time-gain", VariantType::Bool, false, {"use time gain calibration for MC (true) or for data (false)"}}, + {"select-ir-frames", VariantType::Bool, false, {"Subscribe to external IR Frames and filter the TPC compressed clusters input accordingly"}}, {"filtered-output-specs", VariantType::Bool, false, {"use filtered output specs for output DataDescriptions"}}, {"disable-ctp-lumi-request", o2::framework::VariantType::Bool, false, {"do not request CTP lumi"}}, }; @@ -186,6 +187,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) cfg.enableDoublePipeline = cfgc.options().get("enableDoublePipeline"); cfg.tpcDeadMapSources = cfgc.options().get("tpc-deadMap-sources"); cfg.tpcUseMCTimeGain = cfgc.options().get("tpc-mc-time-gain"); + cfg.tpcSelIRFrames = cfgc.options().get("select-ir-frames"); cfg.runITSTracking = isEnabled(outputTypes, ioType::ITSTracks); cfg.itsStaggered = o2::itsmft::DPLAlpideParamInitializer::isITSStaggeringEnabled(cfgc); cfg.itsOverrBeamEst = isEnabled(inputTypes, ioType::MeanVertex);