Skip to content

Commit c166e26

Browse files
committed
GPU: put the orderings of the merger's sorts in a header
Move the comparators of the TPC merger's sorts, and MergeLooperParam they sort, from GPUTPCGMMerger.cxx and GPUTPCGMO2Output.cxx into GPUTPCGMMergerSortComp.h, unchanged. The CUDA and HIP backends see them because they compile the kernel sources into one unit; a backend that runs these sorts in host code needs them from a header.
1 parent 12bdfeb commit c166e26

4 files changed

Lines changed: 113 additions & 89 deletions

File tree

‎GPU/GPUTracking/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ set(HDRS_INSTALL
145145
Global/GPUChainTrackingGetters.inc
146146
Global/GPUErrorCodes.h
147147
Merger/GPUTPCGMMergerTypes.h
148+
Merger/GPUTPCGMMergerSortComp.h
148149
qa/GPUQAHelper.h
149150
qconfigoptions.h
150151
Refit/GPUTrackParamConvert.h

‎GPU/GPUTracking/Merger/GPUTPCGMMerger.cxx‎

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -63,84 +63,7 @@ using namespace o2::gpu;
6363
using namespace o2::tpc;
6464
using namespace gputpcgmmergertypes;
6565

66-
namespace o2::gpu::internal
67-
{
68-
struct MergeLooperParam {
69-
float refz;
70-
float x;
71-
float y;
72-
uint32_t id;
73-
};
74-
75-
struct MergeBorderTracks_compMax {
76-
GPUd() bool operator()(const GPUTPCGMBorderRange& a, const GPUTPCGMBorderRange& b)
77-
{
78-
return GPUCA_DETERMINISTIC_CODE((a.fMax != b.fMax) ? (a.fMax < b.fMax) : (a.fId < b.fId), a.fMax < b.fMax);
79-
}
80-
};
81-
struct MergeBorderTracks_compMin {
82-
GPUd() bool operator()(const GPUTPCGMBorderRange& a, const GPUTPCGMBorderRange& b)
83-
{
84-
return GPUCA_DETERMINISTIC_CODE((a.fMin != b.fMin) ? (a.fMin < b.fMin) : (a.fId < b.fId), a.fMin < b.fMin);
85-
}
86-
};
87-
88-
struct GPUTPCGMMergerSortTracks_comp {
89-
const GPUTPCGMMergedTrack* const mCmp;
90-
GPUhd() GPUTPCGMMergerSortTracks_comp(GPUTPCGMMergedTrack* cmp) : mCmp(cmp) {}
91-
GPUd() bool operator()(const int32_t aa, const int32_t bb)
92-
{
93-
const GPUTPCGMMergedTrack& GPUrestrict() a = mCmp[aa];
94-
const GPUTPCGMMergedTrack& GPUrestrict() b = mCmp[bb];
95-
if (a.OK() != b.OK()) {
96-
return a.OK();
97-
}
98-
if (a.CCE() != b.CCE()) {
99-
return a.CCE() > b.CCE();
100-
}
101-
GPUCA_DETERMINISTIC_CODE( // clang-format off
102-
if (a.NClusters() != b.NClusters()) {
103-
return a.NClusters() > b.NClusters();
104-
} if (CAMath::Abs(a.GetParam().GetQPt()) != CAMath::Abs(b.GetParam().GetQPt())) {
105-
return CAMath::Abs(a.GetParam().GetQPt()) > CAMath::Abs(b.GetParam().GetQPt());
106-
} if (a.GetParam().GetY() != b.GetParam().GetY()) {
107-
return a.GetParam().GetY() > b.GetParam().GetY();
108-
}
109-
return aa > bb;
110-
, // !GPUCA_DETERMINISTIC_CODE
111-
return a.NClusters() > b.NClusters();
112-
) // clang-format on
113-
}
114-
};
115-
116-
struct GPUTPCGMMergerSortTracksQPt_comp {
117-
const GPUTPCGMMergedTrack* const mCmp;
118-
GPUhd() GPUTPCGMMergerSortTracksQPt_comp(GPUTPCGMMergedTrack* cmp) : mCmp(cmp) {}
119-
GPUd() bool operator()(const int32_t aa, const int32_t bb)
120-
{
121-
const GPUTPCGMMergedTrack& GPUrestrict() a = mCmp[aa];
122-
const GPUTPCGMMergedTrack& GPUrestrict() b = mCmp[bb];
123-
GPUCA_DETERMINISTIC_CODE( // clang-format off
124-
if (CAMath::Abs(a.GetParam().GetQPt()) != CAMath::Abs(b.GetParam().GetQPt())) {
125-
return CAMath::Abs(a.GetParam().GetQPt()) > CAMath::Abs(b.GetParam().GetQPt());
126-
} if (a.GetParam().GetY() != b.GetParam().GetY()) {
127-
return a.GetParam().GetY() > b.GetParam().GetY();
128-
}
129-
return a.GetParam().GetZ() > b.GetParam().GetZ();
130-
, // !GPUCA_DETERMINISTIC_CODE
131-
return CAMath::Abs(a.GetParam().GetQPt()) > CAMath::Abs(b.GetParam().GetQPt());
132-
) // clang-format on
133-
}
134-
};
135-
136-
struct GPUTPCGMMergerMergeLoopers_comp {
137-
GPUd() bool operator()(const MergeLooperParam& a, const MergeLooperParam& b)
138-
{
139-
return GPUCA_DETERMINISTIC_CODE(CAMath::Abs(a.refz) != CAMath::Abs(b.refz) ? CAMath::Abs(a.refz) < CAMath::Abs(b.refz) : a.id < b.id, CAMath::Abs(a.refz) < CAMath::Abs(b.refz));
140-
}
141-
};
142-
143-
} // namespace o2::gpu::internal
66+
#include "GPUTPCGMMergerSortComp.h"
14467

14568
using namespace o2::gpu::internal;
14669

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright 2019-2025 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
/// \file GPUTPCGMMergerSortComp.h
13+
/// \brief Orderings of the merger's sorts, for the kernels and for the backends that run these sorts themselves
14+
15+
#ifndef GPUTPCGMMERGERSORTCOMP_H
16+
#define GPUTPCGMMERGERSORTCOMP_H
17+
18+
#include "GPUCommonDef.h"
19+
#include "GPUCommonMath.h"
20+
#include "GPUTPCGMMergedTrack.h"
21+
#include "GPUTPCGMMergerTypes.h"
22+
#include "GPUTPCGMMerger.h"
23+
24+
namespace o2::gpu::internal
25+
{
26+
struct MergeLooperParam {
27+
float refz;
28+
float x;
29+
float y;
30+
uint32_t id;
31+
};
32+
33+
struct MergeBorderTracks_compMax {
34+
GPUd() bool operator()(const gputpcgmmergertypes::GPUTPCGMBorderRange& a, const gputpcgmmergertypes::GPUTPCGMBorderRange& b)
35+
{
36+
return GPUCA_DETERMINISTIC_CODE((a.fMax != b.fMax) ? (a.fMax < b.fMax) : (a.fId < b.fId), a.fMax < b.fMax);
37+
}
38+
};
39+
struct MergeBorderTracks_compMin {
40+
GPUd() bool operator()(const gputpcgmmergertypes::GPUTPCGMBorderRange& a, const gputpcgmmergertypes::GPUTPCGMBorderRange& b)
41+
{
42+
return GPUCA_DETERMINISTIC_CODE((a.fMin != b.fMin) ? (a.fMin < b.fMin) : (a.fId < b.fId), a.fMin < b.fMin);
43+
}
44+
};
45+
46+
struct GPUTPCGMMergerSortTracks_comp {
47+
const GPUTPCGMMergedTrack* const mCmp;
48+
GPUhd() GPUTPCGMMergerSortTracks_comp(GPUTPCGMMergedTrack* cmp) : mCmp(cmp) {}
49+
GPUd() bool operator()(const int32_t aa, const int32_t bb)
50+
{
51+
const GPUTPCGMMergedTrack& GPUrestrict() a = mCmp[aa];
52+
const GPUTPCGMMergedTrack& GPUrestrict() b = mCmp[bb];
53+
if (a.OK() != b.OK()) {
54+
return a.OK();
55+
}
56+
if (a.CCE() != b.CCE()) {
57+
return a.CCE() > b.CCE();
58+
}
59+
GPUCA_DETERMINISTIC_CODE( // clang-format off
60+
if (a.NClusters() != b.NClusters()) {
61+
return a.NClusters() > b.NClusters();
62+
} if (CAMath::Abs(a.GetParam().GetQPt()) != CAMath::Abs(b.GetParam().GetQPt())) {
63+
return CAMath::Abs(a.GetParam().GetQPt()) > CAMath::Abs(b.GetParam().GetQPt());
64+
} if (a.GetParam().GetY() != b.GetParam().GetY()) {
65+
return a.GetParam().GetY() > b.GetParam().GetY();
66+
}
67+
return aa > bb;
68+
, // !GPUCA_DETERMINISTIC_CODE
69+
return a.NClusters() > b.NClusters();
70+
) // clang-format on
71+
}
72+
};
73+
74+
struct GPUTPCGMMergerSortTracksQPt_comp {
75+
const GPUTPCGMMergedTrack* const mCmp;
76+
GPUhd() GPUTPCGMMergerSortTracksQPt_comp(GPUTPCGMMergedTrack* cmp) : mCmp(cmp) {}
77+
GPUd() bool operator()(const int32_t aa, const int32_t bb)
78+
{
79+
const GPUTPCGMMergedTrack& GPUrestrict() a = mCmp[aa];
80+
const GPUTPCGMMergedTrack& GPUrestrict() b = mCmp[bb];
81+
GPUCA_DETERMINISTIC_CODE( // clang-format off
82+
if (CAMath::Abs(a.GetParam().GetQPt()) != CAMath::Abs(b.GetParam().GetQPt())) {
83+
return CAMath::Abs(a.GetParam().GetQPt()) > CAMath::Abs(b.GetParam().GetQPt());
84+
} if (a.GetParam().GetY() != b.GetParam().GetY()) {
85+
return a.GetParam().GetY() > b.GetParam().GetY();
86+
}
87+
return a.GetParam().GetZ() > b.GetParam().GetZ();
88+
, // !GPUCA_DETERMINISTIC_CODE
89+
return CAMath::Abs(a.GetParam().GetQPt()) > CAMath::Abs(b.GetParam().GetQPt());
90+
) // clang-format on
91+
}
92+
};
93+
94+
struct GPUTPCGMMergerMergeLoopers_comp {
95+
GPUd() bool operator()(const MergeLooperParam& a, const MergeLooperParam& b)
96+
{
97+
return GPUCA_DETERMINISTIC_CODE(CAMath::Abs(a.refz) != CAMath::Abs(b.refz) ? CAMath::Abs(a.refz) < CAMath::Abs(b.refz) : a.id < b.id, CAMath::Abs(a.refz) < CAMath::Abs(b.refz));
98+
}
99+
};
100+
101+
struct GPUTPCGMO2OutputSort_comp {
102+
GPUd() bool operator()(const GPUTPCGMMerger::tmpSort& a, const GPUTPCGMMerger::tmpSort& b)
103+
{
104+
return GPUCA_DETERMINISTIC_CODE(a.y != b.y ? a.y > b.y : a.x > b.x, a.y > b.y);
105+
}
106+
};
107+
108+
} // namespace o2::gpu::internal
109+
110+
#endif

‎GPU/GPUTracking/Merger/GPUTPCGMO2Output.cxx‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,7 @@ using namespace o2::tpc::constants;
3333

3434
GPUdi() static constexpr uint8_t getFlagsReject() { return GPUTPCGMMergedTrackHit::flagReject | GPUTPCGMMergedTrackHit::flagHighIncl; }
3535

36-
namespace o2::gpu::internal
37-
{
38-
39-
struct GPUTPCGMO2OutputSort_comp {
40-
GPUd() bool operator()(const GPUTPCGMMerger::tmpSort& a, const GPUTPCGMMerger::tmpSort& b)
41-
{
42-
return GPUCA_DETERMINISTIC_CODE(a.y != b.y ? a.y > b.y : a.x > b.x, a.y > b.y);
43-
}
44-
};
45-
46-
} // namespace o2::gpu::internal
36+
#include "GPUTPCGMMergerSortComp.h"
4737

4838
template <>
4939
GPUdii() void GPUTPCGMO2Output::Thread<GPUTPCGMO2Output::prepare>(int32_t nBlocks, int32_t nThreads, int32_t iBlock, int32_t iThread, GPUsharedref() GPUSharedMemory& smem, processorType& GPUrestrict() merger)

0 commit comments

Comments
 (0)