Skip to content

Commit ae8838e

Browse files
committed
GPU: Make TrackPar / TrackParCov compile for GPU
1 parent 1476dca commit ae8838e

21 files changed

Lines changed: 580 additions & 547 deletions

File tree

Common/MathUtils/include/MathUtils/Utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,12 @@ GPUdi() void sincos(float ang, float& s, float& c)
108108
{
109109
detail::sincos<float>(ang, s, c);
110110
}
111-
111+
#ifndef __OPENCL__
112112
GPUdi() void sincosd(double ang, double& s, double& c)
113113
{
114114
detail::sincos<double>(ang, s, c);
115115
}
116+
#endif
116117

117118
GPUdi() void rotateZ(float xL, float yL, float& xG, float& yG, float snAlp, float csAlp)
118119
{

Common/MathUtils/include/MathUtils/detail/IntervalXY.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "GPUCommonDef.h"
2020
#include "GPUCommonRtypes.h"
21+
#include "GPUCommonMath.h"
2122
#ifndef GPUCA_GPUCODE_DEVICE
2223
#include <cmath>
2324
#include <tuple>
@@ -205,7 +206,7 @@ GPUdi() void IntervalXY<T>::setEdges(T x0, T y0, T x1, T y1)
205206

206207
#ifndef GPUCA_GPUCODE_DEVICE
207208
template <typename T>
208-
GPUdi() std::tuple<T, T> IntervalXY<T>::eval(T t) const
209+
std::tuple<T, T> IntervalXY<T>::eval(T t) const
209210
{
210211
return {mX + t * mDx, mY + t * mDY};
211212
}
@@ -214,7 +215,8 @@ GPUdi() std::tuple<T, T> IntervalXY<T>::eval(T t) const
214215
template <typename T>
215216
GPUdi() void IntervalXY<T>::eval(T t, T& x, T& y) const
216217
{
217-
std::tie(x, y) = eval(t);
218+
x = mX + t * mDx;
219+
y = mY + t * mDY;
218220
}
219221

220222
template <typename T>
@@ -269,11 +271,11 @@ GPUdi() bool IntervalXY<T>::circleCrossParam(const CircleXY<T>& circle, T& t) co
269271
if (det < 0.f) {
270272
return false;
271273
}
272-
det = std::sqrt(det);
274+
det = gpu::CAMath::Sqrt(det);
273275
const T t0 = -b - det;
274276
const T t1 = -b + det;
275277
// select the one closer to [0:1] interval
276-
t = (std::fabs(t0 - 0.5f) < std::fabs(t1 - 0.5f)) ? t0 : t1;
278+
t = (gpu::CAMath::Abs(t0 - 0.5f) < gpu::CAMath::Abs(t1 - 0.5f)) ? t0 : t1;
277279
return true;
278280
}
279281

@@ -282,8 +284,9 @@ GPUdi() bool IntervalXY<T>::seenByLine(const IntervalXY<T>& other, T eps) const
282284
{
283285
T a, b, c; // find equation of the line a*x+b*y+c = 0
284286
other.getLineCoefs(a, b, c);
285-
const auto [x0, y0] = eval(-eps);
286-
const auto [x1, y1] = eval(1.f + eps);
287+
T x0, y0, x1, y1;
288+
eval(-eps, x0, y0);
289+
eval(1.f + eps, x0, y0);
287290

288291
return (a * x0 + b * y0 + c) * (a * x1 + b * y1 + c) < 0;
289292
}
@@ -296,7 +299,7 @@ GPUdi() bool IntervalXY<T>::lineCrossParam(const IntervalXY<T>& other, T& t) con
296299
const T dx = other.getX0() - mX;
297300
const T dy = other.getY0() - mY;
298301
const T det = -mDx * other.getY0() + mDY * other.getX0();
299-
if (std::fabs(det) < eps) {
302+
if (gpu::CAMath::Abs(det) < eps) {
300303
return false; // parallel
301304
}
302305
t = (-dx * other.getY0() + dy * other.getX0()) / det;

Common/MathUtils/include/MathUtils/detail/trigonometric.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,24 @@ inline void bringToPMPiGen(T& phi)
107107
phi = toPMPiGen<T>(phi);
108108
}
109109

