From 3e69d68c64124016aa5db9e6223ce05dce3d775e Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Thu, 12 Nov 2026 14:06:35 +0100 Subject: [PATCH] GPU: skip the rows out of reach of a looper in a loop of their own AttachClustersLooperFollow scans all rows after each propagation step and attaches clusters in the two to four rows within 1.5 cm of the track. On a GPU the threads of a warp sit at different radii, so each of them finds its rows at different iterations of the scan, and the warp runs the attachment once per row that any of its threads is close to, with one or two threads active each time. Skip the rows out of reach in an inner loop without attachment, so that all threads of a warp reach AttachClusters in the same iteration. The inner loop only advances j over rows for which the condition of the attachment is false, evaluated with the same expression and the same track position (AttachClusters does not change it), and stops at the last row, which the unchanged condition below still tests. Each thread therefore calls AttachClusters for the same rows, in the same order and with the same arguments as before. GPUTPCGMMergerFollowLoopers on an M1 Max with Metal, 1/4 of a 30 kHz Pb-Pb time frame: 217 ms -> 77 ms. The code is not specific to Metal. --- GPU/GPUTracking/Merger/GPUTPCGMTrackParam.cxx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/GPU/GPUTracking/Merger/GPUTPCGMTrackParam.cxx b/GPU/GPUTracking/Merger/GPUTPCGMTrackParam.cxx index 7b70d94b9cfc5..03921dbc96286 100644 --- a/GPU/GPUTracking/Merger/GPUTPCGMTrackParam.cxx +++ b/GPU/GPUTracking/Merger/GPUTPCGMTrackParam.cxx @@ -713,6 +713,9 @@ GPUdi() void GPUTPCGMTrackParam::AttachClustersLooperFollow(const GPUTPCGMMerger } 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]));