From 0bef517fcf70b18b79e63f162f41a5422e9354b7 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 16:52:39 +0100 Subject: [PATCH 01/32] GPU: Add compressed clusters to O2 track count print --- .../Global/GPUChainTrackingDebugAndProfiling.cxx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/GPU/GPUTracking/Global/GPUChainTrackingDebugAndProfiling.cxx b/GPU/GPUTracking/Global/GPUChainTrackingDebugAndProfiling.cxx index 13369405ac519..565f094e7990b 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingDebugAndProfiling.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingDebugAndProfiling.cxx @@ -216,11 +216,13 @@ void GPUChainTracking::PrintKernelDebugOutput() void GPUChainTracking::PrintOutputStat() { - int32_t nTracks = 0, nAttachedClusters = 0, nAttachedClustersFitted = 0, nAdjacentClusters = 0; + int32_t nTracks = 0, nAttachedClusters = 0, nAttachedClustersFitted = 0, nAdjacentClusters = 0, nCompressedClusters = 0; uint32_t nCls = GetProcessingSettings().doublePipeline ? mIOPtrs.clustersNative->nClustersTotal : processors()->tpcMerger.NClusters(); + const char* outputType = ""; if (GetProcessingSettings().createO2Output > 1) { nTracks = mIOPtrs.nOutputTracksTPCO2; nAttachedClusters = mIOPtrs.nMergedTrackHits; + outputType = "O2"; } else { for (uint32_t k = 0; k < mIOPtrs.nMergedTracks; k++) { if (mIOPtrs.mergedTracks[k].OK()) { @@ -237,6 +239,11 @@ void GPUChainTracking::PrintOutputStat() nAdjacentClusters++; } } + outputType = "GPU"; + } + if (mIOPtrs.tpcCompressedClusters) { + o2::tpc::CompressedClusters c = *mIOPtrs.tpcCompressedClusters; + nCompressedClusters = c.nAttachedClusters + c.nUnattachedClusters; } char trdText[1024] = ""; @@ -256,7 +263,7 @@ void GPUChainTracking::PrintOutputStat() } snprintf(trdText, 1024, " - TRD Tracker reconstructed %d tracks (%d tracklets)", nTRDTracks, nTRDTracklets); } - GPUInfo("Output Tracks: %d (%d / %d / %d / %d clusters (fitted / attached / adjacent / total) - %s format)%s", nTracks, nAttachedClustersFitted, nAttachedClusters, nAdjacentClusters, nCls, GetProcessingSettings().createO2Output > 1 ? "O2" : "GPU", trdText); + GPUInfo("Output Tracks (%s): %d - Clusters: %d / %d / %d / %d / %d (attached / total / compressed / fitted / adjacent)%s", outputType, nTracks, nAttachedClusters, nCls, nCompressedClusters, nAttachedClustersFitted, nAdjacentClusters, trdText); } void GPUChainTracking::OutputSanityCheck() From a8aaeacda5f7b67184243831956d4bdaeb6bc6ba Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 14:28:32 +0100 Subject: [PATCH 02/32] GPU: Improve ROCm version check, detection of ROCM_PATH, bump minimum version to 10.1 --- dependencies/FindO2GPU.cmake | 42 ++++++++++++++---------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/dependencies/FindO2GPU.cmake b/dependencies/FindO2GPU.cmake index a8a2924872bf0..953fd8d0d7c30 100644 --- a/dependencies/FindO2GPU.cmake +++ b/dependencies/FindO2GPU.cmake @@ -10,7 +10,7 @@ # or submit itself to any jurisdiction. # NOTE!!!! - Whenever this file is changed, move it over to alidist/resources -# FindO2GPU.cmake Version 25 +# FindO2GPU.cmake Version 26 set(CUDA_COMPUTETARGET_DEFAULT_FULL 80-real;86-real;89-real;120-real;75-virtual) set(HIP_AMDGPUTARGET_DEFAULT_FULL gfx906;gfx908) @@ -354,29 +354,13 @@ if(ENABLE_HIP) elseif(NOT "$ENV{CMAKE_PREFIX_PATH}" MATCHES "rocm|ROCm" AND NOT CMAKE_PREFIX_PATH MATCHES "rocm|ROCm" AND EXISTS "/opt/rocm/lib/cmake/") list(APPEND CMAKE_PREFIX_PATH "/opt/rocm/lib/cmake") endif() - # TODO: Use ROCm folder as provided by alidist-gpu recipe - if("$ENV{CMAKE_PREFIX_PATH}" MATCHES "rocm|ROCm" OR CMAKE_PREFIX_PATH MATCHES "rocm|ROCm") - if (DEFINED ENV{O2_GPU_ROCM_HOME}) - set(CMAKE_HIP_COMPILER "$ENV{O2_GPU_ROCM_HOME}/llvm/bin/clang++") - set(TMP_ROCM_DIR "$ENV{O2_GPU_ROCM_HOME}") - elseif (DEFINED ENV{ROCM_PATH}) - set(CMAKE_HIP_COMPILER "$ENV{ROCM_PATH}/llvm/bin/clang++") - set(TMP_ROCM_DIR "$ENV{ROCM_PATH}") - else() - set(TMP_ROCM_DIR_LIST "${CMAKE_PREFIX_PATH}:$ENV{CMAKE_PREFIX_PATH}") - string(REPLACE ":" ";" TMP_ROCM_DIR_LIST "${TMP_ROCM_DIR_LIST}") - list(FILTER TMP_ROCM_DIR_LIST INCLUDE REGEX /rocm/lib/cmake|/ROCm/lib/cmake) - list(POP_FRONT TMP_ROCM_DIR_LIST TMP_ROCM_DIR) - get_filename_component(TMP_ROCM_DIR ${TMP_ROCM_DIR}/../../ ABSOLUTE) + find_package(rocm-core CONFIG) + if(rocm-core_FOUND) + if(NOT DEFINED CMAKE_HIP_COMPILER) + set(CMAKE_HIP_COMPILER "${ROCM_PATH}/llvm/bin/clang++") endif() set(CMAKE_HIP_STANDARD ${CMAKE_CXX_STANDARD}) set(CMAKE_HIP_STANDARD_REQUIRED TRUE) - if (NOT DEFINED CMAKE_HIP_COMPILER) - set(CMAKE_HIP_COMPILER "${TMP_ROCM_DIR}/llvm/bin/clang++") - if(NOT EXISTS ${CMAKE_HIP_COMPILER}) - unset(CMAKE_HIP_COMPILER) - endif() - endif() include(CheckLanguage) check_language(HIP) find_package(hip) @@ -385,7 +369,7 @@ if(ENABLE_HIP) find_package(rocthrust) find_program(hip_HIPIFY_PERL_EXECUTABLE "hipify-perl") if(NOT hip_HIPIFY_PERL_EXECUTABLE) - find_program(hip_HIPIFY_PERL_EXECUTABLE "hipify-perl" HINTS "${TMP_ROCM_DIR}/bin") + find_program(hip_HIPIFY_PERL_EXECUTABLE "hipify-perl" HINTS "${ROCM_PATH}/bin") endif() if(ENABLE_HIP STREQUAL "AUTO") set_package_properties(hip PROPERTIES TYPE OPTIONAL) @@ -411,12 +395,18 @@ if(ENABLE_HIP) enable_language(HIP) endif() elseif(NOT ENABLE_HIP STREQUAL "AUTO") - message(FATAL_ERROR "HIP requested, but CMAKE_PREFIX_PATH (${CMAKE_PREFIX_PATH}) env variable does not contain rocm folder!") + message(FATAL_ERROR "HIP requested, but not found. Perhaps need to set CMAKE_PREFIX_PATH (currently ${CMAKE_PREFIX_PATH})") endif() - if(hip_FOUND AND NOT hip_VERSION VERSION_GREATER_EQUAL "6.3") + if(hip_FOUND AND (NOT hip_VERSION VERSION_GREATER_EQUAL "7.15" OR NOT rocm-core_VERSION VERSION_GREATER_EQUAL "10.1")) + if(ENABLE_HIP STREQUAL "AUTO") + set(FAILURE_SEVERITY STATUS) + else() + set(FAILURE_SEVERITY FATAL_ERROR) + endif() + message(${FAILURE_SEVERITY} "ROCm too old: HIP ${hip_VERSION}, 7.15 required, ROCm: ${rocm-core_VERSION}, 10.1 required") set(hip_FOUND 0) endif() - if(hip_FOUND AND hipcub_FOUND AND rocthrust_FOUND AND rocprim_FOUND AND hip_HIPCC_EXECUTABLE AND hip_HIPIFY_PERL_EXECUTABLE) + if(rocm-core_FOUND AND hip_FOUND AND hipcub_FOUND AND rocthrust_FOUND AND rocprim_FOUND AND hip_HIPCC_EXECUTABLE AND hip_HIPIFY_PERL_EXECUTABLE) set(HIP_ENABLED ON) set_target_properties(roc::rocthrust PROPERTIES IMPORTED_GLOBAL TRUE) set(CMAKE_HIP_FLAGS "${O2_GPU_CMAKE_CXX_FLAGS_NOSTD} ${CMAKE_HIP_FLAGS} ${GPUCA_HIP_DENORMALS_FLAGS}") @@ -434,7 +424,7 @@ if(ENABLE_HIP) if(HIP_AMDGPUTARGET) set(CMAKE_HIP_ARCHITECTURES "${HIP_AMDGPUTARGET}") endif() - message(STATUS "HIP Found (${hip_HIPCC_EXECUTABLE}, ${CMAKE_HIP_COMPILER}, Version ${hip_VERSION}, Architectures ${CMAKE_HIP_ARCHITECTURES})") + message(STATUS "HIP Found (${hip_HIPCC_EXECUTABLE}, ${CMAKE_HIP_COMPILER} ${CMAKE_HIP_COMPILER_VERSION}, Version ${hip_VERSION}, Architectures ${CMAKE_HIP_ARCHITECTURES})") else() set(HIP_ENABLED OFF) endif() From d43fffb9fed4d91e4699dd514e22c058d38a36ef Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 14:33:48 +0100 Subject: [PATCH 03/32] GPU: Remove duplicate math constant --- GPU/Common/GPUCommonConstants.h | 3 ++- .../DataCompression/GPUTPCCompressionTrackModel.cxx | 2 +- GPU/GPUTracking/Merger/GPUTPCGMPhysicalTrackModel.cxx | 4 ++-- GPU/GPUTracking/SectorTracker/GPUTPCTrackParam.cxx | 1 - 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/GPU/Common/GPUCommonConstants.h b/GPU/Common/GPUCommonConstants.h index 95cf89cc6d0a7..fb30ea129f818 100644 --- a/GPU/Common/GPUCommonConstants.h +++ b/GPU/Common/GPUCommonConstants.h @@ -16,10 +16,11 @@ #define GPUCOMMONCONSTANTS_H #include "GPUCommonDef.h" +#include "CommonConstants/MathConstants.h" namespace o2::gpu::gpu_common_constants { -static GPUglobalconstexpr() const float kCLight = 0.000299792458f; // TODO: Duplicate of MathConstants, fix this now that we use only OpenCL CPP +static GPUglobalconstexpr() const float kCLight = -o2::constants::math::B2C; static GPUglobalconstexpr() const float kZeroFieldCut = 0.013f; } // namespace o2::gpu::gpu_common_constants diff --git a/GPU/GPUTracking/DataCompression/GPUTPCCompressionTrackModel.cxx b/GPU/GPUTracking/DataCompression/GPUTPCCompressionTrackModel.cxx index 1fe22e0e88137..39e0b770e0a47 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCCompressionTrackModel.cxx +++ b/GPU/GPUTracking/DataCompression/GPUTPCCompressionTrackModel.cxx @@ -542,7 +542,7 @@ GPUd() int32_t GPUTPCCompressionTrackModel::rotateToAlpha(float newAlpha) GPUd() int32_t GPUTPCCompressionTrackModel::propagateToXBzLightNoUpdate(PhysicalTrackModel& t, float x, float Bz, float& dLp) { // - // transport the track to X=x in magnetic field B = ( 0, 0, Bz[kG*0.000299792458] ) + // transport the track to X=x in magnetic field B = ( 0, 0, Bz[kG*kCLight] ) // dLp is a return value == path length / track momentum [cm/(GeV/c)] // the method returns error code (0 == no error) // diff --git a/GPU/GPUTracking/Merger/GPUTPCGMPhysicalTrackModel.cxx b/GPU/GPUTracking/Merger/GPUTPCGMPhysicalTrackModel.cxx index ed60f2d86f63c..107d1a2833dfe 100644 --- a/GPU/GPUTracking/Merger/GPUTPCGMPhysicalTrackModel.cxx +++ b/GPU/GPUTracking/Merger/GPUTPCGMPhysicalTrackModel.cxx @@ -35,7 +35,7 @@ GPUd() int32_t GPUTPCGMPhysicalTrackModel::PropagateToXBzLight(float x, float Bz GPUd() int32_t GPUTPCGMPhysicalTrackModel::PropagateToXBzLightNoUpdate(float x, float Bz, float& GPUrestrict() dLp) { // - // transport the track to X=x in magnetic field B = ( 0, 0, Bz[kG*0.000299792458f] ) + // transport the track to X=x in magnetic field B = ( 0, 0, Bz[kG*kCLight] ) // dLp is a return value == path length / track momentum [cm/(GeV/c)] // the method returns error code (0 == no error) // @@ -89,7 +89,7 @@ GPUd() int32_t GPUTPCGMPhysicalTrackModel::PropagateToXBzLightNoUpdate(float x, GPUd() int32_t GPUTPCGMPhysicalTrackModel::PropagateToXBxByBz(float x, float Bx, float By, float Bz, float& GPUrestrict() dLp) { // - // transport the track to X=x in magnetic field B = ( Bx, By, Bz )[kG*0.000299792458f] + // transport the track to X=x in magnetic field B = ( Bx, By, Bz )[kG*kCLight] // xyzPxPyPz as well as all the additional values will change. No need to call UpdateValues() afterwards. // the method returns error code (0 == no error) // diff --git a/GPU/GPUTracking/SectorTracker/GPUTPCTrackParam.cxx b/GPU/GPUTracking/SectorTracker/GPUTPCTrackParam.cxx index 774bcfb54b6a5..5c31d509f8a5a 100644 --- a/GPU/GPUTracking/SectorTracker/GPUTPCTrackParam.cxx +++ b/GPU/GPUTracking/SectorTracker/GPUTPCTrackParam.cxx @@ -21,7 +21,6 @@ using namespace o2::gpu; // // Circle in XY: // -// kCLight = 0.000299792458f; // Kappa = -Bz*kCLight*QPt; // R = 1/CAMath::Abs(Kappa); // Xc = X - CAMath::Sin(Phi)/Kappa; From 6fad6e28e9cfcc8459853b79a1dc4caf5b73a44d Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 14:35:37 +0100 Subject: [PATCH 04/32] GPU: Remove obsolete TODO on HIP address spaces --- GPU/Common/GPUCommonDefAPI.h | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/GPU/Common/GPUCommonDefAPI.h b/GPU/Common/GPUCommonDefAPI.h index faddcb027e0c5..07543797f55b9 100644 --- a/GPU/Common/GPUCommonDefAPI.h +++ b/GPU/Common/GPUCommonDefAPI.h @@ -189,15 +189,7 @@ #define GPUhdni() __host__ __device__ #define GPUg() __global__ #define GPUshared() __shared__ - #if defined(GPUCA_GPUCODE_DEVICE) && 0 // TODO: Fix for HIP - #define GPUCA_USE_TEMPLATE_ADDRESS_SPACES - #define GPUglobal() __attribute__((address_space(1))) - #define GPUglobalref() GPUglobal() - #define GPUconstantref() __attribute__((address_space(4))) - #define GPUsharedref() __attribute__((address_space(3))) - #else - #define GPUglobal() - #endif + #define GPUglobal() #define GPUconstant() __constant__ #define GPUconstexpr() constexpr __constant__ #define GPUprivate() From 80b8d74fbe575b5dd1e06b6877d74b563c5b5eb9 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 14:40:30 +0100 Subject: [PATCH 05/32] GPU: Remove obsolete function --- GPU/Common/GPUCommonMath.h | 12 ------------ GPU/GPUTracking/SectorTracker/GPUTPCTrackingData.cxx | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/GPU/Common/GPUCommonMath.h b/GPU/Common/GPUCommonMath.h index 2e542d027307f..6ccdeb90e89e6 100644 --- a/GPU/Common/GPUCommonMath.h +++ b/GPU/Common/GPUCommonMath.h @@ -64,8 +64,6 @@ class GPUCommonMath using half_t = _Float16; #endif - GPUd() static float2 MakeFloat2(float x, float y); // TODO: Find better appraoch that is constexpr - template GPUhd() constexpr static T Min(const T x, const T y) { @@ -292,16 +290,6 @@ GPUdi() constexpr T GPUCommonMath::nextMultipleOf(T val) return 0; // BUG: Cuda complains about missing return value with constexpr if } -GPUdi() float2 GPUCommonMath::MakeFloat2(float x, float y) -{ -#if !defined(GPUCA_GPUCODE) || defined(__OPENCL__) || defined(__OPENCL_HOST__) || defined(__METAL__) || defined(__METAL_HOST__) || defined(__CPUDEVICE__) - float2 ret = {x, y}; - return ret; -#else - return make_float2(x, y); -#endif // GPUCA_GPUCODE -} - GPUdi() constexpr float GPUCommonMath::Modf(float x, float y) { return GPUCA_CHOICE(fmodf(x, y), fmodf(x, y), fmod(x, y)); } GPUhdi() float GPUCommonMath::Remainderf(float x, float y) { diff --git a/GPU/GPUTracking/SectorTracker/GPUTPCTrackingData.cxx b/GPU/GPUTracking/SectorTracker/GPUTPCTrackingData.cxx index 9324198753a44..468ac8ed19504 100644 --- a/GPU/GPUTracking/SectorTracker/GPUTPCTrackingData.cxx +++ b/GPU/GPUTracking/SectorTracker/GPUTPCTrackingData.cxx @@ -213,7 +213,7 @@ GPUdii() int32_t GPUTPCTrackingData::InitFromClusterData(int32_t nBlocks, int32_ float x, y, z; GPUTPCConvertImpl::convert(*mem, iSector, rowIndex, mem->ioPtrs.clustersNative->clusters[iSector][rowIndex][i].getPad(), mem->ioPtrs.clustersNative->clusters[iSector][rowIndex][i].getTime(), x, y, z); UpdateMinMaxYZ(yMin, yMax, zMin, zMax, y, z); - YZData[RowOffset + i] = CAMath::MakeFloat2(y, z); + YZData[RowOffset + i] = float2{y, z}; } if (iThread == 0) { From 59d0354cfd68e85cf9bf68f18a9db8e02a93e863 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 14:47:53 +0100 Subject: [PATCH 06/32] GPU: Remove obsolete workaround for CUDA bug --- GPU/Common/GPUCommonMath.h | 1 - 1 file changed, 1 deletion(-) diff --git a/GPU/Common/GPUCommonMath.h b/GPU/Common/GPUCommonMath.h index 6ccdeb90e89e6..c337d45a30033 100644 --- a/GPU/Common/GPUCommonMath.h +++ b/GPU/Common/GPUCommonMath.h @@ -287,7 +287,6 @@ GPUdi() constexpr T GPUCommonMath::nextMultipleOf(T val) } else { return (val + I - 1) & ~(T)(I - 1); } - return 0; // BUG: Cuda complains about missing return value with constexpr if } GPUdi() constexpr float GPUCommonMath::Modf(float x, float y) { return GPUCA_CHOICE(fmodf(x, y), fmodf(x, y), fmod(x, y)); } From cbe6a1db225f79f61def71511ee96c3c51200031 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 14:48:06 +0100 Subject: [PATCH 07/32] GPU: Can use builtins for OpenCL SPIR-V now --- GPU/Common/GPUCommonMath.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GPU/Common/GPUCommonMath.h b/GPU/Common/GPUCommonMath.h index c337d45a30033..e7ccf1e5c166f 100644 --- a/GPU/Common/GPUCommonMath.h +++ b/GPU/Common/GPUCommonMath.h @@ -429,7 +429,7 @@ GPUdi() constexpr uint32_t GPUCommonMath::Ctz(uint32_t x) GPUdi() constexpr uint32_t GPUCommonMath::Popcount(uint32_t x) { -#if (defined(__GNUC__) || defined(__clang__) || defined(__CUDACC__) || defined(__HIPCC__)) && !defined(__OPENCL__) // TODO: remove OPENCL when reported SPIR-V bug is fixed +#if (defined(__GNUC__) || defined(__clang__) || defined(__CUDACC__) || defined(__HIPCC__)) // use builtin if available return GPUCA_CHOICE(__builtin_popcount(x), __popc(x), __builtin_popcount(x)); #else @@ -469,7 +469,7 @@ GPUdi() constexpr uint32_t GPUCommonMath::Ctz64(uint64_t x) GPUdi() constexpr uint32_t GPUCommonMath::Popcount64(uint64_t x) { -#if (defined(__GNUC__) || defined(__clang__) || defined(__CUDACC__) || defined(__HIPCC__)) && !defined(__OPENCL__) // TODO: remove OPENCL when reported SPIR-V bug is fixed +#if (defined(__GNUC__) || defined(__clang__) || defined(__CUDACC__) || defined(__HIPCC__)) // use builtin if available return GPUCA_CHOICE(__builtin_popcountll(x), __popcll(x), __builtin_popcountll(x)); #else From dd4fb7cc8792db6462514c1548a424019eff6967 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 15:22:29 +0100 Subject: [PATCH 08/32] GPU: Fix namespace for gGPUConstantMemBuffer --- GPU/GPUTracking/Base/GPUConstantMem.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/GPU/GPUTracking/Base/GPUConstantMem.h b/GPU/GPUTracking/Base/GPUConstantMem.h index 05547262ce100..b18382e976f62 100644 --- a/GPU/GPUTracking/Base/GPUConstantMem.h +++ b/GPU/GPUTracking/Base/GPUConstantMem.h @@ -91,12 +91,12 @@ union GPUConstantMemCopyable { #if defined(GPUCA_GPUCODE) static GPUglobalconstexpr() size_t gGPUConstantMemBufferSize = (sizeof(GPUConstantMem) + sizeof(uint4) - 1); #endif -} // namespace o2::gpu + #if defined(GPUCA_HAS_GLOBAL_SYMBOL_CONSTANT_MEM) -GPUconstant() o2::gpu::GPUConstantMemCopyable gGPUConstantMemBuffer; // TODO: This should go into o2::gpu namespace, but then CUDA or HIP would not find the symbol -#endif // GPUCA_HAS_GLOBAL_SYMBOL_CONSTANT_MEM -namespace o2::gpu -{ +extern "C" { // C linkage for the unmangled symbol name that the RTC looks up, the braces make it a definition, not a declaration +GPUconstant() GPUConstantMemCopyable gGPUConstantMemBuffer; +} +#endif // Must be placed here, to avoid circular header dependency GPUdi() GPUconstantref() const GPUConstantMem* GPUProcessor::GetConstantMem() const From 712045094724ffa055c41881a1189ad432bf505a Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 16:24:15 +0100 Subject: [PATCH 09/32] GPU: Move some tracking-related code from GPUReconstruction to GPUChainTracking --- GPU/GPUTracking/Base/GPUReconstruction.cxx | 7 ------- GPU/GPUTracking/Global/GPUChainTracking.cxx | 21 +++++++++++---------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/GPU/GPUTracking/Base/GPUReconstruction.cxx b/GPU/GPUTracking/Base/GPUReconstruction.cxx index fbb8cfb5ff77e..557ccbf750a5b 100644 --- a/GPU/GPUTracking/Base/GPUReconstruction.cxx +++ b/GPU/GPUTracking/Base/GPUReconstruction.cxx @@ -94,13 +94,6 @@ GPUReconstruction::GPUReconstruction(const GPUSettingsDeviceBackend& cfg) : mHos } param().SetDefaults(mGRPSettings.get()); mMemoryScalers.reset(new GPUMemorySizeScalers); - for (uint32_t i = 0; i < NSECTORS; i++) { - processors()->tpcTrackers[i].SetSector(i); // TODO: Move to a better place - processors()->tpcClusterer[i].mISector = i; -#ifdef GPUCA_HAS_ONNX - processors()->tpcNNClusterer[i].mISector = i; -#endif - } } GPUReconstruction::~GPUReconstruction() diff --git a/GPU/GPUTracking/Global/GPUChainTracking.cxx b/GPU/GPUTracking/Global/GPUChainTracking.cxx index b66cc7d49dcc9..48f89958fbc55 100644 --- a/GPU/GPUTracking/Global/GPUChainTracking.cxx +++ b/GPU/GPUTracking/Global/GPUChainTracking.cxx @@ -84,10 +84,19 @@ void GPUChainTracking::RegisterPermanentMemoryAndProcessors() } mRec->RegisterGPUProcessor(mInputsHost.get(), mRec->IsGPU()); - if (GetRecoSteps() & RecoStep::TPCSectorTracking) { - for (uint32_t i = 0; i < NSECTORS; i++) { + for (uint32_t i = 0; i < NSECTORS; i++) { + if (GetRecoSteps() & RecoStep::TPCSectorTracking) { + processors()->tpcTrackers[i].SetSector(i); mRec->RegisterGPUProcessor(&processors()->tpcTrackers[i], GetRecoStepsGPU() & RecoStep::TPCSectorTracking); } + if (GetRecoSteps() & RecoStep::TPCClusterFinding) { + processors()->tpcClusterer[i].mISector = i; + mRec->RegisterGPUProcessor(&processors()->tpcClusterer[i], GetRecoStepsGPU() & RecoStep::TPCClusterFinding); +#ifdef GPUCA_HAS_ONNX + processors()->tpcNNClusterer[i].mISector = i; + mRec->RegisterGPUProcessor(&processors()->tpcNNClusterer[i], GetRecoStepsGPU() & RecoStep::TPCClusterFinding); +#endif + } } if (GetRecoSteps() & RecoStep::TPCMerging) { mRec->RegisterGPUProcessor(&processors()->tpcMerger, GetRecoStepsGPU() & RecoStep::TPCMerging); @@ -104,14 +113,6 @@ void GPUChainTracking::RegisterPermanentMemoryAndProcessors() if (GetRecoSteps() & RecoStep::TPCDecompression) { mRec->RegisterGPUProcessor(&processors()->tpcDecompressor, GetRecoStepsGPU() & RecoStep::TPCDecompression); } - if (GetRecoSteps() & RecoStep::TPCClusterFinding) { - for (uint32_t i = 0; i < NSECTORS; i++) { - mRec->RegisterGPUProcessor(&processors()->tpcClusterer[i], GetRecoStepsGPU() & RecoStep::TPCClusterFinding); -#ifdef GPUCA_HAS_ONNX - mRec->RegisterGPUProcessor(&processors()->tpcNNClusterer[i], GetRecoStepsGPU() & RecoStep::TPCClusterFinding); -#endif - } - } if (GetRecoSteps() & RecoStep::Refit) { mRec->RegisterGPUProcessor(&processors()->trackingRefit, GetRecoStepsGPU() & RecoStep::Refit); } From 3156bd61ee238e1df11aa2ae7e3780cb4e51bfb9 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 18:17:29 +0100 Subject: [PATCH 10/32] GPU: Add overflow check for GPU direct memory --- GPU/GPUTracking/Base/GPUReconstruction.cxx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/GPU/GPUTracking/Base/GPUReconstruction.cxx b/GPU/GPUTracking/Base/GPUReconstruction.cxx index 557ccbf750a5b..8cb4b544b029c 100644 --- a/GPU/GPUTracking/Base/GPUReconstruction.cxx +++ b/GPU/GPUTracking/Base/GPUReconstruction.cxx @@ -746,20 +746,23 @@ void* GPUReconstruction::AllocateDirectMemory(size_t size, int32_t type) void*& pool = (type & GPUMemoryResource::MEMORY_GPU) ? mDeviceMemoryPool : mHostMemoryPool; void*& poolend = (type & GPUMemoryResource::MEMORY_GPU) ? mDeviceMemoryPoolEnd : mHostMemoryPoolEnd; char* retVal; - if ((type & GPUMemoryResource::MEMORY_STACK)) { - poolend = (char*)poolend - size; // TODO: Implement overflow check + if (size > (size_t)((char*)poolend - (char*)pool)) { + GPUError("Insufficient direct memory: requested %zu, available %td bytes", size, ptrDiff(poolend, pool)); + throw std::bad_alloc(); + } else if ((type & GPUMemoryResource::MEMORY_STACK)) { + poolend = (char*)poolend - size; poolend = (char*)poolend - GPUProcessor::getAlignmentMod(poolend); retVal = (char*)poolend; } else { GPUProcessor::computePointerWithAlignment(pool, retVal, size); } if (pool > poolend) { - GPUError("Insufficient unmanaged memory: missing %ld bytes", ptrDiff(pool, poolend)); + GPUError("Insufficient direct memory: missing %td bytes", ptrDiff(pool, poolend)); throw std::bad_alloc(); } UpdateMaxMemoryUsed(); if (GetProcessingSettings().allocDebugLevel >= 2) { - std::cout << "Allocated (unmanaged " << ((type & GPUMemoryResource::MEMORY_GPU) ? "gpu" : "host") << "): " << size << " - available: " << ptrDiff(poolend, pool) << "\n"; + std::cout << "Allocated (direct " << ((type & GPUMemoryResource::MEMORY_GPU) ? "gpu" : "host") << "): " << size << " - available: " << ptrDiff(poolend, pool) << "\n"; } return retVal; } From 9753fac58aa5fa8ce0d79e0781469a4525ac6c0b Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 18:36:31 +0100 Subject: [PATCH 11/32] GPU: Ensure alignment and ordering of GPUParam occupancy struct --- .../SpacePoints/src/TrackInterpolation.cxx | 8 ++++---- GPU/GPUTracking/Base/GPUParam.cxx | 6 +++--- GPU/GPUTracking/Base/GPUParam.h | 9 ++++++--- GPU/GPUTracking/Base/GPUParam.inc | 10 +++++----- GPU/GPUTracking/Base/GPUReconstructionCPU.cxx | 18 +++++------------- .../Interface/GPUO2InterfaceUtils.cxx | 6 +++--- GPU/GPUTracking/Merger/GPUTPCGMMergerDump.cxx | 4 ++-- 7 files changed, 28 insertions(+), 33 deletions(-) diff --git a/Detectors/TPC/calibration/SpacePoints/src/TrackInterpolation.cxx b/Detectors/TPC/calibration/SpacePoints/src/TrackInterpolation.cxx index 64d6156365517..6c4e6011fafc2 100644 --- a/Detectors/TPC/calibration/SpacePoints/src/TrackInterpolation.cxx +++ b/Detectors/TPC/calibration/SpacePoints/src/TrackInterpolation.cxx @@ -554,7 +554,7 @@ void TrackInterpolation::interpolateTrack(int iSeed) mCacheDEDX[row].first = std::min(clTPC.getQtot(), UINT16_MAX); mCacheDEDX[row].second = clTPC.getQmax(); int imb = int(clTPC.getTime() * mNTPCOccBinLengthInv); - if (imb < mTPCParam->occupancyMapSize) { + if (imb < mTPCParam->occupancy.mapSize) { multBins[row] = 1 + std::max(0, imb); } } @@ -799,7 +799,7 @@ void TrackInterpolation::interpolateTrack(int iSeed) if (--mltBinMin >= 0) { // we were offsetting bin IDs by 1! float avMlt = 0; for (int ib = mltBinMin; ib < mltBinMax; ib++) { - avMlt += mTPCParam->occupancyMap[ib]; + avMlt += mTPCParam->occupancy.map[ib]; } avMlt /= (mltBinMax - mltBinMin); trackData.setMultStack(avMlt, ist); @@ -1087,7 +1087,7 @@ void TrackInterpolation::extrapolateTrack(int iSeed) rowPrev = row; } int imb = int(cl.getTime() * mNTPCOccBinLengthInv); - if (imb < mTPCParam->occupancyMapSize) { + if (imb < mTPCParam->occupancy.mapSize) { multBins[row] = 1 + std::max(0, imb); } ++nMeasurements; @@ -1182,7 +1182,7 @@ void TrackInterpolation::extrapolateTrack(int iSeed) if (--mltBinMin >= 0) { // we were offsetting bin IDs by 1! float avMlt = 0; for (int ib = mltBinMin; ib < mltBinMax; ib++) { - avMlt += mTPCParam->occupancyMap[ib]; + avMlt += mTPCParam->occupancy.map[ib]; } avMlt /= (mltBinMax - mltBinMin); trackData.setMultStack(avMlt, ist); diff --git a/GPU/GPUTracking/Base/GPUParam.cxx b/GPU/GPUTracking/Base/GPUParam.cxx index b7f8ccb9fa668..d5bcd098a877c 100644 --- a/GPU/GPUTracking/Base/GPUParam.cxx +++ b/GPU/GPUTracking/Base/GPUParam.cxx @@ -34,9 +34,9 @@ void GPUParam::SetDefaults(float solenoidBz, bool assumeConstantBz) { memset((void*)this, 0, sizeof(*this)); new (&rec) GPUSettingsRec; - occupancyMap = nullptr; - occupancyMapSize = 0; - occupancyTotal = 0; + occupancy.map = nullptr; + occupancy.mapSize = 0; + occupancy.total = 0; #ifndef GPUCA_RUN2 const float kErrorsY[4] = {0.06, 0.24, 0.12, 0.1}; diff --git a/GPU/GPUTracking/Base/GPUParam.h b/GPU/GPUTracking/Base/GPUParam.h index 5fab4b5e0fb54..90531bef8cece 100644 --- a/GPU/GPUTracking/Base/GPUParam.h +++ b/GPU/GPUTracking/Base/GPUParam.h @@ -56,9 +56,12 @@ struct GPUParam_t { int32_t tpcCutTimeBin; GPUTPCGMPolynomialField polynomialField; // Polynomial approx. of magnetic field for TPC GM - const uint32_t* occupancyMap; // Ptr to TPC occupancy map - uint32_t occupancyTotal; // Total occupancy in the TPC (nCl / nHbf) - uint32_t occupancyMapSize; // Size of occupancy map + + struct occupancyStruct { + const uint32_t* map; // Ptr to TPC occupancy map + uint32_t total; // Total occupancy in the TPC (nCl / nHbf) + uint32_t mapSize; // Size of occupancy map + } occupancy; protected: #ifndef GPUCA_RUN2 diff --git a/GPU/GPUTracking/Base/GPUParam.inc b/GPU/GPUTracking/Base/GPUParam.inc index 566592bdd8d61..762afc0ce0968 100644 --- a/GPU/GPUTracking/Base/GPUParam.inc +++ b/GPU/GPUTracking/Base/GPUParam.inc @@ -112,12 +112,12 @@ GPUdi() float GPUParam::GetSystematicClusterErrorIFC2(float x, float y, float z, GPUdi() float GPUParam::GetSystematicClusterErrorC122(float x, float y, uint8_t sector) const { const float dx = x - 83.f; - if (dx > occupancyTotal * rec.tpc.sysClusErrorC12Box) { + if (dx > occupancy.total * rec.tpc.sysClusErrorC12Box) { return 0.f; } constexpr float dEdgeInv = 18.f / CAMath::Pi(); const float dy = (sector == (GPUTPCGeometry::NSECTORS / 2 + 1) ? 0.5f : -0.5f) * (y / x) * dEdgeInv + 0.5f; - const float errC12 = rec.tpc.sysClusErrorC12Norm * occupancyTotal * dy; + const float errC12 = rec.tpc.sysClusErrorC12Norm * occupancy.total * dy; return errC12 * errC12; } @@ -210,11 +210,11 @@ GPUdi() void GPUParam::UpdateClusterError2ByState(int16_t clusterState, float& E GPUdi() float GPUParam::GetUnscaledMult(float time) const { - if (!occupancyMap) { + if (!occupancy.map) { return 0.f; } - const uint32_t bin = CAMath::Min(occupancyMapSize - 1, CAMath::Max(0.f, time / rec.tpc.occupancyMapTimeBins)); - return occupancyMap[bin]; + const uint32_t bin = CAMath::Min(occupancy.mapSize - 1, CAMath::Max(0.f, time / rec.tpc.occupancyMapTimeBins)); + return occupancy.map[bin]; } GPUdi() bool GPUParam::rejectEdgeClusterByY(float uncorrectedY, int32_t iRow, float trackSigmaY) const diff --git a/GPU/GPUTracking/Base/GPUReconstructionCPU.cxx b/GPU/GPUTracking/Base/GPUReconstructionCPU.cxx index b7983a8c81ec1..dfec97fe1a158 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionCPU.cxx +++ b/GPU/GPUTracking/Base/GPUReconstructionCPU.cxx @@ -359,20 +359,12 @@ void GPUReconstructionCPU::UpdateParamOccupancyMap(const uint32_t* mapHost, cons if (mapHost && mapSize != GPUTPCClusterOccupancyMapBin::getNBins(param())) { throw std::runtime_error("Updating occupancy map with object of invalid size"); } - param().occupancyMap = mapHost; - param().occupancyMapSize = mapSize; - param().occupancyTotal = occupancyTotal; + param().occupancy.map = mapHost; + param().occupancy.total = occupancyTotal; + param().occupancy.mapSize = mapSize; if (IsGPU()) { - if (!((size_t)¶m().occupancyMapSize - (size_t)¶m().occupancyMap == sizeof(param().occupancyMap) + sizeof(param().occupancyTotal) && sizeof(param().occupancyMap) == sizeof(void*) && sizeof(param().occupancyTotal) == sizeof(uint32_t))) { // TODO: Make static assert, and check alignment - throw std::runtime_error("occupancy data not consecutive in GPUParam"); - } - struct tmpOccuapncyParam { - const void* ptr; - uint32_t total; - uint32_t size; - }; - tmpOccuapncyParam tmp = {mapGPU, occupancyTotal, mapSize}; + GPUParam::occupancyStruct tmp = {mapGPU, occupancyTotal, mapSize}; const auto holdContext = GetThreadContext(); - WriteToConstantMemory((char*)&processors()->param.occupancyMap - (char*)processors(), &tmp, sizeof(tmp), stream, ev); + WriteToConstantMemory((char*)&processors()->param.occupancy - (char*)processors(), &tmp, sizeof(tmp), stream, ev); } } diff --git a/GPU/GPUTracking/Interface/GPUO2InterfaceUtils.cxx b/GPU/GPUTracking/Interface/GPUO2InterfaceUtils.cxx index f0efaf48c8725..b5a6ef14bd907 100644 --- a/GPU/GPUTracking/Interface/GPUO2InterfaceUtils.cxx +++ b/GPU/GPUTracking/Interface/GPUO2InterfaceUtils.cxx @@ -130,10 +130,10 @@ void GPUO2InterfaceUtils::paramUseExternalOccupancyMap(GPUParam* param, uint32_t throw std::runtime_error("Occupancy map has invalid paramters occupancyMapTimeBins and occupancyMapTimeBinsAverage"); } if (occupancymap) { - param->occupancyTotal = *occupancymap; + param->occupancy.total = *occupancymap; if (param->rec.tpc.occupancyMapTimeBins) { - param->occupancyMap = occupancymap + 2; - param->occupancyMapSize = GPUTPCClusterOccupancyMapBin::getNBins(*param); + param->occupancy.map = occupancymap + 2; + param->occupancy.mapSize = GPUTPCClusterOccupancyMapBin::getNBins(*param); } } } diff --git a/GPU/GPUTracking/Merger/GPUTPCGMMergerDump.cxx b/GPU/GPUTracking/Merger/GPUTPCGMMergerDump.cxx index cabe3eb7db923..6fd631dc71ba7 100644 --- a/GPU/GPUTracking/Merger/GPUTPCGMMergerDump.cxx +++ b/GPU/GPUTracking/Merger/GPUTPCGMMergerDump.cxx @@ -381,7 +381,7 @@ std::vector GPUTPCGMMerger::StreamerOccupancyBin(int32_t iSector, int3 const int32_t bin = CAMath::Max(0.f, time / Param().rec.tpc.occupancyMapTimeBins); for (int32_t i = 0; i < 1 + 2 * size; i++) { const int32_t mybin = bin + i - size; - retVal[i] = (mybin >= 0 && mybin < (int32_t)GPUTPCClusterOccupancyMapBin::getNBins(Param())) ? Param().occupancyMap[mybin] : 0; + retVal[i] = (mybin >= 0 && mybin < (int32_t)GPUTPCClusterOccupancyMapBin::getNBins(Param())) ? Param().occupancy.map[mybin] : 0; } #endif return retVal; @@ -406,7 +406,7 @@ void GPUTPCGMMerger::DebugStreamerUpdate(int32_t iTrk, int32_t ihit, float xx, f int32_t iRow = cluster.row; float unscaledMult = (time >= 0.f ? Param().GetUnscaledMult(time) / GPUTPCGeometry::Row2X(iRow) : 0.f); const float clAlpha = Param().Alpha(cluster.sector); - uint32_t occupancyTotal = Param().occupancyTotal; + uint32_t occupancyTotal = Param().occupancy.total; o2::utils::DebugStreamer::instance()->getStreamer("debug_update_track", "UPDATE") << o2::utils::DebugStreamer::instance()->getUniqueTreeName("tree_update_track").data() << "iTrk=" << iTrk << "ihit=" << ihit From 4e6115ad28ba35bb667e3c405a54cc43052c8a0b Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 23:11:36 +0100 Subject: [PATCH 12/32] GPU: Get rid of gpu_reconstruction_kernels namespace --- GPU/GPUTracking/Base/GPUReconstruction.cxx | 2 +- GPU/GPUTracking/Base/GPUReconstruction.h | 13 +++++-------- .../Base/GPUReconstructionProcessing.cxx | 4 ++-- GPU/GPUTracking/Base/GPUReconstructionProcessing.h | 13 ++----------- GPU/GPUTracking/Global/GPUChainTracking.cxx | 8 ++++---- .../Global/GPUChainTrackingClusterizer.cxx | 4 ++-- .../Global/GPUChainTrackingCompression.cxx | 6 +++--- .../Global/GPUChainTrackingDebugAndProfiling.cxx | 4 ++-- GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx | 2 +- GPU/GPUTracking/Global/GPUChainTrackingRefit.cxx | 2 +- .../Global/GPUChainTrackingSectorTracker.cxx | 2 +- GPU/GPUTracking/Global/GPUChainTrackingTRD.cxx | 2 +- .../Global/GPUChainTrackingTransformation.cxx | 2 +- 13 files changed, 26 insertions(+), 38 deletions(-) diff --git a/GPU/GPUTracking/Base/GPUReconstruction.cxx b/GPU/GPUTracking/Base/GPUReconstruction.cxx index 8cb4b544b029c..e788b0d650af3 100644 --- a/GPU/GPUTracking/Base/GPUReconstruction.cxx +++ b/GPU/GPUTracking/Base/GPUReconstruction.cxx @@ -431,7 +431,7 @@ int32_t GPUReconstruction::InitPhaseAfterDevice() void GPUReconstruction::WriteConstantParams(int32_t stream) { if (IsGPU()) { - const auto threadContext = GetThreadContext(); + const auto holdContext = GetThreadContext(); WriteToConstantMemory(ptrDiff(&processors()->param, processors()), ¶m(), sizeof(param()), stream); } } diff --git a/GPU/GPUTracking/Base/GPUReconstruction.h b/GPU/GPUTracking/Base/GPUReconstruction.h index 3a2d644ac71f1..1a23c67add845 100644 --- a/GPU/GPUTracking/Base/GPUReconstruction.h +++ b/GPU/GPUTracking/Base/GPUReconstruction.h @@ -62,12 +62,6 @@ struct GPUSettingsRec; struct GPUSettingsRecDynamic; struct GPUMemoryReuse; -namespace gpu_reconstruction_kernels -{ -struct deviceEvent; -class threadContext; -} // namespace gpu_reconstruction_kernels - class GPUReconstruction { protected: @@ -140,6 +134,9 @@ class GPUReconstruction Device = 1, Auto = -1 }; + struct deviceEvent; + struct threadContext; + // Global steering functions template T* AddChain(Args... args); @@ -278,7 +275,7 @@ class GPUReconstruction int32_t InitPhaseAfterDevice(); 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; + virtual size_t WriteToConstantMemory(size_t offset, const void* src, size_t size, int32_t stream = -1, deviceEvent* ev = nullptr) = 0; void UpdateMaxMemoryUsed(); int32_t EnqueuePipeline(bool terminate = false); GPUChain* GetNextChainInQueue(); @@ -288,7 +285,7 @@ class GPUReconstruction virtual int32_t unregisterMemoryForGPU_internal(const void* ptr) = 0; // Management for GPU thread contexts - virtual std::unique_ptr GetThreadContext() = 0; + virtual std::unique_ptr GetThreadContext() = 0; // Private helpers for library loading static std::shared_ptr* GetLibraryInstance(DeviceType type, bool verbose); diff --git a/GPU/GPUTracking/Base/GPUReconstructionProcessing.cxx b/GPU/GPUTracking/Base/GPUReconstructionProcessing.cxx index a511102a492ef..935db0e640857 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionProcessing.cxx +++ b/GPU/GPUTracking/Base/GPUReconstructionProcessing.cxx @@ -140,8 +140,8 @@ std::unique_ptr GPUReconstructionPro return std::make_unique(); } -gpu_reconstruction_kernels::threadContext::threadContext() = default; -gpu_reconstruction_kernels::threadContext::~threadContext() = default; +GPUReconstruction::threadContext::threadContext() = default; +GPUReconstruction::threadContext::~threadContext() = default; const std::vector GPUReconstructionProcessing::mKernelNames = { #define GPUCA_KRNL(x_class, ...) GPUCA_M_STR(GPUCA_M_KRNL_NAME(x_class)), diff --git a/GPU/GPUTracking/Base/GPUReconstructionProcessing.h b/GPU/GPUTracking/Base/GPUReconstructionProcessing.h index 3d9507e48e292..1c4c45f410410 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionProcessing.h +++ b/GPU/GPUTracking/Base/GPUReconstructionProcessing.h @@ -31,9 +31,7 @@ namespace o2::gpu struct GPUDefParameters; -namespace gpu_reconstruction_kernels // TODO: Get rid of this namespace -{ -struct deviceEvent { +struct GPUReconstruction::deviceEvent { constexpr deviceEvent() = default; constexpr deviceEvent(std::nullptr_t p) : v(nullptr) {}; template @@ -57,23 +55,16 @@ struct deviceEvent { void* v = nullptr; // We use only pointers anyway, and since cl_event and cudaEvent_t and hipEvent_t are actually pointers, we can cast them to deviceEvent (void*) this way. }; -class threadContext -{ - public: +struct GPUReconstruction::threadContext { threadContext(); virtual ~threadContext(); }; -} // namespace gpu_reconstruction_kernels - class GPUReconstructionProcessing : public GPUReconstruction { public: ~GPUReconstructionProcessing() override; - using deviceEvent = gpu_reconstruction_kernels::deviceEvent; - using threadContext = gpu_reconstruction_kernels::threadContext; - struct RecoStepTimerMeta { HighResTimer timerToGPU; HighResTimer timerToHost; diff --git a/GPU/GPUTracking/Global/GPUChainTracking.cxx b/GPU/GPUTracking/Global/GPUChainTracking.cxx index 48f89958fbc55..5f1b7a6f28ae9 100644 --- a/GPU/GPUTracking/Global/GPUChainTracking.cxx +++ b/GPU/GPUTracking/Global/GPUChainTracking.cxx @@ -335,7 +335,7 @@ bool GPUChainTracking::ValidateSettings() int32_t GPUChainTracking::Init() { - const auto& threadContext = GetThreadContext(); + const auto& holdContext = GetThreadContext(); if (GetProcessingSettings().debugLevel >= 1) { printf("Enabled Reconstruction Steps: 0x%x (on GPU: 0x%x)", (int32_t)GetRecoSteps().get(), (int32_t)GetRecoStepsGPU().get()); for (uint32_t i = 0; i < sizeof(gpudatatypes::RECO_STEP_NAMES) / sizeof(gpudatatypes::RECO_STEP_NAMES[0]); i++) { @@ -687,7 +687,7 @@ int32_t GPUChainTracking::RunChain() if (GetProcessingSettings().autoAdjustHostThreads && !mRec->IsGPU()) { mRec->SetNActiveThreads(-1); } - const auto threadContext = GetThreadContext(); + const auto holdContext = GetThreadContext(); if (GetProcessingSettings().runCompressionStatistics && mCompressionStatistics == nullptr) { mCompressionStatistics.reset(new GPUTPCClusterStatistics); } @@ -909,7 +909,7 @@ int32_t GPUChainTracking::CheckErrorCodes(bool cpuOnly, bool forceShowErrors, st bool hasDebugError = false; for (int32_t i = 0; i < 1 + (!cpuOnly && mRec->IsGPU()); i++) { if (i) { - const auto& threadContext = GetThreadContext(); + const auto& holdContext = GetThreadContext(); if (GetProcessingSettings().doublePipeline) { TransferMemoryResourceLinkToHost(RecoStep::NoRecoStep, mInputsHost->mResourceErrorCodes, 0); SynchronizeStream(0); @@ -975,7 +975,7 @@ void GPUChainTracking::ClearErrorCodes(bool cpuOnly) { processors()->errorCodes.clear(); if (mRec->IsGPU() && !cpuOnly) { - const auto& threadContext = GetThreadContext(); + const auto& holdContext = GetThreadContext(); WriteToConstantMemory(RecoStep::NoRecoStep, (char*)&processors()->errorCodes - (char*)processors(), &processorsShadow()->errorCodes, sizeof(processorsShadow()->errorCodes), 0); TransferMemoryResourceLinkToGPU(RecoStep::NoRecoStep, mInputsHost->mResourceErrorCodes, 0); } diff --git a/GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx b/GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx index 7d76c5abbe421..fc10e672b5264 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx @@ -655,7 +655,7 @@ int32_t GPUChainTracking::RunTPCClusterizer_prepare(bool restorePointers, const processorsShadow()->ioPtrs.clustersNative = mCFContext->ptrClusterNativeSave; return 0; } - const auto& threadContext = GetThreadContext(); + const auto& holdContext = GetThreadContext(); mRec->MemoryScalers()->nTPCdigits = 0; if (mCFContext == nullptr) { mCFContext.reset(new GPUTPCCFChainContext); @@ -763,7 +763,7 @@ int32_t GPUChainTracking::RunTPCClusterizer(bool synchronizeOutput) int32_t tpcTimeBinCut = (mUpdateNewCalibObjects && mNewCalibValues->newTPCTimeBinCut) ? mNewCalibValues->tpcTimeBinCut : param().tpcCutTimeBin; mRec->PushNonPersistentMemory(qStr2Tag("TPCCLUST")); - const auto& threadContext = GetThreadContext(); + const auto& holdContext = GetThreadContext(); const bool doGPU = GetRecoStepsGPU() & RecoStep::TPCClusterFinding; GPUTPCExtraADC extraADCs; diff --git a/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx b/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx index 5d7a785b7a25e..2caf7b3df4e54 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingCompression.cxx @@ -41,7 +41,7 @@ int32_t GPUChainTracking::RunTPCCompression() int32_t gatherMode = mRec->GetProcessingSettings().tpcCompressionGatherMode == -1 ? mRec->getGPUParameters(doGPU).par_COMP_GATHER_MODE : mRec->GetProcessingSettings().tpcCompressionGatherMode; GPUTPCCompression& Compressor = processors()->tpcCompressor; GPUTPCCompression& CompressorShadow = doGPU ? processorsShadow()->tpcCompressor : Compressor; - const auto& threadContext = GetThreadContext(); + const auto& holdContext = GetThreadContext(); if (mPipelineFinalizationCtx && GetProcessingSettings().doublePipelineClusterizer) { RecordMarker(&mEvents->single, 0); } @@ -239,7 +239,7 @@ int32_t GPUChainTracking::RunTPCDecompression() } if (GetProcessingSettings().tpcUseOldCPUDecoding) { const bool runFiltering = needFullFiltering || runTimeBinCutFiltering; - const auto& threadContext = GetThreadContext(); + const auto& holdContext = GetThreadContext(); TPCClusterDecompressor decomp; auto allocatorFinal = [this](size_t size) { this->mInputsHost->mNClusterNative = this->mInputsShadow->mNClusterNative = size; @@ -279,7 +279,7 @@ int32_t GPUChainTracking::RunTPCDecompression() bool doGPU = GetRecoStepsGPU() & RecoStep::TPCDecompression; GPUTPCDecompression& Decompressor = processors()->tpcDecompressor; GPUTPCDecompression& DecompressorShadow = doGPU ? processorsShadow()->tpcDecompressor : Decompressor; - const auto& threadContext = GetThreadContext(); + const auto& holdContext = GetThreadContext(); CompressedClusters& inputGPU = Decompressor.mInputGPU; CompressedClusters& inputGPUShadow = DecompressorShadow.mInputGPU; diff --git a/GPU/GPUTracking/Global/GPUChainTrackingDebugAndProfiling.cxx b/GPU/GPUTracking/Global/GPUChainTrackingDebugAndProfiling.cxx index 565f094e7990b..15061ada83206 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingDebugAndProfiling.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingDebugAndProfiling.cxx @@ -195,7 +195,7 @@ void GPUChainTracking::PrintMemoryRelations() void GPUChainTracking::PrepareKernelDebugOutput() { #ifdef GPUCA_KERNEL_DEBUGGER_OUTPUT - const auto& threadContext = GetThreadContext(); + const auto& holdContext = GetThreadContext(); if (mRec->IsGPU()) { SetupGPUProcessor(&processors()->debugOutput, false); WriteToConstantMemory(RecoStep::NoRecoStep, (char*)&processors()->debugOutput - (char*)processors(), &processorsShadow()->debugOutput, sizeof(processors()->debugOutput), -1); @@ -208,7 +208,7 @@ void GPUChainTracking::PrepareKernelDebugOutput() void GPUChainTracking::PrintKernelDebugOutput() { #ifdef GPUCA_KERNEL_DEBUGGER_OUTPUT - const auto& threadContext = GetThreadContext(); + const auto& holdContext = GetThreadContext(); TransferMemoryResourcesToHost(RecoStep::NoRecoStep, &processors()->debugOutput, -1); processors()->debugOutput.Print(); #endif diff --git a/GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx b/GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx index 32cad4d62b82c..ef549fda636cb 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx @@ -101,7 +101,7 @@ int32_t GPUChainTracking::RunTPCTrackingMerger(bool synchronizeOutput) if (GetProcessingSettings().debugLevel >= 2) { GPUInfo("Running TPC Merger"); } - const auto& threadContext = GetThreadContext(); + const auto& holdContext = GetThreadContext(); SynchronizeGPU(); // Need to know the full number of sector tracks SetupGPUProcessor(&Merger, true); diff --git a/GPU/GPUTracking/Global/GPUChainTrackingRefit.cxx b/GPU/GPUTracking/Global/GPUChainTrackingRefit.cxx index eeabab6ed395f..62d35df61414c 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingRefit.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingRefit.cxx @@ -28,7 +28,7 @@ int32_t GPUChainTracking::RunRefit() GPUTrackingRefitProcessor& Refit = processors()->trackingRefit; GPUTrackingRefitProcessor& RefitShadow = doGPU ? processorsShadow()->trackingRefit : Refit; - [[maybe_unused]] const auto& threadContext = GetThreadContext(); + [[maybe_unused]] const auto& holdContext = GetThreadContext(); SetupGPUProcessor(&Refit, false); RefitShadow.SetPtrsFromGPUConstantMem(processorsShadow(), doGPU ? &processorsDevice()->param : nullptr); RefitShadow.SetPropagator(doGPU ? processorsShadow()->calibObjects.o2Propagator : GetO2Propagator()); diff --git a/GPU/GPUTracking/Global/GPUChainTrackingSectorTracker.cxx b/GPU/GPUTracking/Global/GPUChainTrackingSectorTracker.cxx index bcaaa92bddb12..b2fd37f0d2c94 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingSectorTracker.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingSectorTracker.cxx @@ -58,7 +58,7 @@ int32_t GPUChainTracking::RunTPCTrackingSectors() return (1); } - const auto& threadContext = GetThreadContext(); + const auto& holdContext = GetThreadContext(); int32_t retVal = RunTPCTrackingSectors_internal(); if (retVal) { diff --git a/GPU/GPUTracking/Global/GPUChainTrackingTRD.cxx b/GPU/GPUTracking/Global/GPUChainTrackingTRD.cxx index ca47d65b32cd4..7489f9eb87c09 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingTRD.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingTRD.cxx @@ -150,7 +150,7 @@ int32_t GPUChainTracking::DoTRDGPUTracking(T* externalInstance) int32_t useStream = 0; - const auto& threadContext = GetThreadContext(); + const auto& holdContext = GetThreadContext(); SetupGPUProcessor(Tracker, false); if (doGPU) { TrackerShadow->OverrideGPUGeometry(reinterpret_cast(mFlatObjectsDevice.mCalibObjects.trdGeometry)); diff --git a/GPU/GPUTracking/Global/GPUChainTrackingTransformation.cxx b/GPU/GPUTracking/Global/GPUChainTrackingTransformation.cxx index 46bcd6931c302..be73dfab87faa 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingTransformation.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingTransformation.cxx @@ -38,7 +38,7 @@ bool GPUChainTracking::NeedTPCClustersOnGPU() int32_t GPUChainTracking::ConvertNativeToClusterData() { mRec->PushNonPersistentMemory(qStr2Tag("TPCTRANS")); - const auto& threadContext = GetThreadContext(); + const auto& holdContext = GetThreadContext(); bool transferClusters = false; if (mRec->IsGPU() && !(mRec->GetRecoStepsGPU() & gpudatatypes::RecoStep::TPCClusterFinding) && NeedTPCClustersOnGPU()) { From 4648e2a8201e22a334e4e68a9476674d9bbecb04 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 23:14:53 +0100 Subject: [PATCH 13/32] GPU: Clean up leftovers from hipify conversion --- GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu index d81b1e2cdfb4a..574e9acdd1d31 100644 --- a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu +++ b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu @@ -331,11 +331,7 @@ int32_t GPUReconstructionCUDA::InitDevice_Runtime() } } -#ifndef __HIPCC__ // CUDA - dummyInitKernel<<>>(mDeviceMemoryBase); // TODO: Can't we just use the CUDA version and hipify will take care of the rest? -#else // HIP - hipLaunchKernelGGL(HIP_KERNEL_NAME(dummyInitKernel), dim3(mMultiprocessorCount), dim3(256), 0, 0, mDeviceMemoryBase); -#endif + dummyInitKernel<<>>(mDeviceMemoryBase); if (GetProcessingSettings().rtc.enable) { genAndLoadRTC(); From d1823ee34955732243a38109d28260eaf6288ba2 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 23:17:09 +0100 Subject: [PATCH 14/32] GPU CUDA: Remove pragmas from CUDA warning suppressions, which were fixed upstread --- .../Base/cuda/GPUReconstructionCUDAIncludesSystem.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAIncludesSystem.h b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAIncludesSystem.h index 263d6939909c8..90a674d203778 100644 --- a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAIncludesSystem.h +++ b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAIncludesSystem.h @@ -22,14 +22,11 @@ #include #include #include -#pragma GCC diagnostic push // FIXME: Is this still needed? -#pragma GCC diagnostic ignored "-Wshadow" #include #include #include #include #include -#pragma GCC diagnostic pop #include #include From d63e1ed167911a2cdab42a569a89c3e279e56fa6 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 23:21:03 +0100 Subject: [PATCH 15/32] GPU: Replace workarounds by [[maybe_unused]] --- GPU/GPUTracking/Base/GPUReconstructionConvert.cxx | 5 ++--- GPU/GPUTracking/Base/GPUReconstructionIO.h | 4 ++-- .../DataCompression/GPUTPCClusterRejection.h | 4 +--- GPU/GPUTracking/Global/GPUChainTrackingIO.cxx | 3 +-- .../TPCClusterFinder/GPUTPCNNClusterizer.cxx | 10 ++++------ 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/GPU/GPUTracking/Base/GPUReconstructionConvert.cxx b/GPU/GPUTracking/Base/GPUReconstructionConvert.cxx index 0b5e15303f22a..441c15de289cb 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionConvert.cxx +++ b/GPU/GPUTracking/Base/GPUReconstructionConvert.cxx @@ -1064,9 +1064,8 @@ inline uint32_t zsEncoderRun::run(std::vector* buffer, std::vectorbc : 0; int32_t orbitShift = ir ? ir->orbit : 0; - int32_t rawcru = 0; - int32_t rawendpoint = 0; - (void)(rawcru + rawendpoint); // avoid compiler warning + [[maybe_unused]] int32_t rawcru = 0; + [[maybe_unused]] int32_t rawendpoint = 0; encodeBitsFactor = (1 << (encodeBits - 10)); std::sort(tmpBuffer.begin(), tmpBuffer.end(), [this](const o2::tpc::Digit a, const o2::tpc::Digit b) { return sort(a, b); }); diff --git a/GPU/GPUTracking/Base/GPUReconstructionIO.h b/GPU/GPUTracking/Base/GPUReconstructionIO.h index 494e1cc308ed7..c1a656e9f61d3 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionIO.h +++ b/GPU/GPUTracking/Base/GPUReconstructionIO.h @@ -81,7 +81,8 @@ inline size_t GPUReconstruction::ReadData(FILE* fp, const T** entries, S* num, s return 0; } InOutPointerType inType; - size_t r, pos = ftell(fp); + [[maybe_unused]] size_t r; + size_t pos = ftell(fp); r = fread(&inType, sizeof(inType), 1, fp); if (r != 1 || inType != type) { fseek(fp, pos, SEEK_SET); @@ -101,7 +102,6 @@ inline size_t GPUReconstruction::ReadData(FILE* fp, const T** entries, S* num, s } numTotal += num[i]; } - (void)r; if (GetProcessingSettings().debugLevel >= 2) { GPUInfo("Read %zu %s", numTotal, IOTYPENAMES[type]); } diff --git a/GPU/GPUTracking/DataCompression/GPUTPCClusterRejection.h b/GPU/GPUTracking/DataCompression/GPUTPCClusterRejection.h index 8ec8c85c4c73f..2ac38ae236ba0 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCClusterRejection.h +++ b/GPU/GPUTracking/DataCompression/GPUTPCClusterRejection.h @@ -28,10 +28,8 @@ struct GPUTPCClusterRejection { } template - GPUdi() static constexpr bool GetRejectionStatus(int32_t attach, bool& physics, T* counts = nullptr, S* mev200 = nullptr) + GPUdi() static constexpr bool GetRejectionStatus(int32_t attach, bool& physics, [[maybe_unused]] T* counts = nullptr, [[maybe_unused]] S* mev200 = nullptr) { - (void)counts; // FIXME: Avoid incorrect -Wunused-but-set-parameter warning - (void)mev200; bool retVal = false; if (attach == 0) { retVal = false; diff --git a/GPU/GPUTracking/Global/GPUChainTrackingIO.cxx b/GPU/GPUTracking/Global/GPUChainTrackingIO.cxx index ac8cb2ba11736..c7aa8768cea4c 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingIO.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingIO.cxx @@ -168,7 +168,7 @@ int32_t GPUChainTracking::ReadData(const char* filename) } char buf[DUMP_HEADER_SIZE + 1] = ""; - size_t r = fread(buf, 1, DUMP_HEADER_SIZE, fp); + [[maybe_unused]] size_t r = fread(buf, 1, DUMP_HEADER_SIZE, fp); if (strncmp(DUMP_HEADER, buf, DUMP_HEADER_SIZE)) { GPUError("Invalid file header"); fclose(fp); @@ -265,7 +265,6 @@ int32_t GPUChainTracking::ReadData(const char* filename) GPUError("Error reading data file, reading incomplete"); return 1; } - (void)r; for (uint32_t i = 0; i < NSECTORS; i++) { for (uint32_t j = 0; j < mIOPtrs.nClusterData[i]; j++) { ptrClusterData[i][j].id = nClustersTotal++; diff --git a/GPU/GPUTracking/TPCClusterFinder/GPUTPCNNClusterizer.cxx b/GPU/GPUTracking/TPCClusterFinder/GPUTPCNNClusterizer.cxx index c041cfcc10121..5edc3afbc75e4 100644 --- a/GPU/GPUTracking/TPCClusterFinder/GPUTPCNNClusterizer.cxx +++ b/GPU/GPUTracking/TPCClusterFinder/GPUTPCNNClusterizer.cxx @@ -70,8 +70,7 @@ void* GPUTPCNNClusterizer::setIOPointers(void* mem) auto fmt = [](size_t bytes) -> const char* { static char buf[64]; double mb = (double)bytes / (1024.0 * 1024.0); - int n = snprintf(buf, sizeof(buf), "%zu bytes (%.3f MB)", bytes, mb); - (void)n; + [[maybe_unused]] int n = snprintf(buf, sizeof(buf), "%zu bytes (%.3f MB)", bytes, mb); return buf; }; @@ -136,10 +135,9 @@ void* GPUTPCNNClusterizer::setIOPointers(void* mem) double allocatedMB = static_cast(allocatedBytes) / (1024.0 * 1024.0); { char allocMsg[256]; - int nn = snprintf(allocMsg, sizeof(allocMsg), - "(NNCLUS, GPUTPCNNClusterizer, this=%p) Total scratch allocation in setIOPointers: %zu bytes (%.3f MB)", - (void*)this, (size_t)allocatedBytes, allocatedMB); - (void)nn; + [[maybe_unused]] int nn = snprintf(allocMsg, sizeof(allocMsg), + "(NNCLUS, GPUTPCNNClusterizer, this=%p) Total scratch allocation in setIOPointers: %zu bytes (%.3f MB)", + (void*)this, (size_t)allocatedBytes, allocatedMB); LOG(info) << allocMsg; } } From cd3b5bd84b1ce6bf5876124496c613e3a0aa8091 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 23:24:36 +0100 Subject: [PATCH 16/32] GPU: No need that TPCCompression knows about the merger or constant memory --- GPU/GPUTracking/DataCompression/GPUTPCCompression.cxx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/GPU/GPUTracking/DataCompression/GPUTPCCompression.cxx b/GPU/GPUTracking/DataCompression/GPUTPCCompression.cxx index 00f1f6500e9f0..3ecc7bb606c1e 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCCompression.cxx +++ b/GPU/GPUTracking/DataCompression/GPUTPCCompression.cxx @@ -17,7 +17,6 @@ #include "GPUO2DataTypes.h" #include "GPUMemorySizeScalers.h" #include "GPUDefParametersRuntime.h" -#include "GPUConstantMem.h" using namespace o2::gpu; @@ -124,8 +123,8 @@ void GPUTPCCompression::SetMaxData(const GPUTrackingInOutPointers& io) mMaxClusters = io.clustersNative->nClustersTotal; mMaxClusterFactorBase1024 = mMaxClusters > 100000000 ? mRec->MemoryScalers()->NTPCUnattachedHitsBase1024(mRec->GetParam().rec.tpc.rejectionStrategy) : 1024; mMaxClustersInCache = mMaxClusters * mMaxClusterFactorBase1024 / 1024; - mMaxTrackClusters = mRec->GetConstantMem().tpcMerger.NMergedTrackClusters(); // TODO: Why is this not using ioPtrs? Could remove GPUConstantMem.h include - mMaxTracks = mRec->GetConstantMem().tpcMerger.NMergedTracks(); + mMaxTrackClusters = io.nMergedTrackHits; + mMaxTracks = io.nMergedTracks; if (mMaxClusters % 16) { mMaxClusters += 16 - (mMaxClusters % 16); } From a6ac4a69988973abe31a1f7c64baa7f2916f04e3 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 23:28:58 +0100 Subject: [PATCH 17/32] GPU TPC: Deduplicate clusterNative state enums --- .../TPC/include/DataFormatsTPC/ClusterNative.h | 2 +- GPU/GPUTracking/DataTypes/GPUTPCGMMergedTrackHit.h | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/DataFormats/Detectors/TPC/include/DataFormatsTPC/ClusterNative.h b/DataFormats/Detectors/TPC/include/DataFormatsTPC/ClusterNative.h index 54dbb559709fa..926cff81dc838 100644 --- a/DataFormats/Detectors/TPC/include/DataFormatsTPC/ClusterNative.h +++ b/DataFormats/Detectors/TPC/include/DataFormatsTPC/ClusterNative.h @@ -53,7 +53,7 @@ namespace tpc * Not for permanent storage. */ struct ClusterNative { - // NOTE: These states must match those from GPUTPCGMMergedTrackHit! + // NOTE: GPUTPCGMMergedTrackHit uses these states, we must not add a state beyond 0x8, since it uses 0x10 and above for its own flags enum clusterState { flagSplitPad = 0x1, // Split in pad direction flagSplitTime = 0x2, // Split in time direction flagEdge = 0x4, // At edge of TPC sector diff --git a/GPU/GPUTracking/DataTypes/GPUTPCGMMergedTrackHit.h b/GPU/GPUTracking/DataTypes/GPUTPCGMMergedTrackHit.h index 789c1f00262f8..6d2e3977b347b 100644 --- a/GPU/GPUTracking/DataTypes/GPUTPCGMMergedTrackHit.h +++ b/GPU/GPUTracking/DataTypes/GPUTPCGMMergedTrackHit.h @@ -16,6 +16,7 @@ #define GPUTPCGMMERGEDTRACKHIT_H #include "GPUCommonDef.h" +#include "DataFormatsTPC/ClusterNative.h" namespace o2::gpu { @@ -23,13 +24,11 @@ struct GPUTPCGMMergedTrackHit { uint32_t num; uint8_t sector, row, state; - // NOTE: the lower states must match those from ClusterNative! - // TODO: take them directly from clusterNative header. - enum hitState { flagSplitPad = 0x1, - flagSplitTime = 0x2, - flagSplit = 0x3, - flagEdge = 0x4, - flagSingle = 0x8, + enum hitState { flagSplitPad = o2::tpc::ClusterNative::clusterState::flagSplitPad, + flagSplitTime = o2::tpc::ClusterNative::clusterState::flagSplitTime, + flagEdge = o2::tpc::ClusterNative::clusterState::flagEdge, + flagSingle = o2::tpc::ClusterNative::clusterState::flagSingle, + flagSplit = flagSplitPad | flagSplitTime, flagShared = 0x10, clustererAndSharedFlags = 0x1F, flagRejectDistance = 0x20, From 92aaa31027340650ad79d81ec65325981076ebf5 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Mon, 23 Nov 2026 23:32:41 +0100 Subject: [PATCH 18/32] GPU HIP: Remove obsolete performance workarounds for compiler issues --- .../SectorTracker/GPUTPCStartHitsSorter.cxx | 4 ---- .../SectorTracker/GPUTPCTrackletConstructor.cxx | 16 ---------------- 2 files changed, 20 deletions(-) diff --git a/GPU/GPUTracking/SectorTracker/GPUTPCStartHitsSorter.cxx b/GPU/GPUTracking/SectorTracker/GPUTPCStartHitsSorter.cxx index 8918c6cab5604..aeb101ffe469d 100644 --- a/GPU/GPUTracking/SectorTracker/GPUTPCStartHitsSorter.cxx +++ b/GPU/GPUTracking/SectorTracker/GPUTPCStartHitsSorter.cxx @@ -42,11 +42,7 @@ GPUdii() void GPUTPCStartHitsSorter::Thread<0>(int32_t nBlocks, int32_t nThreads GPUbarrier(); int32_t startOffset = s.mStartOffset; -#ifdef __HIPCC__ // TODO: Fixme - for (int32_t ir = -1; ++ir < (int32_t)s.mNRows;) { -#else for (uint32_t ir = 0; ir < s.mNRows; ir++) { -#endif GPUglobalref() GPUTPCHitId* const GPUrestrict() startHits = tracker.mTrackletStartHits; GPUglobalref() GPUTPCHitId* const GPUrestrict() tmpStartHits = tracker.mTrackletTmpStartHits + (s.mStartRow + ir) * tracker.mNMaxRowStartHits; diff --git a/GPU/GPUTracking/SectorTracker/GPUTPCTrackletConstructor.cxx b/GPU/GPUTracking/SectorTracker/GPUTPCTrackletConstructor.cxx index 2f89a998f8e9f..b076a0a9c0417 100644 --- a/GPU/GPUTracking/SectorTracker/GPUTPCTrackletConstructor.cxx +++ b/GPU/GPUTracking/SectorTracker/GPUTPCTrackletConstructor.cxx @@ -88,11 +88,7 @@ GPUd() void GPUTPCTrackletConstructor::StoreTracklet(int32_t /*nBlocks*/, int32_ tracklet.SetParam(tParam.GetParam()); int32_t w = tracker.CalculateHitWeight(r.mNHits, tParam.GetChi2()); tracklet.SetHitWeight(w); -#ifdef __HIPCC__ // Todo: fixme! - for (int32_t iRow = r.mFirstRow - 1; ++iRow <= (int32_t)r.mLastRow; /*iRow++*/) { -#else for (uint32_t iRow = r.mFirstRow; iRow <= r.mLastRow; iRow++) { -#endif calink ih = rowHits[iRow]; tracker.TrackletRowHits()[hitout + (iRow - r.mFirstRow)] = ih; if (ih != CALINK_INVAL && ih != CALINK_DEAD_CHANNEL) { @@ -313,20 +309,12 @@ GPUdic(2, 1) void GPUTPCTrackletConstructor::UpdateTracklet(int32_t /*nBlocks*/, row.Grid().GetBinArea(yUncorrected, zUncorrected + tParam.ZOffset(), CAMath::Sqrt(sy2), CAMath::Sqrt(sz2), bin, ny, nz); float ds = 1e6f; -#ifdef __HIPCC__ // Todo: fixme! - for (int32_t k = -1; ++k <= nz; /*k++*/) { -#else for (int32_t k = 0; k <= nz; k++) { -#endif int32_t nBinsY = row.Grid().Ny(); int32_t mybin = bin + k * nBinsY; uint32_t hitFst = firsthit[mybin]; uint32_t hitLst = firsthit[mybin + ny + 1]; -#ifdef __HIPCC__ // Todo: fixme! - for (uint32_t ih = hitFst - 1; ++ih < hitLst; /*ih++*/) { -#else for (uint32_t ih = hitFst; ih < hitLst; ih++) { -#endif cahit2 hh = hits[ih]; float y = y0 + hh.x * stepY; float z = z0 + hh.y * stepZ; @@ -420,11 +408,7 @@ GPUdic(2, 1) void GPUTPCTrackletConstructor::DoTracklet(GPUconstantref() GPUTPCT r.mNHits = 0; CADEBUG(printf("Start tracklet\n")); -#ifdef __HIPCC__ // Todo: fixme! - for (int32_t iStage = -1; ++iStage < 2; /*iStage++*/) { -#else for (int32_t iStage = 0; iStage < 2; iStage++) { -#endif for (; iRow != iRowEnd; iRow += r.mStage == 2 ? -1 : 1) { if (!r.mGo) { break; From 5dc5d30c8fd61c9d77a72c504bc8cbf0dab468c9 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Tue, 24 Nov 2026 10:47:33 +0100 Subject: [PATCH 19/32] GPU Standalone: Add testAsync option --- GPU/GPUTracking/Base/GPUParam.cxx | 2 +- GPU/GPUTracking/Definitions/GPUSettingsList.h | 2 +- .../Definitions/GPUSettingsListStandalone.h | 3 ++- GPU/GPUTracking/Global/GPUChainTracking.cxx | 14 ++++++++++++-- GPU/GPUTracking/Global/GPUChainTracking.h | 2 +- GPU/GPUTracking/Interface/GPUO2Interface.cxx | 2 +- .../Standalone/Benchmark/standalone.cxx | 6 +++--- 7 files changed, 21 insertions(+), 10 deletions(-) diff --git a/GPU/GPUTracking/Base/GPUParam.cxx b/GPU/GPUTracking/Base/GPUParam.cxx index d5bcd098a877c..3ac88150b64a3 100644 --- a/GPU/GPUTracking/Base/GPUParam.cxx +++ b/GPU/GPUTracking/Base/GPUParam.cxx @@ -107,7 +107,7 @@ void GPUParam::UpdateSettings(const GPUSettingsGRP* g, const GPUSettingsProcessi if (w) { par.dodEdx = dodEdxEnabled = w->steps.isSet(gpudatatypes::RecoStep::TPCdEdx); if (dodEdxEnabled && p && p->tpcDownscaledEdx != 0) { - dodEdxEnabled = (rand() % 100) < p->tpcDownscaledEdx; + dodEdxEnabled = p->tpcDownscaledEdx <= 100 && (rand() % 100) < p->tpcDownscaledEdx; } } if (d) { diff --git a/GPU/GPUTracking/Definitions/GPUSettingsList.h b/GPU/GPUTracking/Definitions/GPUSettingsList.h index d60a9bf5775f4..53b16949d2995 100644 --- a/GPU/GPUTracking/Definitions/GPUSettingsList.h +++ b/GPU/GPUTracking/Definitions/GPUSettingsList.h @@ -428,7 +428,7 @@ AddOption(mergerSanityCheck, bool, false, "", 0, "Run some simple sanity checks AddOption(clusterizerZSSanityCheck, bool, false, "", 0, "Run some simple sanity checks on ZS decoding during clusterization") AddOption(allSanityChecks, bool, false, "", 0, "Enable all sanity checks") AddOption(tpcSingleSector, int32_t, -1, "", 0, "Restrict TPC processing to a single sector") -AddOption(tpcDownscaledEdx, uint8_t, 0, "", 0, "If != 0, downscale dEdx processing (if enabled) to x %") +AddOption(tpcDownscaledEdx, uint8_t, 0, "", 0, "If != 0, downscale dEdx processing (if enabled) to x % (> 100: enable setting but always return false)") AddOption(tpcMaxAttachedClustersPerSectorRow, uint32_t, 51000, "", 0, "Maximum number of TPC attached clusters which can be decoded per SectorRow") AddOption(tpcUseOldCPUDecoding, bool, false, "", 0, "Enable old CPU-based TPC decoding") AddOption(tpcApplyCFCutsAtDecoding, bool, false, "", 0, "Apply cluster cuts from clusterization during decoding of compressed clusters") diff --git a/GPU/GPUTracking/Definitions/GPUSettingsListStandalone.h b/GPU/GPUTracking/Definitions/GPUSettingsListStandalone.h index 61e2e91a55a63..bf7f1a8d24eb6 100644 --- a/GPU/GPUTracking/Definitions/GPUSettingsListStandalone.h +++ b/GPU/GPUTracking/Definitions/GPUSettingsListStandalone.h @@ -81,8 +81,9 @@ AddOption(stripDumpedEvents, bool, false, "", 0, "Remove redundant inputs (e.g. AddOption(printSettings, int32_t, 0, "", 0, "Print all settings", def(1)) AddOption(testSyncAsync, bool, false, "syncAsync", 0, "Test first synchronous and then asynchronous processing") AddOption(testSync, bool, false, "sync", 0, "Test settings for synchronous phase") +AddOption(testAsync, bool, false, "async", 0, "Test settings for asynchronous phase") AddOption(testSyncAsyncQcInSync, bool, false, "syncAsyncSyncQC", 0, "Run QC in sync phase of testSyncAsync") -AddOption(testSyncAsyncNoSyncSettings, bool, false, "", 0, "Do not apply the settings for synchronous processing in testSyncAsync / testSync") +AddOption(testSyncAsyncNoSyncSettings, bool, false, "", 0, "Do not apply the settings for synchronous processing in testSyncAsync") AddOption(testSyncAsyncMC, bool, false, "", 0, "Propagate the TPC cluster MC labels of the clusters surviving the compression to the asynchronous phase of testSyncAsync (enforces tpcSortClusters)") AddOption(timeFrameTime, bool, false, "tfTime", 0, "Print some debug information about time frame processing time") AddOption(controlProfiler, bool, false, "", 0, "Issues GPU profiler stop and start commands to profile only the relevant processing part") diff --git a/GPU/GPUTracking/Global/GPUChainTracking.cxx b/GPU/GPUTracking/Global/GPUChainTracking.cxx index 5f1b7a6f28ae9..bd5e7105667d1 100644 --- a/GPU/GPUTracking/Global/GPUChainTracking.cxx +++ b/GPU/GPUTracking/Global/GPUChainTracking.cxx @@ -1016,16 +1016,26 @@ void GPUChainTracking::SetO2Propagator(const o2::base::Propagator* prop) } } -void GPUChainTracking::ApplySyncSettings(GPUSettingsProcessing& proc, GPUSettingsRec& rec, gpudatatypes::RecoStepField& steps, bool syncMode, int32_t dEdxMode) +void GPUChainTracking::ApplySyncSettings(GPUSettingsProcessing& proc, GPUSettingsRec& rec, gpudatatypes::RecoStepField& steps, bool syncMode, bool asyncMode, int32_t dEdxMode) { + if (syncMode && asyncMode) { + throw std::runtime_error("Cannot apply sync and async settings at the same time"); + } if (syncMode) { rec.useMatLUT = false; rec.tpc.rebuildTrackMaxNonIntCov = 0.f; // TODO: Check if this yields a performance benefit + } else if (asyncMode) { + rec.useMatLUT = true; } if (proc.rtc.optSpecialCode == -1) { proc.rtc.optSpecialCode = syncMode; } if (dEdxMode != -2) { - steps.setBits(gpudatatypes::RecoStep::TPCdEdx, dEdxMode == -1 ? !syncMode : (dEdxMode > 0)); + steps.setBits(gpudatatypes::RecoStep::TPCdEdx, dEdxMode == -1 ? 1 : (dEdxMode > 0)); + } + if (syncMode) { + proc.tpcDownscaledEdx = 127; + } else if (asyncMode) { + proc.tpcDownscaledEdx = 0; } } diff --git a/GPU/GPUTracking/Global/GPUChainTracking.h b/GPU/GPUTracking/Global/GPUChainTracking.h index 1fef646f803c4..7a021f6430d70 100644 --- a/GPU/GPUTracking/Global/GPUChainTracking.h +++ b/GPU/GPUTracking/Global/GPUChainTracking.h @@ -94,7 +94,7 @@ class GPUChainTracking : public GPUChain void ClearErrorCodes(bool cpuOnly = false); int32_t DoQueuedUpdates(int32_t stream, bool updateSlave = true); // Forces doing queue calib updates, don't call when you are not sure you are allowed to do so! bool QARanForTF() const { return mFractionalQAEnabled; } - static void ApplySyncSettings(GPUSettingsProcessing& proc, GPUSettingsRec& rec, gpudatatypes::RecoStepField& steps, bool syncMode, int32_t dEdxMode = -2); + static void ApplySyncSettings(GPUSettingsProcessing& proc, GPUSettingsRec& rec, gpudatatypes::RecoStepField& steps, bool syncMode, bool asyncMode, int32_t dEdxMode = -2); // Structures for input and output data GPUTrackingInOutPointers& mIOPtrs; diff --git a/GPU/GPUTracking/Interface/GPUO2Interface.cxx b/GPU/GPUTracking/Interface/GPUO2Interface.cxx index ca22df5b95695..6460d5949e1a8 100644 --- a/GPU/GPUTracking/Interface/GPUO2Interface.cxx +++ b/GPU/GPUTracking/Interface/GPUO2Interface.cxx @@ -280,5 +280,5 @@ void GPUO2Interface::UseGPUPolynomialFieldInPropagator(o2::base::Propagator* pro void GPUO2Interface::ApplySyncSettings(GPUSettingsProcessing& proc, GPUSettingsRec& rec, gpudatatypes::RecoStepField& steps, bool syncMode, int32_t dEdxMode) { - GPUChainTracking::ApplySyncSettings(proc, rec, steps, syncMode, dEdxMode); + GPUChainTracking::ApplySyncSettings(proc, rec, steps, syncMode, false, dEdxMode); } diff --git a/GPU/GPUTracking/Standalone/Benchmark/standalone.cxx b/GPU/GPUTracking/Standalone/Benchmark/standalone.cxx index 62d53f7bb9580..5ccbe33d5979b 100644 --- a/GPU/GPUTracking/Standalone/Benchmark/standalone.cxx +++ b/GPU/GPUTracking/Standalone/Benchmark/standalone.cxx @@ -498,7 +498,7 @@ int32_t SetupReconstruction() GPURecoStepConfiguration stepsAsync = steps; // Set settings for synchronous - GPUChainTracking::ApplySyncSettings(procSet, recSet, steps.steps, (configStandalone.testSyncAsync || configStandalone.testSync) && !configStandalone.testSyncAsyncNoSyncSettings, configStandalone.rundEdx); + GPUChainTracking::ApplySyncSettings(procSet, recSet, steps.steps, (configStandalone.testSyncAsync && !configStandalone.testSyncAsyncNoSyncSettings) || configStandalone.testSync, configStandalone.testAsync && !configStandalone.testSyncAsync, configStandalone.rundEdx); int32_t runAsyncQA = procSet.runQA && !configStandalone.testSyncAsyncQcInSync ? procSet.runQA : 0; if (configStandalone.testSyncAsync) { procSet.eventDisplay = nullptr; @@ -532,7 +532,7 @@ int32_t SetupReconstruction() if (configStandalone.proc.doublePipeline) { recPipeline->SetSettings(&grp, &recSet, &procSet, &steps); } - if (configStandalone.testSyncAsync) { // TODO: Add --async mode / flag + if (configStandalone.testSyncAsync) { // Set settings for asynchronous stepsAsync.steps.setBits(gpudatatypes::RecoStep::TPCDecompression, true); stepsAsync.steps.setBits(gpudatatypes::RecoStep::TPCdEdx, true); @@ -550,7 +550,7 @@ int32_t SetupReconstruction() } recSetAsync.tpc.disableMarkAdjacent = 0xFF; recSetAsync.maxTrackQPtB5 = CAMath::Min(recSetAsync.maxTrackQPtB5, recSetAsync.tpc.rejectQPtB5); - GPUChainTracking::ApplySyncSettings(procSetAsync, recSetAsync, stepsAsync.steps, false, configStandalone.rundEdx); + GPUChainTracking::ApplySyncSettings(procSetAsync, recSetAsync, stepsAsync.steps, false, true, configStandalone.rundEdx); finalizeSteps(stepsAsync, procSetAsync); recAsync->SetSettings(&grp, &recSetAsync, &procSetAsync, &stepsAsync); } From 60a481d994dcf8e18fddbb531f6e51b63e2c4e25 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Tue, 24 Nov 2026 08:43:05 +0100 Subject: [PATCH 20/32] GPU Standalone: add missing options to setO2Settings --- .../Standalone/Benchmark/standalone.cxx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/GPU/GPUTracking/Standalone/Benchmark/standalone.cxx b/GPU/GPUTracking/Standalone/Benchmark/standalone.cxx index 5ccbe33d5979b..5a3fa6b3d9a3e 100644 --- a/GPU/GPUTracking/Standalone/Benchmark/standalone.cxx +++ b/GPU/GPUTracking/Standalone/Benchmark/standalone.cxx @@ -204,6 +204,10 @@ int32_t ReadConfiguration(int argc, char** argv) return 1; } #endif + if (configStandalone.setO2Settings && configStandalone.runGPU && !(configStandalone.testAsync || configStandalone.testSyncAsync)) { + configStandalone.proc.rtc.enable = 1; + configStandalone.proc.doublePipeline = 1; + } if (configStandalone.proc.doublePipeline && configStandalone.testSyncAsync) { printf("Cannot run asynchronous processing with double pipeline\n"); return 1; @@ -274,10 +278,10 @@ int32_t ReadConfiguration(int argc, char** argv) configStandalone.QA.clusterRejectionHistograms = 1; configStandalone.proc.tpcIncreasedMinClustersPerRow = 500000; configStandalone.proc.ignoreNonFatalGPUErrors = 1; - // TODO: rundEdx=1 - // GPU_proc.qcRunFraction=$TPC_TRACKING_QC_RUN_FRACTION;" - // [[ $CTFINPUT == 1 ]] && GPU_CONFIG_KEY+="GPU_proc.tpcInputWithClusterRejection=1;" - // double pipeline / rtc + if (configStandalone.testSync && configStandalone.rundEdx == -1) { + configStandalone.rundEdx = 1; + configStandalone.proc.qcRunFraction = 0.f; + } } if (configStandalone.outputcontrolmem) { @@ -401,6 +405,10 @@ int32_t SetupReconstruction() procSet = configStandalone.proc; GPURecoStepConfiguration steps; + if (configStandalone.setO2Settings && grp.doCompClusterDecode) { + procSet.tpcInputWithClusterRejection = 1; + } + if (configStandalone.solenoidBzNominalGPU != -1e6f) { grp.solenoidBzNominalGPU = configStandalone.solenoidBzNominalGPU; } From d73c0048f050ba29d32f431b6fde38fbf6e1d597 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Tue, 24 Nov 2026 12:33:52 +0100 Subject: [PATCH 21/32] GPU: Remove obsolete TODOs --- .../DataCompression/GPUTPCCompression.cxx | 2 +- .../GPUTPCCompressionTrackModel.cxx | 2 +- GPU/GPUTracking/DataTypes/TPCZSLinkMapping.cxx | 2 +- .../Definitions/GPUDefConstantsAndSettings.h | 2 +- GPU/GPUTracking/Definitions/GPUSettingsList.h | 2 +- GPU/GPUTracking/Global/GPUChainTracking.cxx | 2 -- .../TPCClusterFinder/GPUTPCCFDecodeZS.cxx | 18 +----------------- 7 files changed, 6 insertions(+), 24 deletions(-) diff --git a/GPU/GPUTracking/DataCompression/GPUTPCCompression.cxx b/GPU/GPUTracking/DataCompression/GPUTPCCompression.cxx index 3ecc7bb606c1e..9222f9f555a1c 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCCompression.cxx +++ b/GPU/GPUTracking/DataCompression/GPUTPCCompression.cxx @@ -110,7 +110,7 @@ void GPUTPCCompression::RegisterMemoryAllocation() if (gatherMode == 3) { mMemoryResOutputGPU = mRec->RegisterMemoryAllocation(this, &GPUTPCCompression::SetPointersOutputGPU, GPUMemoryResource::MEMORY_SCRATCH | GPUMemoryResource::MEMORY_GPU | GPUMemoryResource::MEMORY_CUSTOM | GPUMemoryResource::MEMORY_STACK, "TPCCompressionOutputGPU"); } - uint32_t stackScratch = (gatherMode != 3) ? GPUMemoryResource::MEMORY_STACK : 0; // TODO: Can we use stacked memory also with gather mode 3? + uint32_t stackScratch = (gatherMode != 3) ? GPUMemoryResource::MEMORY_STACK : 0; // Not stacked in gather mode 3: scratch is volatile and freed before the GPU output buffer allocated on the stack after it, which must survive for the async copy / double pipeline if (gatherMode < 2) { mRec->RegisterMemoryAllocation(this, &GPUTPCCompression::SetPointersOutput, GPUMemoryResource::MEMORY_OUTPUT | stackScratch, "TPCCompressionOutput"); } diff --git a/GPU/GPUTracking/DataCompression/GPUTPCCompressionTrackModel.cxx b/GPU/GPUTracking/DataCompression/GPUTPCCompressionTrackModel.cxx index 39e0b770e0a47..a2e0e7ad5d12e 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCCompressionTrackModel.cxx +++ b/GPU/GPUTracking/DataCompression/GPUTPCCompressionTrackModel.cxx @@ -890,7 +890,7 @@ GPUd() void GPUTPCCompressionTrackModel::getClusterErrors2(int32_t iRow, float z { int32_t rowType = iRow < 97 ? (iRow < 63 ? 0 : 1) : (iRow < 127 ? 2 : 3); if (rowType > 2) { - rowType = 2; // TODO: Add type 3 + rowType = 2; } constexpr float tpcLength = 250.f - 0.275f; z = CAMath::Abs(tpcLength - CAMath::Abs(z)); diff --git a/GPU/GPUTracking/DataTypes/TPCZSLinkMapping.cxx b/GPU/GPUTracking/DataTypes/TPCZSLinkMapping.cxx index b8349b2cd137f..88cf0d44ad7c1 100644 --- a/GPU/GPUTracking/DataTypes/TPCZSLinkMapping.cxx +++ b/GPU/GPUTracking/DataTypes/TPCZSLinkMapping.cxx @@ -25,7 +25,7 @@ using namespace o2::gpu; TPCZSLinkMapping::TPCZSLinkMapping(o2::tpc::Mapper& mapper) { #ifndef GPUCA_STANDALONE - const auto& fecToGlobalPad = mapper.getMapFECIDGlobalPad(); // TODO: Can we get this from TPUTPCGeometry? + const auto& fecToGlobalPad = mapper.getMapFECIDGlobalPad(); assert(fecToGlobalPad.size() == TPC_FEC_IDS_IN_SECTOR); const auto& globalPadToPadPos = mapper.getMapGlobalPadToPadPos(); diff --git a/GPU/GPUTracking/Definitions/GPUDefConstantsAndSettings.h b/GPU/GPUTracking/Definitions/GPUDefConstantsAndSettings.h index a9fe70a286e04..91a6b9b9c84a4 100644 --- a/GPU/GPUTracking/Definitions/GPUDefConstantsAndSettings.h +++ b/GPU/GPUTracking/Definitions/GPUDefConstantsAndSettings.h @@ -46,7 +46,7 @@ static GPUglobalconstexpr() uint32_t TPC_MAX_TIME_BIN_TRIGGERED = 600; #endif } // namespace o2::gpu::constants -//#define GPUCA_MERGER_BY_MC_LABEL // Use MC labels for TPC track merging - for performance studies // TODO: Cleanup unneeded options +//#define GPUCA_MERGER_BY_MC_LABEL // Use MC labels for TPC track merging - for performance studies // clang-format on diff --git a/GPU/GPUTracking/Definitions/GPUSettingsList.h b/GPU/GPUTracking/Definitions/GPUSettingsList.h index 53b16949d2995..ce80db8d28299 100644 --- a/GPU/GPUTracking/Definitions/GPUSettingsList.h +++ b/GPU/GPUTracking/Definitions/GPUSettingsList.h @@ -208,7 +208,7 @@ AddOptionRTC(extraRoadY, float, 5.f, "", 0, "Addition to search road around trac AddOptionRTC(extraRoadZ, float, 10.f, "", 0, "Addition to search road around track prolongation along Z in cm") AddOptionRTC(trkltResRPhiIdeal, float, 1.f, "", 0, "Optimal tracklet rphi resolution in cm (in case phi of track = lorentz angle)") AddOptionRTC(trkltResVsTanPhiMisalign, float, 0.f, "", 0, "tan(phi) dependence of tracklet error due to radial misalignment (centered at 0 angle)") -AddOptionRTC(maxChi2Red, float, 99.f, "", 0, "maximum chi2 per attached tracklet for TRD tracks TODO: currently effectively disabled, requires tuning") +AddOptionRTC(maxChi2Red, float, 99.f, "", 0, "maximum chi2 per attached tracklet for TRD tracks") AddOptionRTC(applyDeflectionCut, uint8_t, 0, "", 0, "Set to 1 to enable tracklet selection based on deflection") AddOptionRTC(addDeflectionInChi2, uint8_t, 0, "", 0, "1 = add the slope in the chi2 calculation for matching, 2 = in addition, take into account the full likelihood of the slope including exponential tails") AddOptionRTC(stopTrkAfterNMissLy, uint8_t, 6, "", 0, "Abandon track following after N layers without a TRD match") diff --git a/GPU/GPUTracking/Global/GPUChainTracking.cxx b/GPU/GPUTracking/Global/GPUChainTracking.cxx index bd5e7105667d1..e2b896f95c01d 100644 --- a/GPU/GPUTracking/Global/GPUChainTracking.cxx +++ b/GPU/GPUTracking/Global/GPUChainTracking.cxx @@ -409,7 +409,6 @@ int32_t GPUChainTracking::Init() void GPUChainTracking::UpdateGPUCalibObjects(int32_t stream, const GPUCalibObjectsConst* ptrMask) { - // TODO: Is this correct? if (processors()->calibObjects.fastTransform && (ptrMask == nullptr || ptrMask->fastTransform)) { memcpy((void*)mFlatObjectsShadow.mCalibObjects.fastTransform, (const void*)processors()->calibObjects.fastTransform, processors()->calibObjects.fastTransform->size()); } @@ -504,7 +503,6 @@ void* GPUChainTracking::GPUTrackingFlatObjects::SetPointersFlatObjects(void* mem { char* fastTransformBase = (char*)mem; if (mChainTracking->processors()->calibObjects.fastTransform) { - // TODO: Is this correct?! char* podBuf = nullptr; computePointerWithAlignment(mem, podBuf, mChainTracking->processors()->calibObjects.fastTransform->size()); // raw bytes mCalibObjects.fastTransform = reinterpret_cast(podBuf); diff --git a/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFDecodeZS.cxx b/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFDecodeZS.cxx index cd1b9b32494fd..be8c46699b992 100644 --- a/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFDecodeZS.cxx +++ b/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFDecodeZS.cxx @@ -105,7 +105,7 @@ GPUdii() void GPUTPCCFDecodeZS::decode(GPUTPCClusterFinder& clusterer, GPUshared const int32_t rowOffset = s.regionStartRow + ((endpoint & 1) ? (s.nRowsRegion / 2) : 0); const int32_t nRows = (endpoint & 1) ? (s.nRowsRegion - s.nRowsRegion / 2) : (s.nRowsRegion / 2); - for (int32_t l = 0; l < hdr->nTimeBinSpan; l++) { // TODO: Parallelize over time bins + for (int32_t l = 0; l < hdr->nTimeBinSpan; l++) { pagePtr += (pagePtr - page) & 1; // Ensure 16 bit alignment const TPCZSTBHDR* tbHdr = reinterpret_cast(pagePtr); if ((tbHdr->rowMask & 0x7FFF) == 0) { @@ -120,22 +120,6 @@ GPUdii() void GPUTPCCFDecodeZS::decode(GPUTPCClusterFinder& clusterer, GPUshared const uint8_t* rowData = n == 0 ? pagePtr : (page + tbHdr->rowAddr1()[n - 1]); s.RowClusterOffset[n] = CAMath::AtomicAddShared(&s.rowOffsetCounter, rowData[2 * *rowData]); } - /*if (iThread < GPUCA_WARP_SIZE) { // TODO: Seems to miscompile with HIP, CUDA performance doesn't really change, for now sticking to the AtomicAdd - GPUSharedMemory& smem = s; - int32_t o; - if (iThread < nRowsUsed) { - const uint8_t* rowData = iThread == 0 ? pagePtr : (page + tbHdr->rowAddr1()[iThread - 1]); - o = rowData[2 * *rowData]; - } else { - o = 0; - } - int32_t x = warp_scan_inclusive_add(o); - if (iThread < nRowsUsed) { - s.RowClusterOffset[iThread] = s.rowOffsetCounter + x - o; - } else if (iThread == GPUCA_WARP_SIZE - 1) { - s.rowOffsetCounter += x; - } - }*/ GPUbarrier(); if (myRow < s.rowStride) { From e2dbe77b200e623d9c98f674f4aaa786c9b514d3 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Tue, 24 Nov 2026 12:34:12 +0100 Subject: [PATCH 22/32] GPU: Can clear unused output buffers also with double pipeline --- GPU/GPUTracking/Standalone/Benchmark/standalone.cxx | 4 +--- GPU/Workflow/src/GPUWorkflowSpec.cxx | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/GPU/GPUTracking/Standalone/Benchmark/standalone.cxx b/GPU/GPUTracking/Standalone/Benchmark/standalone.cxx index 5a3fa6b3d9a3e..a24ed41065ef9 100644 --- a/GPU/GPUTracking/Standalone/Benchmark/standalone.cxx +++ b/GPU/GPUTracking/Standalone/Benchmark/standalone.cxx @@ -785,9 +785,7 @@ int32_t RunBenchmark(GPUReconstruction* recUse, GPUChainTracking* chainTrackingU } recAsync->ClearAllocatedMemory(); } - if (!configStandalone.proc.doublePipeline) { - recUse->ClearAllocatedMemory(); - } + recUse->ClearAllocatedMemory(); if (tmpRetVal == GPUReconstruction::retValValue::retDoExit) { configStandalone.continueOnError = 0; // Forced exit from event display loop diff --git a/GPU/Workflow/src/GPUWorkflowSpec.cxx b/GPU/Workflow/src/GPUWorkflowSpec.cxx index 990873f053fe3..7b166851a9a9d 100644 --- a/GPU/Workflow/src/GPUWorkflowSpec.cxx +++ b/GPU/Workflow/src/GPUWorkflowSpec.cxx @@ -518,10 +518,7 @@ int32_t GPURecoWorkflowSpec::runMain(o2::framework::ProcessingContext* pc, GPUTr retVal = runITSTracking(*pc); } } - - if (!mSpecConfig.enableDoublePipeline) { // TODO: Why is this needed for double-pipeline? - mGPUReco->Clear(false, threadIndex); // clean non-output memory used by GPU Reconstruction - } + mGPUReco->Clear(false, threadIndex); // clean non-output memory used by GPU Reconstruction return retVal; } From e05054058cc268b9d729e5120ba01fa26575d3dd Mon Sep 17 00:00:00 2001 From: David Rohr Date: Tue, 24 Nov 2026 12:42:41 +0100 Subject: [PATCH 23/32] GPU: Guarantee memory alignment for tpcZSpagesChar and tpcCompressedClusters --- GPU/Common/GPUCommonAlignedAlloc.h | 3 ++- GPU/GPUTracking/Base/GPUReconstruction.h | 8 ++++---- GPU/GPUTracking/Base/GPUReconstructionIO.h | 15 ++++++++++----- GPU/GPUTracking/Global/GPUChain.h | 8 ++++---- GPU/GPUTracking/Global/GPUChainTracking.h | 4 ++-- GPU/GPUTracking/Global/GPUChainTrackingIO.cxx | 2 ++ 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/GPU/Common/GPUCommonAlignedAlloc.h b/GPU/Common/GPUCommonAlignedAlloc.h index 8dffcb8e3973e..ce071a46c2334 100644 --- a/GPU/Common/GPUCommonAlignedAlloc.h +++ b/GPU/Common/GPUCommonAlignedAlloc.h @@ -22,7 +22,8 @@ namespace o2::gpu template struct alignedDeleter { - void operator()(void* ptr) { ::operator delete(ptr, std::align_val_t(std::max(MIN_ALIGN, alignof(T)))); }; // TODO: Make this static once we go to C++ 23 + static constexpr std::size_t alignment = std::max(MIN_ALIGN, alignof(T)); + void operator()(void* ptr) { ::operator delete(ptr, std::align_val_t(alignment)); }; // TODO: Make this static once we go to C++ 23 }; template diff --git a/GPU/GPUTracking/Base/GPUReconstruction.h b/GPU/GPUTracking/Base/GPUReconstruction.h index 1a23c67add845..c94b66a9a5cc5 100644 --- a/GPU/GPUTracking/Base/GPUReconstruction.h +++ b/GPU/GPUTracking/Base/GPUReconstruction.h @@ -298,10 +298,10 @@ class GPUReconstruction // Private helper functions for reading / writing / allocating IO buffer from/to file template uint32_t DumpData(FILE* fp, const T* const* entries, const S* num, InOutPointerType type); - template - size_t ReadData(FILE* fp, const T** entries, S* num, std::unique_ptr* mem, InOutPointerType type, T** nonConstPtrs = nullptr); - template - T* AllocateIOMemoryHelper(size_t n, const T*& ptr, std::unique_ptr& u); + template + size_t ReadData(FILE* fp, const T** entries, S* num, std::unique_ptr* mem, InOutPointerType type, T** nonConstPtrs = nullptr); + template + T* AllocateIOMemoryHelper(size_t n, const T*& ptr, std::unique_ptr& u); int16_t RegisterMemoryAllocationHelper(GPUProcessor* proc, void* (GPUProcessor::*setPtr)(void*), int32_t type, const char* name, const GPUMemoryReuse& re); // Private helper functions to dump / load flat objects diff --git a/GPU/GPUTracking/Base/GPUReconstructionIO.h b/GPU/GPUTracking/Base/GPUReconstructionIO.h index c1a656e9f61d3..d2214fa6b79b2 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionIO.h +++ b/GPU/GPUTracking/Base/GPUReconstructionIO.h @@ -17,12 +17,13 @@ #include "GPUReconstruction.h" #include "GPUSettings.h" +#include namespace o2::gpu { -template -inline T* GPUReconstruction::AllocateIOMemoryHelper(size_t n, const T*& ptr, std::unique_ptr& u) +template +inline T* GPUReconstruction::AllocateIOMemoryHelper(size_t n, const T*& ptr, std::unique_ptr& u) { if (n == 0) { u.reset(nullptr); @@ -37,7 +38,11 @@ inline T* GPUReconstruction::AllocateIOMemoryHelper(size_t n, const T*& ptr, std throw std::bad_alloc(); } } else { - u.reset(new T[n]); + if constexpr (std::is_same_v>) { + u.reset(new T[n]); + } else { + u.reset(alignedAllocator::allocate(n * sizeof(T))); + } retVal = u.get(); if (GetProcessingSettings().registerStandaloneInputMemory) { if (registerMemoryForGPU(u.get(), n * sizeof(T))) { @@ -74,8 +79,8 @@ inline uint32_t GPUReconstruction::DumpData(FILE* fp, const T* const* entries, c return numTotal; } -template -inline size_t GPUReconstruction::ReadData(FILE* fp, const T** entries, S* num, std::unique_ptr* mem, InOutPointerType type, T** nonConstPtrs) +template +inline size_t GPUReconstruction::ReadData(FILE* fp, const T** entries, S* num, std::unique_ptr* mem, InOutPointerType type, T** nonConstPtrs) { if (feof(fp)) { return 0; diff --git a/GPU/GPUTracking/Global/GPUChain.h b/GPU/GPUTracking/Global/GPUChain.h index 4b0391dae1f5a..e97880a9beaa3 100644 --- a/GPU/GPUTracking/Global/GPUChain.h +++ b/GPU/GPUTracking/Global/GPUChain.h @@ -136,8 +136,8 @@ class GPUChain } } - template - inline void AllocateIOMemoryHelper(uint32_t n, const T*& ptr, std::unique_ptr& u) + template + inline void AllocateIOMemoryHelper(uint32_t n, const T*& ptr, std::unique_ptr& u) { mRec->AllocateIOMemoryHelper(n, ptr, u); } @@ -146,8 +146,8 @@ class GPUChain { return mRec->DumpData(fp, entries, num, type); } - template - inline size_t ReadData(FILE* fp, const T** entries, S* num, std::unique_ptr* mem, InOutPointerType type, T** nonConstPtrs = nullptr) + template + inline size_t ReadData(FILE* fp, const T** entries, S* num, std::unique_ptr* mem, InOutPointerType type, T** nonConstPtrs = nullptr) { return mRec->ReadData(fp, entries, num, mem, type, nonConstPtrs); } diff --git a/GPU/GPUTracking/Global/GPUChainTracking.h b/GPU/GPUTracking/Global/GPUChainTracking.h index 7a021f6430d70..87723cdddd088 100644 --- a/GPU/GPUTracking/Global/GPUChainTracking.h +++ b/GPU/GPUTracking/Global/GPUChainTracking.h @@ -106,8 +106,8 @@ class GPUChainTracking : public GPUChain InOutMemory& operator=(InOutMemory&&); std::unique_ptr tpcZSpages; - std::unique_ptr tpcZSpagesChar; // Same as above, but as char (needed for reading dumps, but deprecated, since alignment can be wrong) // TODO: Fix alignment - std::unique_ptr tpcCompressedClusters; // TODO: Fix alignment + std::unique_ptr> tpcZSpagesChar; // Same as above, but as char (needed for reading dumps) + std::unique_ptr> tpcCompressedClusters; std::unique_ptr tpcZSmeta; std::unique_ptr tpcZSmeta2; std::unique_ptr tpcDigits[NSECTORS]; diff --git a/GPU/GPUTracking/Global/GPUChainTrackingIO.cxx b/GPU/GPUTracking/Global/GPUChainTrackingIO.cxx index c7aa8768cea4c..909581e5c6c04 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingIO.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingIO.cxx @@ -54,6 +54,8 @@ using namespace o2::tpc; using namespace o2::trd; using namespace o2::dataformats; +static_assert(decltype(GPUChainTracking::InOutMemory::tpcCompressedClusters)::deleter_type::alignment >= alignof(o2::tpc::CompressedClustersFlat)); + static constexpr uint32_t DUMP_HEADER_SIZE = 4; static constexpr char DUMP_HEADER[DUMP_HEADER_SIZE + 1] = "CAv1"; From 9132a0eec32a6be40cd97b29ba81f818abf09edf Mon Sep 17 00:00:00 2001 From: David Rohr Date: Tue, 24 Nov 2026 12:51:51 +0100 Subject: [PATCH 24/32] GPU: Fix race condition at cleanup of double pipeline --- GPU/GPUTracking/Base/GPUReconstruction.cxx | 9 ++++++--- GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx | 6 ++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/GPU/GPUTracking/Base/GPUReconstruction.cxx b/GPU/GPUTracking/Base/GPUReconstruction.cxx index e788b0d650af3..904db3c9c0065 100644 --- a/GPU/GPUTracking/Base/GPUReconstruction.cxx +++ b/GPU/GPUTracking/Base/GPUReconstruction.cxx @@ -1141,10 +1141,13 @@ void GPUReconstruction::RunPipelineWorker() { std::lock_guard lk(q->m); q->done = true; + q->c.notify_one(); + } + { + std::lock_guard lk(mPipelineContext->mutex); + mPipelineContext->workerRunning = false; + mPipelineContext->cond.notify_one(); } - q->c.notify_one(); - mPipelineContext->workerRunning = false; - mPipelineContext->cond.notify_one(); } if (GetProcessingSettings().debugLevel >= 3) { GPUInfo("Pipeline worker ended"); diff --git a/GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx b/GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx index fc10e672b5264..0d2701bbfb969 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx @@ -984,10 +984,8 @@ int32_t GPUChainTracking::RunTPCClusterizer(bool synchronizeOutput) auto notifyForeignChainFinished = [this]() { if (mPipelineNotifyCtx) { SynchronizeStream(OutputStream()); // Must finish before updating ioPtrs in (global) constant memory - { - std::lock_guard lock(mPipelineNotifyCtx->mutex); - mPipelineNotifyCtx->ready = true; - } + std::lock_guard lock(mPipelineNotifyCtx->mutex); + mPipelineNotifyCtx->ready = true; mPipelineNotifyCtx->cond.notify_one(); } }; From b409dec1e68d41ecc7e5c6a04503c62f12a9ae6b Mon Sep 17 00:00:00 2001 From: David Rohr Date: Tue, 24 Nov 2026 13:02:59 +0100 Subject: [PATCH 25/32] GPU: Move some static_asserts from headers to cxx files --- GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu | 1 + .../Base/cuda/GPUReconstructionCUDAInternals.h | 2 -- .../DataCompression/GPUTPCCompressionKernels.cxx | 5 +++++ .../DataCompression/GPUTPCCompressionKernels.h | 4 ---- GPU/GPUTracking/DataTypes/GPUTriggerOutputs.h | 1 - GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx | 2 ++ GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx | 2 ++ GPU/GPUTracking/Merger/GPUTPCGMMergerRebuildInternal.h | 1 - GPU/GPUTracking/SectorTracker/GPUTPCNeighboursFinder.cxx | 2 ++ GPU/GPUTracking/SectorTracker/GPUTPCNeighboursFinder.h | 1 - GPU/GPUTracking/SectorTracker/GPUTPCTrackletSelector.cxx | 2 ++ GPU/GPUTracking/SectorTracker/GPUTPCTrackletSelector.h | 1 - .../TPCClusterFinder/GPUTPCCFNoiseSuppression.cxx | 2 ++ .../TPCClusterFinder/GPUTPCCFNoiseSuppression.h | 1 - .../TPCClusterFinder/GPUTPCCFStreamCompaction.cxx | 8 ++++++++ .../TPCClusterFinder/GPUTPCCFStreamCompaction.h | 5 ----- 16 files changed, 24 insertions(+), 16 deletions(-) diff --git a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu index 574e9acdd1d31..ed4e8bbf042e0 100644 --- a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu +++ b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.cu @@ -84,6 +84,7 @@ GPUReconstructionCUDA::~GPUReconstructionCUDA() } static_assert(sizeof(cudaError_t) <= sizeof(int64_t) && cudaSuccess == 0); +static_assert(std::is_convertible_v, "CUDA event type incompatible to deviceEvent"); int32_t GPUReconstructionCUDA::GPUChkErrInternal(const int64_t retval, const char* file, int32_t line) const { return internal::GPUReconstructionCUDAChkErr(retval, file, line); diff --git a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAInternals.h b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAInternals.h index 8ce21652247fc..acc3ee06e3f9a 100644 --- a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAInternals.h +++ b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAInternals.h @@ -79,8 +79,6 @@ class GPUDebugTiming bool mDo; }; -static_assert(std::is_convertible_v, "CUDA event type incompatible to deviceEvent"); - } // namespace o2::gpu #endif diff --git a/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.cxx b/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.cxx index 588340bd73e64..211e45264ca51 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.cxx +++ b/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.cxx @@ -24,6 +24,11 @@ using namespace o2::gpu; using namespace o2::tpc; +static_assert(GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCompressionGatherKernels_unbuffered) == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCompressionGatherKernels_buffered32)); +static_assert(GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCompressionGatherKernels_unbuffered) == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCompressionGatherKernels_buffered64)); +static_assert(GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCompressionGatherKernels_unbuffered) == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCompressionGatherKernels_buffered128)); +static_assert(GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCompressionGatherKernels_unbuffered) == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCompressionGatherKernels_multiBlock)); + template <> GPUdii() void GPUTPCCompressionKernels::Thread(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUsharedref() GPUSharedMemory& smem, processorType& processors) { diff --git a/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.h b/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.h index 1edf718de8128..ac8fc72376ecf 100644 --- a/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.h +++ b/GPU/GPUTracking/DataCompression/GPUTPCCompressionKernels.h @@ -72,10 +72,6 @@ class GPUTPCCompressionGatherKernels : public GPUKernelTemplate using Vec64 = uint64_t; using Vec128 = uint4; - static_assert(GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCompressionGatherKernels_unbuffered) == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCompressionGatherKernels_buffered32)); - static_assert(GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCompressionGatherKernels_unbuffered) == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCompressionGatherKernels_buffered64)); - static_assert(GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCompressionGatherKernels_unbuffered) == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCompressionGatherKernels_buffered128)); - static_assert(GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCompressionGatherKernels_unbuffered) == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCompressionGatherKernels_multiBlock)); struct GPUSharedMemory : public GPUKernelTemplate::GPUSharedMemoryScan64 { union { uint32_t warpOffset[GPUCA_GET_WARP_COUNT(GPUCA_LB_GPUTPCCompressionGatherKernels_unbuffered)]; diff --git a/GPU/GPUTracking/DataTypes/GPUTriggerOutputs.h b/GPU/GPUTracking/DataTypes/GPUTriggerOutputs.h index 41ed5d0859efe..49714e6788f5a 100644 --- a/GPU/GPUTracking/DataTypes/GPUTriggerOutputs.h +++ b/GPU/GPUTracking/DataTypes/GPUTriggerOutputs.h @@ -47,7 +47,6 @@ struct GPUTriggerOutputs { }; std::unordered_set triggers; - static_assert(sizeof(o2::tpc::TriggerInfoDLBZS) % sizeof(uint32_t) == 0); }; } // namespace o2::gpu diff --git a/GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx b/GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx index 0d2701bbfb969..0bfba37377582 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingClusterizer.cxx @@ -69,6 +69,8 @@ using namespace o2::tpc; using namespace o2::tpc::constants; using namespace o2::dataformats; +static_assert(sizeof(o2::tpc::TriggerInfoDLBZS) % sizeof(uint32_t) == 0); // GPUTriggerOutputs::hasher hashes it as uint32_t words + #ifndef GPUCA_RUN2 std::pair GPUChainTracking::TPCClusterizerDecodeZSCountUpdate(uint32_t iSector, const CfFragment& frag) { diff --git a/GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx b/GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx index 103cc4998e97c..1333f92ca3201 100644 --- a/GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx +++ b/GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx @@ -63,6 +63,8 @@ using namespace o2::gpu; using namespace o2::tpc; + +static_assert(sizeof(GPUTPCGMMerger::trackRebuildHelperCandidate) == 6); using namespace gputpcgmmergertypes; namespace o2::gpu::internal diff --git a/GPU/GPUTracking/Merger/GPUTPCGMMergerRebuildInternal.h b/GPU/GPUTracking/Merger/GPUTPCGMMergerRebuildInternal.h index 6ff2870dbb92c..f6b8efe46b9c9 100644 --- a/GPU/GPUTracking/Merger/GPUTPCGMMergerRebuildInternal.h +++ b/GPU/GPUTracking/Merger/GPUTPCGMMergerRebuildInternal.h @@ -42,7 +42,6 @@ struct GPUTPCGMMerger::trackRebuildHelperCandidate { // Per track, row and candi error = e; } }; -static_assert(sizeof(GPUTPCGMMerger::trackRebuildHelperCandidate) == 6); struct __attribute__((packed)) GPUTPCGMMerger::trackRebuildHelperRowInfo { // Per track, only with GPUCA_PAR_TPC_MERGER_REBUILD_CONSTRAINED_ROW_MEMORY >= 1 uint32_t firstRowIndex; // Index of firstRow of the track in mTrackRebuildHelperRow and (times the number of candidates) in mClusterCandidates diff --git a/GPU/GPUTracking/SectorTracker/GPUTPCNeighboursFinder.cxx b/GPU/GPUTracking/SectorTracker/GPUTPCNeighboursFinder.cxx index eb3038602283e..7884e32d8599c 100644 --- a/GPU/GPUTracking/SectorTracker/GPUTPCNeighboursFinder.cxx +++ b/GPU/GPUTracking/SectorTracker/GPUTPCNeighboursFinder.cxx @@ -19,6 +19,8 @@ #include "GPUDefMacros.h" using namespace o2::gpu; +static_assert(o2::gpu::constants::NEIGHBOURS_MAX_N >= GPUCA_PAR_NEIGHBOURS_FINDER_MAX_NNEIGHUP); + template <> GPUdii() void GPUTPCNeighboursFinder::Thread<0>(int32_t /*nBlocks*/, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUsharedref() GPUSharedMemory& s, processorType& GPUrestrict() tracker) { diff --git a/GPU/GPUTracking/SectorTracker/GPUTPCNeighboursFinder.h b/GPU/GPUTracking/SectorTracker/GPUTPCNeighboursFinder.h index 02a75643874f5..7e5c2be3e687f 100644 --- a/GPU/GPUTracking/SectorTracker/GPUTPCNeighboursFinder.h +++ b/GPU/GPUTracking/SectorTracker/GPUTPCNeighboursFinder.h @@ -40,7 +40,6 @@ class GPUTPCNeighboursFinder : public GPUKernelTemplate uint32_t mIRow; // row number uint32_t mIRowUp; // next row number uint32_t mIRowDn; // previous row number - static_assert(constants::NEIGHBOURS_MAX_N >= GPUCA_PAR_NEIGHBOURS_FINDER_MAX_NNEIGHUP); float mA1[GPUCA_PAR_NEIGHBOURS_FINDER_MAX_NNEIGHUP][GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCNeighboursFinder)]; float mA2[GPUCA_PAR_NEIGHBOURS_FINDER_MAX_NNEIGHUP][GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCNeighboursFinder)]; calink mB[GPUCA_PAR_NEIGHBOURS_FINDER_MAX_NNEIGHUP][GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCNeighboursFinder)]; diff --git a/GPU/GPUTracking/SectorTracker/GPUTPCTrackletSelector.cxx b/GPU/GPUTracking/SectorTracker/GPUTPCTrackletSelector.cxx index 0a68a64c9a204..ae78c36682d84 100644 --- a/GPU/GPUTracking/SectorTracker/GPUTPCTrackletSelector.cxx +++ b/GPU/GPUTracking/SectorTracker/GPUTPCTrackletSelector.cxx @@ -21,6 +21,8 @@ using namespace o2::gpu; +static_assert(GPUTPCGeometry::NROWS >= GPUCA_PAR_TRACKLET_SELECTOR_HITS_REG_SIZE); + template <> GPUdii() void GPUTPCTrackletSelector::Thread<0>(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUsharedref() GPUSharedMemory& s, processorType& GPUrestrict() tracker) { diff --git a/GPU/GPUTracking/SectorTracker/GPUTPCTrackletSelector.h b/GPU/GPUTracking/SectorTracker/GPUTPCTrackletSelector.h index 95cb2f987a14d..dd5c650c2a8b7 100644 --- a/GPU/GPUTracking/SectorTracker/GPUTPCTrackletSelector.h +++ b/GPU/GPUTracking/SectorTracker/GPUTPCTrackletSelector.h @@ -36,7 +36,6 @@ class GPUTPCTrackletSelector : public GPUKernelTemplate int32_t mNThreadsTotal; // total n threads int32_t mNTracklets; // n of tracklets int32_t mReserved; // for alignment reasons - static_assert(GPUTPCGeometry::NROWS >= GPUCA_PAR_TRACKLET_SELECTOR_HITS_REG_SIZE); GPUTPCHitId mHits[GPUCA_PAR_TRACKLET_SELECTOR_HITS_REG_SIZE][GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCTrackletSelector)]; }; diff --git a/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFNoiseSuppression.cxx b/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFNoiseSuppression.cxx index ea7e0c577031f..cbe13c33ccaba 100644 --- a/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFNoiseSuppression.cxx +++ b/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFNoiseSuppression.cxx @@ -21,6 +21,8 @@ using namespace o2::gpu; using namespace o2::gpu::tpccf; +static_assert(GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCFNoiseSuppression_noiseSuppression) == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCFNoiseSuppression_updatePeaks)); + template <> GPUdii() void GPUTPCCFNoiseSuppression::Thread(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUSharedMemory& smem, processorType& clusterer) { diff --git a/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFNoiseSuppression.h b/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFNoiseSuppression.h index f07f0d7cc2066..9f1788cfef568 100644 --- a/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFNoiseSuppression.h +++ b/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFNoiseSuppression.h @@ -35,7 +35,6 @@ class GPUTPCCFNoiseSuppression : public GPUKernelTemplate updatePeaks = 1, }; static GPUglobalconstexpr() size_t SCRATCH_PAD_WORK_GROUP_SIZE = GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCFNoiseSuppression_noiseSuppression); - static_assert(GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCFNoiseSuppression_noiseSuppression) == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCFNoiseSuppression_updatePeaks)); struct GPUSharedMemory { CfChargePos posBcast[SCRATCH_PAD_WORK_GROUP_SIZE]; diff --git a/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFStreamCompaction.cxx b/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFStreamCompaction.cxx index 8ea2b209907ed..62f5c86d97373 100644 --- a/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFStreamCompaction.cxx +++ b/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFStreamCompaction.cxx @@ -21,6 +21,14 @@ using namespace o2::gpu; using namespace o2::gpu::tpccf; +#if defined(GPUCA_GPUCODE) && !defined(GPUCA_GPUCODE_NO_LAUNCH_BOUNDS) +static_assert(GPUCA_PAR_CF_SCAN_WORKGROUP_SIZE == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCFStreamCompaction_scanStart)); +static_assert(GPUCA_PAR_CF_SCAN_WORKGROUP_SIZE == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCFStreamCompaction_scanUp)); +static_assert(GPUCA_PAR_CF_SCAN_WORKGROUP_SIZE == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCFStreamCompaction_scanTop)); +static_assert(GPUCA_PAR_CF_SCAN_WORKGROUP_SIZE == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCFStreamCompaction_scanDown)); +static_assert(GPUCA_PAR_CF_SCAN_WORKGROUP_SIZE == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCFStreamCompaction_compactDigits)); +#endif + template <> GPUdii() void GPUTPCCFStreamCompaction::Thread(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUSharedMemory& smem, processorType& clusterer, int32_t iBuf, int32_t stage) { diff --git a/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFStreamCompaction.h b/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFStreamCompaction.h index 3b9b7e2b8329a..d74a1c0720291 100644 --- a/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFStreamCompaction.h +++ b/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFStreamCompaction.h @@ -38,11 +38,6 @@ class GPUTPCCFStreamCompaction : public GPUKernelTemplate #if defined(GPUCA_GPUCODE) && !defined(GPUCA_GPUCODE_NO_LAUNCH_BOUNDS) struct GPUSharedMemory : public GPUKernelTemplate::GPUSharedMemoryScan64 { }; - static_assert(GPUCA_PAR_CF_SCAN_WORKGROUP_SIZE == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCFStreamCompaction_scanStart)); - static_assert(GPUCA_PAR_CF_SCAN_WORKGROUP_SIZE == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCFStreamCompaction_scanUp)); - static_assert(GPUCA_PAR_CF_SCAN_WORKGROUP_SIZE == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCFStreamCompaction_scanTop)); - static_assert(GPUCA_PAR_CF_SCAN_WORKGROUP_SIZE == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCFStreamCompaction_scanDown)); - static_assert(GPUCA_PAR_CF_SCAN_WORKGROUP_SIZE == GPUCA_GET_THREAD_COUNT(GPUCA_LB_GPUTPCCFStreamCompaction_compactDigits)); #endif typedef GPUTPCClusterFinder processorType; From 722e41a074b3a5497210166462224b0b5fd4133e Mon Sep 17 00:00:00 2001 From: David Rohr Date: Tue, 24 Nov 2026 13:12:43 +0100 Subject: [PATCH 26/32] GPT TRD: Have track default values C++11-in-class --- GPU/GPUTracking/DataTypes/GPUTRDTrack.h | 17 ++++++++------- GPU/GPUTracking/DataTypes/GPUTRDTrack.inc | 25 ----------------------- 2 files changed, 8 insertions(+), 34 deletions(-) diff --git a/GPU/GPUTracking/DataTypes/GPUTRDTrack.h b/GPU/GPUTracking/DataTypes/GPUTRDTrack.h index b358e8b82d480..07c98c2323f24 100644 --- a/GPU/GPUTracking/DataTypes/GPUTRDTrack.h +++ b/GPU/GPUTracking/DataTypes/GPUTRDTrack.h @@ -48,7 +48,7 @@ class GPUTRDTrack_t : public T kStopFlag = 7 }; - GPUd() GPUTRDTrack_t(); + GPUdDefault() GPUTRDTrack_t() = default; GPUTRDTrack_t(const typename T::baseClass& t) = delete; GPUd() GPUTRDTrack_t(const GPUTRDTrack_t& t); GPUd() GPUTRDTrack_t(const AliHLTExternalTrackParam& t); @@ -107,16 +107,15 @@ class GPUTRDTrack_t : public T GPUd() void setHasPadrowCrossing() { mIsCrossingNeighbor |= (1U << 7); } protected: - float mChi2; // total chi2. - float mSignal{-1.f}; // electron Likelihood for track - uint32_t mRefGlobalTrackId; // raw GlobalTrackID of the seeding track (either ITS-TPC or TPC) - int32_t mAttachedTracklets[kNLayers]; // indices of the tracklets attached to this track; -1 means no tracklet in that layer - int16_t mCollisionId; // the collision ID of the tracklets attached to this track; is used to retrieve the BC information for this track after the tracking is done - uint8_t mFlags; // bits 0 to 5 indicate whether track is findable in layer 0 to 5, bit 6 indicates an ambiguous track and bit 7 flags if the track is stopped in the TRD - uint8_t mIsCrossingNeighbor; // bits 0 to 5 indicate if a tracklet was either a neighboring tracklet (e.g. a potential split tracklet) or crossed a padrow, bit 6 indicates that a neighbor in any layer has been found and bit 7 if a padrow was crossed + float mChi2{0.f}; // total chi2. + float mSignal{-1.f}; // electron Likelihood for track + uint32_t mRefGlobalTrackId{0}; // raw GlobalTrackID of the seeding track (either ITS-TPC or TPC) + int32_t mAttachedTracklets[kNLayers]{-1, -1, -1, -1, -1, -1}; // indices of the tracklets attached to this track; -1 means no tracklet in that layer + int16_t mCollisionId{-1}; // the collision ID of the tracklets attached to this track; is used to retrieve the BC information for this track after the tracking is done + uint8_t mFlags{0}; // bits 0 to 5 indicate whether track is findable in layer 0 to 5, bit 6 indicates an ambiguous track and bit 7 flags if the track is stopped in the TRD + uint8_t mIsCrossingNeighbor{0}; // bits 0 to 5 indicate if a tracklet was either a neighboring tracklet (e.g. a potential split tracklet) or crossed a padrow, bit 6 indicates that a neighbor in any layer has been found and bit 7 if a padrow was crossed private: - GPUd() void initialize(); #if !defined(GPUCA_STANDALONE) ClassDefNV(GPUTRDTrack_t, 4); #endif diff --git a/GPU/GPUTracking/DataTypes/GPUTRDTrack.inc b/GPU/GPUTracking/DataTypes/GPUTRDTrack.inc index b0d54f05aaa25..acb4fd66bd7e8 100644 --- a/GPU/GPUTracking/DataTypes/GPUTRDTrack.inc +++ b/GPU/GPUTracking/DataTypes/GPUTRDTrack.inc @@ -17,41 +17,17 @@ #include "GPUTRDTrack.h" -template -GPUd() GPUTRDTrack_t::GPUTRDTrack_t() -{ - // default constructor - initialize(); -} - -template -GPUd() void GPUTRDTrack_t::initialize() -{ - // TODO: Use in-class initialization instead of setting all members to their default values - mChi2 = 0.f; - mSignal = -1.f; - mRefGlobalTrackId = 0; - mCollisionId = -1; - mFlags = 0; - mIsCrossingNeighbor = 0; - for (int32_t i = 0; i < kNLayers; ++i) { - mAttachedTracklets[i] = -1; - } -} - #include "ReconstructionDataFormats/TrackTPCITS.h" #include "DataFormatsTPC/TrackTPC.h" template GPUd() GPUTRDTrack_t::GPUTRDTrack_t(const o2::dataformats::TrackTPCITS& t) : T(static_cast(t)) { - initialize(); } template GPUd() GPUTRDTrack_t::GPUTRDTrack_t(const o2::tpc::TrackTPC& t) : T(static_cast(t)) { - initialize(); } template @@ -68,7 +44,6 @@ template GPUd() GPUTRDTrack_t::GPUTRDTrack_t(const T& t) : T(t) { // copy constructor from anything - initialize(); } template From 210980f1c36506619a6dde1c683923e2273e5bb3 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Tue, 24 Nov 2026 13:14:41 +0100 Subject: [PATCH 27/32] GPU TRD: Remove Run2 leftovers --- GPU/GPUTracking/DataTypes/GPUTRDTrack.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/GPU/GPUTracking/DataTypes/GPUTRDTrack.h b/GPU/GPUTracking/DataTypes/GPUTRDTrack.h index 07c98c2323f24..457dc6f7debf3 100644 --- a/GPU/GPUTracking/DataTypes/GPUTRDTrack.h +++ b/GPU/GPUTracking/DataTypes/GPUTRDTrack.h @@ -20,7 +20,6 @@ #include "GPUCommonRtypes.h" struct GPUTRDTrackDataRecord; -class AliHLTExternalTrackParam; namespace o2::tpc { @@ -51,7 +50,6 @@ class GPUTRDTrack_t : public T GPUdDefault() GPUTRDTrack_t() = default; GPUTRDTrack_t(const typename T::baseClass& t) = delete; GPUd() GPUTRDTrack_t(const GPUTRDTrack_t& t); - GPUd() GPUTRDTrack_t(const AliHLTExternalTrackParam& t); GPUd() GPUTRDTrack_t(const o2::dataformats::TrackTPCITS& t); GPUd() GPUTRDTrack_t(const o2::tpc::TrackTPC& t); GPUd() GPUTRDTrack_t(const T& t); From f59368a78734caaa381b3b1cf14e7b7942833127 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Tue, 24 Nov 2026 13:20:13 +0100 Subject: [PATCH 28/32] GPU: Use AddOptionArrayRTC via GPUConstexpr() --- GPU/GPUTracking/Base/GPUParam.cxx | 4 +- GPU/GPUTracking/Base/GPUParamRTC.h | 8 +-- .../Base/GPUReconstructionDeviceBase.h | 10 ++++ .../Base/GPUReconstructionRTCHelpers.inc | 14 +++-- .../cpudevice/GPUReconstructionCPUDevice.cxx | 3 +- .../cpudevice/GPUReconstructionCPUDevice.h | 2 +- .../GPUReconstructionCPUDeviceGenRTC.cxx | 28 ++++----- .../Base/cuda/GPUReconstructionCUDA.h | 2 +- .../Base/cuda/GPUReconstructionCUDAGenRTC.cxx | 28 ++++----- .../cuda/GPUReconstructionCUDARTCCalls.cu | 3 +- GPU/GPUTracking/Definitions/GPUSettingsList.h | 4 +- GPU/GPUTracking/utils/qconfig_internal.h | 58 ++++++++++++++----- GPU/GPUTracking/utils/qconfig_rtc.h | 7 ++- 13 files changed, 112 insertions(+), 59 deletions(-) diff --git a/GPU/GPUTracking/Base/GPUParam.cxx b/GPU/GPUTracking/Base/GPUParam.cxx index 3ac88150b64a3..d5c5f8f7dd6b8 100644 --- a/GPU/GPUTracking/Base/GPUParam.cxx +++ b/GPU/GPUTracking/Base/GPUParam.cxx @@ -159,14 +159,14 @@ void GPUParamRTC::setFrom(const GPUParam& param) memcpy((void*)this, (void*)¶m, sizeof(param)); } -std::string GPUParamRTC::generateRTCCode(const GPUParam& param, bool useConstexpr) +std::string GPUParamRTC::generateRTCCode(const GPUParam& param, bool useConstexpr, bool gpuConstexprArrayInConstantMem) { return "#include \n" "#include \n" "#include \n" "#include \n" "namespace o2::gpu { class GPUDisplayFrontendInterface; }\n" + - qConfigPrintRtc(std::make_tuple(¶m.rec.tpc, ¶m.rec.trd, ¶m.rec, ¶m.par), useConstexpr); + qConfigPrintRtc(std::make_tuple(¶m.rec.tpc, ¶m.rec.trd, ¶m.rec, ¶m.par), useConstexpr, gpuConstexprArrayInConstantMem); } static_assert(sizeof(o2::gpu::GPUParam) == sizeof(o2::gpu::GPUParamRTC), "RTC param size mismatch"); diff --git a/GPU/GPUTracking/Base/GPUParamRTC.h b/GPU/GPUTracking/Base/GPUParamRTC.h index 96341a0555398..152bbfe84006c 100644 --- a/GPU/GPUTracking/Base/GPUParamRTC.h +++ b/GPU/GPUTracking/Base/GPUParamRTC.h @@ -22,7 +22,7 @@ namespace o2::gpu { -namespace gpu_rtc +namespace internal::rtc { #define QCONFIG_GENRTC #define BeginNamespace(...) @@ -31,11 +31,11 @@ namespace gpu_rtc #undef QCONFIG_GENRTC #undef BeginNamespace #undef EndNamespace -} // namespace gpu_rtc +} // namespace internal::rtc -struct GPUParamRTC : public internal::GPUParam_t { +struct GPUParamRTC : public internal::GPUParam_t { void setFrom(const GPUParam& param); - static std::string generateRTCCode(const GPUParam& param, bool useConstexpr); + static std::string generateRTCCode(const GPUParam& param, bool useConstexpr, bool gpuConstexprArrayInConstantMem); }; } // namespace o2::gpu diff --git a/GPU/GPUTracking/Base/GPUReconstructionDeviceBase.h b/GPU/GPUTracking/Base/GPUReconstructionDeviceBase.h index 0b1cb5f643571..1621e1e4608c3 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionDeviceBase.h +++ b/GPU/GPUTracking/Base/GPUReconstructionDeviceBase.h @@ -80,6 +80,16 @@ inline size_t GPUReconstructionDeviceBase::GPUMemCpyAlways(bool onGpu, void* dst return GPUReconstructionCPU::GPUMemCpyAlways(false, dst, src, size, stream, toGPU, ev, evList, nEvents); } } + +namespace internal::rtchelpers +{ +static inline void getRTCMacroDefinitions(std::vector& definitions) // Device macros used by the RTC code of qConfigPrintRtc, as "name expansion"; static, so each translation unit gets its own expansion: call only in backend sources compiled with the device macros +{ +#define GPUCA_RTC_M_STR_DEFINITION(a) #a " " GPUCA_M_STR(a) + definitions = {GPUCA_RTC_M_STR_DEFINITION(GPUdi()), GPUCA_RTC_M_STR_DEFINITION(GPUconstexpr())}; +#undef GPUCA_RTC_M_STR_DEFINITION +} +} // namespace internal::rtchelpers } // namespace o2::gpu #endif diff --git a/GPU/GPUTracking/Base/GPUReconstructionRTCHelpers.inc b/GPU/GPUTracking/Base/GPUReconstructionRTCHelpers.inc index a09dacc874ed0..08a6ca5df25b8 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionRTCHelpers.inc +++ b/GPU/GPUTracking/Base/GPUReconstructionRTCHelpers.inc @@ -36,15 +36,19 @@ #include #include -namespace o2::gpu::internal::rtc +namespace o2::gpu::internal::rtchelpers { -static std::string paramCode(const GPUSettingsProcessing& proc, const GPUParam& param) // RTC defines and parameters, common to all compilations +static std::string paramCode(const GPUSettingsProcessing& proc, const GPUParam& param, const std::vector& macroDefinitions, bool gpuConstexprArrayInConstantMem) // RTC defines and parameters, common to all compilations; macroDefinitions: device macros used by the generated code (the embedded source is already preprocessed), stringified by the backend { - return std::string("#define GPUCA_RTC_CODE\n") + + std::string defines; + for (const auto& def : macroDefinitions) { + defines += "#define " + def + "\n"; + } + return defines + "#define GPUCA_RTC_CODE\n" + (proc.rtc.optSpecialCode ? "#define GPUCA_RTC_SPECIAL_CODE(...) __VA_ARGS__\n" : "#define GPUCA_RTC_SPECIAL_CODE(...)\n") + (proc.rtc.optConstexpr ? "#define GPUCA_RTC_CONSTEXPR constexpr\n" : "#define GPUCA_RTC_CONSTEXPR\n") + - GPUParamRTC::generateRTCCode(param, proc.rtc.optConstexpr); + GPUParamRTC::generateRTCCode(param, proc.rtc.optConstexpr, gpuConstexprArrayInConstantMem); } static void tmpFilename(std::string& filename, const char* defaultPrefix) @@ -357,4 +361,4 @@ class Cache // RTC cache file /rtc..cache. (no id with int32_t mFd = -1; }; -} // namespace o2::gpu::internal::rtc +} // namespace o2::gpu::internal::rtchelpers diff --git a/GPU/GPUTracking/Base/cpudevice/GPUReconstructionCPUDevice.cxx b/GPU/GPUTracking/Base/cpudevice/GPUReconstructionCPUDevice.cxx index 149bb75c52792..9e2b82db67a9e 100644 --- a/GPU/GPUTracking/Base/cpudevice/GPUReconstructionCPUDevice.cxx +++ b/GPU/GPUTracking/Base/cpudevice/GPUReconstructionCPUDevice.cxx @@ -445,8 +445,9 @@ template void GPUReconstructionProcessing::KernelInterface& kernels) +void GPUReconstructionCPUDevice::getGPURTCBackendCode(std::vector& kernels, std::vector& macroDefinitions) { + internal::rtchelpers::getRTCMacroDefinitions(macroDefinitions); #define GPUCA_KRNL(...) kernels.emplace_back(GPUCA_M_STR(GPUCA_CPUDEVICE_KRNL_RTC(__VA_ARGS__))); #include "GPUReconstructionKernelList.h" #undef GPUCA_KRNL diff --git a/GPU/GPUTracking/Base/cpudevice/GPUReconstructionCPUDevice.h b/GPU/GPUTracking/Base/cpudevice/GPUReconstructionCPUDevice.h index 239afd60c6d0e..8ef4973c9cad4 100644 --- a/GPU/GPUTracking/Base/cpudevice/GPUReconstructionCPUDevice.h +++ b/GPU/GPUTracking/Base/cpudevice/GPUReconstructionCPUDevice.h @@ -72,7 +72,7 @@ class GPUReconstructionCPUDevice : public GPUReconstructionProcessing::KernelInt std::vector> mEventStorage; // Backs the deviceEvents in mEvents, inner vectors are never resized int32_t genRTC(std::string& filename, uint32_t& nCompile); - void getRTCKernelCalls(std::vector& kernels); + void getGPURTCBackendCode(std::vector& kernels, std::vector& macroDefinitions); // Kernel calls and device macros for the RTC code, stringified with the backend's device macros void genAndLoadRTC(); }; diff --git a/GPU/GPUTracking/Base/cpudevice/GPUReconstructionCPUDeviceGenRTC.cxx b/GPU/GPUTracking/Base/cpudevice/GPUReconstructionCPUDeviceGenRTC.cxx index afa6b24098972..311315b92db05 100644 --- a/GPU/GPUTracking/Base/cpudevice/GPUReconstructionCPUDeviceGenRTC.cxx +++ b/GPU/GPUTracking/Base/cpudevice/GPUReconstructionCPUDeviceGenRTC.cxx @@ -33,7 +33,7 @@ QGET_LD_BINARY_SYMBOLS(GPUReconstructionCPUDevicertc_command); QGET_LD_BINARY_SYMBOLS(GPUReconstructionCPUDevicertc_command_no_fast_math); using namespace o2::gpu; -namespace rtc = o2::gpu::internal::rtc; +namespace rtchelpers = o2::gpu::internal::rtchelpers; static constexpr const char* RTC_SRC_EXTENSION = ".cxx"; static constexpr const char* RTC_BIN_EXTENSION = ".so"; @@ -45,39 +45,39 @@ int32_t GPUReconstructionCPUDevice::genRTC(std::string& filename, uint32_t& nCom { const auto& proc = GetProcessingSettings(); const std::string_view rtcSource(_binary_GPUReconstructionCPUDevicertc_src_start, _binary_GPUReconstructionCPUDevicertc_src_len); - const std::string rtcparam = rtc::paramCode(proc, param()); - rtc::tmpFilename(filename, "/tmp/o2cagpu_rtc_cpudevice_"); + std::vector kernels, macroDefinitions; + getGPURTCBackendCode(kernels, macroDefinitions); + const std::string rtcparam = rtchelpers::paramCode(proc, param(), macroDefinitions, false); + rtchelpers::tmpFilename(filename, "/tmp/o2cagpu_rtc_cpudevice_"); - std::vector kernels; - getRTCKernelCalls(kernels); for (uint32_t i = 0; i < kernels.size(); i++) { if (kernelWithoutRTC(GetKernelName(i))) { kernels[i].clear(); } } - const std::string kernelsall = rtc::joinKernels(kernels); + const std::string kernelsall = rtchelpers::joinKernels(kernels); - const std::string baseCommand = rtc::baseCommand(proc, std::string_view(_binary_GPUReconstructionCPUDevicertc_command_start, _binary_GPUReconstructionCPUDevicertc_command_len)) + " " + proc.rtctech.overrideArchitecture; + const std::string baseCommand = rtchelpers::baseCommand(proc, std::string_view(_binary_GPUReconstructionCPUDevicertc_command_start, _binary_GPUReconstructionCPUDevicertc_command_len)) + " " + proc.rtctech.overrideArchitecture; const std::string noFastMath(_binary_GPUReconstructionCPUDevicertc_command_no_fast_math_start, _binary_GPUReconstructionCPUDevicertc_command_no_fast_math_len); mParDevice->par_CF_SCAN_WORKGROUP_SIZE = 1; // Must match the 1 thread per block for the scan kernels to compile, the clusterizer uses the CPU stream compaction - rtc::loadLaunchBounds(proc, *mParDevice); - const std::string launchBounds = rtc::launchBoundsCode(proc, *mParDevice, 0, mWarpSize); + rtchelpers::loadLaunchBounds(proc, *mParDevice); + const std::string launchBounds = rtchelpers::launchBoundsCode(proc, *mParDevice, 0, mWarpSize); if (proc.rtctech.printLaunchBounds >= 2) { return 1; } nCompile = proc.rtc.compilePerKernel ? kernels.size() : 1; const std::string compilerVersions = getBackendVersions(); - rtc::Cache cache(proc, "cpudevice", {rtcSource, rtcparam, baseCommand, kernelsall, launchBounds, compilerVersions}); + rtchelpers::Cache cache(proc, "cpudevice", {rtcSource, rtcparam, baseCommand, kernelsall, launchBounds, compilerVersions}); if (!cache.load(filename, RTC_BIN_EXTENSION, nCompile)) { - rtc::compile(proc, nCompile, "CPUDevice", [&](uint32_t i) { + rtchelpers::compile(proc, nCompile, "CPUDevice", [&](uint32_t i) { const std::string fileBase = filename + "_" + std::to_string(i); if (proc.debugLevel >= 3) { printf("Compiling %s\n", (fileBase + RTC_SRC_EXTENSION).c_str()); } - const bool deterministic = rtc::deterministic(proc, GetKernelName(i)); - rtc::writeSource(fileBase + RTC_SRC_EXTENSION, deterministic, rtcparam, launchBounds, rtcSource, proc.rtc.compilePerKernel ? kernels[i] : kernelsall); + const bool deterministic = rtchelpers::deterministic(proc, GetKernelName(i)); + rtchelpers::writeSource(fileBase + RTC_SRC_EXTENSION, deterministic, rtcparam, launchBounds, rtcSource, proc.rtc.compilePerKernel ? kernels[i] : kernelsall); // Export only the kernel entry points, everything else stays local to the RTC library to avoid symbol collisions FILE* fp = fopen((fileBase + RTC_MAP_EXTENSION).c_str(), "w+b"); @@ -87,7 +87,7 @@ int32_t GPUReconstructionCPUDevice::genRTC(std::string& filename, uint32_t& nCom fclose(fp); const std::string command = baseCommand + (deterministic ? " " + noFastMath : "") + " -Wl,--version-script=" + fileBase + RTC_MAP_EXTENSION + " -x c++ " + fileBase + RTC_SRC_EXTENSION + " -o " + fileBase + RTC_BIN_EXTENSION; - rtc::runCommand(proc, command, fileBase + RTC_SRC_EXTENSION, "Error during CPUDevice RTC compilation"); + rtchelpers::runCommand(proc, command, fileBase + RTC_SRC_EXTENSION, "Error during CPUDevice RTC compilation"); }); cache.store(filename, RTC_BIN_EXTENSION, nCompile); } diff --git a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.h b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.h index 6f92ca1938e0d..225a381defee6 100644 --- a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.h +++ b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDA.h @@ -88,7 +88,7 @@ class GPUReconstructionCUDA : public GPUReconstructionProcessing::KernelInterfac private: int32_t genRTC(std::string& filename, uint32_t& nCompile); - void getRTCKernelCalls(std::vector& kernels); + void getGPURTCBackendCode(std::vector& kernels, std::vector& macroDefinitions); // Kernel calls and device macros for the RTC code, stringified with the backend's device macros void genAndLoadRTC(); void loadKernelModules(bool perKernel); const char *mRtcSrcExtension = ".src", *mRtcBinExtension = ".o"; diff --git a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAGenRTC.cxx b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAGenRTC.cxx index c16bbae598e72..aa820357d92e7 100644 --- a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAGenRTC.cxx +++ b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDAGenRTC.cxx @@ -20,7 +20,7 @@ #include using namespace o2::gpu; -namespace rtc = o2::gpu::internal::rtc; +namespace rtchelpers = o2::gpu::internal::rtchelpers; #include "utils/qGetLdBinarySymbols.h" QGET_LD_BINARY_SYMBOLS(GPUReconstructionCUDArtc_src); @@ -32,18 +32,18 @@ int32_t GPUReconstructionCUDA::genRTC(std::string& filename, uint32_t& nCompile) { const auto& proc = GetProcessingSettings(); const std::string_view rtcSource(_binary_GPUReconstructionCUDArtc_src_start, _binary_GPUReconstructionCUDArtc_src_len); - const std::string rtcparam = rtc::paramCode(proc, param()); - rtc::tmpFilename(filename, "/tmp/o2cagpu_rtc_"); + std::vector kernels, macroDefinitions; + getGPURTCBackendCode(kernels, macroDefinitions); + const std::string rtcparam = rtchelpers::paramCode(proc, param(), macroDefinitions, true); + rtchelpers::tmpFilename(filename, "/tmp/o2cagpu_rtc_"); - std::vector kernels; - getRTCKernelCalls(kernels); - const std::string kernelsall = rtc::joinKernels(kernels); + const std::string kernelsall = rtchelpers::joinKernels(kernels); - const std::string baseCommand = rtc::baseCommand(proc, std::string_view(_binary_GPUReconstructionCUDArtc_command_start, _binary_GPUReconstructionCUDArtc_command_len)) + " " + + const std::string baseCommand = rtchelpers::baseCommand(proc, std::string_view(_binary_GPUReconstructionCUDArtc_command_start, _binary_GPUReconstructionCUDArtc_command_len)) + " " + (proc.rtctech.overrideArchitecture != "" ? proc.rtctech.overrideArchitecture : std::string(_binary_GPUReconstructionCUDArtc_command_arch_start, _binary_GPUReconstructionCUDArtc_command_arch_len)); const std::string noFastMath(_binary_GPUReconstructionCUDArtc_command_no_fast_math_start, _binary_GPUReconstructionCUDArtc_command_no_fast_math_len); - rtc::loadLaunchBounds(proc, *mParDevice); + rtchelpers::loadLaunchBounds(proc, *mParDevice); if constexpr (std::string_view("CUDA") == "HIP") { // Check if we are RTC-compiling for HIP if (proc.hipOverrideAMDEUSperCU > 0) { mParDevice->par_AMD_EUS_PER_CU = proc.hipOverrideAMDEUSperCU; @@ -56,25 +56,25 @@ int32_t GPUReconstructionCUDA::genRTC(std::string& filename, uint32_t& nCompile) mParDevice->par_LB_maxThreads[i] = mWarpSize; } } - const std::string launchBounds = rtc::launchBoundsCode(proc, *mParDevice, mParDevice->par_AMD_EUS_PER_CU ? (mParDevice->par_AMD_EUS_PER_CU * mWarpSize) : 0, mWarpSize); + const std::string launchBounds = rtchelpers::launchBoundsCode(proc, *mParDevice, mParDevice->par_AMD_EUS_PER_CU ? (mParDevice->par_AMD_EUS_PER_CU * mWarpSize) : 0, mWarpSize); if (proc.rtctech.printLaunchBounds >= 2) { return 1; } nCompile = proc.rtc.compilePerKernel ? kernels.size() : 1; const std::string compilerVersions = getBackendVersions(); - rtc::Cache cache(proc, "cuda", {rtcSource, rtcparam, baseCommand, kernelsall, launchBounds, compilerVersions}); + rtchelpers::Cache cache(proc, "cuda", {rtcSource, rtcparam, baseCommand, kernelsall, launchBounds, compilerVersions}); if (!cache.load(filename, mRtcBinExtension, nCompile)) { - rtc::compile(proc, nCompile, "CUDA", [&](uint32_t i) { + rtchelpers::compile(proc, nCompile, "CUDA", [&](uint32_t i) { const std::string fileBase = filename + "_" + std::to_string(i); if (proc.debugLevel >= 3) { printf("Compiling %s\n", (fileBase + mRtcSrcExtension).c_str()); } - const bool deterministic = rtc::deterministic(proc, GetKernelName(i)); + const bool deterministic = rtchelpers::deterministic(proc, GetKernelName(i)); const std::string kernel = std::string("extern \"C\" {") + (proc.rtc.compilePerKernel ? kernels[i] : kernelsall) + "}"; - rtc::writeSource(fileBase + mRtcSrcExtension, deterministic, rtcparam, launchBounds, rtcSource, kernel); + rtchelpers::writeSource(fileBase + mRtcSrcExtension, deterministic, rtcparam, launchBounds, rtcSource, kernel); const std::string command = baseCommand + (deterministic ? " " + noFastMath : "") + " -c " + fileBase + mRtcSrcExtension + " -o " + fileBase + mRtcBinExtension; - rtc::runCommand(proc, command, fileBase + mRtcSrcExtension, "Error during CUDA compilation"); + rtchelpers::runCommand(proc, command, fileBase + mRtcSrcExtension, "Error during CUDA compilation"); }); cache.store(filename, mRtcBinExtension, nCompile); } diff --git a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDARTCCalls.cu b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDARTCCalls.cu index 571428dc39e21..b82e7180858a6 100644 --- a/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDARTCCalls.cu +++ b/GPU/GPUTracking/Base/cuda/GPUReconstructionCUDARTCCalls.cu @@ -23,8 +23,9 @@ using namespace o2::gpu; -void GPUReconstructionCUDA::getRTCKernelCalls(std::vector& kernels) +void GPUReconstructionCUDA::getGPURTCBackendCode(std::vector& kernels, std::vector& macroDefinitions) { + internal::rtchelpers::getRTCMacroDefinitions(macroDefinitions); #undef GPUCA_KRNL #define GPUCA_KRNL(...) kernels.emplace_back(GPUCA_M_STR(GPUCA_KRNLGPU(__VA_ARGS__))); #undef __launch_bounds__ diff --git a/GPU/GPUTracking/Definitions/GPUSettingsList.h b/GPU/GPUTracking/Definitions/GPUSettingsList.h index ce80db8d28299..cc8f3f5bca0c5 100644 --- a/GPU/GPUTracking/Definitions/GPUSettingsList.h +++ b/GPU/GPUTracking/Definitions/GPUSettingsList.h @@ -90,7 +90,7 @@ AddOptionRTC(extraClusterErrorSplitPadSharedSingleY2, float, 0.03f, "", 0, "Addi AddOptionRTC(extraClusterErrorFactorSplitPadSharedSingleY2, float, 3.0f, "", 0, "Multiplicative extra cluster error for Y2 if splitpad, shared, or single set") AddOptionRTC(extraClusterErrorSplitTimeSharedSingleZ2, float, 0.03f, "", 0, "Additive extra cluster error for Z2 if splittime, shared, or single set") AddOptionRTC(extraClusterErrorFactorSplitTimeSharedSingleZ2, float, 3.0f, "", 0, "Multiplicative extra cluster error for Z2 if splittime, shared, or single set") -AddOptionArray(errorsCECrossing, float, 5, (0.f, 0.f, 0.f, 0.f, 0.f), "", 0, "Extra errors to add to track when crossing CE, depending on addErrorsCECrossing") // BUG: CUDA cannot yet handle AddOptionArrayRTC +AddOptionArrayRTC(errorsCECrossing, float, 5, (0.f, 0.f, 0.f, 0.f, 0.f), "", 0, "Extra errors to add to track when crossing CE, depending on addErrorsCECrossing") AddOptionRTC(extrapolationTrackingYRangeUpper, float, 0.85f, "", 0, "Inner portion of y-range in sector that is not used in searching for extrapolated track candidates") AddOptionRTC(extrapolationTrackingYRangeLower, float, 0.85f, "", 0, "Inner portion of y-range in sector that is not used in searching for extrapolated track candidates") AddOptionRTC(trackFollowingYFactor, float, 4.f, "", 0, "Weight of y residual vs z residual in tracklet constructor") @@ -190,7 +190,7 @@ AddOptionRTC(rebuildTrackCandidateErrChi2, uint8_t, 0, "", 0, "Rank cluster cand AddOptionRTC(rebuildTrackMaxRowsFromEnd, uint8_t, 10, "", 0, "If the last fitted hit of the outward way of the rebuild is more than this number of rows away from the end of the track, the final fit starts from the original track parameters") AddOptionRTC(rebuildTrackFallbackMaxNCl, uint8_t, 20, "", 0, "For tracks with at most this number of clusters, keep the original cluster of a row as candidate during rebuild if no candidate was found but it passes the interpolated chi2 cut (0 = disabled)") AddOptionRTC(rebuildTrackNonIntMinNDF, uint8_t, 10, "", 0, "NDF the track must exceed for non-interpolated cluster attachment (one-sided search and extrapolation) during rebuild") -AddOptionArray(PID_remap, int8_t, 9, (0, 1, 2, 3, 4, 5, 6, 7, 8), "", 0, "Remap Ipid to PID_reamp[Ipid] (no remap if<0)") // BUG: CUDA cannot yet handle AddOptionArrayRTC +AddOptionArrayRTC(PID_remap, int8_t, 9, (0, 1, 2, 3, 4, 5, 6, 7, 8), "", 0, "Remap Ipid to PID_reamp[Ipid] (no remap if<0)") AddVariableRTC(nWays, uint8_t, 0) AddHelp("help", 0) EndConfig() diff --git a/GPU/GPUTracking/utils/qconfig_internal.h b/GPU/GPUTracking/utils/qconfig_internal.h index 26076699ffda7..098dae010de1e 100644 --- a/GPU/GPUTracking/utils/qconfig_internal.h +++ b/GPU/GPUTracking/utils/qconfig_internal.h @@ -168,6 +168,31 @@ void qConfigPrint(const T& qconfig_tmp_object, const std::string& blockName); // #define EndConfig() // End QCONFIG_INSTANCE +#elif defined(QCONFIG_PRINT_RTC_ARRAYS) // GPUconstexpr() arrays at namespace scope for the AddOptionArrayRTC entries, printed before the structs by qConfigPrintRtc if gpuConstexprArrayInConstantMem is set +#define AddOption(name, type, default, optname, optnameshort, help, ...) +#define AddVariable(name, type, default) +#define AddOptionArray(name, type, count, default, optname, optnameshort, help, ...) +#define AddOptionVec(name, type, optname, optnameshort, help, ...) +#define AddOptionSet(...) +#define AddSubConfig(name, instance) +#define AddVariableRTC(name, type, default) +#define AddOptionRTC(name, type, default, optname, optnameshort, help, ...) +#define AddOptionArrayRTC(name, type, count, default, optname, optnameshort, help, ...) \ + out << "GPUconstexpr() " << qon_mxstr(type) << " qConfigRTC_" << qConfigCurrentName << "_" << qon_mxstr(name) << "[" << count << "] = {"; \ + for (int32_t i = 0; i < count; i++) { \ + out << (i ? ", " : "") << ::qConfig::print_type(std::get(tSrc)->name[i], true); \ + } \ + out << "};\n"; +#define BeginConfig(name, instance) \ + { \ + using qConfigCurrentType = name; \ + [[maybe_unused]] constexpr const char* qConfigCurrentName = qon_mxstr(name); +#define BeginSubConfig(name, instance, parent, preoptname, preoptnameshort, descr, ...) BeginConfig(name, instance) +#define EndConfig() } +#define BeginNamespace(name) out << "namespace " << qon_mxstr(name) << " {\n"; +#define EndNamespace() out << "}\n"; + +// End QCONFIG_PRINT_RTC_ARRAYS #elif defined(QCONFIG_PRINT_RTC) #define AddOption(name, type, default, optname, optnameshort, help, ...) out << qon_mxstr(type) << " " << qon_mxstr(name) << ";\n"; #define AddVariable(name, type, default) out << qon_mxstr(type) << " " << qon_mxstr(name) << ";\n"; @@ -181,20 +206,27 @@ void qConfigPrint(const T& qconfig_tmp_object, const std::string& blockName); // AddOption(name, type, default, optname, optnameshort, help); \ } #define AddOptionRTC(name, type, default, optname, optnameshort, help, ...) AddVariableRTC(name, type, default) -#define AddOptionArrayRTC(name, type, count, default, optname, optnameshort, help, ...) \ - if (useConstexpr) { \ - out << "static constexpr " << qon_mxstr(type) << " " << qon_mxstr(name) << "[" << count << "] = {" << ::qConfig::print_type(std::get(tSrc)->name[0]); \ - for (int32_t i = 1; i < count; i++) { \ - out << ", " << qConfig::print_type(std::get(tSrc)->name[i]); \ - } \ - out << "};\n"; \ - out << qon_mxstr(type) << " " << qon_mxstr(qon_mxcat(_dummy_, name)) << ";\n"; \ - } else { \ - AddOptionArray(name, type, count, default, optname, optnameshort, help); \ +#define AddOptionArrayRTC(name, type, count, default, optname, optnameshort, help, ...) \ + if (useConstexpr && gpuConstexprArrayInConstantMem) { /* CUDA cannot access static constexpr member arrays in device code, so the values are in a GPUconstexpr() array (QCONFIG_PRINT_RTC_ARRAYS), the storage keeps the layout */ \ + const std::string arrayName = std::string("qConfigRTC_") + qConfigCurrentName + "_" + qon_mxstr(name); \ + out << "struct " << qon_mxstr(qon_mxcat(qConfigArrayRTC_, name)) << " {\n" \ + << qon_mxstr(type) << " values[" << count << "];\n"; \ + out << "template GPUdi() constexpr " << qon_mxstr(type) << " operator[](I i) const { return " << arrayName << "[i]; }\n"; \ + out << "GPUdi() constexpr operator const " << qon_mxstr(type) << "*() const { return " << arrayName << "; }\n} " << qon_mxstr(name) << ";\n"; \ + } else if (useConstexpr) { \ + out << "static constexpr " << qon_mxstr(type) << " " << qon_mxstr(name) << "[" << count << "] = {"; \ + for (int32_t i = 0; i < count; i++) { \ + out << (i ? ", " : "") << ::qConfig::print_type(std::get(tSrc)->name[i], true); \ + } \ + out << "};\n" \ + << qon_mxstr(type) << " " << qon_mxstr(qon_mxcat(_dummy_, name)) << "[" << count << "];\n"; \ + } else { \ + AddOptionArray(name, type, count, default, optname, optnameshort, help); \ } -#define BeginConfig(name, instance) \ - { \ - using qConfigCurrentType = name; \ +#define BeginConfig(name, instance) \ + { \ + using qConfigCurrentType = name; \ + [[maybe_unused]] constexpr const char* qConfigCurrentName = qon_mxstr(name); \ out << "struct " << qon_mxstr(name) << " {\n"; #define BeginSubConfig(name, instance, parent, preoptname, preoptnameshort, descr, ...) BeginConfig(name, instance) #define EndConfig() \ diff --git a/GPU/GPUTracking/utils/qconfig_rtc.h b/GPU/GPUTracking/utils/qconfig_rtc.h index c98f1f8cf309a..efbca93681e56 100644 --- a/GPU/GPUTracking/utils/qconfig_rtc.h +++ b/GPU/GPUTracking/utils/qconfig_rtc.h @@ -19,10 +19,15 @@ #include "qconfig_helpers.h" template -static std::string qConfigPrintRtc(const T& tSrc, bool useConstexpr) +static std::string qConfigPrintRtc(const T& tSrc, bool useConstexpr, bool gpuConstexprArrayInConstantMem) // gpuConstexprArrayInConstantMem: put the values of constexpr arrays in GPUconstexpr() arrays at namespace scope (needed for CUDA / HIP), instead of static constexpr members { std::stringstream out; out << std::hexfloat; + if (useConstexpr && gpuConstexprArrayInConstantMem) { +#define QCONFIG_PRINT_RTC_ARRAYS +#include "qconfig_internal.h" +#undef QCONFIG_PRINT_RTC_ARRAYS + } #define QCONFIG_PRINT_RTC #include "qconfig_internal.h" #undef QCONFIG_PRINT_RTC From 02860951a388db37f26453abbe95b3556ab28f3b Mon Sep 17 00:00:00 2001 From: David Rohr Date: Tue, 24 Nov 2026 13:42:52 +0100 Subject: [PATCH 29/32] GPU TPC: Add option to disable marking history clusters as adjacent --- GPU/GPUTracking/Definitions/GPUSettingsList.h | 2 +- GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GPU/GPUTracking/Definitions/GPUSettingsList.h b/GPU/GPUTracking/Definitions/GPUSettingsList.h index cc8f3f5bca0c5..9c8c66ecdcb38 100644 --- a/GPU/GPUTracking/Definitions/GPUSettingsList.h +++ b/GPU/GPUTracking/Definitions/GPUSettingsList.h @@ -158,7 +158,7 @@ AddOptionRTC(mergerNonInterpolateRejectMinNDF, uint8_t, 5, "", 0, "Minimum NDF o AddOptionRTC(rebuildTrackInFit, uint8_t, 1, "", 0, "Rebuild track completely during fit based on clusters closed to interpolated track positions, adds 2 fit iterations") AddOptionRTC(rebuildTrackInFitClusterCandidates, uint8_t, 3, "", 0, "Number of cluster candidates per row for rebuilt track") AddOptionRTC(disableRebuildAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during track rebuid (1: current row, 2: interpolate missing row, 4: one sided interpolation, 8: original hit, 16: extrapolation)") -AddOptionRTC(disableMarkAdjacent, uint8_t, 0, "", 0, "Bitmask to disable certain steps during refit to mark adjacenrt clusters (1: current row, 2: interpolate missing rows, 4: extrapolate inwards / outwards, 8: loop following)") // TODO: Add history +AddOptionRTC(disableMarkAdjacent, uint8_t, 0, "", 0, "Bitmask to disable certain steps during refit to mark adjacenrt clusters (1: current row, 2: interpolate missing rows, 4: extrapolate inwards / outwards, 8: loop following, 16 track history)") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking (prolong tracks to adjacent sectors to find short segments)") diff --git a/GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx b/GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx index 1333f92ca3201..d1b8be4fd811b 100644 --- a/GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx +++ b/GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx @@ -1908,7 +1908,7 @@ GPUd() void GPUTPCGMMerger::PrepareForFit1(int32_t nBlocks, int32_t nThreads, in mTrackOrderAttach[mTrackSort[i]] = i; GPUTPCGMMergedTrack& trk = mMergedTracks[i]; if (trk.OK()) { - const bool protect = CAMath::Abs(trk.GetParam().GetQPt() * Param().qptB5Scaler) <= Param().rec.tpc.rejectQPtB5 && !trk.MergedLooper() && trk.Leg() == 0; + const bool protect = CAMath::Abs(trk.GetParam().GetQPt() * Param().qptB5Scaler) <= Param().rec.tpc.rejectQPtB5 && !trk.MergedLooper() && trk.Leg() == 0 && !(Param().rec.tpc.disableMarkAdjacent & 16); [[maybe_unused]] uint8_t rowMin = 255, rowMax = 0; for (uint32_t j = 0; j < trk.NClusters(); j++) { rowMin = CAMath::Min(rowMin, mClusters[trk.FirstClusterRef() + j].row); From 269f4b3ecc53cdd720a55fe0b78fb3acd1aa1af0 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Tue, 24 Nov 2026 13:59:30 +0100 Subject: [PATCH 30/32] GPU: Automatically sort entries of GPU Settings structures by datatype size --- Detectors/TPC/qc/include/TPCQC/Tracking.h | 2 +- Detectors/TRD/workflow/README.md | 2 +- GPU/GPUTracking/CMakeLists.txt | 19 +++- .../DataTypes/GPUO2ConfigurableParam.h | 2 +- GPU/GPUTracking/DataTypes/GPUSettings.h | 2 +- ...ettingsList.h => GPUSettingsList.template} | 2 +- ...play.h => GPUSettingsListDisplay.template} | 0 ...e.h => GPUSettingsListStandalone.template} | 0 .../Global/GPUChainTrackingDebug.h | 2 +- .../TRDTracking/macros/run_trd_tracker.C | 2 +- .../cmake/gpu_settings_list_generator.cmake | 90 +++++++++++++++++++ GPU/GPUTracking/utils/qconfig.cxx | 13 +++ GPU/GPUTracking/utils/qconfig_genrtti.inc | 2 +- GPU/GPUTracking/utils/qconfig_internal.h | 44 +++++---- GPU/documentation/run-time-compilation.md | 2 +- 15 files changed, 153 insertions(+), 31 deletions(-) rename GPU/GPUTracking/Definitions/{GPUSettingsList.h => GPUSettingsList.template} (99%) rename GPU/GPUTracking/Definitions/{GPUSettingsListDisplay.h => GPUSettingsListDisplay.template} (100%) rename GPU/GPUTracking/Definitions/{GPUSettingsListStandalone.h => GPUSettingsListStandalone.template} (100%) create mode 100644 GPU/GPUTracking/cmake/gpu_settings_list_generator.cmake diff --git a/Detectors/TPC/qc/include/TPCQC/Tracking.h b/Detectors/TPC/qc/include/TPCQC/Tracking.h index 7f9f231468895..4880cc9f5fc6c 100644 --- a/Detectors/TPC/qc/include/TPCQC/Tracking.h +++ b/Detectors/TPC/qc/include/TPCQC/Tracking.h @@ -44,7 +44,7 @@ struct ClusterNativeAccess; namespace qc { // Class for tracking QA (efficiency / resolution) -// Some settings can be steered via --configKeyValues: (See GPUSettingsList.h for actual definitions). Relevant QA parameters are: +// Some settings can be steered via --configKeyValues: (See GPUSettingsList.template for actual definitions). Relevant QA parameters are: // "GPU_QA.strict=[bool]" Strict QA mode: Only consider resolution of tracks where the fit ended within 5 cm of the reference, and remove outliers. (Default: true) // "GPU_QA.qpt=[float]" Set cut for Q/Pt. (Default: 10.0) // "GPU_QA.recThreshold=[float]" Compute the efficiency including impure tracks with fake contamination. (Default 0.9) diff --git a/Detectors/TRD/workflow/README.md b/Detectors/TRD/workflow/README.md index 1d54af5612e39..be6566920b680 100644 --- a/Detectors/TRD/workflow/README.md +++ b/Detectors/TRD/workflow/README.md @@ -19,7 +19,7 @@ We have the following binaries which can be used to assemble a global workflow: Run any of the workflows with `--help` or `--help full` to see the available options and their explanations. -The available `--configKeyValues` for the global tracking workflow are mostly listed in [GPUSettingsList.h](../../../../dev/GPU/GPUTracking/Definitions/GPUSettingsList.h). Search for GPUSettingsRecTRD to find options as for example the minimum number of TRD tracklets required for a TRD track to not be discarded. +The available `--configKeyValues` for the global tracking workflow are mostly listed in [GPUSettingsList.template](../../../../dev/GPU/GPUTracking/Definitions/GPUSettingsList.template). Search for GPUSettingsRecTRD to find options as for example the minimum number of TRD tracklets required for a TRD track to not be discarded. diff --git a/GPU/GPUTracking/CMakeLists.txt b/GPU/GPUTracking/CMakeLists.txt index c6a6906911680..6993bbae056e1 100644 --- a/GPU/GPUTracking/CMakeLists.txt +++ b/GPU/GPUTracking/CMakeLists.txt @@ -67,9 +67,17 @@ set(SRCS set(SRCS_DATATYPES DataTypes/GPUDataTypesConfig.cxx DataTypes/GPUConfigDump.cxx DataTypes/GPUTPCGMPolynomialField.cxx) +set(ON_THE_FLY_DIR ${CMAKE_CURRENT_BINARY_DIR}/include_gpu_onthefly) +file(MAKE_DIRECTORY ${ON_THE_FLY_DIR}) +include(cmake/gpu_settings_list_generator.cmake) +foreach(GPU_SETTINGS_LIST GPUSettingsList GPUSettingsListDisplay GPUSettingsListStandalone) + generate_gpu_settings_list(${CMAKE_CURRENT_SOURCE_DIR}/Definitions/${GPU_SETTINGS_LIST}.template ${ON_THE_FLY_DIR}/${GPU_SETTINGS_LIST}.h) + list(APPEND GPU_SETTINGS_LIST_HEADERS ${ON_THE_FLY_DIR}/${GPU_SETTINGS_LIST}.h) +endforeach() + set(HDRS_CINT_O2 Merger/GPUTPCGMTrackParam.h Merger/GPUTPCGMMergedTrack.h Merger/GPUTPCGMSectorTrack.h Merger/GPUTPCGMBorderTrack.h TRDTracking/GPUTRDInterfaces.h) set(HDRS_CINT_DATATYPES DataTypes/GPUTPCGMMergedTrackHit.h) -set(HDRS_CINT_O2_ADDITIONAL DataTypes/GPUSettings.h DataTypes/GPUSettingsTypes.h Definitions/GPUSettingsListDisplay.h Definitions/GPUSettingsList.h DataTypes/GPUDataTypesIO.h DataTypes/GPUDataTypesConfig.h DataTypes/GPUDataTypesQA.h DataTypes/GPUTRDTrack.h DataTypes/GPUTRDRecoParam.h DataTypes/CalibdEdxTrackTopologyPol.h DataTypes/CalibdEdxTrackTopologySpline.h) # Manual dependencies for ROOT dictionary generation +set(HDRS_CINT_O2_ADDITIONAL DataTypes/GPUSettings.h DataTypes/GPUSettingsTypes.h DataTypes/GPUDataTypesIO.h DataTypes/GPUDataTypesConfig.h DataTypes/GPUDataTypesQA.h DataTypes/GPUTRDTrack.h DataTypes/GPUTRDRecoParam.h DataTypes/CalibdEdxTrackTopologyPol.h DataTypes/CalibdEdxTrackTopologySpline.h) # Manual dependencies for ROOT dictionary generation set(SRCS_NO_CINT DataTypes/GPUMemorySizeScalers.cxx @@ -108,6 +116,7 @@ set(SRCS_NO_H SectorTracker/GPUTPCTrackerDump.cxx Global/GPUChainTrackingIO.cxx) set(HDRS_INSTALL + ${GPU_SETTINGS_LIST_HEADERS} ${HDRS_CINT_O2} ${HDRS_CINT_DATATYPES} ${HDRS_CINT_O2_ADDITIONAL} @@ -168,7 +177,6 @@ set(HDRS_INSTALL TRDTracking/GPUTRDTrackPoint.h DataTypes/GPUTPCGMPolynomialField.h DataTypes/GPUSettingsParam.h - Definitions/GPUSettingsListStandalone.h ) set(SRCS_NO_CINT ${SRCS_NO_CINT} display/GPUDisplayInterface.cxx) @@ -234,8 +242,6 @@ if(ALIGPU_BUILD_TYPE STREQUAL "O2") DataTypes/GPUO2ConfigurableParam.cxx) endif() -set(ON_THE_FLY_DIR ${CMAKE_CURRENT_BINARY_DIR}/include_gpu_onthefly) -file(MAKE_DIRECTORY ${ON_THE_FLY_DIR}) set(TEMPLATE_HEADER_LIST Base/GPUReconstructionKernelList.template.h Base/GPUReconstructionKernelIncludes.template.h Base/GPUReconstructionIncludesDeviceAll.template.h @@ -370,6 +376,8 @@ if(ALIGPU_BUILD_TYPE STREQUAL "O2") o2_target_root_dictionary(GPUDataTypes HEADERS ${HDRS_CINT_DATATYPES} ${HDRS_CINT_O2_ADDITIONAL} LINKDEF GPUTrackingLinkDef_O2_DataTypes.h) + get_target_property(GPU_DICT_NAME ${targetName} OUTPUT_NAME) + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/G__${GPU_DICT_NAME}.cxx APPEND DEPENDS ${GPU_SETTINGS_LIST_HEADERS}) # Generated headers cannot be in HEADERS, which must be relative to the source dir o2_add_library(${MODULE} TARGETVARNAME targetName @@ -399,6 +407,8 @@ if(ALIGPU_BUILD_TYPE STREQUAL "O2") o2_target_root_dictionary(${MODULE} HEADERS ${HDRS_CINT_O2} ${HDRS_CINT_O2_ADDITIONAL} LINKDEF GPUTrackingLinkDef_O2.h) + get_target_property(GPU_DICT_NAME ${targetName} OUTPUT_NAME) + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/G__${GPU_DICT_NAME}.cxx APPEND DEPENDS ${GPU_SETTINGS_LIST_HEADERS}) # Generated headers cannot be in HEADERS, which must be relative to the source dir o2_add_test_root_macro(Standalone/tools/createGeo.C PUBLIC_LINK_LIBRARIES O2::GPUTracking @@ -421,6 +431,7 @@ if(ALIGPU_BUILD_TYPE STREQUAL "Standalone") if(GPUCA_CONFIG_ROOT) ROOT_GENERATE_DICTIONARY(G__${targetName} ${HDRS_CINT_O2} ${HDRS_CINT_DATATYPES} ${HDRS_CINT_O2_ADDITIONAL} GPUTrackingLinkDef_Standalone.h MODULE ${targetName}) + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/G__${targetName}.cxx APPEND DEPENDS ${GPU_SETTINGS_LIST_HEADERS}) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/lib${targetName}_rdict.pcm ${CMAKE_CURRENT_BINARY_DIR}/lib${targetName}.rootmap diff --git a/GPU/GPUTracking/DataTypes/GPUO2ConfigurableParam.h b/GPU/GPUTracking/DataTypes/GPUO2ConfigurableParam.h index d5102dc71c96d..99a28ea1be71b 100644 --- a/GPU/GPUTracking/DataTypes/GPUO2ConfigurableParam.h +++ b/GPU/GPUTracking/DataTypes/GPUO2ConfigurableParam.h @@ -17,7 +17,7 @@ // --configKeyValues "GPU_global.[x]=[y]" : for global GPU run configurations, like solenoidBz, gpuType, configuration object files. // --configKeyValues "GPU_rec.[x]=[y]" : for GPU reconstruction related settings used on the GPU, like pt threshold for track rejection. // --configKeyValues "GPU_proc.[x]=[y]" : for processing options steering GPU reconstruction like GPU device ID, debug output level, number of CPU threads. -// Check GPUSettingsList.h for all options +// Check GPUSettingsList.template for all options #ifndef GPUO2CONFIGURABLEPARAM_H #define GPUO2CONFIGURABLEPARAM_H diff --git a/GPU/GPUTracking/DataTypes/GPUSettings.h b/GPU/GPUTracking/DataTypes/GPUSettings.h index bfbd3df33526f..f30d7d747c659 100644 --- a/GPU/GPUTracking/DataTypes/GPUSettings.h +++ b/GPU/GPUTracking/DataTypes/GPUSettings.h @@ -24,7 +24,7 @@ #ifdef GPUCA_GPUCODE_DEVICE #define QCONFIG_GPU #endif -// See GPUSettingsList.h for a list of all available settings of GPU Reconstruction +// See GPUSettingsList.template for a list of all available settings of GPU Reconstruction #ifndef GPUCA_GPUCODE_GENRTC #include "utils/qconfig.h" #endif diff --git a/GPU/GPUTracking/Definitions/GPUSettingsList.h b/GPU/GPUTracking/Definitions/GPUSettingsList.template similarity index 99% rename from GPU/GPUTracking/Definitions/GPUSettingsList.h rename to GPU/GPUTracking/Definitions/GPUSettingsList.template index 9c8c66ecdcb38..302ca1b315ca8 100644 --- a/GPU/GPUTracking/Definitions/GPUSettingsList.h +++ b/GPU/GPUTracking/Definitions/GPUSettingsList.template @@ -32,7 +32,7 @@ BeginNamespace(o2::gpu) // Reconstruction parameters for TPC, no bool in here !!! BeginSubConfig(GPUSettingsRecTPC, tpc, configStandalone.rec, "RECTPC", 0, "Reconstruction settings", rec_tpc) -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 +AddOptionRTC(rejectQPtB5, float, 1.f / 0.050f, "", 0, "QPt threshold to reject clusters of TPC tracks (Inverse Pt, scaled to B=0.5T!!!)") AddOptionRTC(hitPickUpFactor, float, 1.f, "", 0, "multiplier for the combined cluster+track error during track following") AddOptionRTC(hitSearchArea2, float, 2.f, "", 0, "square of maximum search road of hits during seeding") AddOptionRTC(neighboursSearchArea, float, 3.f, "", 0, "area in cm for the search of neighbours, for z only used if searchWindowDZDR = 0") diff --git a/GPU/GPUTracking/Definitions/GPUSettingsListDisplay.h b/GPU/GPUTracking/Definitions/GPUSettingsListDisplay.template similarity index 100% rename from GPU/GPUTracking/Definitions/GPUSettingsListDisplay.h rename to GPU/GPUTracking/Definitions/GPUSettingsListDisplay.template diff --git a/GPU/GPUTracking/Definitions/GPUSettingsListStandalone.h b/GPU/GPUTracking/Definitions/GPUSettingsListStandalone.template similarity index 100% rename from GPU/GPUTracking/Definitions/GPUSettingsListStandalone.h rename to GPU/GPUTracking/Definitions/GPUSettingsListStandalone.template diff --git a/GPU/GPUTracking/Global/GPUChainTrackingDebug.h b/GPU/GPUTracking/Global/GPUChainTrackingDebug.h index 6ceb2a89cd091..c347069347e59 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingDebug.h +++ b/GPU/GPUTracking/Global/GPUChainTrackingDebug.h @@ -21,7 +21,7 @@ namespace o2::gpu { -// NOTE: Values below 262144 are activated by default with --debug 6 in GPUSettingsList.h::debugMask +// NOTE: Values below 262144 are activated by default with --debug 6 in GPUSettingsList.template::debugMask enum GPUChainTrackingDebugFlags : uint32_t { TPCSectorTrackingData = 1 << 0, TPCPreLinks = 1 << 1, diff --git a/GPU/GPUTracking/TRDTracking/macros/run_trd_tracker.C b/GPU/GPUTracking/TRDTracking/macros/run_trd_tracker.C index e4b37500e1a60..79664bea9fc75 100644 --- a/GPU/GPUTracking/TRDTracking/macros/run_trd_tracker.C +++ b/GPU/GPUTracking/TRDTracking/macros/run_trd_tracker.C @@ -61,7 +61,7 @@ void run_trd_tracker(std::string path = "./", const o2::trd::GeometryFlat geoFlat(*geo); o2::gpu::GPUTRDRecoParam trdRecoParam; //-------- init GPU reconstruction --------// - // different settings are defined in GPUSettingsList.h + // different settings are defined in GPUSettingsList.template GPUSettingsGRP cfgGRP; // defaults should be ok GPUSettingsRec cfgRec; // settings concerning reconstruction cfgRec.trd.minTrackPt = .5f; diff --git a/GPU/GPUTracking/cmake/gpu_settings_list_generator.cmake b/GPU/GPUTracking/cmake/gpu_settings_list_generator.cmake new file mode 100644 index 0000000000000..42f6fbd3fc27e --- /dev/null +++ b/GPU/GPUTracking/cmake/gpu_settings_list_generator.cmake @@ -0,0 +1,90 @@ +# 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 gpu_settings_list_generator.cmake +# author David Rohr + +# Generates the settings list header from the template: within each config block, the members are stable-sorted by alignment (8, 4, 2, 1 bytes), all other entries follow in their original order, comment lines are dropped +function(generate_gpu_settings_list INPUT OUTPUT) + set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${INPUT}") + get_filename_component(INPUT_NAME "${INPUT}" NAME) + file(READ "${INPUT}" CONTENT) + string(REGEX REPLACE "\n$" "" CONTENT "${CONTENT}") + string(REPLACE ";" "QCONFIG_CMAKE_INTERNAL_SEMICOLON" CONTENT "${CONTENT}") # Protect characters with special meaning in CMake lists + string(REPLACE "[" "QCONFIG_CMAKE_INTERNAL_BRACKET_OPEN" CONTENT "${CONTENT}") + string(REPLACE "]" "QCONFIG_CMAKE_INTERNAL_BRACKET_CLOSE" CONTENT "${CONTENT}") + string(REPLACE "\n" ";" LINES "${CONTENT}") + + set(RESULT "// Generated by CMake from ${INPUT_NAME}, do not edit\n") + set(BLOCK "") + foreach(LINE IN LISTS LINES) + string(REPLACE "QCONFIG_CMAKE_INTERNAL_SEMICOLON" ";" LINE_ORIG "${LINE}") # Only for error messages + string(REPLACE "QCONFIG_CMAKE_INTERNAL_BRACKET_OPEN" "[" LINE_ORIG "${LINE_ORIG}") + string(REPLACE "QCONFIG_CMAKE_INTERNAL_BRACKET_CLOSE" "]" LINE_ORIG "${LINE_ORIG}") + if(BLOCK STREQUAL "") + if(LINE MATCHES "^[ \t]*Begin(Sub|Hidden)?Config\\(([A-Za-z0-9_]+)") + set(BLOCK "${CMAKE_MATCH_2}") + foreach(ALIGN 8 4 2 1 OTHER) + set(ENTRIES_${ALIGN} "") + endforeach() + endif() + string(APPEND RESULT "${LINE}\n") + elseif(LINE MATCHES "^[ \t]*#") + message(FATAL_ERROR "${INPUT_NAME}: preprocessor directive in config block ${BLOCK} not supported, since the entries are reordered: ${LINE_ORIG}") + elseif(LINE MATCHES "^[ \t]*//") # Comment lines would be detached from their entries by the reordering, drop them + elseif(LINE MATCHES "^[ \t]*EndConfig\\(") + string(APPEND RESULT "${ENTRIES_8}${ENTRIES_4}${ENTRIES_2}${ENTRIES_1}${ENTRIES_OTHER}${LINE}\n") + set(BLOCK "") + else() + set(TYPE "") + if(LINE MATCHES "^[ \t]*Add(Option|Variable)(RTC)?\\([A-Za-z0-9_]+,([^,]+),") + set(TYPE "${CMAKE_MATCH_3}") + elseif(LINE MATCHES "^[ \t]*AddOptionArray(RTC)?\\([A-Za-z0-9_]+,([^,]+),") + set(TYPE "${CMAKE_MATCH_2}") + elseif(LINE MATCHES "^[ \t]*AddOptionVec\\(") + set(TYPE "std::vector") + elseif(LINE MATCHES "^[ \t]*Add[A-Za-z]*\\(" AND NOT LINE MATCHES "^[ \t]*(AddOptionSet|AddSubConfig|AddHelp|AddHelpAll|AddHelpText|AddShortcut|AddCommand|AddCustomCPP)\\(") + message(FATAL_ERROR "${INPUT_NAME}: unknown macro in config block ${BLOCK}, add it to generate_gpu_settings_list: ${LINE_ORIG}") + endif() + string(STRIP "${TYPE}" TYPE) + if(TYPE STREQUAL "") + set(ALIGN OTHER) + elseif(TYPE MATCHES "\\*$" OR TYPE MATCHES "^(std::string|std::vector|double|int64_t|uint64_t|size_t)$") + set(ALIGN 8) + elseif(TYPE MATCHES "^(float|int32_t|uint32_t)$") + set(ALIGN 4) + elseif(TYPE MATCHES "^(int16_t|uint16_t)$") + set(ALIGN 2) + elseif(TYPE MATCHES "^(bool|char|int8_t|uint8_t)$") + set(ALIGN 1) + else() + message(FATAL_ERROR "${INPUT_NAME}: unknown type ${TYPE} in config block ${BLOCK}, add it to generate_gpu_settings_list: ${LINE_ORIG}") + endif() + if(TYPE STREQUAL "bool" AND BLOCK MATCHES "^GPUSettingsRec") + message(FATAL_ERROR "${INPUT_NAME}: bool is forbidden in config block ${BLOCK}, since sizeof(bool) is implementation-defined: ${LINE_ORIG}") + endif() + string(APPEND ENTRIES_${ALIGN} "${LINE}\n") + endif() + endforeach() + if(NOT BLOCK STREQUAL "") + message(FATAL_ERROR "${INPUT_NAME}: config block ${BLOCK} not terminated by EndConfig()") + endif() + + string(REPLACE "QCONFIG_CMAKE_INTERNAL_SEMICOLON" ";" RESULT "${RESULT}") + string(REPLACE "QCONFIG_CMAKE_INTERNAL_BRACKET_OPEN" "[" RESULT "${RESULT}") + string(REPLACE "QCONFIG_CMAKE_INTERNAL_BRACKET_CLOSE" "]" RESULT "${RESULT}") + if(EXISTS "${OUTPUT}") + file(READ "${OUTPUT}" OLD_RESULT) + endif() + if(NOT "${OLD_RESULT}" STREQUAL "${RESULT}") # Do not touch the file if unchanged, to avoid rebuilds + file(WRITE "${OUTPUT}" "${RESULT}") + endif() +endfunction() diff --git a/GPU/GPUTracking/utils/qconfig.cxx b/GPU/GPUTracking/utils/qconfig.cxx index 74fecab4371be..74c1ef8262c3e 100644 --- a/GPU/GPUTracking/utils/qconfig.cxx +++ b/GPU/GPUTracking/utils/qconfig.cxx @@ -411,6 +411,19 @@ inline void qAddOptionMessage(qConfigSettings& settings, T& ref) } } +using qConfigHelpEntries = std::vector>>; // Name (nullptr for non-options) and print function of help entries + +static void qConfigHelpPrintSorted(qConfigHelpEntries& options, const qConfigHelpEntries& other) // Prints the options sorted by name, then the other entries in the listed order +{ + std::stable_sort(options.begin(), options.end(), [](const auto& a, const auto& b) { return std::lexicographical_compare(a.first, a.first + strlen(a.first), b.first, b.first + strlen(b.first), [](char x, char y) { return tolower(x) < tolower(y); }); }); + for (const auto& entry : options) { + entry.second(); + } + for (const auto& entry : other) { + entry.second(); + } +} + static inline void qConfigHelp(const char* subConfig = nullptr, int32_t followSub = 0) { if (followSub < 2) { diff --git a/GPU/GPUTracking/utils/qconfig_genrtti.inc b/GPU/GPUTracking/utils/qconfig_genrtti.inc index b309727799f9e..bd3cf35394e72 100644 --- a/GPU/GPUTracking/utils/qconfig_genrtti.inc +++ b/GPU/GPUTracking/utils/qconfig_genrtti.inc @@ -75,7 +75,7 @@ static inline void qConfigRTTIEntry(std::vector& retVal, R entry, size_t arra template static inline std::tuple, std::vector> qConfigGenRTTI(const std::vector* configStructs = nullptr) // Entries (of type T, derived from qConfigRTTIentry) and list of config structs. Filter: struct types Structs at compile time (code only generated for those), else the names in configStructs at runtime (all if nullptr) { - using namespace ::qConfig; // For the settings helpers (min, max, ...) and print_type used in GPUSettingsList.h / qconfig_internal.h + using namespace ::qConfig; // For the settings helpers (min, max, ...) and print_type used in GPUSettingsList.template / qconfig_internal.h std::vector retVal; std::vector retStructs; if constexpr (sizeof...(Structs) > 0) { diff --git a/GPU/GPUTracking/utils/qconfig_internal.h b/GPU/GPUTracking/utils/qconfig_internal.h index 098dae010de1e..dbdb5180f28e5 100644 --- a/GPU/GPUTracking/utils/qconfig_internal.h +++ b/GPU/GPUTracking/utils/qconfig_internal.h @@ -77,20 +77,23 @@ // End QCONFIG_PARSE #elif defined(QCONFIG_HELP) -#define AddOption(name, type, default, optname, optnameshort, ...) qConfigType::qConfigHelpOption(qon_mxstr(name), qon_mxstr(type), qon_mxstr(default), optname, optnameshort, preopt, preoptshort, 0, __VA_ARGS__); -#define AddOptionSet(name, type, value, optname, optnameshort, ...) qConfigType::qConfigHelpOption(qon_mxstr(name), qon_mxstr(type), qon_mxstr(value), optname, optnameshort, preopt, preoptshort, 1, __VA_ARGS__); -#define AddOptionVec(name, type, optname, optnameshort, ...) qConfigType::qConfigHelpOption(qon_mxstr(name), qon_mxstr(type), nullptr, optname, optnameshort, preopt, preoptshort, 2, __VA_ARGS__); -#define AddOptionArray(name, type, count, default, optname, optnameshort, ...) qConfigType::qConfigHelpOption(qon_mxstr(name), qon_mxstr(type) "[" qon_mxstr(count) "]", nullptr, optname, optnameshort, preopt, preoptshort, 2, __VA_ARGS__); -#define AddSubConfig(name, instance) \ - printf("\t%s\n\n", qon_mxcat(qConfig_subconfig_, name)); \ - if (followSub) { \ - qConfigHelp(qon_mxstr(name), 2); \ - } +#define AddOption(name, type, default, optname, optnameshort, ...) qconfig_help_options.emplace_back(qon_mxstr(name), [=]() { qConfigType::qConfigHelpOption(qon_mxstr(name), qon_mxstr(type), qon_mxstr(default), optname, optnameshort, preopt, preoptshort, 0, __VA_ARGS__); }); +#define AddOptionSet(name, type, value, optname, optnameshort, ...) qconfig_help_options.emplace_back(qon_mxstr(name), [=]() { qConfigType::qConfigHelpOption(qon_mxstr(name), qon_mxstr(type), qon_mxstr(value), optname, optnameshort, preopt, preoptshort, 1, __VA_ARGS__); }); +#define AddOptionVec(name, type, optname, optnameshort, ...) qconfig_help_options.emplace_back(qon_mxstr(name), [=]() { qConfigType::qConfigHelpOption(qon_mxstr(name), qon_mxstr(type), nullptr, optname, optnameshort, preopt, preoptshort, 2, __VA_ARGS__); }); +#define AddOptionArray(name, type, count, default, optname, optnameshort, ...) qconfig_help_options.emplace_back(qon_mxstr(name), [=]() { qConfigType::qConfigHelpOption(qon_mxstr(name), qon_mxstr(type) "[" qon_mxstr(count) "]", nullptr, optname, optnameshort, preopt, preoptshort, 2, __VA_ARGS__); }); +#define AddSubConfig(name, instance) \ + qconfig_help_other.emplace_back(nullptr, [=]() { \ + printf("\t%s\n\n", qon_mxcat(qConfig_subconfig_, name)); \ + if (followSub) { \ + qConfigHelp(qon_mxstr(name), 2); \ + } \ + }); #define BeginConfig(name, instance) \ if (subConfig == nullptr || *subConfig == 0) { \ constexpr const char* preopt = ""; \ constexpr const char preoptshort = 0; \ - printf("\n"); + printf("\n"); \ + qConfigHelpEntries qconfig_help_options, qconfig_help_other; #define BeginSubConfig(name, instance, parent, preoptname, preoptnameshort, descr, ...) \ const char* qon_mxcat(qConfig_subconfig_, name) = preoptnameshort == 0 ? (qon_mxstr(name) ": --" preoptname "\n\t\t" descr) : (qon_mxstr(name) ": -" qon_mxstr('a') " (--" preoptname ")\n\t\t" descr); \ (void)qon_mxcat(qConfig_subconfig_, name); \ @@ -98,14 +101,19 @@ [[maybe_unused]] constexpr const char* preopt = preoptname; \ [[maybe_unused]] constexpr const char preoptshort = preoptnameshort; \ char argBuffer[2] = {preoptnameshort, 0}; \ - printf("\n %s: (--%s%s%s)\n", descr, preoptname, preoptnameshort == 0 ? "" : " or -", argBuffer); -#define BeginHiddenConfig(name, instance) { -#define EndConfig() } -#define AddHelp(cmd, cmdshort) qConfigType::qConfigHelpOption("help", "help", nullptr, cmd, cmdshort, preopt, preoptshort, 3, "Show usage information"); -#define AddHelpAll(cmd, cmdshort) qConfigType::qConfigHelpOption("help all", "help all", nullptr, cmd, cmdshort, preopt, preoptshort, 3, "Show usage info including all subparameters"); -#define AddCommand(cmd, cmdshort, command, help) qConfigType::qConfigHelpOption("command", "command", nullptr, cmd, cmdshort, preopt, preoptshort, 4, help); -#define AddShortcut(cmd, cmdshort, forward, help, ...) qConfigType::qConfigHelpOption("shortcut", "shortcut", nullptr, cmd, cmdshort, preopt, preoptshort, 4, help); -#define AddHelpText(text) printf("\n " text ":\n"); + printf("\n %s: (--%s%s%s)\n", descr, preoptname, preoptnameshort == 0 ? "" : " or -", argBuffer); \ + qConfigHelpEntries qconfig_help_options, qconfig_help_other; +#define BeginHiddenConfig(name, instance) \ + { \ + qConfigHelpEntries qconfig_help_options, qconfig_help_other; +#define EndConfig() \ + qConfigHelpPrintSorted(qconfig_help_options, qconfig_help_other); \ + } +#define AddHelp(cmd, cmdshort) qconfig_help_other.emplace_back(nullptr, [=]() { qConfigType::qConfigHelpOption("help", "help", nullptr, cmd, cmdshort, preopt, preoptshort, 3, "Show usage information"); }); +#define AddHelpAll(cmd, cmdshort) qconfig_help_other.emplace_back(nullptr, [=]() { qConfigType::qConfigHelpOption("help all", "help all", nullptr, cmd, cmdshort, preopt, preoptshort, 3, "Show usage info including all subparameters"); }); +#define AddCommand(cmd, cmdshort, command, help) qconfig_help_other.emplace_back(nullptr, [=]() { qConfigType::qConfigHelpOption("command", "command", nullptr, cmd, cmdshort, preopt, preoptshort, 4, help); }); +#define AddShortcut(cmd, cmdshort, forward, help, ...) qconfig_help_other.emplace_back(nullptr, [=]() { qConfigType::qConfigHelpOption("shortcut", "shortcut", nullptr, cmd, cmdshort, preopt, preoptshort, 4, help); }); +#define AddHelpText(text) qconfig_help_other.emplace_back(nullptr, []() { printf("\n " text ":\n"); }); // End QCONFIG_HELP #elif defined(QCONFIG_PRINT) diff --git a/GPU/documentation/run-time-compilation.md b/GPU/documentation/run-time-compilation.md index f819b744e095c..f4693171e1360 100644 --- a/GPU/documentation/run-time-compilation.md +++ b/GPU/documentation/run-time-compilation.md @@ -7,7 +7,7 @@ The changes that can be applied are: - Compiling for different target architectures. This allows us to enable running on hardware, for which the code was not compiled in the original compilation. Generally, RTC is enabled via the `--RTCenable` flag for the standalone benchmark, or via the `GPU_proc_rtc.enable=1` `configKeyValue` for O2. -For a list of RTC options, please see [GPUSettingsList.h](https://github.com/AliceO2Group/AliceO2/blob/80a80a17f5a1d9cb77743e2a39b15b653fe1a4f9/GPU/GPUTracking/Definitions/GPUSettingsList.h#L215). +For a list of RTC options, please see the block `GPUSettingsProcessingRTC` in [GPUSettingsList.template](https://github.com/AliceO2Group/AliceO2/blob/dev/GPU/GPUTracking/Definitions/GPUSettingsList.template). Caching the output: - The RTC output can be cached and reused, so that when running multiple times, compilation is not repeated. This is enabled via the `--RTCcacheOutput` setting. The folder to store the cache files can be selected via `--RTCTECHcacheFolder` and with `--RTCTECHcacheMutex` (default: enabled), a file-lock mutex (`cache_.lock`, one per backend) can be used to synchronize access to the cache folder. Each backend can have multiple cache files `rtc..cache.`, where the id is derived from the SHA1 hashes below, so that switching between configurations does not require recompilation; when a new cache file is written, only the `--RTCTECHcacheSize` (default 10, 0 = no limit) most recent files of the backend are kept. The cached code is checked against the to-be-compiled source code with SHA1 hashes, and only if the code is not change the cache is used, otherwise the code is recompiled and the cache updated. It is possible to force using outdated cache files via the `--RTCTECHignoreCacheValid` option; in this case the cache file is `rtc..cache` without id, and old cache files are not removed. From deab00e416cc62b303fdf33c89436aa734946b6f Mon Sep 17 00:00:00 2001 From: David Rohr Date: Tue, 24 Nov 2026 19:17:24 +0100 Subject: [PATCH 31/32] GPU TPC: Don't iterate over all rows in FollowLoopers --- GPU/GPUTracking/DataTypes/GPUTPCGeometry.h | 20 +++++++++++++++++ GPU/GPUTracking/Merger/GPUTPCGMTrackParam.cxx | 22 +++++++++---------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/GPU/GPUTracking/DataTypes/GPUTPCGeometry.h b/GPU/GPUTracking/DataTypes/GPUTPCGeometry.h index ac2560a45ef90..6d5745f243a2d 100644 --- a/GPU/GPUTracking/DataTypes/GPUTPCGeometry.h +++ b/GPU/GPUTracking/DataTypes/GPUTPCGeometry.h @@ -137,6 +137,26 @@ class GPUTPCGeometry #endif GPUd() static constexpr float Row2X(uint32_t row) { return (gputpcgeometry_internal::mX[row]); } + GPUd() static constexpr float X2Row(float x) // Approximate inverse of Row2X, linear within the sections of equal pad height (switching in the middle of the gap between them), exact at the rows, clamped to [0, NROWS - 1] + { + if (x <= Row2X(0)) { + return 0.f; + } + if (x >= Row2X(NROWS - 1)) { + return NROWS - 1.f; + } + uint32_t row = 0; + if (x < 0.5f * (Row2X(EndOROC1() - 1) + Row2X(EndOROC1()))) { + row = x < 0.5f * (Row2X(EndIROC() - 1) + Row2X(EndIROC())) ? 0 : EndIROC(); + } else { +#ifndef GPUCA_RUN2 + row = x < 0.5f * (Row2X(EndOROC2() - 1) + Row2X(EndOROC2())) ? EndOROC1() : EndOROC2(); +#else + row = EndOROC1(); +#endif + } + return row + (x - Row2X(row)) / PadHeight(row); + } GPUd() static constexpr float NRegions() { return gputpcgeometry_internal::NREGIONS; } GPUd() static constexpr float TPCLength() { return gputpcgeometry_internal::TPC_LENGTH; } GPUd() static constexpr float PadHeight(uint32_t row) { return (gputpcgeometry_internal::mPadHeight[GetRegion(row)]); } diff --git a/GPU/GPUTracking/Merger/GPUTPCGMTrackParam.cxx b/GPU/GPUTracking/Merger/GPUTPCGMTrackParam.cxx index 9ae90368ae109..028293eaa1f29 100644 --- a/GPU/GPUTracking/Merger/GPUTPCGMTrackParam.cxx +++ b/GPU/GPUTracking/Merger/GPUTPCGMTrackParam.cxx @@ -1294,16 +1294,17 @@ GPUdi() void GPUTPCGMTrackParam::FindAdjacentClustersLooperFollow(const GPUTPCGM uint32_t maxTries = 100; while (true) { while (CAMath::Abs(mX) <= CAMath::Abs(mP[0]) * CAMath::Tan(GPUTPCGeometry::kSectAngle() / 2.f) + 0.1f) { + float localX = -mP[0] * lrFactor; if (maxTries-- == 0) { return; } if (CAMath::Abs(mP[2]) > 0.7f) { return; } - if (up ? (-mP[0] * lrFactor > GPUTPCGeometry::Row2X(GPUTPCGeometry::NROWS - 1)) : (-mP[0] * lrFactor < GPUTPCGeometry::Row2X(0))) { + if (up ? (localX > GPUTPCGeometry::Row2X(GPUTPCGeometry::NROWS - 1)) : (localX < GPUTPCGeometry::Row2X(0))) { return; } - if (!((up ? (-mP[0] * lrFactor >= toX) : (-mP[0] * lrFactor <= toX)) || (right ^ (mP[2] > 0)))) { + if (!((up ? (localX >= toX) : (localX <= toX)) || (right ^ (mP[2] > 0)))) { return; } int32_t err = prop.PropagateToXAlpha(mX + (up ? 1.f : -1.f), prop.GetAlpha(), inFlyDirection); @@ -1312,15 +1313,14 @@ GPUdi() void GPUTPCGMTrackParam::FindAdjacentClustersLooperFollow(const GPUTPCGM return; } CADEBUG(printf("\tPropagated to y = %f: X %f Z %f SinPhi %f\n", mX, mP[0], mP[1], mP[2])); - for (uint32_t j = 0; j < GPUTPCGeometry::NROWS; j++) { // TODO: Avoid iterating over all rows - while (j < GPUTPCGeometry::NROWS - 1 && !(CAMath::Abs(GPUTPCGeometry::Row2X(j) - (-mP[0] * lrFactor)) < 1.5f)) { - j++; // Skip the rows out of reach in a loop of its own, so that the threads of a GPU warp reach the attachment together - } - float rowX = GPUTPCGeometry::Row2X(j); - if (CAMath::Abs(rowX - (-mP[0] * lrFactor)) < 1.5f) { - CADEBUG(printf("\t\tAttempt row %d (X %f Y %f Z %f)\n", j, rowX, mX * lrFactor, mP[1])); - FindAdjacentClusters(merger, sector, j, iTrack, false, mX * lrFactor, mP[1]); - } + localX = -mP[0] * lrFactor; + uint32_t j = CAMath::Max(0.f, GPUTPCGeometry::X2Row(localX) - 2.5f); + while (j < GPUTPCGeometry::NROWS && !(GPUTPCGeometry::Row2X(j) - localX > -1.5f)) { + j++; + } + for (float rowX; j < GPUTPCGeometry::NROWS && (rowX = GPUTPCGeometry::Row2X(j), rowX - localX < 1.5f); j++) { + CADEBUG(printf("\t\tAttempt row %d (X %f Y %f Z %f)\n", j, rowX, mX * lrFactor, mP[1])); + FindAdjacentClusters(merger, sector, j, iTrack, false, mX * lrFactor, mP[1]); } } if (maxTries-- == 0) { From cd31bbe0c89eac4d2a4062fc9026fb6104d950e4 Mon Sep 17 00:00:00 2001 From: David Rohr Date: Tue, 24 Nov 2026 20:49:41 +0100 Subject: [PATCH 32/32] GPU TPC: Run Sector Refit and Unpacking of Extrapolated Tracks in parallel during Track Merging --- .../Global/GPUChainTrackingMerger.cxx | 40 ++++++--- GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx | 48 +++++----- GPU/GPUTracking/Merger/GPUTPCGMMerger.h | 10 +-- GPU/GPUTracking/Merger/GPUTPCGMMergerDump.cxx | 18 ++-- GPU/GPUTracking/Merger/GPUTPCGMMergerGPU.cxx | 8 -- GPU/GPUTracking/Merger/GPUTPCGMMergerGPU.h | 7 -- .../Merger/GPUTPCGlobalDebugSortKernels.cxx | 87 ++++++++++--------- .../Merger/GPUTPCGlobalDebugSortKernels.h | 9 +- GPU/GPUTracking/kernels.cmake | 4 +- 9 files changed, 117 insertions(+), 114 deletions(-) diff --git a/GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx b/GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx index ef549fda636cb..798689feb5805 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx @@ -121,27 +121,47 @@ int32_t GPUChainTracking::RunTPCTrackingMerger(bool synchronizeOutput) if (GetProcessingSettings().deterministicGPUReconstruction) { runKernel(GetGridAuto(0, deviceType), 1); } + const uint32_t nStreams = doGPU ? std::min(mRec->NStreams(), NSECTORS) : 1; + auto recordStreamMarkers = [&]() { + for (uint32_t i = 0; i < nStreams; i++) { + RecordMarker(&mEvents->stream[i], i); + } + }; + auto releaseStreamMarkers = [&]() { + for (uint32_t i = 0; i < nStreams; i++) { + ReleaseEvent(mEvents->stream[i]); + } + }; + RecordMarker(&mEvents->single, 0); for (uint32_t i = 0; i < NSECTORS; i++) { - runKernel({{1, -WarpSize(), 0, deviceType}}, i); - runKernel(GetGridAuto(0, deviceType), i); - runKernel(GetGridAuto(0, deviceType), i); // TODO: Why all in stream 0? + const int32_t stream = i % nStreams; + runKernel({GetGridAuto(stream, deviceType), krnlRunRangeNone, {nullptr, i < nStreams ? &mEvents->single : nullptr}}, i); + runKernel(GetGridAuto(stream, deviceType), i); } + ReleaseEvent(mEvents->single); + recordStreamMarkers(); if (GetProcessingSettings().deterministicGPUReconstruction) { - runKernel({{1, -WarpSize(), 0, deviceType}}, NSECTORS); - runKernel({{GPUTPCGeometry::NSECTORS, -WarpSize(), 0, deviceType}}, 0); + SynchronizeGPU(); + runKernel({{GPUTPCGeometry::NSECTORS, -WarpSize(), 0, deviceType}}, 0); + runKernel({{1, -WarpSize(), 0, deviceType}}, 0); + SynchronizeGPU(); } for (uint32_t i = 0; i < NSECTORS; i++) { - runKernel({{1, -WarpSize(), 0, deviceType}}, NSECTORS + i); - runKernel(GetGridAuto(0, deviceType), i); + const int32_t stream = i % nStreams; + runKernel({GetGridAuto(stream, deviceType), krnlRunRangeNone, {nullptr, i < nStreams ? mEvents->stream : nullptr, (int32_t)nStreams}}, i); } - runKernel({{1, -WarpSize(), 0, deviceType}}, 2 * NSECTORS); + releaseStreamMarkers(); + recordStreamMarkers(); if (GetProcessingSettings().deterministicGPUReconstruction) { - runKernel({{GPUTPCGeometry::NSECTORS, -WarpSize(), 0, deviceType}}, 1); + SynchronizeGPU(); + runKernel({{GPUTPCGeometry::NSECTORS, -WarpSize(), 0, deviceType}}, 1); + runKernel({{1, -WarpSize(), 0, deviceType}}, 1); } DoDebugAndDump(RecoStep::TPCMerging, GPUChainTrackingDebugFlags::TPCMergingSectorTracks, doGPU, Merger, &GPUTPCGMMerger::DumpSectorTracks, *mDebugFile); // Merge within Sectors - runKernel(GetGridAuto(0, deviceType), false); + runKernel({GetGridAuto(0, deviceType), krnlRunRangeNone, {nullptr, mEvents->stream, (int32_t)nStreams}}, false); + releaseStreamMarkers(); runKernel({{1, -WarpSize(), 0, deviceType, RecoStep::TPCMerging}}, MergerShadow.TmpCounter(), NSECTORS * sizeof(*MergerShadow.TmpCounter())); runKernel(GetGridAuto(0, deviceType)); RunTPCTrackingMerger_MergeBorderTracks(GPUTPCGMMerger::mergeModes::mergeWithinSector, deviceType); diff --git a/GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx b/GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx index d1b8be4fd811b..3d57a1470636a 100644 --- a/GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx +++ b/GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx @@ -266,12 +266,12 @@ void GPUTPCGMMerger::CheckCollectedTracks() void GPUTPCGMMerger::CheckMergeGraph() { uint32_t nErr = 0; - std::vector trkUsed(SectorTrackInfoLocalTotal()); - for (int32_t i = 0; i < SectorTrackInfoLocalTotal(); i++) { + std::vector trkUsed(mMemory->nUnpackedTracks); + for (uint32_t i = 0; i < mMemory->nUnpackedTracks; i++) { trkUsed[i] = false; } - for (int32_t itr = 0; itr < SectorTrackInfoLocalTotal(); itr++) { + for (int32_t itr = 0; itr < (int32_t)mMemory->nUnpackedTracks; itr++) { GPUTPCGMSectorTrack& track = mSectorTrackInfos[itr]; if (track.PrevSegmentNeighbour() >= 0 && mSectorTrackInfos[track.PrevSegmentNeighbour()].NextSegmentNeighbour() != itr) { GPUError("FAILURE: Invalid reciprocal segment link: %d PrevSegmentNeighbour %d NextSegmentNeighbour %d", itr, track.PrevSegmentNeighbour(), mSectorTrackInfos[track.PrevSegmentNeighbour()].NextSegmentNeighbour()); @@ -328,7 +328,7 @@ void GPUTPCGMMerger::CheckMergeGraph() break; } } - for (int32_t i = 0; i < SectorTrackInfoLocalTotal(); i++) { + for (uint32_t i = 0; i < mMemory->nUnpackedTracks; i++) { if (trkUsed[i] == false) { GPUError("FAILURE: trk missed"); nErr++; @@ -380,7 +380,6 @@ void GPUTPCGMMerger::InitializeProcessor() {} void* GPUTPCGMMerger::SetPointersMerger(void* mem) { computePointerWithAlignment(mem, mSectorTrackInfos, mNTotalSectorTracks); - computePointerWithAlignment(mem, mSectorTrackInfoIndex, NSECTORS * 2 + 1); if (mRec->GetProcessingSettings().deterministicGPUReconstruction) { computePointerWithAlignment(mem, mTmpSortMemory, std::max(mNTotalSectorTracks, mNMaxTracks * 2)); } @@ -611,7 +610,7 @@ void GPUTPCGMMerger::CreateMCLabels(int32_t nBlocks, int32_t nThreads, int32_t i GPUd() void GPUTPCGMMerger::ClearTrackLinks(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, bool output) { - const int32_t n = output ? mMemory->nMergedTracks : SectorTrackInfoLocalTotal(); + const int32_t n = output ? mMemory->nMergedTracks : mMemory->nUnpackedTracks; for (int32_t i = iBlock * nThreads + iThread; i < n; i += nThreads * nBlocks) { mTrackLinks[i] = -1; } @@ -685,11 +684,6 @@ GPUd() void GPUTPCGMMerger::SetTrackClusterT(GPUTPCGMSectorTrack& track, int32_t track.SetClusterT(cl[clusterIndex1].getTime(), cl[clusterIndex2].getTime()); } -GPUd() void GPUTPCGMMerger::UnpackSaveNumber(int32_t id) -{ - mSectorTrackInfoIndex[id] = mMemory->nUnpackedTracks; -} - GPUd() void GPUTPCGMMerger::UnpackSectorGlobal(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, int32_t iSector) { const GPUTPCTracker& trk = GetConstantMem()->tpcTrackers[iSector]; @@ -703,7 +697,7 @@ GPUd() void GPUTPCGMMerger::UnpackSectorGlobal(int32_t nBlocks, int32_t nThreads if (localId == -1) { continue; } - uint32_t myTrack = CAMath::AtomicAdd(&mMemory->nUnpackedTracks, 1u); + uint32_t myTrack = mMemory->nUnpackedTracks + CAMath::AtomicAdd(&mMemory->nUnpackedTracksGlobal, 1u); GPUTPCGMSectorTrack& track = mSectorTrackInfos[myTrack]; SetTrackClusterT(track, iSector, sectorTr); track.Set(this, sectorTr, alpha, iSector); @@ -760,7 +754,7 @@ GPUd() void GPUTPCGMMerger::RefitSectorTracks(int32_t nBlocks, int32_t nThreads, GPUd() void GPUTPCGMMerger::LinkExtrapolatedTracks(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread) { - for (int32_t itr = SectorTrackInfoGlobalFirst(0) + iBlock * nThreads + iThread; itr < SectorTrackInfoGlobalLast(NSECTORS - 1); itr += nThreads * nBlocks) { + for (uint32_t itr = mMemory->nUnpackedTracks + iBlock * nThreads + iThread; itr < mMemory->nUnpackedTracks + mMemory->nUnpackedTracksGlobal; itr += nThreads * nBlocks) { GPUTPCGMSectorTrack& extrapolatedTrack = mSectorTrackInfos[itr]; GPUTPCGMSectorTrack& localTrack = mSectorTrackInfos[extrapolatedTrack.LocalTrackId() & 0xFFFFFF]; int up = (extrapolatedTrack.LocalTrackId() & 0x40000000) ? 1 : 0; @@ -794,7 +788,7 @@ GPUd() void GPUTPCGMMerger::MergeSectorsPrepareStep2(int32_t nBlocks, int32_t nT float sinAlpha = CAMath::Sin(dAlpha); GPUTPCGMSectorTrack trackTmp; - for (int32_t itr = iBlock * nThreads + iThread; itr < SectorTrackInfoLocalTotal(); itr += nThreads * nBlocks) { + for (uint32_t itr = iBlock * nThreads + iThread; itr < mMemory->nUnpackedTracks; itr += nThreads * nBlocks) { const GPUTPCGMSectorTrack* track = &mSectorTrackInfos[itr]; int32_t iSector = track->Sector(); @@ -1076,7 +1070,7 @@ GPUd() void GPUTPCGMMerger::MergeWithinSectorsPrepare(int32_t nBlocks, int32_t n float x0 = GPUTPCGeometry::Row2X(63); const float maxSin = CAMath::Sin(60.f / 180.f * CAMath::Pi()); - for (int32_t itr = iBlock * nThreads + iThread; itr < SectorTrackInfoLocalTotal(); itr += nThreads * nBlocks) { + for (uint32_t itr = iBlock * nThreads + iThread; itr < mMemory->nUnpackedTracks; itr += nThreads * nBlocks) { const GPUTPCGMSectorTrack& track = mSectorTrackInfos[itr]; int32_t iSector = track.Sector(); GPUTPCGMBorderTrack b; @@ -1137,7 +1131,7 @@ GPUd() void GPUTPCGMMerger::hookEdge(int32_t u, int32_t v) GPUd() void GPUTPCGMMerger::ResolveFindConnectedComponentsSetup(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread) { int32_t start, end; - setBlockRange(SectorTrackInfoLocalTotal(), nBlocks, iBlock, start, end); + setBlockRange(mMemory->nUnpackedTracks, nBlocks, iBlock, start, end); for (int32_t i = start + iThread; i < end; i += nThreads) { mTrackCCRoots[i] = i; } @@ -1148,7 +1142,7 @@ GPUd() void GPUTPCGMMerger::ResolveFindConnectedComponentsHookLinks(int32_t nBlo // Compute connected components in parallel, step 1. // Source: Adaptive Work-Efficient Connected Components on the GPU, Sutton et al, 2016 (https://arxiv.org/pdf/1612.01178.pdf) int32_t start, end; - setBlockRange(SectorTrackInfoLocalTotal(), nBlocks, iBlock, start, end); + setBlockRange(mMemory->nUnpackedTracks, nBlocks, iBlock, start, end); for (int32_t itr = start + iThread; itr < end; itr += nThreads) { hookEdge(itr, mTrackLinks[itr]); } @@ -1163,7 +1157,7 @@ GPUd() void GPUTPCGMMerger::ResolveFindConnectedComponentsHookNeighbors(int32_t } int32_t start, end; - setBlockRange(SectorTrackInfoLocalTotal(), nBlocks / 4, iBlock / 4, start, end); + setBlockRange(mMemory->nUnpackedTracks, nBlocks / 4, iBlock / 4, start, end); int32_t myNeighbor = iBlock % 4; @@ -1177,7 +1171,7 @@ GPUd() void GPUTPCGMMerger::ResolveFindConnectedComponentsMultiJump(int32_t nBlo { // Compute connected components in parallel, step 2. int32_t start, end; - setBlockRange(SectorTrackInfoLocalTotal(), nBlocks, iBlock, start, end); + setBlockRange(mMemory->nUnpackedTracks, nBlocks, iBlock, start, end); for (int32_t itr = start + iThread; itr < end; itr += nThreads) { int32_t root = itr; int32_t next = mTrackCCRoots[root]; @@ -1225,7 +1219,7 @@ GPUd() void GPUTPCGMMerger::ResolveMergeSectors(GPUResolveSharedMemory& smem, in } int32_t start, end; - setBlockRange(SectorTrackInfoLocalTotal(), nBlocks, iBlock, start, end); + setBlockRange(mMemory->nUnpackedTracks, nBlocks, iBlock, start, end); // Walk a segment chain to its end, dir 0 towards the head and 1 towards the // tail, reporting whether target was met on the way. @@ -1252,9 +1246,9 @@ GPUd() void GPUTPCGMMerger::ResolveMergeSectors(GPUResolveSharedMemory& smem, in return false; }; - for (int32_t baseIdx = 0; baseIdx < SectorTrackInfoLocalTotal(); baseIdx += nThreads) { - int32_t itr = baseIdx + iThread; - bool inRange = itr < SectorTrackInfoLocalTotal(); + for (uint32_t baseIdx = 0; baseIdx < mMemory->nUnpackedTracks; baseIdx += nThreads) { + uint32_t itr = baseIdx + iThread; + bool inRange = itr < mMemory->nUnpackedTracks; int32_t itr2 = -1; if (inRange) { @@ -1279,9 +1273,9 @@ GPUd() void GPUTPCGMMerger::ResolveMergeSectors(GPUResolveSharedMemory& smem, in continue; } - const int32_t nSectors = smemIdx; + const uint32_t nSectors = smemIdx; - for (int32_t i = 0; i < nSectors; i++) { + for (uint32_t i = 0; i < nSectors; i++) { itr = smem.iTrack1[i]; itr2 = smem.iTrack2[i]; @@ -1576,7 +1570,7 @@ GPUd() void GPUTPCGMMerger::CollectMergedTracks(int32_t nBlocks, int32_t nThread } if (trbase == nullptr) { - while (itr < SectorTrackInfoLocalTotal()) { + while (itr < (int32_t)mMemory->nUnpackedTracks) { trbase = &mSectorTrackInfos[itr]; if (trbase->PrevSegmentNeighbour() >= 0 || trbase->PrevNeighbour() >= 0) { itr += nThreads * nBlocks; @@ -1584,7 +1578,7 @@ GPUd() void GPUTPCGMMerger::CollectMergedTracks(int32_t nBlocks, int32_t nThread } break; } - if (itr >= SectorTrackInfoLocalTotal()) { + if (itr >= (int32_t)mMemory->nUnpackedTracks) { break; } revertSegments = false; diff --git a/GPU/GPUTracking/Merger/GPUTPCGMMerger.h b/GPU/GPUTracking/Merger/GPUTPCGMMerger.h index f35e231d6dbc7..77b0fc8ddbbae 100644 --- a/GPU/GPUTracking/Merger/GPUTPCGMMerger.h +++ b/GPU/GPUTracking/Merger/GPUTPCGMMerger.h @@ -71,6 +71,7 @@ class GPUTPCGMMerger : public GPUProcessor GPUAtomic(uint32_t) nRetryRefit; GPUAtomic(uint32_t) nLoopData; GPUAtomic(uint32_t) nUnpackedTracks; + GPUAtomic(uint32_t) nUnpackedTracksGlobal; GPUAtomic(uint32_t) nMergedTracks; GPUAtomic(uint32_t) nMergedTrackClusters; GPUAtomic(uint32_t) nRebuildTrackRow; @@ -199,7 +200,6 @@ class GPUTPCGMMerger : public GPUProcessor int32_t CheckSectors(); GPUd() void RefitSectorTracks(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, int32_t iSector); GPUd() void UnpackSectorGlobal(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, int32_t iSector); - GPUd() void UnpackSaveNumber(int32_t id); GPUd() void UnpackResetIds(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, int32_t iSector); GPUd() void MergeCE(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread); GPUd() void ClearTrackLinks(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, bool output); @@ -267,13 +267,6 @@ class GPUTPCGMMerger : public GPUProcessor void DebugStreamerUpdate(int32_t iTrk, int32_t ihit, float xx, float yy, float zz, const GPUTPCGMMergedTrackHit& cluster, const o2::tpc::ClusterNative& clusterNative, const GPUTPCGMTrackParam& track, const GPUTPCGMPropagator& prop, const gputpcgmmergertypes::InterpolationErrorHit& interpolation, int8_t rejectChi2, bool refit, int32_t retVal, float avgInvCharge, float posY, float posZ, int16_t clusterState, int32_t retValReject, float err2Y, float err2Z) const; #endif - GPUdi() int32_t SectorTrackInfoFirst(int32_t iSector) const { return mSectorTrackInfoIndex[iSector]; } - GPUdi() int32_t SectorTrackInfoLast(int32_t iSector) const { return mSectorTrackInfoIndex[iSector + 1]; } - GPUdi() int32_t SectorTrackInfoGlobalFirst(int32_t iSector) const { return mSectorTrackInfoIndex[NSECTORS + iSector]; } - GPUdi() int32_t SectorTrackInfoGlobalLast(int32_t iSector) const { return mSectorTrackInfoIndex[NSECTORS + iSector + 1]; } - GPUdi() int32_t SectorTrackInfoLocalTotal() const { return mSectorTrackInfoIndex[NSECTORS]; } - GPUdi() int32_t SectorTrackInfoTotal() const { return mSectorTrackInfoIndex[2 * NSECTORS]; } - void CheckMergeGraph(); void CheckCollectedTracks(); @@ -331,7 +324,6 @@ class GPUTPCGMMerger : public GPUProcessor GPUdEdxInfo* mMergedTracksdEdx = nullptr; //* dEdx information GPUdEdxInfo* mMergedTracksdEdxAlt = nullptr; //* dEdx alternative information GPUTPCGMSectorTrack* mSectorTrackInfos = nullptr; //* additional information for sector tracks - int32_t* mSectorTrackInfoIndex = nullptr; GPUTPCGMMergedTrackHit* mClusters = nullptr; GPUAtomic(uint32_t) * mClusterAttachment = nullptr; o2::tpc::TrackTPC* mOutputTracksTPCO2 = nullptr; diff --git a/GPU/GPUTracking/Merger/GPUTPCGMMergerDump.cxx b/GPU/GPUTracking/Merger/GPUTPCGMMergerDump.cxx index 6fd631dc71ba7..ac25a25426a01 100644 --- a/GPU/GPUTracking/Merger/GPUTPCGMMergerDump.cxx +++ b/GPU/GPUTracking/Merger/GPUTPCGMMergerDump.cxx @@ -47,11 +47,13 @@ void GPUTPCGMMerger::DumpSectorTracks(std::ostream& out) const out << std::setprecision(6); out << "\nTPC Merger Sector Tracks\n"; for (int32_t iSector = 0; iSector < NSECTORS; iSector++) { - out << "Sector Track Info Sector " << iSector << " Index " << (mSectorTrackInfoIndex[iSector + 1] - mSectorTrackInfoIndex[iSector]) << " / " << (mSectorTrackInfoIndex[NSECTORS + iSector + 1] - mSectorTrackInfoIndex[NSECTORS + iSector]) << "\n"; for (int32_t iGlobal = 0; iGlobal < 2; iGlobal++) { out << " Track type " << iGlobal << "\n"; - for (int32_t j = mSectorTrackInfoIndex[iSector + NSECTORS * iGlobal]; j < mSectorTrackInfoIndex[iSector + NSECTORS * iGlobal + 1]; j++) { + for (uint32_t j = iGlobal ? mMemory->nUnpackedTracks : 0; j < (iGlobal ? mMemory->nUnpackedTracks + mMemory->nUnpackedTracksGlobal : mMemory->nUnpackedTracks); j++) { const auto& trk = mSectorTrackInfos[j]; + if (trk.Sector() != iSector) { + continue; + } out << " Track " << j << ": LocalId " << (iGlobal ? (trk.LocalTrackId() >> 24) : -1) << "/" << (iGlobal ? (trk.LocalTrackId() & 0xFFFFFF) : -1) << " NCl " << trk.NClusters() << " X " << trk.X() << " offsetz " << trk.TOffset() << " A " << trk.Alpha() << " Y " << trk.Y() << " Z " << trk.Z() << " SinPhi " << trk.SinPhi() << " CosPhi " << trk.CosPhi() << " SecPhi " << trk.SecPhi() << " Tgl " << trk.DzDs() << " QPt " << trk.QPt() << "\n"; } } @@ -94,7 +96,7 @@ void GPUTPCGMMerger::DumpMergeRanges(std::ostream& out, uint8_t mergeMode) const void GPUTPCGMMerger::DumpTrackLinks(std::ostream& out, bool output, const char* type) const { out << "\nTPC Merger Links " << type << "\n"; - const int32_t n = output ? mMemory->nMergedTracks : SectorTrackInfoLocalTotal(); + const int32_t n = output ? mMemory->nMergedTracks : mMemory->nUnpackedTracks; for (int32_t i = 0; i < n; i++) { if (mTrackLinks[i] != -1) { out << " " << i << ": " << mTrackLinks[i] << "\n"; @@ -107,8 +109,11 @@ void GPUTPCGMMerger::DumpMergedWithinSectors(std::ostream& out) const DumpTrackLinks(out, false, "within Sectors"); out << "\nTPC Merger Merge Within Sectors\n"; for (int32_t iSector = 0; iSector < NSECTORS; iSector++) { - for (int32_t j = mSectorTrackInfoIndex[iSector]; j < mSectorTrackInfoIndex[iSector + 1]; j++) { + for (uint32_t j = 0; j < mMemory->nUnpackedTracks; j++) { const auto& trk = mSectorTrackInfos[j]; + if (trk.Sector() != iSector) { + continue; + } if (trk.NextSegmentNeighbour() >= 0 || trk.PrevSegmentNeighbour() >= 0) { out << " Track " << j << ": Neighbour " << trk.PrevSegmentNeighbour() << " / " << trk.NextSegmentNeighbour() << "\n"; } @@ -121,8 +126,11 @@ void GPUTPCGMMerger::DumpMergedBetweenSectors(std::ostream& out) const DumpTrackLinks(out, false, "between Sectors"); out << "\nTPC Merger Merge Between Sectors\n"; for (int32_t iSector = 0; iSector < NSECTORS; iSector++) { - for (int32_t j = mSectorTrackInfoIndex[iSector]; j < mSectorTrackInfoIndex[iSector + 1]; j++) { + for (uint32_t j = 0; j < mMemory->nUnpackedTracks; j++) { const auto& trk = mSectorTrackInfos[j]; + if (trk.Sector() != iSector) { + continue; + } if (trk.NextNeighbour() >= 0 || trk.PrevNeighbour() >= 0) { out << " Track " << j << ": Neighbour " << trk.PrevNeighbour() << " / " << trk.NextNeighbour() << "\n"; } diff --git a/GPU/GPUTracking/Merger/GPUTPCGMMergerGPU.cxx b/GPU/GPUTracking/Merger/GPUTPCGMMergerGPU.cxx index 48780cb060d90..1a54ba4edb365 100644 --- a/GPU/GPUTracking/Merger/GPUTPCGMMergerGPU.cxx +++ b/GPU/GPUTracking/Merger/GPUTPCGMMergerGPU.cxx @@ -68,14 +68,6 @@ GPUdii() void GPUTPCGMMergerUnpackGlobal::Thread<0>(int32_t nBlocks, int32_t nTh merger.UnpackSectorGlobal(nBlocks, nThreads, iBlock, iThread, iSector); } -template <> -GPUdii() void GPUTPCGMMergerUnpackSaveNumber::Thread<0>(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUsharedref() GPUSharedMemory& smem, processorType& GPUrestrict() merger, int32_t id) -{ - if (iThread == 0 && iBlock == 0) { - merger.UnpackSaveNumber(id); - } -} - template <> GPUdii() void GPUTPCGMMergerResolve::Thread<0>(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUsharedref() GPUSharedMemory& smem, processorType& GPUrestrict() merger) { diff --git a/GPU/GPUTracking/Merger/GPUTPCGMMergerGPU.h b/GPU/GPUTracking/Merger/GPUTPCGMMergerGPU.h index 023a72f276de3..72300566a3d90 100644 --- a/GPU/GPUTracking/Merger/GPUTPCGMMergerGPU.h +++ b/GPU/GPUTracking/Merger/GPUTPCGMMergerGPU.h @@ -63,13 +63,6 @@ class GPUTPCGMMergerUnpackGlobal : public GPUTPCGMMergerGeneral GPUd() static void Thread(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUsharedref() GPUSharedMemory& smem, processorType& merger, int32_t iSector); }; -class GPUTPCGMMergerUnpackSaveNumber : public GPUTPCGMMergerGeneral -{ - public: - template - GPUd() static void Thread(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUsharedref() GPUSharedMemory& smem, processorType& merger, int32_t id); -}; - class GPUTPCGMMergerUnpackResetIds : public GPUTPCGMMergerGeneral { public: diff --git a/GPU/GPUTracking/Merger/GPUTPCGlobalDebugSortKernels.cxx b/GPU/GPUTracking/Merger/GPUTPCGlobalDebugSortKernels.cxx index a3a1db5630944..83781998e2806 100644 --- a/GPU/GPUTracking/Merger/GPUTPCGlobalDebugSortKernels.cxx +++ b/GPU/GPUTracking/Merger/GPUTPCGlobalDebugSortKernels.cxx @@ -17,9 +17,6 @@ #include "GPUCommonMath.h" #include "GPUCommonAlgorithm.h" #include "GPUTPCGlobalDebugSortKernels.h" -#ifndef GPUCA_GPUCODE_DEVICE -#include -#endif using namespace o2::gpu; @@ -32,66 +29,72 @@ GPUdii() void GPUTPCGlobalDebugSortKernels::Thread -GPUdii() void GPUTPCGlobalDebugSortKernels::Thread(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUsharedref() GPUSharedMemory& smem, processorType& GPUrestrict() merger, int8_t parameter) +GPUdii() void GPUTPCGlobalDebugSortKernels::Thread(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUsharedref() GPUSharedMemory& smem, processorType& GPUrestrict() merger, int8_t parameter) { if (iThread) { return; } - int32_t iStart = parameter ? GPUTPCGeometry::NSECTORS : 0; - int32_t iEnd = iStart + GPUTPCGeometry::NSECTORS; - for (int32_t i = iStart + iBlock; i < iEnd; i += nBlocks) { - const int32_t offset = merger.SectorTrackInfoFirst(i); - int32_t* GPUrestrict() tmp = merger.TmpSortMemory() + offset; - const int32_t n = merger.SectorTrackInfoLast(i) - merger.SectorTrackInfoFirst(i); - if (n < 2) { - continue; + const uint32_t offset = parameter ? merger.Memory()->nUnpackedTracks : 0; + const uint32_t n = parameter ? merger.Memory()->nUnpackedTracksGlobal : merger.Memory()->nUnpackedTracks; + const GPUTPCGMSectorTrack* GPUrestrict() tracks = merger.SectorTrackInfos() + offset; + for (uint32_t iSector = iBlock; iSector < GPUTPCGeometry::NSECTORS; iSector += nBlocks) { + uint32_t sectorOffset = 0; + for (uint32_t j = 0; j < n; j++) { + sectorOffset += tracks[j].Sector() < iSector; } - for (int32_t j = 0; j < n; j++) { - tmp[j] = j; + int32_t* GPUrestrict() tmp = merger.TmpSortMemory() + sectorOffset; // Slice of this sector, so that tmp is sorted by sector over the full range + uint32_t nSector = 0; + for (uint32_t j = 0; j < n; j++) { + if (tracks[j].Sector() == iSector) { + tmp[nSector++] = j; + } } - GPUCommonAlgorithm::sort(tmp, tmp + n, [&merger, offset](const int32_t& aa, const int32_t& bb) { - const auto& a = merger.SectorTrackInfos()[offset + aa]; - const auto& b = merger.SectorTrackInfos()[offset + bb]; - return (a.X() != b.X()) ? (a.X() < b.X()) + GPUCommonAlgorithm::sort(tmp, tmp + nSector, [tracks, parameter](const int32_t& aa, const int32_t& bb) { + const auto& a = tracks[aa]; + const auto& b = tracks[bb]; + return !parameter ? (a.OrigTrack() < b.OrigTrack()) // Local tracks: order of the sector tracker, which is sorted in deterministic mode + : (a.X() != b.X()) ? (a.X() < b.X()) : (a.Y() != b.Y()) ? (a.Y() < b.Y()) : (a.Z() < b.Z()); }); - for (int32_t j = 0; j < n; j++) { - if (tmp[j] >= 0 && tmp[j] != j) { - auto getTrackIDIndex = [&merger](const int32_t iSector, const int32_t iTrack) { - const int32_t kEnd = merger.NMaxSingleSectorTracks(); - for (int32_t k = 0; k < kEnd; k++) { - if (merger.TrackIDs()[iSector * merger.NMaxSingleSectorTracks() + k] == iTrack) { - return k; - } - } -#ifndef GPUCA_GPUCODE_DEVICE - throw std::runtime_error("Internal error, track id missing"); -#endif - return -1; - }; + } +} + +template <> +GPUdii() void GPUTPCGlobalDebugSortKernels::Thread(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUsharedref() GPUSharedMemory& smem, processorType& GPUrestrict() merger, int8_t parameter) +{ + if (iBlock) { + return; + } + const uint32_t offset = parameter ? merger.Memory()->nUnpackedTracks : 0; + const uint32_t n = parameter ? merger.Memory()->nUnpackedTracksGlobal : merger.Memory()->nUnpackedTracks; + int32_t* GPUrestrict() tmp = merger.TmpSortMemory(); + GPUTPCGMSectorTrack* GPUrestrict() tracks = merger.SectorTrackInfos() + offset; + if (iThread == 0) { + for (uint32_t j = 0; j < n; j++) { + if (tmp[j] >= 0 && tmp[j] != (int32_t)j) { int32_t firstIdx = j; - auto firstItem = merger.SectorTrackInfos()[offset + firstIdx]; - int32_t firstTrackIDIndex = parameter ? 0 : getTrackIDIndex(i, offset + firstIdx); + auto firstItem = tracks[firstIdx]; int32_t currIdx = firstIdx; int32_t sourceIdx = tmp[currIdx]; do { tmp[currIdx] = -1; - merger.SectorTrackInfos()[offset + currIdx] = merger.SectorTrackInfos()[offset + sourceIdx]; - if (!parameter) { - merger.TrackIDs()[i * merger.NMaxSingleSectorTracks() + getTrackIDIndex(i, offset + sourceIdx)] = offset + currIdx; - } + tracks[currIdx] = tracks[sourceIdx]; currIdx = sourceIdx; sourceIdx = tmp[currIdx]; } while (sourceIdx != firstIdx); tmp[currIdx] = -1; - merger.SectorTrackInfos()[offset + currIdx] = firstItem; - if (!parameter) { - merger.TrackIDs()[i * merger.NMaxSingleSectorTracks() + firstTrackIDIndex] = offset + currIdx; - } + tracks[currIdx] = firstItem; } } } + if (parameter) { + return; + } + GPUbarrier(); + for (uint32_t j = iThread; j < n; j += nThreads) { + merger.TrackIDs()[tracks[j].Sector() * merger.NMaxSingleSectorTracks() + tracks[j].OrigTrack()->LocalTrackId()] = j; + } } template <> diff --git a/GPU/GPUTracking/Merger/GPUTPCGlobalDebugSortKernels.h b/GPU/GPUTracking/Merger/GPUTPCGlobalDebugSortKernels.h index 87204449749b6..42ceed0d30332 100644 --- a/GPU/GPUTracking/Merger/GPUTPCGlobalDebugSortKernels.h +++ b/GPU/GPUTracking/Merger/GPUTPCGlobalDebugSortKernels.h @@ -28,10 +28,11 @@ class GPUTPCGlobalDebugSortKernels : public GPUKernelTemplate public: enum K { defaultKernel = 0, clearIds = 0, - sectorTracks = 1, - mergedTracks1 = 2, - mergedTracks2 = 3, - borderTracks = 4 }; + sectorTracks1 = 1, + sectorTracks2 = 2, + mergedTracks1 = 3, + mergedTracks2 = 4, + borderTracks = 5 }; GPUhdi() constexpr static gpudatatypes::RecoStep GetRecoStep() { return gpudatatypes::RecoStep::TPCMerging; } typedef GPUTPCGMMerger processorType; GPUhdi() static processorType* Processor(GPUConstantMem& processors) { return &processors.tpcMerger; } diff --git a/GPU/GPUTracking/kernels.cmake b/GPU/GPUTracking/kernels.cmake index 45e9f30add615..0e95c09a3ef78 100644 --- a/GPU/GPUTracking/kernels.cmake +++ b/GPU/GPUTracking/kernels.cmake @@ -45,7 +45,8 @@ o2_gpu_add_kernel("GPUTPCSectorDebugSortKernels, hitData" "= TPC o2_gpu_add_kernel("GPUTPCSectorDebugSortKernels, startHits" "= TPCTRACKER") o2_gpu_add_kernel("GPUTPCSectorDebugSortKernels, sectorTracks" "= TPCTRACKER") o2_gpu_add_kernel("GPUTPCGlobalDebugSortKernels, clearIds" "= TPCMERGER" NO int8_t parameter) -o2_gpu_add_kernel("GPUTPCGlobalDebugSortKernels, sectorTracks" "= TPCMERGER" NO int8_t parameter) +o2_gpu_add_kernel("GPUTPCGlobalDebugSortKernels, sectorTracks1" "= TPCMERGER" NO int8_t parameter) +o2_gpu_add_kernel("GPUTPCGlobalDebugSortKernels, sectorTracks2" "= TPCMERGER" NO int8_t parameter) o2_gpu_add_kernel("GPUTPCGlobalDebugSortKernels, mergedTracks1" "= TPCMERGER" NO int8_t parameter) o2_gpu_add_kernel("GPUTPCGlobalDebugSortKernels, mergedTracks2" "= TPCMERGER" NO int8_t parameter) o2_gpu_add_kernel("GPUTPCGlobalDebugSortKernels, borderTracks" "= TPCMERGER" NO int8_t parameter) @@ -58,7 +59,6 @@ o2_gpu_add_kernel("GPUTPCGMMergerFollowLoopers" "GPUTP o2_gpu_add_kernel("GPUTPCGMMergerUnpackResetIds" "GPUTPCGMMergerGPU TPCMERGER" LB int32_t iSector) o2_gpu_add_kernel("GPUTPCGMMergerSectorRefit" "GPUTPCGMMergerGPU TPCMERGER MATLUT" LB int32_t iSector) o2_gpu_add_kernel("GPUTPCGMMergerUnpackGlobal" "GPUTPCGMMergerGPU TPCMERGER" LB int32_t iSector) -o2_gpu_add_kernel("GPUTPCGMMergerUnpackSaveNumber" "GPUTPCGMMergerGPU TPCMERGER" NO int32_t id) o2_gpu_add_kernel("GPUTPCGMMergerResolve, step0" "GPUTPCGMMergerGPU TPCMERGER" LB) o2_gpu_add_kernel("GPUTPCGMMergerResolve, step1" "GPUTPCGMMergerGPU TPCMERGER" LB) o2_gpu_add_kernel("GPUTPCGMMergerResolve, step2" "GPUTPCGMMergerGPU TPCMERGER" LB)