From f841169ab30e91e8fb0136fdc4fa07cbcfc44acf Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Fri, 27 Nov 2026 06:59:44 +0100 Subject: [PATCH 1/3] GPU: run the merger's sorts on the host on backends sharing their memory The sorts of the TPC merger, which CUDA and HIP run with thrust, run on a single GPU thread on the other backends. A backend whose memory is shared with the host can sort there instead, with the CPU code of the kernels, once its stream is drained. The new parameter UNIFIED_MEM_SORT_ON_HOST selects this for the sorts of the merged tracks, of the looper candidates, of the O2 output and of the border ranges, through the new kernel device type HostOnDeviceMemory. It differs from CPU, whose kernels work on the host processors and their host memory: these kernels run on a copy of the device processors, which points at the host view of the device memory (mDeviceMemoryHostView, set by the backend if that is at another address), with the host's parameters and calibration objects. Pointer arguments are moved to the host view as well. The parameter is 0 for all backends. --- GPU/GPUTracking/Base/GPUReconstruction.h | 4 +- GPU/GPUTracking/Base/GPUReconstructionCPU.cxx | 61 ++++++++++++++++++- GPU/GPUTracking/Base/GPUReconstructionCPU.h | 4 ++ .../Base/GPUReconstructionCPUKernels.h | 2 +- .../Definitions/Parameters/GPUParameters.csv | 1 + .../Global/GPUChainTrackingMerger.cxx | 14 +++-- GPU/GPUTracking/Global/GPUErrors.cxx | 5 ++ GPU/GPUTracking/Global/GPUErrors.h | 1 + GPU/GPUTracking/kernels.cmake | 1 + 9 files changed, 83 insertions(+), 10 deletions(-) diff --git a/GPU/GPUTracking/Base/GPUReconstruction.h b/GPU/GPUTracking/Base/GPUReconstruction.h index c94b66a9a5cc5..fe281cf5bda0f 100644 --- a/GPU/GPUTracking/Base/GPUReconstruction.h +++ b/GPU/GPUTracking/Base/GPUReconstruction.h @@ -132,7 +132,8 @@ class GPUReconstruction enum class krnlDeviceType : int32_t { CPU = 0, Device = 1, - Auto = -1 }; + Auto = -1, + HostOnDeviceMemory = 2 }; // CPU code on the host, on the device memory (UNIFIED_MEM_SORT_ON_HOST) struct deviceEvent; struct threadContext; @@ -352,6 +353,7 @@ class GPUReconstruction size_t mHostMemoryUSSMax = 0; // Maximum USS of the process seen by QueryHostMemoryUSS std::string mHostMemoryUSSMaxWhere; // and where it was seen void* mDeviceMemoryBase = nullptr; // Same for device ... + void* mDeviceMemoryHostView = nullptr; // Host address of the device memory, if shared with the host at another address void* mDeviceMemoryPermanent = nullptr; // ... void* mDeviceMemoryPool = nullptr; // ... void* mDeviceMemoryPoolEnd = nullptr; // ... diff --git a/GPU/GPUTracking/Base/GPUReconstructionCPU.cxx b/GPU/GPUTracking/Base/GPUReconstructionCPU.cxx index dfec97fe1a158..58fba0b7a3569 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionCPU.cxx +++ b/GPU/GPUTracking/Base/GPUReconstructionCPU.cxx @@ -65,6 +65,15 @@ inline void GPUReconstructionCPU::runKernelBackend(const krnlSetupTime& _xyz, co throw std::runtime_error("Cannot run device kernel on host with nThreads != 1"); } int32_t nThreads = getNKernelHostThreads(false); + const auto deviceProcessors = IsGPU() && x.device == krnlDeviceType::HostOnDeviceMemory ? DeviceProcessorOnHostView(_xyz) : nullptr; + GPUConstantMem& mem = deviceProcessors ? *(GPUConstantMem*)deviceProcessors.get() : *mHostConstantMem; + auto arg = [&](const auto& a) -> decltype(auto) { + if constexpr (std::is_pointer_v>) { + return deviceProcessors ? static_cast>(HostPointer(a)) : a; + } else { + return a; + } + }; if (nThreads > 1) { if (GetProcessingSettings().debugLevel >= 5) { GPUInfo("Running %d Threads", mThreading->activeThreads->max_concurrency()); @@ -74,7 +83,7 @@ inline void GPUReconstructionCPU::runKernelBackend(const krnlSetupTime& _xyz, co tbb::parallel_for(tbb::blocked_range(0, x.nBlocks, 1), [&](const tbb::blocked_range& r) { typename T::GPUSharedMemory smem; for (uint32_t iB = r.begin(); iB < r.end(); iB++) { - T::template Thread(x.nBlocks, 1, iB, 0, smem, T::Processor(*mHostConstantMem)[y.index], args...); + T::template Thread(x.nBlocks, 1, iB, 0, smem, T::Processor(mem)[y.index], arg(args)...); } }); }); @@ -82,9 +91,57 @@ inline void GPUReconstructionCPU::runKernelBackend(const krnlSetupTime& _xyz, co } else { for (uint32_t iB = 0; iB < x.nBlocks; iB++) { typename T::GPUSharedMemory smem; - T::template Thread(x.nBlocks, 1, iB, 0, smem, T::Processor(*mHostConstantMem)[y.index], args...); + T::template Thread(x.nBlocks, 1, iB, 0, smem, T::Processor(mem)[y.index], arg(args)...); + } + } + if (deviceProcessors && _xyz.z.ev) { + RecordMarker(_xyz.z.ev, x.stream); + } +} + +void GPUReconstructionCPU::runKernelOnHost(const int num, const void* args) +{ + GPUReconstructionCPU::runKernelVirtual(num, args); +} + +const void* GPUReconstructionCPU::HostPointer(const void* ptr) const +{ + const size_t offset = (const char*)ptr - (const char*)mDeviceMemoryBase; + return mDeviceMemoryHostView && offset < mDeviceMemorySize ? (const char*)mDeviceMemoryHostView + offset : ptr; +} + +// A kernel run with krnlDeviceType::HostOnDeviceMemory, on a GPU sharing its memory with the host +// (UNIFIED_MEM_SORT_ON_HOST), runs the CPU code on the device processors, once the work before it in +// the stream is done: on a copy of them pointing at the host view of the device memory, with the +// host's parameters and calibration objects. The copy is their constant memory. +std::unique_ptr GPUReconstructionCPU::DeviceProcessorOnHostView(const krnlSetupTime& _xyz) +{ + if (_xyz.z.evList) { + StreamWaitForEvents(_xyz.x.stream, _xyz.z.evList, _xyz.z.nEvents); + } + SynchronizeStream(_xyz.x.stream); + static_assert(alignof(GPUConstantMem) <= __STDCPP_DEFAULT_NEW_ALIGNMENT__); + auto buffer = std::make_unique(sizeof(GPUConstantMem)); + GPUConstantMem* mem = (GPUConstantMem*)buffer.get(); + memcpy((void*)mem, (const void*)mProcessorsShadow, sizeof(GPUConstantMem)); + auto onHost = [&](const GPUProcessor* p) { + const size_t offset = (const char*)p - (const char*)mProcessorsShadow; + return offset < sizeof(GPUConstantMem) ? (GPUProcessor*)((char*)mem + offset) : nullptr; + }; + for (const auto& res : mMemoryResources) { + if (GPUProcessor* p = res.PtrDevice() ? onHost(res.mProcessor->mLinkedProcessor) : nullptr) { + (p->*res.mSetPointers)(HostPointer(res.PtrDevice())); + } + } + for (const auto& proc : mProcessors) { + if (GPUProcessor* p = onHost(proc.proc->mLinkedProcessor)) { + p->mConstantMem = mem; } } + mem->param = param(); + mem->calibObjects = processors()->calibObjects; + mem->errorCodes.setMemory(static_cast(HostPointer(mem->errorCodes.getErrorPtr() - 1))); + return buffer; } template <> diff --git a/GPU/GPUTracking/Base/GPUReconstructionCPU.h b/GPU/GPUTracking/Base/GPUReconstructionCPU.h index 466ad318bbe3b..db7ac66b09239 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionCPU.h +++ b/GPU/GPUTracking/Base/GPUReconstructionCPU.h @@ -71,6 +71,10 @@ class GPUReconstructionCPU : public GPUReconstructionProcessing::KernelInterface virtual void RecordMarker(deviceEvent* ev, int32_t stream) {} virtual void SynchronizeGPU() {} virtual void ReleaseEvent(deviceEvent ev) {} + const void* HostPointer(const void* ptr) const; + void* HostPointer(void* ptr) const { return const_cast(HostPointer(static_cast(ptr))); } + std::unique_ptr DeviceProcessorOnHostView(const krnlSetupTime& _xyz); + void runKernelOnHost(const int num, const void* args); // For the kernel specializations of a backend, e.g. with HostOnDeviceMemory size_t TransferMemoryResourceToGPU(GPUMemoryResource* res, int32_t stream = -1, deviceEvent* ev = nullptr, deviceEvent* evList = nullptr, int32_t nEvents = 1) { return TransferMemoryInternal(res, stream, ev, evList, nEvents, true, res->Ptr(), res->PtrDevice()); } size_t TransferMemoryResourceToHost(GPUMemoryResource* res, int32_t stream = -1, deviceEvent* ev = nullptr, deviceEvent* evList = nullptr, int32_t nEvents = 1) { return TransferMemoryInternal(res, stream, ev, evList, nEvents, false, res->PtrDevice(), res->Ptr()); } diff --git a/GPU/GPUTracking/Base/GPUReconstructionCPUKernels.h b/GPU/GPUTracking/Base/GPUReconstructionCPUKernels.h index 3e330cd82ef6c..9fbb4d2e6040d 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionCPUKernels.h +++ b/GPU/GPUTracking/Base/GPUReconstructionCPUKernels.h @@ -30,7 +30,7 @@ inline void GPUReconstructionCPU::runKernelInterface(krnlSetup&& setup, Args con if (myStep == gpudatatypes::RecoStep::NoRecoStep) { throw std::runtime_error("Failure running general kernel without defining RecoStep"); } - int32_t cpuFallback = IsGPU() ? (setup.x.device == krnlDeviceType::CPU ? 2 : (mRecoSteps.stepsGPUMask & myStep) != myStep) : 0; + int32_t cpuFallback = IsGPU() ? ((setup.x.device == krnlDeviceType::CPU || setup.x.device == krnlDeviceType::HostOnDeviceMemory) ? 2 : (mRecoSteps.stepsGPUMask & myStep) != myStep) : 0; uint32_t& nThreads = setup.x.nThreads; uint32_t& nBlocks = setup.x.nBlocks; const uint32_t stream = setup.x.stream; diff --git a/GPU/GPUTracking/Definitions/Parameters/GPUParameters.csv b/GPU/GPUTracking/Definitions/Parameters/GPUParameters.csv index 87336277eadbd..c55e0840dea22 100644 --- a/GPU/GPUTracking/Definitions/Parameters/GPUParameters.csv +++ b/GPU/GPUTracking/Definitions/Parameters/GPUParameters.csv @@ -116,6 +116,7 @@ NEIGHBOURS_FINDER_UNROLL_SHARED,1,0,0,0,,,,,,1,,1,0,,1,,1,1, TRACKLET_SELECTOR_HITS_REG_SIZE,12,0,9,27,,,,,,20,20,20,20,,20,,2,20, ALTERNATE_BORDER_SORT,1,0,1,1,,,,,,1,1,1,1,,1,,1,1, SORT_BEFORE_FIT,1,0,1,1,,,,,,1,1,1,1,,1,,1,1, +UNIFIED_MEM_SORT_ON_HOST,0,0,,,,,,,,,,,,,,,,, NO_ATOMIC_PRECHECK,0,0,1,1,,,,,,1,1,1,1,,1,,1,1, DEDX_STORAGE_TYPE,"""CAMath::half_t""","""float""",,,,,,,,,,,,,,,,, MERGER_INTERPOLATION_ERROR_TYPE,"""CAMath::half_t""","""float""",,,,,,,,,,,,,,,,, diff --git a/GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx b/GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx index 798689feb5805..06e3e2fe70ace 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx @@ -34,6 +34,7 @@ void GPUChainTracking::RunTPCTrackingMerger_MergeBorderTracks(uint8_t mergeMode, GPUTPCGMMerger& Merger = processors()->tpcMerger; bool doGPU = GetRecoStepsGPU() & RecoStep::TPCMerging; GPUTPCGMMerger& MergerShadow = doGPU ? processorsShadow()->tpcMerger : Merger; + const auto sortDeviceType = mRec->getGPUParameters(doGPU).par_UNIFIED_MEM_SORT_ON_HOST ? GPUReconstruction::krnlDeviceType::HostOnDeviceMemory : deviceType; if (GetProcessingSettings().deterministicGPUReconstruction) { uint32_t nBorderTracks = (mergeMode & GPUTPCGMMerger::mergeModes::mergeWithinSector) ? NSECTORS : (2 * NSECTORS); runKernel({{nBorderTracks, -WarpSize(), 0, deviceType}}, 0); @@ -56,8 +57,8 @@ void GPUChainTracking::RunTPCTrackingMerger_MergeBorderTracks(uint8_t mergeMode, Merger.MergeBorderTracksSetup(n1, n2, b1, b2, jSector, i, mergeMode); gputpcgmmergertypes::GPUTPCGMBorderRange* range1 = MergerShadow.BorderRange(i); gputpcgmmergertypes::GPUTPCGMBorderRange* range2 = MergerShadow.BorderRange(jSector) + *processors()->tpcTrackers[jSector].NTracks(); - runKernel({{1, -WarpSize(), stream, deviceType}}, range1, n1, 0); - runKernel({{1, -WarpSize(), stream, deviceType}}, range2, n2, 1); + runKernel({{1, -WarpSize(), stream, sortDeviceType}}, range1, n1, 0); + runKernel({{1, -WarpSize(), stream, sortDeviceType}}, range2, n2, 1); runKernel({GetGridAuto(stream, deviceType)}, i, mergeMode); } int32_t ne = std::min(n, mRec->NStreams()) - 1; // Stream 0 must wait for all streams, Note n > 1 @@ -94,6 +95,7 @@ int32_t GPUChainTracking::RunTPCTrackingMerger(bool synchronizeOutput) mRec->PushNonPersistentMemory(qStr2Tag("TPCMERGE")); bool doGPU = GetRecoStepsGPU() & RecoStep::TPCMerging; GPUReconstruction::krnlDeviceType deviceType = doGPU ? GPUReconstruction::krnlDeviceType::Auto : GPUReconstruction::krnlDeviceType::CPU; + const auto sortDeviceType = mRec->getGPUParameters(doGPU).par_UNIFIED_MEM_SORT_ON_HOST ? GPUReconstruction::krnlDeviceType::HostOnDeviceMemory : deviceType; uint32_t numBlocks = (!mRec->IsGPU() || doGPU) ? BlockCount() : 1; GPUTPCGMMerger& Merger = processors()->tpcMerger; GPUTPCGMMerger& MergerShadow = doGPU ? processorsShadow()->tpcMerger : Merger; @@ -221,7 +223,7 @@ int32_t GPUChainTracking::RunTPCTrackingMerger(bool synchronizeOutput) if (mergerSortTracks) { runKernel(GetGridAuto(0, deviceType)); CondWaitEvent(waitForTransfer, &mEvents->single); - runKernel(GetGridAuto(0, deviceType)); + runKernel(GetGridAuto(0, sortDeviceType)); } if (GetProcessingSettings().mergerSanityCheck) { Merger.CheckCollectedTracks(); @@ -239,7 +241,7 @@ int32_t GPUChainTracking::RunTPCTrackingMerger(bool synchronizeOutput) runKernel({{numBlocks, -ThreadCount(), 0, deviceType, RecoStep::TPCMerging}}, MergerShadow.ClusterAttachment(), Merger.NClusters() * sizeof(*MergerShadow.ClusterAttachment())); runKernel(GetGridAuto(0, deviceType)); CondWaitEvent(waitForTransfer, &mEvents->single); - runKernel(GetGridAuto(0, deviceType)); + runKernel(GetGridAuto(0, sortDeviceType)); runKernel(GetGridAuto(0, deviceType)); runKernel(GetGridAuto(0, deviceType)); if (doGPU && rebuildConstrainedRows == 1) { // PrepareForFit1 computed nRebuildTrackRow, needed on the host to allocate the rebuild memory, waited for below @@ -313,7 +315,7 @@ int32_t GPUChainTracking::RunTPCTrackingMerger(bool synchronizeOutput) SynchronizeStream(0); // TODO: could probably synchronize on an event after runKernel } if (param().rec.tpc.mergeLoopersAfterburner) { - runKernel(GetGridAuto(0, deviceType)); + runKernel(GetGridAuto(0, sortDeviceType)); runKernel(doGPU ? GetGrid(Merger.Memory()->nLooperMatchCandidates, 0, deviceType) : GetGridAuto(0, deviceType)); DoDebugAndDump(RecoStep::TPCMerging, GPUChainTrackingDebugFlags::TPCMergingLoopers, Merger, &GPUTPCGMMerger::DumpLoopers, *mDebugFile); } @@ -371,7 +373,7 @@ int32_t GPUChainTracking::RunTPCTrackingMerger(bool synchronizeOutput) } TransferMemoryResourceLinkToHost(RecoStep::TPCMerging, Merger.MemoryResMemory(), 0, &mEvents->single); SynchronizeEventAndRelease(mEvents->single, doGPU); // The CUDA / HIP specialization of the sort reads nO2Tracks on the host - runKernel(GetGridAuto(0, deviceType)); + runKernel(GetGridAuto(0, sortDeviceType)); mRec->ReturnVolatileDeviceMemory(); if (GetProcessingSettings().clearO2OutputFromGPU) { diff --git a/GPU/GPUTracking/Global/GPUErrors.cxx b/GPU/GPUTracking/Global/GPUErrors.cxx index dfe7a84f0f179..801d686b7657f 100644 --- a/GPU/GPUTracking/Global/GPUErrors.cxx +++ b/GPU/GPUTracking/Global/GPUErrors.cxx @@ -98,4 +98,9 @@ const uint32_t* GPUErrors::getErrorPtr() const return mErrors + 1; } +uint32_t* GPUErrors::getErrorPtr() +{ + return mErrors + 1; +} + #endif diff --git a/GPU/GPUTracking/Global/GPUErrors.h b/GPU/GPUTracking/Global/GPUErrors.h index 535364bf08ce1..64fc5365e904b 100644 --- a/GPU/GPUTracking/Global/GPUErrors.h +++ b/GPU/GPUTracking/Global/GPUErrors.h @@ -42,6 +42,7 @@ class GPUErrors #endif uint32_t getNErrors() const; const uint32_t* getErrorPtr() const; + uint32_t* getErrorPtr(); static uint32_t getMaxErrors(); private: diff --git a/GPU/GPUTracking/kernels.cmake b/GPU/GPUTracking/kernels.cmake index 0e95c09a3ef78..22462a58d0322 100644 --- a/GPU/GPUTracking/kernels.cmake +++ b/GPU/GPUTracking/kernels.cmake @@ -150,6 +150,7 @@ o2_gpu_kernel_add_parameter(NEIGHBOURS_FINDER_MAX_NNEIGHUP # Number o TRACKLET_SELECTOR_HITS_REG_SIZE # Number of hits to cache in shared memory in tracklet selector ALTERNATE_BORDER_SORT # Use alternative border sort approach [0/1] SORT_BEFORE_FIT # Sort tracks after length to reduce warp serialization [0/1] + UNIFIED_MEM_SORT_ON_HOST # Run the sorts on the host, on the memory shared with the GPU [0/1] NO_ATOMIC_PRECHECK # Skip atomic precheck to reduce posterior synchronization [0/1] COMP_GATHER_KERNEL # Default kernel to use for Compression Gather Operation [0 - 4] COMP_GATHER_MODE # TPC Compression Gather Mode [0 - 3] From a500c9e8f87db85d8095ce023d243f03d031a1bd Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Fri, 27 Nov 2026 06:59:44 +0100 Subject: [PATCH 2/3] GPU Metal: run the merger's sorts on the host On a single GPU thread, the sorts of the merged tracks by quality and by q/pT, of the looper candidates and of the O2 output tracks took about 730 ms per event on a 30-collision Pb-Pb time frame, at up to 140 times the CPU's time, and the 360 border-range sorts per time frame another 312 ms. The GPU memory is shared with the host, so sort there with UNIFIED_MEM_SORT_ON_HOST, which also orders the elements that compare equal as on the CPU. --- GPU/GPUTracking/Base/metal/GPUReconstructionMetal.mm | 1 + GPU/GPUTracking/Definitions/Parameters/GPUParameters.csv | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/GPU/GPUTracking/Base/metal/GPUReconstructionMetal.mm b/GPU/GPUTracking/Base/metal/GPUReconstructionMetal.mm index 2f8a28da23922..6f1d8ee9d95cf 100644 --- a/GPU/GPUTracking/Base/metal/GPUReconstructionMetal.mm +++ b/GPU/GPUTracking/Base/metal/GPUReconstructionMetal.mm @@ -185,6 +185,7 @@ uint32_t metalGPUCoreCount() // The kernels reconstruct device pointers from these bases, so they must be // the addresses the GPU sees, not the CPU-visible ones of a shared buffer. mDeviceMemoryBase = (void*)(uintptr_t)mInternals->mem_gpu.gpuAddress; + mDeviceMemoryHostView = mInternals->mem_gpu.contents; mDeviceMemorySize = mInternals->mem_gpu.allocatedSize - sizeof(uint32_t); *(uint32_t*)((char*)mInternals->mem_gpu.contents + mDeviceMemorySize) = mInternals->canaryMagic; if (getenv("GPUCA_METAL_CANARY")) { diff --git a/GPU/GPUTracking/Definitions/Parameters/GPUParameters.csv b/GPU/GPUTracking/Definitions/Parameters/GPUParameters.csv index c55e0840dea22..4861a5d669fb8 100644 --- a/GPU/GPUTracking/Definitions/Parameters/GPUParameters.csv +++ b/GPU/GPUTracking/Definitions/Parameters/GPUParameters.csv @@ -116,7 +116,7 @@ NEIGHBOURS_FINDER_UNROLL_SHARED,1,0,0,0,,,,,,1,,1,0,,1,,1,1, TRACKLET_SELECTOR_HITS_REG_SIZE,12,0,9,27,,,,,,20,20,20,20,,20,,2,20, ALTERNATE_BORDER_SORT,1,0,1,1,,,,,,1,1,1,1,,1,,1,1, SORT_BEFORE_FIT,1,0,1,1,,,,,,1,1,1,1,,1,,1,1, -UNIFIED_MEM_SORT_ON_HOST,0,0,,,,,,,,,,,,,,,,, +UNIFIED_MEM_SORT_ON_HOST,0,0,,,,,,,,,,,,,,,,,1 NO_ATOMIC_PRECHECK,0,0,1,1,,,,,,1,1,1,1,,1,,1,1, DEDX_STORAGE_TYPE,"""CAMath::half_t""","""float""",,,,,,,,,,,,,,,,, MERGER_INTERPOLATION_ERROR_TYPE,"""CAMath::half_t""","""float""",,,,,,,,,,,,,,,,, From d2a893ca6bf56086a87a6cac6227d77eb93ae495 Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Fri, 27 Nov 2026 06:59:44 +0100 Subject: [PATCH 3/3] GPU: run the second step of the border merging on the host on backends sharing their memory The candidate search of the border track merging, 180 launches per time frame of a few thousand tracks each, took 46 ms per event (kernels serialized) on a 30-collision Pb-Pb time frame on the Metal GPU, where each thread first walks the sorted ranges from the start. On the host, right after the range sorts which already drained the stream, it takes 4.6 ms, including pointing the processors at the host view of the shared memory for each launch. One block, so that the merging across the central electrode stays as on the CPU. Benchmark, 6 interleaved rounds of 10 events: -6 +- 2 ms per event. The new parameter UNIFIED_MEM_MERGE_BORDERS_ON_HOST selects it at the call site, as UNIFIED_MEM_SORT_ON_HOST does for the sorts: the CPU code runs on the device processors in the memory shared with the host. On for Metal only. --- GPU/GPUTracking/Definitions/Parameters/GPUParameters.csv | 1 + GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx | 5 +++-- GPU/GPUTracking/kernels.cmake | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/GPU/GPUTracking/Definitions/Parameters/GPUParameters.csv b/GPU/GPUTracking/Definitions/Parameters/GPUParameters.csv index 4861a5d669fb8..231c6843645f3 100644 --- a/GPU/GPUTracking/Definitions/Parameters/GPUParameters.csv +++ b/GPU/GPUTracking/Definitions/Parameters/GPUParameters.csv @@ -117,6 +117,7 @@ TRACKLET_SELECTOR_HITS_REG_SIZE,12,0,9,27,,,,,,20,20,20,20,,20,,2,20, ALTERNATE_BORDER_SORT,1,0,1,1,,,,,,1,1,1,1,,1,,1,1, SORT_BEFORE_FIT,1,0,1,1,,,,,,1,1,1,1,,1,,1,1, UNIFIED_MEM_SORT_ON_HOST,0,0,,,,,,,,,,,,,,,,,1 +UNIFIED_MEM_MERGE_BORDERS_ON_HOST,0,0,,,,,,,,,,,,,,,,,1 NO_ATOMIC_PRECHECK,0,0,1,1,,,,,,1,1,1,1,,1,,1,1, DEDX_STORAGE_TYPE,"""CAMath::half_t""","""float""",,,,,,,,,,,,,,,,, MERGER_INTERPOLATION_ERROR_TYPE,"""CAMath::half_t""","""float""",,,,,,,,,,,,,,,,, diff --git a/GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx b/GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx index 06e3e2fe70ace..fd19d5c39f9c7 100644 --- a/GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx +++ b/GPU/GPUTracking/Global/GPUChainTrackingMerger.cxx @@ -35,6 +35,7 @@ void GPUChainTracking::RunTPCTrackingMerger_MergeBorderTracks(uint8_t mergeMode, bool doGPU = GetRecoStepsGPU() & RecoStep::TPCMerging; GPUTPCGMMerger& MergerShadow = doGPU ? processorsShadow()->tpcMerger : Merger; const auto sortDeviceType = mRec->getGPUParameters(doGPU).par_UNIFIED_MEM_SORT_ON_HOST ? GPUReconstruction::krnlDeviceType::HostOnDeviceMemory : deviceType; + const bool mergeBordersOnHost = mRec->getGPUParameters(doGPU).par_UNIFIED_MEM_MERGE_BORDERS_ON_HOST; if (GetProcessingSettings().deterministicGPUReconstruction) { uint32_t nBorderTracks = (mergeMode & GPUTPCGMMerger::mergeModes::mergeWithinSector) ? NSECTORS : (2 * NSECTORS); runKernel({{nBorderTracks, -WarpSize(), 0, deviceType}}, 0); @@ -59,7 +60,7 @@ void GPUChainTracking::RunTPCTrackingMerger_MergeBorderTracks(uint8_t mergeMode, gputpcgmmergertypes::GPUTPCGMBorderRange* range2 = MergerShadow.BorderRange(jSector) + *processors()->tpcTrackers[jSector].NTracks(); runKernel({{1, -WarpSize(), stream, sortDeviceType}}, range1, n1, 0); runKernel({{1, -WarpSize(), stream, sortDeviceType}}, range2, n2, 1); - runKernel({GetGridAuto(stream, deviceType)}, i, mergeMode); + runKernel({mergeBordersOnHost ? krnlExec{1, -WarpSize(), stream, GPUReconstruction::krnlDeviceType::HostOnDeviceMemory} : GetGridAuto(stream, deviceType)}, i, mergeMode); } int32_t ne = std::min(n, mRec->NStreams()) - 1; // Stream 0 must wait for all streams, Note n > 1 for (int32_t j = 0; j < ne; j++) { @@ -74,7 +75,7 @@ void GPUChainTracking::RunTPCTrackingMerger_MergeBorderTracks(uint8_t mergeMode, } runKernel({{2 * n, -WarpSize(), 0, deviceType}}, 0, mergeMode); for (uint32_t i = 0; i < n; i++) { - runKernel(GetGridAuto(0, deviceType), i, mergeMode); + runKernel(mergeBordersOnHost ? krnlExec{1, -WarpSize(), 0, GPUReconstruction::krnlDeviceType::HostOnDeviceMemory} : GetGridAuto(0, deviceType), i, mergeMode); } } DoDebugAndDump(RecoStep::TPCMerging, GPUChainTrackingDebugFlags::TPCMergingRanges, doGPU, Merger, &GPUTPCGMMerger::DumpMergeRanges, *mDebugFile, mergeMode); diff --git a/GPU/GPUTracking/kernels.cmake b/GPU/GPUTracking/kernels.cmake index 22462a58d0322..27ebc6df7475e 100644 --- a/GPU/GPUTracking/kernels.cmake +++ b/GPU/GPUTracking/kernels.cmake @@ -151,6 +151,7 @@ o2_gpu_kernel_add_parameter(NEIGHBOURS_FINDER_MAX_NNEIGHUP # Number o ALTERNATE_BORDER_SORT # Use alternative border sort approach [0/1] SORT_BEFORE_FIT # Sort tracks after length to reduce warp serialization [0/1] UNIFIED_MEM_SORT_ON_HOST # Run the sorts on the host, on the memory shared with the GPU [0/1] + UNIFIED_MEM_MERGE_BORDERS_ON_HOST # Run the candidate search of the border merging on the host, on the memory shared with the GPU [0/1] NO_ATOMIC_PRECHECK # Skip atomic precheck to reduce posterior synchronization [0/1] COMP_GATHER_KERNEL # Default kernel to use for Compression Gather Operation [0 - 4] COMP_GATHER_MODE # TPC Compression Gather Mode [0 - 3]