From a1e8808dbadcf663395e19ef5cbdcfe43c32d85d Mon Sep 17 00:00:00 2001 From: David Rohr Date: Tue, 1 Dec 2026 01:02:35 +0100 Subject: [PATCH 1/3] GPU: Use gather mode 0 for doublePipeline, if default would be -1 --> 1 --- GPU/GPUTracking/Base/GPUReconstruction.cxx | 13 +++++++++++++ GPU/GPUTracking/Base/GPUReconstruction.h | 1 + .../DataCompression/GPUTPCCompression.cxx | 6 +++--- GPU/GPUTracking/Global/GPUChainTracking.cxx | 4 ++-- .../Global/GPUChainTrackingCompression.cxx | 2 +- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/GPU/GPUTracking/Base/GPUReconstruction.cxx b/GPU/GPUTracking/Base/GPUReconstruction.cxx index 843030d532559..2ddabe4d52c94 100644 --- a/GPU/GPUTracking/Base/GPUReconstruction.cxx +++ b/GPU/GPUTracking/Base/GPUReconstruction.cxx @@ -33,6 +33,7 @@ #include "GPUConstantMem.h" #include "GPUCommonHelpers.h" #include "GPUSettings.h" +#include "GPUDefParametersRuntime.h" #include "GPUMemoryResource.h" #include "GPUChain.h" @@ -443,6 +444,18 @@ void GPUReconstruction::WriteConstantParams(int32_t stream) } } +int32_t GPUReconstruction::GetTPCCompressionGatherMode() const +{ + int32_t mode = GetProcessingSettings().tpcCompressionGatherMode; // TODO: Move this to GPUChainTracking, once the interface allows for SetPointers... + if (mode == -1) { + mode = getGPUParameters(GetRecoStepsGPU() & gpudatatypes::RecoStep::TPCCompression).par_COMP_GATHER_MODE; + if (mode == 1 && GetProcessingSettings().doublePipeline) { + mode = 0; + } + } + return mode; +} + int32_t GPUReconstruction::Finalize() { for (uint32_t i = 0; i < mChains.size(); i++) { diff --git a/GPU/GPUTracking/Base/GPUReconstruction.h b/GPU/GPUTracking/Base/GPUReconstruction.h index 68e2359434bc7..8a9e4989e3d57 100644 --- a/GPU/GPUTracking/Base/GPUReconstruction.h +++ b/GPU/GPUTracking/Base/GPUReconstruction.h @@ -228,6 +228,7 @@ class GPUReconstruction uint32_t NStreams() const { return mNStreams; } const void* DeviceMemoryBase() const { return mDeviceMemoryBase; } virtual const GPUDefParameters& getGPUParameters(bool doGPU) const = 0; + int32_t GetTPCCompressionGatherMode() const; // tpcCompressionGatherMode with -1 (auto) resolved RecoStepField GetRecoSteps() const { return mRecoSteps.steps; } RecoStepField GetRecoStepsGPU() const { return mRecoSteps.stepsGPUMask; } diff --git a/GPU/GPUTracking/DataCompression/GPUTPCCompression.cxx b/GPU/GPUTracking/DataCompression/GPUTPCCompression.cxx index 9222f9f555a1c..4f44b8ff9fb34 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCCompression.cxx +++ b/GPU/GPUTracking/DataCompression/GPUTPCCompression.cxx @@ -37,7 +37,7 @@ void* GPUTPCCompression::SetPointersOutputHost(void* mem) void* GPUTPCCompression::SetPointersScratch(void* mem) { - int32_t gatherMode = mRec->GetProcessingSettings().tpcCompressionGatherMode == -1 ? mRec->getGPUParameters(mRec->GetRecoStepsGPU() & gpudatatypes::RecoStep::TPCCompression).par_COMP_GATHER_MODE : mRec->GetProcessingSettings().tpcCompressionGatherMode; + int32_t gatherMode = mRec->GetTPCCompressionGatherMode(); computePointerWithAlignment(mem, mClusterStatus, mMaxClusters); if (gatherMode >= 2) { computePointerWithAlignment(mem, mAttachedClusterFirstIndex, mMaxTracks); @@ -50,7 +50,7 @@ void* GPUTPCCompression::SetPointersScratch(void* mem) void* GPUTPCCompression::SetPointersOutput(void* mem) { - int32_t gatherMode = mRec->GetProcessingSettings().tpcCompressionGatherMode == -1 ? mRec->getGPUParameters(mRec->GetRecoStepsGPU() & gpudatatypes::RecoStep::TPCCompression).par_COMP_GATHER_MODE : mRec->GetProcessingSettings().tpcCompressionGatherMode; + int32_t gatherMode = mRec->GetTPCCompressionGatherMode(); computePointerWithAlignment(mem, mAttachedClusterFirstIndex, mMaxTrackClusters); if (gatherMode == 1) { SetPointersCompressedClusters(mem, mPtrs, mMaxTrackClusters, mMaxTracks, mMaxClustersInCache, false); @@ -105,7 +105,7 @@ void* GPUTPCCompression::SetPointersMemory(void* mem) void GPUTPCCompression::RegisterMemoryAllocation() { AllocateAndInitializeLate(); - int32_t gatherMode = mRec->GetProcessingSettings().tpcCompressionGatherMode == -1 ? mRec->getGPUParameters(mRec->GetRecoStepsGPU() & gpudatatypes::RecoStep::TPCCompression).par_COMP_GATHER_MODE : mRec->GetProcessingSettings().tpcCompressionGatherMode; + int32_t gatherMode = mRec->GetTPCCompressionGatherMode(); mMemoryResOutputHost = mRec->RegisterMemoryAllocation(this, &GPUTPCCompression::SetPointersOutputHost, GPUMemoryResource::MEMORY_OUTPUT_FLAG | GPUMemoryResource::MEMORY_HOST | GPUMemoryResource::MEMORY_CUSTOM, "TPCCompressionOutputHost"); if (gatherMode == 3) { mMemoryResOutputGPU = mRec->RegisterMemoryAllocation(this, &GPUTPCCompression::SetPointersOutputGPU, GPUMemoryResource::MEMORY_SCRATCH | GPUMemoryResource::MEMORY_GPU | GPUMemoryResource::MEMORY_CUSTOM | GPUMemoryResource::MEMORY_STACK, "TPCCompressionOutputGPU"); diff --git a/GPU/GPUTracking/Global/GPUChainTracking.cxx b/GPU/GPUTracking/Global/GPUChainTracking.cxx index bc0cb5dcbbbad..16d40b934e18a 100644 --- a/GPU/GPUTracking/Global/GPUChainTracking.cxx +++ b/GPU/GPUTracking/Global/GPUChainTracking.cxx @@ -168,7 +168,7 @@ void GPUChainTracking::RegisterGPUProcessors() void GPUChainTracking::MemorySize(size_t& gpuMem, size_t& pageLockedHostMem) { - const int32_t gatherMode = mRec->GetProcessingSettings().tpcCompressionGatherMode == -1 ? mRec->getGPUParameters(mRec->GetRecoStepsGPU() & gpudatatypes::RecoStep::TPCCompression).par_COMP_GATHER_MODE : mRec->GetProcessingSettings().tpcCompressionGatherMode; + const int32_t gatherMode = mRec->GetTPCCompressionGatherMode(); gpuMem = constants::GPU_DEFAULT_MEMORY_SIZE; pageLockedHostMem = constants::GPU_DEFAULT_HOST_MEMORY_SIZE * (gatherMode < 2 ? 2 : 1) + (gatherMode == 1 ? 2 * 1024 * 1024 * 1024ull : 0); // Gather mode 1 gathers the compressed clusters in host memory } @@ -259,7 +259,7 @@ bool GPUChainTracking::ValidateSteps() bool GPUChainTracking::ValidateSettings() { - int32_t gatherMode = mRec->GetProcessingSettings().tpcCompressionGatherMode == -1 ? mRec->getGPUParameters(mRec->GetRecoStepsGPU() & gpudatatypes::RecoStep::TPCCompression).par_COMP_GATHER_MODE : mRec->GetProcessingSettings().tpcCompressionGatherMode; + int32_t gatherMode = mRec->GetTPCCompressionGatherMode(); if (param().rec.tpc.rebuildTrackInFit && (param().rec.tpc.rebuildTrackInFitClusterCandidates == 0 || param().rec.tpc.rebuildTrackInFitClusterCandidates > 13)) { GPUError("Need between 1 and 13 cluster candidates to rebuild tracks during fit"); return false; diff --git a/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx b/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx index 609ae5e9d14c8..b41aaba066544 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx @@ -38,7 +38,7 @@ int32_t GPUChainTracking::RunTPCCompression() mRec->PushNonPersistentMemory(qStr2Tag("TPCCOMPR")); RecoStep myStep = RecoStep::TPCCompression; bool doGPU = GetRecoStepsGPU() & RecoStep::TPCCompression; - int32_t gatherMode = mRec->GetProcessingSettings().tpcCompressionGatherMode == -1 ? mRec->getGPUParameters(doGPU).par_COMP_GATHER_MODE : mRec->GetProcessingSettings().tpcCompressionGatherMode; + int32_t gatherMode = mRec->GetTPCCompressionGatherMode(); GPUTPCCompression& Compressor = processors()->tpcCompressor; GPUTPCCompression& CompressorShadow = doGPU ? processorsShadow()->tpcCompressor : Compressor; const auto& holdContext = GetThreadContext(); From 05957c1c0e5334202115ed05e3111cde83ce9e3f Mon Sep 17 00:00:00 2001 From: David Rohr Date: Tue, 1 Dec 2026 10:31:09 +0100 Subject: [PATCH 2/3] GPU OpenCL: Clang >=23 no longer supports non-integrated object emitter --- GPU/GPUTracking/Base/opencl/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/GPU/GPUTracking/Base/opencl/CMakeLists.txt b/GPU/GPUTracking/Base/opencl/CMakeLists.txt index ee6d46942b35c..d0eaed7fcd2b9 100644 --- a/GPU/GPUTracking/Base/opencl/CMakeLists.txt +++ b/GPU/GPUTracking/Base/opencl/CMakeLists.txt @@ -51,14 +51,12 @@ endif() if(OPENCL_ENABLED_SPIRV) # BUILD OpenCL intermediate code for SPIR-V target # executes clang to create llvm IL code - # Add -fintegrated-objemitter once we switch to clang >= 17 cmake_path(GET LLVM_SPIRV PARENT_PATH TMP_LLVM_SPIRV_PATH) add_custom_command( OUTPUT ${CL_BIN}.spirv COMMAND ${CMAKE_COMMAND} -E env "PATH=${TMP_LLVM_SPIRV_PATH}:\$$PATH" ${LLVM_CLANG} -O0 --target=spirv64v${GPUCA_OCL_SPIRV_VERSION} - -fno-integrated-objemitter -ferror-limit=1000 -Wno-invalid-constexpr -Wno-unused-command-line-argument ${OCL_FLAGS} ${OCL_DEFINECL} From 30f6cfe3db8fcfbaced61520eec6b762450467d2 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Tue, 1 Dec 2026 10:33:16 +0100 Subject: [PATCH 3/3] GPU: Drop support for GPUCA_OPENCL_CLANG_C11_ATOMICS, unlikely they will every support shared memory, so we cannot use them --- GPU/Common/GPUCommonDefAPI.h | 11 +---------- GPU/Common/GPUCommonDefSettings.h | 2 -- GPU/Common/GPUCommonMath.h | 28 +++++++--------------------- 3 files changed, 8 insertions(+), 33 deletions(-) diff --git a/GPU/Common/GPUCommonDefAPI.h b/GPU/Common/GPUCommonDefAPI.h index fdd752404e582..fac9b70eef490 100644 --- a/GPU/Common/GPUCommonDefAPI.h +++ b/GPU/Common/GPUCommonDefAPI.h @@ -108,16 +108,7 @@ #define GPUbarrier() barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE) #define GPUbarrierWarp() sub_group_barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE) #define GPUbarrierWarpAlive() - #if defined(__OPENCL__) && defined(GPUCA_OPENCL_CLANG_C11_ATOMICS) - namespace o2 { namespace gpu { - template struct oclAtomic; - template <> struct oclAtomic {typedef atomic_uint t;}; - static_assert(sizeof(oclAtomic::t) == sizeof(uint32_t), "Invalid size of atomic type"); - }} - #define GPUAtomic(type) o2::gpu::oclAtomic::t - #else - #define GPUAtomic(type) volatile type - #endif + #define GPUAtomic(type) volatile type #endif #if !defined(__OPENCL__) // Other special defines for OpenCL 1 #define GPUCA_USE_TEMPLATE_ADDRESS_SPACES // TODO: check if we can make this (partially, where it is already implemented) compatible with OpenCL CPP diff --git a/GPU/Common/GPUCommonDefSettings.h b/GPU/Common/GPUCommonDefSettings.h index 860ca8792eb88..09aef767ce4ee 100644 --- a/GPU/Common/GPUCommonDefSettings.h +++ b/GPU/Common/GPUCommonDefSettings.h @@ -22,8 +22,6 @@ #error Please include GPUCommonDef.h! #endif -//#define GPUCA_OPENCL_CLANG_C11_ATOMICS // Use C11 atomic instead of old style atomics for OpenCL C++ in clang (OpenCL 2.2 C++ will use C++11 atomics irrespectively) - //#define GPUCA_CUDA_NO_CONSTANT_MEMORY // Do not use constant memory for CUDA //#define GPUCA_HIP_NO_CONSTANT_MEMORY // Do not use constant memory for HIP #define GPUCA_OPENCL_NO_CONSTANT_MEMORY // Do not use constant memory for OpenCL C++ - MANDATORY as OpenCL cannot cast between __constant and __generic yet! diff --git a/GPU/Common/GPUCommonMath.h b/GPU/Common/GPUCommonMath.h index c7d55ff43fef4..205013b08ad88 100644 --- a/GPU/Common/GPUCommonMath.h +++ b/GPU/Common/GPUCommonMath.h @@ -605,9 +605,7 @@ GPUdi() device metal::atomic* GPUCommonMathMetalAtomic(T* p) template GPUdi() uint32_t GPUCommonMath::AtomicExchInternal(S* addr, T val) { -#if defined(GPUCA_GPUCODE) && defined(__OPENCL__) && (!defined(__clang__) || defined(GPUCA_OPENCL_CLANG_C11_ATOMICS)) - return ::atomic_exchange(addr, val); -#elif defined(GPUCA_GPUCODE) && defined(__OPENCL__) +#if defined(GPUCA_GPUCODE) && defined(__OPENCL__) return ::atomic_xchg(addr, val); #elif defined(GPUCA_GPUCODE) && (defined(__CUDACC__) || defined(__HIPCC__)) return ::atomicExch(addr, val); @@ -625,9 +623,7 @@ GPUdi() uint32_t GPUCommonMath::AtomicExchInternal(S* addr, T val) template GPUdi() bool GPUCommonMath::AtomicCASInternal(S* addr, T cmp, T val) { -#if defined(GPUCA_GPUCODE) && defined(__OPENCL__) && (!defined(__clang__) || defined(GPUCA_OPENCL_CLANG_C11_ATOMICS)) - return ::atomic_compare_exchange(addr, cmp, val) == cmp; -#elif defined(GPUCA_GPUCODE) && defined(__OPENCL__) +#if defined(GPUCA_GPUCODE) && defined(__OPENCL__) return ::atomic_cmpxchg(addr, cmp, val) == cmp; #elif defined(GPUCA_GPUCODE) && (defined(__CUDACC__) || defined(__HIPCC__)) return ::atomicCAS(addr, cmp, val) == cmp; @@ -643,9 +639,7 @@ GPUdi() bool GPUCommonMath::AtomicCASInternal(S* addr, T cmp, T val) template GPUdi() uint32_t GPUCommonMath::AtomicAddInternal(S* addr, T val) { -#if defined(GPUCA_GPUCODE) && defined(__OPENCL__) && (!defined(__clang__) || defined(GPUCA_OPENCL_CLANG_C11_ATOMICS)) - return ::atomic_fetch_add(addr, val); -#elif defined(GPUCA_GPUCODE) && defined(__OPENCL__) +#if defined(GPUCA_GPUCODE) && defined(__OPENCL__) return ::atomic_add(addr, val); #elif defined(GPUCA_GPUCODE) && (defined(__CUDACC__) || defined(__HIPCC__)) return ::atomicAdd(addr, val); @@ -661,9 +655,7 @@ GPUdi() uint32_t GPUCommonMath::AtomicAddInternal(S* addr, T val) template GPUdi() void GPUCommonMath::AtomicMaxInternal(S* addr, T val) { -#if defined(GPUCA_GPUCODE) && defined(__OPENCL__) && (!defined(__clang__) || defined(GPUCA_OPENCL_CLANG_C11_ATOMICS)) - ::atomic_fetch_max(addr, val); -#elif defined(GPUCA_GPUCODE) && defined(__OPENCL__) +#if defined(GPUCA_GPUCODE) && defined(__OPENCL__) ::atomic_max(addr, val); #elif defined(GPUCA_GPUCODE) && (defined(__CUDACC__) || defined(__HIPCC__)) ::atomicMax(addr, val); @@ -679,9 +671,7 @@ GPUdi() void GPUCommonMath::AtomicMaxInternal(S* addr, T val) template GPUdi() void GPUCommonMath::AtomicMinInternal(S* addr, T val) { -#if defined(GPUCA_GPUCODE) && defined(__OPENCL__) && (!defined(__clang__) || defined(GPUCA_OPENCL_CLANG_C11_ATOMICS)) - ::atomic_fetch_min(addr, val); -#elif defined(GPUCA_GPUCODE) && defined(__OPENCL__) +#if defined(GPUCA_GPUCODE) && defined(__OPENCL__) ::atomic_min(addr, val); #elif defined(GPUCA_GPUCODE) && (defined(__CUDACC__) || defined(__HIPCC__)) ::atomicMin(addr, val); @@ -697,9 +687,7 @@ GPUdi() void GPUCommonMath::AtomicMinInternal(S* addr, T val) template GPUdi() T GPUCommonMath::AtomicLoadInternal(S* addr) { -#if defined(GPUCA_GPUCODE) && defined(__OPENCL__) && (!defined(__clang__) || defined(GPUCA_OPENCL_CLANG_C11_ATOMICS)) - return ::atomic_load_explicit(addr, memory_order_relaxed); -#elif defined(GPUCA_GPUCODE) && (defined(__OPENCL__) || defined(__CUDACC__) || defined(__HIPCC__)) +#if defined(GPUCA_GPUCODE) && (defined(__OPENCL__) || defined(__CUDACC__) || defined(__HIPCC__)) return *(volatile S*)addr; #elif defined(GPUCA_GPUCODE) && defined(__METAL__) return atomic_load_explicit(GPUCommonMathMetalAtomic(addr), memory_order_relaxed); @@ -715,9 +703,7 @@ GPUdi() T GPUCommonMath::AtomicLoadInternal(S* addr) template GPUdi() void GPUCommonMath::AtomicStoreInternal(S* addr, T val) { -#if defined(GPUCA_GPUCODE) && defined(__OPENCL__) && (!defined(__clang__) || defined(GPUCA_OPENCL_CLANG_C11_ATOMICS)) - ::atomic_store_explicit(addr, val, memory_order_relaxed); -#elif defined(GPUCA_GPUCODE) && (defined(__OPENCL__) || defined(__CUDACC__) || defined(__HIPCC__)) +#if defined(GPUCA_GPUCODE) && (defined(__OPENCL__) || defined(__CUDACC__) || defined(__HIPCC__)) *(volatile S*)addr = val; #elif defined(GPUCA_GPUCODE) && defined(__METAL__) atomic_store_explicit(GPUCommonMathMetalAtomic(addr), val, memory_order_relaxed);