|
| 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 |
0 commit comments