Skip to content

Commit 9f4b216

Browse files
Avoid copy-paste code
1 parent 3ecb319 commit 9f4b216

7 files changed

Lines changed: 79 additions & 78 deletions

File tree

GPU/Common/MemLayout.h

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,52 @@ struct wrapper<S, F, Flag::soa> : public S<F> {
9797
template <template <template <class> class> class S, template <class> class F>
9898
using SoA = wrapper<S, F, Flag::soa>;
9999

100+
namespace type_traits {
101+
102+
template<bool B, class T = void>
103+
struct enable_if {};
104+
105+
template<class T>
106+
struct enable_if<true, T> { typedef T type; };
107+
108+
template< bool B, class T = void >
109+
using enable_if_t = typename enable_if<B, T>::type;
110+
111+
struct false_type {
112+
static constexpr bool value = false;
113+
constexpr operator bool() const noexcept { return value; }
114+
};
115+
116+
struct true_type {
117+
static constexpr bool value = true;
118+
constexpr operator bool() const noexcept { return value; }
119+
};
120+
121+
template<class T, class U>
122+
struct is_same : false_type {};
123+
124+
template<class T>
125+
struct is_same<T, T> : true_type {};
126+
127+
} // namespace type_traits
128+
129+
template<class T_left, class T_right>
130+
using enable_if_equal = type_traits::enable_if_t<type_traits::is_same<T_left, T_right>::value>;
131+
132+
template<class T_left, class T_right>
133+
using disable_if_equal = type_traits::enable_if_t<!type_traits::is_same<T_left, T_right>::value>;
134+
135+
#if __cplusplus >= 202002L
136+
template<template <class> class F_left, template <class> class F_right>
137+
concept is_same = type_traits::is_same<F_left<int>, F_right<int>>::value;
138+
template<template <class> class F>
139+
concept is_value = is_same<F, value>;
140+
template<template <class> class F>
141+
concept is_reference = is_same<F, reference>;
142+
template<template <class> class F>
143+
concept is_const_reference = is_same<F, const_reference>;
144+
#endif
145+
100146
} // namespace MemLayout
101147

102-
#endif // MEMLAYOUT_H
148+
#endif // MEMLAYOUT_H

GPU/GPUTracking/DataTypes/GPUDataTypes.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <cstddef>
2525
#endif
2626
#include "GPUTRDDef.h"
27-
#include "GPUTPCDef.h"
2827
#include "MemLayout.h"
2928