110+
#ifdef __OPENCL__ // TODO: get rid of that stupid workaround for OpenCL template address spaces
110111
template <typename T>
111-
GPUhdi() void sincos(T ang, GPUgeneric() T& s, GPUgeneric() T& c)
112+
GPUhdi() void sincos(T ang, float& s, float& c)
113+
{
114+
return o2::gpu::GPUCommonMath::SinCos(ang, s, c);
115+
}
116+
#else
117+
template <typename T>
118+
GPUhdi() void sincos(T ang, T& s, T& c)
112119
{
113120
return o2::gpu::GPUCommonMath::SinCos(ang, s, c);
114121
}
115-
116122
template <>
117-
GPUhdi() void sincos(double ang, GPUgeneric() double& s, GPUgeneric() double& c)
123+
GPUhdi() void sincos(double ang, double& s, double& c)
118124
{
119125
return o2::gpu::GPUCommonMath::SinCosd(ang, s, c);
120126
}
127+
#endif
121128

122129
#ifndef GPUCA_GPUCODE_DEVICE
123130

DataFormats/Reconstruction/include/ReconstructionDataFormats/DCA.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
#ifndef ALICEO2_DCA_H
1212
#define ALICEO2_DCA_H
1313

14+
#include "GPUCommonDef.h"
1415
#include "GPUCommonRtypes.h"
16+
#include "GPUCommonArray.h"
1517

16-
#ifndef __OPENCL__
17-
#include <array>
18-
#endif
19-
#ifndef GPUCA_ALIGPUCODE
18+
#ifndef GPUCA_GPUCODE_DEVICE
2019
#include <iosfwd>
2120
#endif
2221

@@ -32,14 +31,14 @@ class DCA
3231
{
3332

3433
public:
35-
DCA() = default;
34+
GPUdDefault() DCA() = default;
3635

37-
DCA(float y, float z, float syy = 0.f, float syz = 0.f, float szz = 0.f)
36+
GPUd() DCA(float y, float z, float syy = 0.f, float syz = 0.f, float szz = 0.f)
3837
{
3938
set(y, z, syy, syz, szz);
4039
}
4140

42-
void set(float y, float z, float syy, float syz, float szz)
41+
GPUd() void set(float y, float z, float syy, float syz, float szz)
4342
{
4443
mY = y;
4544
mZ = z;
@@ -48,30 +47,32 @@ class DCA
4847
mCov[2] = szz;
4948
}
5049

51-
void set(float y, float z)
50+
GPUd() void set(float y, float z)
5251
{
5352
mY = y;
5453
mZ = z;
5554
}
5655

57-
auto getY() const { return mY; }
58-
auto getZ() const { return mZ; }
59-
auto getSigmaY2() const { return mCov[0]; }
60-
auto getSigmaYZ() const { return mCov[1]; }
61-
auto getSigmaZ2() const { return mCov[2]; }
62-
const auto& getCovariance() const { return mCov; }
56+
GPUd() auto getY() const { return mY; }
57+
GPUd() auto getZ() const { return mZ; }
58+
GPUd() auto getSigmaY2() const { return mCov[0]; }
59+
GPUd() auto getSigmaYZ() const { return mCov[1]; }
60+
GPUd() auto getSigmaZ2() const { return mCov[2]; }
61+
GPUd() const auto& getCovariance() const { return mCov; }
6362

6463
void print() const;
6564

6665
private:
6766
float mY = 0.f;
6867
float mZ = 0.f;
69-
std::array<float, 3> mCov; ///< s2y, syz, s2z
68+
gpu::gpustd::array<float, 3> mCov; ///< s2y, syz, s2z
7069

7170
ClassDefNV(DCA, 1);
7271
};
7372

