Skip to content

GPU: run the second step of the border merging on the host on backends sharing their memory - #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 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.

@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:

ktf added 3 commits November 27, 2026 06:59
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.
…s 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.
@ktf ktf changed the title GPU Metal: run the second step of the border merging on the host GPU: run the second step of the border merging on the host on backends sharing their memory Nov 27, 2026
@ktf

ktf commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

@davidrohr I think I have taken into account all your comments.

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