3029
struct AliHLTTPCClusterMCLabel;
@@ -227,7 +226,7 @@ struct GPUTrackingInOutPointers {
227226
const AliHLTTPCRawCluster* rawClusters[NSECTORS] = {nullptr};
228227
uint32_t nRawClusters[NSECTORS] = {0};
229228
const o2::tpc::ClusterNativeAccess* clustersNative = nullptr;
230-
const GPUTPCTrackSkeleton<MemLayout::value>* sectorTracks[NSECTORS] = {nullptr}; // GPUTPCTrack
229+
const GPUTPCTrackSkeleton<MemLayout::value>* sectorTracks[NSECTORS] = {nullptr};
231230
uint32_t nSectorTracks[NSECTORS] = {0};
232231
const GPUTPCHitId* sectorClusters[NSECTORS] = {nullptr};
233232
uint32_t nSectorClusters[NSECTORS] = {0};

GPU/GPUTracking/SectorTracker/GPUTPCBaseTrackParam.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,32 @@ namespace o2::gpu
3131
template <template <class> class F>
3232
struct GPUTPCBaseTrackParamSkeleton {
3333
MEMLAYOUT_MEMBERFUNCTIONS(GPUTPCBaseTrackParamSkeleton, mX, mC, mZOffset, mP)
34-
34+
35+
GPUhd() void ElementwiseAssignment(GPUTPCBaseTrackParamSkeleton<MemLayout::const_reference> v) {
36+
mX = v.mX;
37+
mC[0] = v.mC[0];
38+
mC[1] = v.mC[1];
39+
mC[2] = v.mC[2];
40+
mC[3] = v.mC[3];
41+
mC[4] = v.mC[4];
42+
mC[5] = v.mC[5];
43+
mC[6] = v.mC[6];
44+
mC[7] = v.mC[7];
45+
mC[8] = v.mC[8];
46+
mC[9] = v.mC[9];
47+
mC[10] = v.mC[10];
48+
mC[11] = v.mC[11];
49+
mC[12] = v.mC[12];
50+
mC[13] = v.mC[13];
51+
mC[14] = v.mC[14];
52+
mZOffset = v.mZOffset;
53+
mP[0] = v.mP[0];
54+
mP[1] = v.mP[1];
55+
mP[2] = v.mP[2];
56+
mP[3] = v.mP[3];
57+
mP[4] = v.mP[4];
58+
}
59+
3560
GPUd() float X() const { return mX; }
3661
GPUd() float Y() const { return mP[0]; }
3762
GPUd() float Z() const { return mP[1]; }

GPU/GPUTracking/SectorTracker/GPUTPCTrack.h

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,7 @@ class GPUTPCTrackSkeleton
4848
GPUhd() void SetNHits(int32_t v) { mNHits = v; }
4949
GPUhd() void SetLocalTrackId(int32_t v) { mLocalTrackId = v; }
5050
GPUhd() void SetFirstHitID(int32_t v) { mFirstHitID = v; }
51-
GPUhd() void SetParam(GPUTPCBaseTrackParamSkeleton<MemLayout::const_reference> v) {
52-
mParam.mX = v.mX;
53-
mParam.mC[0] = v.mC[0];
54-
mParam.mC[1] = v.mC[1];
55-
mParam.mC[2] = v.mC[2];
56-
mParam.mC[3] = v.mC[3];
57-
mParam.mC[4] = v.mC[4];
58-
mParam.mC[5] = v.mC[5];
59-
mParam.mC[6] = v.mC[6];
60-
mParam.mC[7] = v.mC[7];
61-
mParam.mC[8] = v.mC[8];
62-
mParam.mC[9] = v.mC[9];
63-
mParam.mC[10] = v.mC[10];
64-
mParam.mC[11] = v.mC[11];
65-
mParam.mC[12] = v.mC[12];
66-
mParam.mC[13] = v.mC[13];
67-
mParam.mC[14] = v.mC[14];
68-
mParam.mZOffset = v.mZOffset;
69-
mParam.mP[0] = v.mP[0];
70-
mParam.mP[1] = v.mP[1];
71-
mParam.mP[2] = v.mP[2];
72-
mParam.mP[3] = v.mP[3];
73-
mParam.mP[4] = v.mP[4];
74-
}
51+
GPUhd() void SetParam(GPUTPCBaseTrackParamSkeleton<MemLayout::const_reference> v) { mParam.ElementwiseAssignment(v); }
7552

7653
private:
7754
F<int32_t> mFirstHitID; // index of the first track cell in the track->cell pointer array

GPU/GPUTracking/SectorTracker/GPUTPCTrackLinearisation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class GPUTPCTrackLinearisation
4040
GPUTPCTrackLinearisation() : mSinPhi(0), mCosPhi(1), mDzDs(0), mQPt(0) {}
4141
GPUTPCTrackLinearisation(float SinPhi1, float CosPhi1, float DzDs1, float QPt1) : mSinPhi(SinPhi1), mCosPhi(CosPhi1), mDzDs(DzDs1), mQPt(QPt1) {}
4242

43-
GPUd() GPUTPCTrackLinearisation(GPUTPCTrackParamSkeleton<MemLayout::const_reference> t);
43+
GPUd() GPUTPCTrackLinearisation(GPUTPCTrackParamSkeleton<MemLayout::const_reference_restrict> t);
4444

4545
GPUd() void Set(float SinPhi1, float CosPhi1, float DzDs1, float QPt1);
4646

@@ -66,7 +66,7 @@ class GPUTPCTrackLinearisation
6666
float mQPt; // QPt
6767
};
6868

69-
GPUdi() GPUTPCTrackLinearisation::GPUTPCTrackLinearisation(GPUTPCTrackParamSkeleton<MemLayout::const_reference> t) : mSinPhi(t.SinPhi()), mCosPhi(0), mDzDs(t.DzDs()), mQPt(t.QPt())
69+
GPUdi() GPUTPCTrackLinearisation::GPUTPCTrackLinearisation(GPUTPCTrackParamSkeleton<MemLayout::const_reference_restrict> t) : mSinPhi(t.SinPhi()), mCosPhi(0), mDzDs(t.DzDs()), mQPt(t.QPt())
7070
{
7171
if (mSinPhi > GPUCA_MAX_SIN_PHI) {
7272
mSinPhi = GPUCA_MAX_SIN_PHI;

GPU/GPUTracking/SectorTracker/GPUTPCTrackParam.h

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -159,30 +159,7 @@ class GPUTPCTrackParamSkeleton
159159
};
160160

161161
template <template <class> class F>
162-
GPUd() void GPUTPCTrackParamSkeleton<F>::SetParam(GPUTPCBaseTrackParamSkeleton<MemLayout::const_reference> v) {
163-
mParam.mX = v.mX;
164-
mParam.mC[0] = v.mC[0];
165-
mParam.mC[1] = v.mC[1];
166-
mParam.mC[2] = v.mC[2];
167-
mParam.mC[3] = v.mC[3];
168-
mParam.mC[4] = v.mC[4];
169-
mParam.mC[5] = v.mC[5];
170-
mParam.mC[6] = v.mC[6];
171-
mParam.mC[7] = v.mC[7];
172-
mParam.mC[8] = v.mC[8];
173-
mParam.mC[9] = v.mC[9];
174-
mParam.mC[10] = v.mC[10];
175-
mParam.mC[11] = v.mC[11];
176-
mParam.mC[12] = v.mC[12];
177-
mParam.mC[13] = v.mC[13];
178-
mParam.mC[14] = v.mC[14];
179-
mParam.mZOffset = v.mZOffset;
180-
mParam.mP[0] = v.mP[0];
181-
mParam.mP[1] = v.mP[1];
182-
mParam.mP[2] = v.mP[2];
183-
mParam.mP[3] = v.mP[3];
184-
mParam.mP[4] = v.mP[4];
185-
}
162+
GPUd() void GPUTPCTrackParamSkeleton<F>::SetParam(GPUTPCBaseTrackParamSkeleton<MemLayout::const_reference> v) { mParam.ElementwiseAssignment(v); }
186163

187164
template <template <class> class F>
188165
GPUd() void GPUTPCTrackParamSkeleton<F>::InitParam()

GPU/GPUTracking/SectorTracker/GPUTPCTracklet.h

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,7 @@ class GPUTPCTrackletSkeleton
4545
GPUhd() void SetFirstRow(int32_t v) { mFirstRow = v; }
4646
GPUhd() void SetLastRow(int32_t v) { mLastRow = v; }
4747
GPUhd() void SetFirstHit(uint32_t v) { mFirstHit = v; }
48-
GPUhd() void SetParam(GPUTPCBaseTrackParamSkeleton<MemLayout::const_reference> v) {
49-
mParam.mX = v.mX;
50-
mParam.mC[0] = v.mC[0];
51-
mParam.mC[1] = v.mC[1];
52-
mParam.mC[2] = v.mC[2];
53-
mParam.mC[3] = v.mC[3];
54-
mParam.mC[4] = v.mC[4];
55-
mParam.mC[5] = v.mC[5];
56-
mParam.mC[6] = v.mC[6];
57-
mParam.mC[7] = v.mC[7];
58-
mParam.mC[8] = v.mC[8];
59-
mParam.mC[9] = v.mC[9];
60-
mParam.mC[10] = v.mC[10];
61-
mParam.mC[11] = v.mC[11];
62-
mParam.mC[12] = v.mC[12];
63-
mParam.mC[13] = v.mC[13];
64-
mParam.mC[14] = v.mC[14];
65-
mParam.mZOffset = v.mZOffset;
66-
mParam.mP[0] = v.mP[0];
67-
mParam.mP[1] = v.mP[1];
68-
mParam.mP[2] = v.mP[2];
69-
mParam.mP[3] = v.mP[3];
70-
mParam.mP[4] = v.mP[4];
71-
}
48+
GPUhd() void SetParam(GPUTPCBaseTrackParamSkeleton<MemLayout::const_reference> v) { mParam.ElementwiseAssignment(v); }
7249
GPUhd() void SetHitWeight(const int32_t w) { mHitWeight = w; }
7350

7451
// private:

0 commit comments

Comments
 (0)