73+
#ifndef GPUCA_GPUCODE_DEVICE
7474
std::ostream& operator<<(std::ostream& os, const DCA& d);
75+
#endif
7576

7677
} // namespace dataformats
7778
} // namespace o2

DataFormats/Reconstruction/include/ReconstructionDataFormats/PID.h

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef ALICEO2_track_PID_H_
1616
#define ALICEO2_track_PID_H_
1717

18+
#include "GPUCommonDef.h"
1819
#include "GPUCommonRtypes.h"
1920
#include "CommonConstants/PhysicsConstants.h"
2021

@@ -99,44 +100,46 @@ class PID
99100
static constexpr ID NIDsTot = pid_constants::NIDsTot; ///< total number of defined IDs
100101
static_assert(NIDsTot == LastExt + 1, "Incorrect NIDsTot, please update!");
101102

102-
PID() = default;
103-
PID(ID id) : mID(id) {}
104-
PID(const char* name);
105-
PID(const PID& src) = default;
106-
PID& operator=(const PID& src) = default;
103+
GPUdDefault() PID() = default;
104+
GPUd() PID(ID id) : mID(id) {}
105+
GPUd() PID(const char* name);
106+
GPUdDefault() PID(const PID& src) = default;
107+
GPUdDefault() PID& operator=(const PID& src) = default;
107108

108-
ID getID() const { return mID; }
109-
operator ID() const { return getID(); }
109+
GPUd() ID getID() const { return mID; }
110+
GPUd() operator ID() const { return getID(); }
110111

111-
float getMass() const { return getMass(mID); }
112-
float getMass2Z() const { return getMass2Z(mID); }
113-
int getCharge() const { return getCharge(mID); }
112+
GPUd() float getMass() const { return getMass(mID); }
113+
GPUd() float getMass2Z() const { return getMass2Z(mID); }
114+
GPUd() int getCharge() const { return getCharge(mID); }
114115

115-
static float getMass(ID id) { return pid_constants::sMasses[id]; }
116-
static float getMass2(ID id) { return pid_constants::sMasses2[id]; }
117-
static float getMass2Z(ID id) { return pid_constants::sMasses2Z[id]; }
118-
static int getCharge(ID id) { return pid_constants::sCharges[id]; }
116+
GPUd() static float getMass(ID id) { return pid_constants::sMasses[id]; }
117+
GPUd() static float getMass2(ID id) { return pid_constants::sMasses2[id]; }
118+
GPUd() static float getMass2Z(ID id) { return pid_constants::sMasses2Z[id]; }
119+
GPUd() static int getCharge(ID id) { return pid_constants::sCharges[id]; }
119120
#ifndef GPUCA_GPUCODE_DEVICE
120-
const char* getName() const
121+
GPUd() const char* getName() const
121122
{
122123
return getName(mID);
123124
}
124-
static const char* getName(ID id) { return pid_constants::sNames[id]; }
125+
GPUd() static const char* getName(ID id) { return pid_constants::sNames[id]; }
125126
#endif
126127

127128
private:
128129
ID mID = Pion;
129130

130131
// are 2 strings equal ? (trick from Giulio)
131-
inline static constexpr bool sameStr(char const* x, char const* y)
132+
GPUdi() static constexpr bool sameStr(char const* x, char const* y)
132133
{
133134
return !*x && !*y ? true : /* default */ (*x == *y && sameStr(x + 1, y + 1));
134135
}
135136

136-
inline static constexpr ID nameToID(char const* name, ID id)
137+
#ifndef GPUCA_GPUCODE_DEVICE
138+
GPUdi() static constexpr ID nameToID(char const* name, ID id)
137139
{
138-
return id > LastExt ? id : sameStr(name, sNames[id]) ? id : nameToID(name, id + 1);
140+
return id > LastExt ? id : sameStr(name, pid_constants::sNames[id]) ? id : nameToID(name, id + 1);
139141
}
142+
#endif
140143

141144
ClassDefNV(PID, 2);
142145
};

0 commit comments

Comments
 (0)