Skip to content

GPU Metal: run the second step of the border merging on the host - #16217

Open
ktf wants to merge 3 commits into
AliceO2Group:devfrom
ktf:pr16217
Open

ktf wants to merge 3 commits into
AliceO2Group:devfrom
ktf:pr16217

Conversation

@ktf

@ktf ktf commented Nov 26, 2026

Copy link
Copy Markdown
Member

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 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 host thread, 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.

It runs as the sorts with UNIFIED_MEM_SORT_ON_HOST do: the CPU code, on
the device processors in the memory shared with the host.

ktf added 3 commits November 26, 2026 15:07
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.
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.
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 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 host thread, 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.

It runs as the sorts with UNIFIED_MEM_SORT_ON_HOST do: the CPU code, on
the device processors in the memory shared with the host.
@ktf
ktf requested a review from davidrohr as a code owner November 26, 2026 16:59
@ktf

ktf commented Nov 26, 2026

Copy link
Copy Markdown
Member Author

@davidrohr our understanding of your comments. Notice the accounting for CPU running in what is considered (shared) device memory.

@davidrohr davidrohr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks quite good and is pretty much what I had in mind. There is one issue with converting const ptr to non-const, that should be fixed. And 2 minor comments:

GPUReconstructionCPU::runKernelVirtual(num, args);
}

void* GPUReconstructionCPU::HostPointer(const void* ptr) const

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like that this converts a const ptr to a non-const ptr. If you need only 1 version, input and output should have the same constness. Otherwise, please provide 2 overloads.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect it's the usual address-space-part-of-the-type issue. I'll let you know.

RecordMarker(_xyz.z.ev, _xyz.x.stream);
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, why can't you use the HostOnDeviceMemory for this like for all the sorting?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason, just historical of how the patch came to be.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants