From 84b9947aedf03b36a90d701ec5b5e27e110ec279 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 16 Mar 2026 18:25:38 +0100 Subject: [PATCH] GPU TPC: Use stored field value during TPC track model decoding --- GPU/GPUTracking/Base/GPUParam.h | 4 ++-- GPU/GPUTracking/Base/GPUReconstruction.cxx | 4 ++-- GPU/GPUTracking/Base/GPUReconstruction.h | 2 +- GPU/GPUTracking/Global/GPUChain.h | 1 + .../Global/GPUChainTrackingCompression.cxx | 19 +++++++++++++++++-- .../Interface/GPUO2InterfaceRefit.cxx | 2 +- .../Interface/GPUO2InterfaceUtils.cxx | 2 +- 7 files changed, 25 insertions(+), 9 deletions(-) diff --git a/GPU/GPUTracking/Base/GPUParam.h b/GPU/GPUTracking/Base/GPUParam.h index 847f3e05ea32e..0716274c5e198 100644 --- a/GPU/GPUTracking/Base/GPUParam.h +++ b/GPU/GPUTracking/Base/GPUParam.h @@ -80,10 +80,10 @@ struct GPUParam_t { struct GPUParam : public internal::GPUParam_t { #ifndef GPUCA_GPUCODE - void SetDefaults(float solenoidBz, bool assumeConstantBz); + void SetDefaults(float solenoidBz, bool assumeConstantBz = false); void SetDefaults(const GPUSettingsGRP* g, const GPUSettingsRec* r = nullptr, const GPUSettingsProcessing* p = nullptr, const GPURecoStepConfiguration* w = nullptr); void UpdateSettings(const GPUSettingsGRP* g, const GPUSettingsProcessing* p = nullptr, const GPURecoStepConfiguration* w = nullptr, const GPUSettingsRecDynamic* d = nullptr); - void UpdateBzOnly(float newSolenoidBz, bool assumeConstantBz); + void UpdateBzOnly(float newSolenoidBz, bool assumeConstantBz = false); void UpdateRun3ClusterErrors(const float* yErrorParam, const float* zErrorParam); #endif diff --git a/GPU/GPUTracking/Base/GPUReconstruction.cxx b/GPU/GPUTracking/Base/GPUReconstruction.cxx index fbbe815f63c33..f34a049a1588d 100644 --- a/GPU/GPUTracking/Base/GPUReconstruction.cxx +++ b/GPU/GPUTracking/Base/GPUReconstruction.cxx @@ -433,11 +433,11 @@ int32_t GPUReconstruction::InitPhaseAfterDevice() return 0; } -void GPUReconstruction::WriteConstantParams() +void GPUReconstruction::WriteConstantParams(int32_t stream) { if (IsGPU()) { const auto threadContext = GetThreadContext(); - WriteToConstantMemory(ptrDiff(&processors()->param, processors()), ¶m(), sizeof(param()), -1); + WriteToConstantMemory(ptrDiff(&processors()->param, processors()), ¶m(), sizeof(param()), stream); } } diff --git a/GPU/GPUTracking/Base/GPUReconstruction.h b/GPU/GPUTracking/Base/GPUReconstruction.h index b5dd29f940143..9a337c02ad26d 100644 --- a/GPU/GPUTracking/Base/GPUReconstruction.h +++ b/GPU/GPUTracking/Base/GPUReconstruction.h @@ -260,7 +260,7 @@ class GPUReconstruction virtual int32_t InitDevice() = 0; int32_t InitPhasePermanentMemory(); int32_t InitPhaseAfterDevice(); - void WriteConstantParams(); + void WriteConstantParams(int32_t stream = -1); virtual int32_t ExitDevice() = 0; virtual size_t WriteToConstantMemory(size_t offset, const void* src, size_t size, int32_t stream = -1, gpu_reconstruction_kernels::deviceEvent* ev = nullptr) = 0; void UpdateMaxMemoryUsed(); diff --git a/GPU/GPUTracking/Global/GPUChain.h b/GPU/GPUTracking/Global/GPUChain.h index 907ed7ea97c12..a524fd9ec3992 100644 --- a/GPU/GPUTracking/Global/GPUChain.h +++ b/GPU/GPUTracking/Global/GPUChain.h @@ -124,6 +124,7 @@ class GPUChain inline void TransferMemoryResourceLinkToGPU(RecoStep step, int16_t res, int32_t stream = -1, deviceEvent* ev = nullptr, deviceEvent* evList = nullptr, int32_t nEvents = 1) { timeCpy(step, true, &GPUReconstructionCPU::TransferMemoryResourceLinkToGPU, res, stream, ev, evList, nEvents); } inline void TransferMemoryResourceLinkToHost(RecoStep step, int16_t res, int32_t stream = -1, deviceEvent* ev = nullptr, deviceEvent* evList = nullptr, int32_t nEvents = 1) { timeCpy(step, false, &GPUReconstructionCPU::TransferMemoryResourceLinkToHost, res, stream, ev, evList, nEvents); } // Todo: retrieve step from proc, move kernelClass->GetStep to retrieve it from GetProcessor + inline void WriteConstantParams(int32_t stream = -1) { mRec->WriteConstantParams(stream); } inline void WriteToConstantMemory(RecoStep step, size_t offset, const void* src, size_t size, int32_t stream = -1, deviceEvent* ev = nullptr) { timeCpy(step, true, &GPUReconstructionCPU::WriteToConstantMemory, offset, src, size, stream, ev); } inline void GPUMemCpy(RecoStep step, void* dst, const void* src, size_t size, int32_t stream, int32_t toGPU, deviceEvent* ev = nullptr, deviceEvent* evList = nullptr, int32_t nEvents = 1) { timeCpy(step, toGPU, &GPUReconstructionCPU::GPUMemCpy, dst, src, size, stream, toGPU, ev, evList, nEvents); } inline void GPUMemCpyAlways(RecoStep step, void* dst, const void* src, size_t size, int32_t stream, int32_t toGPU, deviceEvent* ev = nullptr, deviceEvent* evList = nullptr, int32_t nEvents = 1) diff --git a/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx b/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx index 89d47d0e1b86c..f185348ed9169 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx @@ -225,6 +225,17 @@ int32_t GPUChainTracking::RunTPCDecompression() GPUFatal("tpcApplyCFCutsAtDecoding, tpcApplyClusterFilterOnCPU and tpcCutTimeBin currently require tpcUseOldCPUDecoding"); } + CompressedClusters cmprClsHost = *mIOPtrs.tpcCompressedClusters; + const bool useTemporaryBz = cmprClsHost.nTracks && cmprClsHost.solenoidBz != -1e6f && cmprClsHost.solenoidBz != param().bzkG && !GetProcessingSettings().doublePipeline; + std::unique_ptr tmpParam; + int32_t inputStream = 0; + + if (useTemporaryBz) { + tmpParam = std::make_unique(param()); + SynchronizeGPU(); + param().UpdateBzOnly(cmprClsHost.solenoidBz, mRec->GetGRPSettings().constBz); + WriteConstantParams(inputStream); + } if (GetProcessingSettings().tpcUseOldCPUDecoding) { const bool runFiltering = needFullFiltering || runTimeBinCutFiltering; const auto& threadContext = GetThreadContext(); @@ -268,7 +279,6 @@ int32_t GPUChainTracking::RunTPCDecompression() GPUTPCDecompression& Decompressor = processors()->tpcDecompressor; GPUTPCDecompression& DecompressorShadow = doGPU ? processorsShadow()->tpcDecompressor : Decompressor; const auto& threadContext = GetThreadContext(); - CompressedClusters cmprClsHost = *mIOPtrs.tpcCompressedClusters; CompressedClusters& inputGPU = Decompressor.mInputGPU; CompressedClusters& inputGPUShadow = DecompressorShadow.mInputGPU; @@ -279,7 +289,6 @@ int32_t GPUChainTracking::RunTPCDecompression() throw std::runtime_error("Configured max time bin " + std::to_string(param().continuousMaxTimeBin) + " does not match value used for track model encoding " + std::to_string(cmprClsHost.maxTimeBin)); } - int32_t inputStream = 0; int32_t unattachedStream = mRec->NStreams() - 1; inputGPU = cmprClsHost; SetupGPUProcessor(&Decompressor, true); @@ -437,6 +446,12 @@ int32_t GPUChainTracking::RunTPCDecompression() } mRec->PopNonPersistentMemory(RecoStep::TPCDecompression, qStr2Tag("TPCDCMPR")); } + if (useTemporaryBz) { + SynchronizeGPU(); + param() = *tmpParam; + tmpParam.reset(); + WriteConstantParams(); + } DoDebugDump(GPUChainTrackingDebugFlags::TPCDecompressedClusters, &GPUChainTracking::DumpClusters, *mDebugFile, mIOPtrs.clustersNative); return 0; } diff --git a/GPU/GPUTracking/Interface/GPUO2InterfaceRefit.cxx b/GPU/GPUTracking/Interface/GPUO2InterfaceRefit.cxx index f09c5d0a4b1cb..10a1a75368c96 100644 --- a/GPU/GPUTracking/Interface/GPUO2InterfaceRefit.cxx +++ b/GPU/GPUTracking/Interface/GPUO2InterfaceRefit.cxx @@ -129,7 +129,7 @@ GPUO2InterfaceRefit::GPUO2InterfaceRefit(const ClusterNativeAccess* cl, const Co void GPUO2InterfaceRefit::updateCalib(const CorrectionMapsHelper* trans, float bzNominalGPU) { - mParam->UpdateBzOnly(bzNominalGPU, false); + mParam->UpdateBzOnly(bzNominalGPU); mRefit->SetFastTransformHelper(trans); } diff --git a/GPU/GPUTracking/Interface/GPUO2InterfaceUtils.cxx b/GPU/GPUTracking/Interface/GPUO2InterfaceUtils.cxx index 43b8dc21eaf15..7f230ff20eb10 100644 --- a/GPU/GPUTracking/Interface/GPUO2InterfaceUtils.cxx +++ b/GPU/GPUTracking/Interface/GPUO2InterfaceUtils.cxx @@ -52,7 +52,7 @@ template <> void GPUO2InterfaceUtils::RunZSEncoder(const DigitArray& in, std::unique_ptr* outBuffer, uint32_t* outSizes, o2::raw::RawFileWriter* raw, const o2::InteractionRecord* ir, int32_t version, bool verify, float threshold, bool padding, std::function&)> digitsFilter) { GPUParam param; - param.SetDefaults(5.00668, false); + param.SetDefaults(5.00668); o2::gpu::GPUReconstructionConvert::RunZSEncoder(in, outBuffer, outSizes, raw, ir, param, version, verify, threshold, padding, digitsFilter); } template <>