Skip to content

Commit 9d75196

Browse files
committed
GPU: Some work towards making the o2 propagator work on GPU
1 parent fcffd99 commit 9d75196

File tree

4 files changed

+100
-85
lines changed

4 files changed

+100
-85
lines changed

DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackLTIntegral.h

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
#ifndef ALICEO2_TRACK_LTINTEGRAL_H_
1616
#define ALICEO2_TRACK_LTINTEGRAL_H_
1717

18-
#include <Rtypes.h>
18+
#include "GPUCommonRtypes.h"
19+
#include "GPUCommonDef.h"
1920
#include "ReconstructionDataFormats/PID.h"
2021
#include "ReconstructionDataFormats/Track.h"
2122

@@ -27,17 +28,17 @@ namespace track
2728
class TrackLTIntegral
2829
{
2930
public:
30-
TrackLTIntegral() = default;
31-
TrackLTIntegral(const TrackLTIntegral& stc) = default;
32-
~TrackLTIntegral() = default;
31+
GPUdDefault() TrackLTIntegral() = default;
32+
GPUdDefault() TrackLTIntegral(const TrackLTIntegral& stc) = default;
33+
GPUdDefault() ~TrackLTIntegral() = default;
3334

34-
static constexpr int getNTOFs() { return o2::track::PID::NIDs; }
35+
GPUd() static constexpr int getNTOFs() { return o2::track::PID::NIDs; }
3536

36-
float getL() const { return mL; }
37-
float getX2X0() const { return mX2X0; }
38-
float getTOF(int id) const { return mT[id]; }
37+
GPUd() float getL() const { return mL; }
38+
GPUd() float getX2X0() const { return mX2X0; }
39+
GPUd() float getTOF(int id) const { return mT[id]; }
3940

40-
void clear()
41+
GPUd() void clear()
4142
{
4243
mL = 0.f;
4344
mX2X0 = 0.f;
@@ -46,14 +47,14 @@ class TrackLTIntegral
4647
}
4748
}
4849

49-
void addStep(float dL, const TrackPar& track);
50-
void addX2X0(float d) { mX2X0 += d; }
50+
GPUd() void addStep(float dL, const TrackPar& track);
51+
GPUd() void addX2X0(float d) { mX2X0 += d; }
5152

52-
void setL(float l) { mL = l; }
53-
void setX2X0(float x) { mX2X0 = x; }
54-
void setTOF(float t, int id) { mT[id] = t; }
53+
GPUd() void setL(float l) { mL = l; }
54+
GPUd() void setX2X0(float x) { mX2X0 = x; }
55+
GPUd() void setTOF(float t, int id) { mT[id] = t; }
5556

56-
void print() const;
57+
GPUd() void print() const;
5758

5859
private:
5960
float mL = 0.; // length in cm

DataFormats/Reconstruction/src/TrackLTIntegral.cxx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,27 @@
1010

1111
#include "ReconstructionDataFormats/TrackLTIntegral.h"
1212
#include "CommonConstants/PhysicsConstants.h"
13+
14+
#ifndef GPUCA_GPUCODE_DEVICE
1315
#include <cmath>
16+
#endif
1417

1518
using namespace o2::track;
1619

1720
//_____________________________________________________
18-
void TrackLTIntegral::print() const
21+
GPUd() void TrackLTIntegral::print() const
1922
{
23+
#ifndef GPUCA_GPUCODE_DEVICE
2024
printf("L(cm): %6.2f, X2X0: %5.3f TOF(ps): ", getL(), getX2X0());
2125
for (int i = 0; i < getNTOFs(); i++) {
2226
printf(" %7.1f |", getTOF(i));
2327
}
2428
printf("\n");
29+
#endif
2530
}
2631

2732
//_____________________________________________________
28-
void TrackLTIntegral::addStep(float dL, const TrackPar& track)
33+
GPUd() void TrackLTIntegral::addStep(float dL, const TrackPar& track)
2934
{
3035
///< add step in cm to integrals
3136
mL += dL;

Detectors/Base/include/DetectorsBase/Propagator.h

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@
1515
#ifndef ALICEO2_BASE_PROPAGATOR_
1616
#define ALICEO2_BASE_PROPAGATOR_
1717

18-
#include <string>
18+
#include "GPUCommonRtypes.h"
19+
#include "GPUCommonArray.h"
1920
#include "CommonConstants/PhysicsConstants.h"
2021
#include "ReconstructionDataFormats/Track.h"
2122
#include "ReconstructionDataFormats/DCA.h"
2223
#include "ReconstructionDataFormats/TrackLTIntegral.h"
2324
#include "DetectorsBase/MatLayerCylSet.h"
2425

26+
#ifndef GPUCA_GPUCODE
27+
#include <string>
28+
#endif
29+
2530
namespace o2
2631
{
2732
namespace parameters
@@ -50,70 +55,74 @@ class Propagator
5055
USEMatCorrLUT
5156
}; // flag to use LUT for material queries (user must provide a pointer
5257

53-
static Propagator* Instance()
54-
{
55-
static Propagator instance;
56-
return &instance;
57-
}
58-
5958
static constexpr float MAX_SIN_PHI = 0.85f;
6059
static constexpr float MAX_STEP = 2.0f;
6160

62-
bool PropagateToXBxByBz(o2::track::TrackParCov& track, float x,
63-
float maxSnp = MAX_SIN_PHI, float maxStep = MAX_STEP, MatCorrType matCorr = MatCorrType::USEMatCorrTGeo,
64-
o2::track::TrackLTIntegral* tofInfo = nullptr, int signCorr = 0) const;
61+
GPUd() bool PropagateToXBxByBz(o2::track::TrackParCov& track, float x,
62+
float maxSnp = MAX_SIN_PHI, float maxStep = MAX_STEP, MatCorrType matCorr = MatCorrType::USEMatCorrTGeo,
63+
o2::track::TrackLTIntegral* tofInfo = nullptr, int signCorr = 0) const;
6564

66-
bool PropagateToXBxByBz(o2::track::TrackPar& track, float x,
67-
float maxSnp = MAX_SIN_PHI, float maxStep = MAX_STEP, MatCorrType matCorr = MatCorrType::USEMatCorrTGeo,
68-
o2::track::TrackLTIntegral* tofInfo = nullptr, int signCorr = 0) const;
65+
GPUd() bool PropagateToXBxByBz(o2::track::TrackPar& track, float x,
66+
float maxSnp = MAX_SIN_PHI, float maxStep = MAX_STEP, MatCorrType matCorr = MatCorrType::USEMatCorrTGeo,
67+
o2::track::TrackLTIntegral* tofInfo = nullptr, int signCorr = 0) const;
6968

70-
bool propagateToX(o2::track::TrackParCov& track, float x, float bZ,
71-
float maxSnp = MAX_SIN_PHI, float maxStep = MAX_STEP, MatCorrType matCorr = MatCorrType::USEMatCorrTGeo,
72-
o2::track::TrackLTIntegral* tofInfo = nullptr, int signCorr = 0) const;
69+
GPUd() bool propagateToX(o2::track::TrackParCov& track, float x, float bZ,
70+
float maxSnp = MAX_SIN_PHI, float maxStep = MAX_STEP, MatCorrType matCorr = MatCorrType::USEMatCorrTGeo,
71+
o2::track::TrackLTIntegral* tofInfo = nullptr, int signCorr = 0) const;
7372

74-
bool propagateToX(o2::track::TrackPar& track, float x, float bZ,
75-
float maxSnp = MAX_SIN_PHI, float maxStep = MAX_STEP, MatCorrType matCorr = MatCorrType::USEMatCorrTGeo,
76-
o2::track::TrackLTIntegral* tofInfo = nullptr, int signCorr = 0) const;
73+
GPUd() bool propagateToX(o2::track::TrackPar& track, float x, float bZ,
74+
float maxSnp = MAX_SIN_PHI, float maxStep = MAX_STEP, MatCorrType matCorr = MatCorrType::USEMatCorrTGeo,
75+
o2::track::TrackLTIntegral* tofInfo = nullptr, int signCorr = 0) const;
7776

78-
bool propagateToDCA(const o2::dataformats::VertexBase& vtx, o2::track::TrackParCov& track, float bZ,
79-
float maxStep = MAX_STEP, MatCorrType matCorr = MatCorrType::USEMatCorrTGeo,
80-
o2::dataformats::DCA* dcaInfo = nullptr, o2::track::TrackLTIntegral* tofInfo = nullptr,
81-
int signCorr = 0, float maxD = 999.f) const;
77+
GPUd() bool propagateToDCA(const o2::dataformats::VertexBase& vtx, o2::track::TrackParCov& track, float bZ,
78+
float maxStep = MAX_STEP, MatCorrType matCorr = MatCorrType::USEMatCorrTGeo,
79+
o2::dataformats::DCA* dcaInfo = nullptr, o2::track::TrackLTIntegral* tofInfo = nullptr,
80+
int signCorr = 0, float maxD = 999.f) const;
8281

83-
bool propagateToDCABxByBz(const o2::dataformats::VertexBase& vtx, o2::track::TrackParCov& track,
84-
float maxStep = MAX_STEP, MatCorrType matCorr = MatCorrType::USEMatCorrTGeo,
85-
o2::dataformats::DCA* dcaInfo = nullptr, o2::track::TrackLTIntegral* tofInfo = nullptr,
86-
int signCorr = 0, float maxD = 999.f) const;
82+
GPUd() bool propagateToDCABxByBz(const o2::dataformats::VertexBase& vtx, o2::track::TrackParCov& track,
83+
float maxStep = MAX_STEP, MatCorrType matCorr = MatCorrType::USEMatCorrTGeo,
84+
o2::dataformats::DCA* dcaInfo = nullptr, o2::track::TrackLTIntegral* tofInfo = nullptr,
85+
int signCorr = 0, float maxD = 999.f) const;
8786

88-
bool propagateToDCA(const o2::math_utils::Point3D<float>& vtx, o2::track::TrackPar& track, float bZ,
89-
float maxStep = MAX_STEP, MatCorrType matCorr = MatCorrType::USEMatCorrTGeo,
90-
std::array<float, 2>* dca = nullptr, o2::track::TrackLTIntegral* tofInfo = nullptr,
91-
int signCorr = 0, float maxD = 999.f) const;
87+
GPUd() bool propagateToDCA(const o2::math_utils::Point3D<float>& vtx, o2::track::TrackPar& track, float bZ,
88+
float maxStep = MAX_STEP, MatCorrType matCorr = MatCorrType::USEMatCorrTGeo,
89+
gpu::gpustd::array<float, 2>* dca = nullptr, o2::track::TrackLTIntegral* tofInfo = nullptr,
90+
int signCorr = 0, float maxD = 999.f) const;
9291

93-
bool propagateToDCABxByBz(const o2::math_utils::Point3D<float>& vtx, o2::track::TrackPar& track,
94-
float maxStep = MAX_STEP, MatCorrType matCorr = MatCorrType::USEMatCorrTGeo,
95-
std::array<float, 2>* dca = nullptr, o2::track::TrackLTIntegral* tofInfo = nullptr,
96-
int signCorr = 0, float maxD = 999.f) const;
92+
GPUd() bool propagateToDCABxByBz(const o2::math_utils::Point3D<float>& vtx, o2::track::TrackPar& track,
93+
float maxStep = MAX_STEP, MatCorrType matCorr = MatCorrType::USEMatCorrTGeo,
94+
gpu::gpustd::array<float, 2>* dca = nullptr, o2::track::TrackLTIntegral* tofInfo = nullptr,
95+
int signCorr = 0, float maxD = 999.f) const;
9796

9897
Propagator(Propagator const&) = delete;
9998
Propagator(Propagator&&) = delete;
10099
Propagator& operator=(Propagator const&) = delete;
101100
Propagator& operator=(Propagator&&) = delete;
102101

103102
// Bz at the origin
104-
float getNominalBz() const { return mBz; }
103+
GPUd() float getNominalBz() const { return mBz; }
105104

106-
void setMatLUT(const o2::base::MatLayerCylSet* lut) { mMatLUT = lut; }
107-
const o2::base::MatLayerCylSet* getMatLUT() const { return mMatLUT; }
105+
GPUd() void setMatLUT(const o2::base::MatLayerCylSet* lut) { mMatLUT = lut; }
106+
GPUd() const o2::base::MatLayerCylSet* getMatLUT() const { return mMatLUT; }
107+
108+
#ifndef GPUCA_GPUCODE
109+
static Propagator* Instance()
110+
{
111+
static Propagator instance;
112+
return &instance;
113+
}
108114

109115
static int initFieldFromGRP(const o2::parameters::GRPObject* grp, bool verbose = false);
110116
static int initFieldFromGRP(const std::string grpFileName, std::string grpName = "GRP", bool verbose = false);
117+
#endif
111118

112119
private:
120+
#ifndef GPUCA_GPUCODE
113121
Propagator();
114122
~Propagator() = default;
123+
#endif
115124

116-
MatBudget getMatBudget(MatCorrType corrType, const o2::math_utils::Point3D<float>& p0, const o2::math_utils::Point3D<float>& p1) const;
125+
GPUd() MatBudget getMatBudget(MatCorrType corrType, const o2::math_utils::Point3D<float>& p0, const o2::math_utils::Point3D<float>& p1) const;
117126

118127
const o2::field::MagFieldFast* mField = nullptr; ///< External fast field (barrel only for the moment)
119128
float mBz = 0; // nominal field

Detectors/Base/src/Propagator.cxx

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ int Propagator::initFieldFromGRP(const o2::parameters::GRPObject* grp, bool verb
9696
#endif
9797

9898
//_______________________________________________________________________
99-
bool Propagator::PropagateToXBxByBz(o2::track::TrackParCov& track, float xToGo, float maxSnp, float maxStep,
100-
Propagator::MatCorrType matCorr, o2::track::TrackLTIntegral* tofInfo, int signCorr) const
99+
GPUd() bool Propagator::PropagateToXBxByBz(o2::track::TrackParCov& track, float xToGo, float maxSnp, float maxStep,
100+
Propagator::MatCorrType matCorr, o2::track::TrackLTIntegral* tofInfo, int signCorr) const
101101
{
102102
//----------------------------------------------------------------
103103
//
@@ -117,15 +117,15 @@ bool Propagator::PropagateToXBxByBz(o2::track::TrackParCov& track, float xToGo,
117117
signCorr = -dir; // sign of eloss correction is not imposed
118118
}
119119

120-
std::array<float, 3> b;
120+
gpu::gpustd::array<float, 3> b;
121121
while (std::abs(dx) > Epsilon) {
122122
auto step = std::min(std::abs(dx), maxStep);
123123
if (dir < 0) {
124124
step = -step;
125125
}
126126
auto x = track.getX() + step;
127127
auto xyz0 = track.getXYZGlo();
128-
mField->Field(xyz0, b.data());
128+
mField->Field(xyz0, &b[0]);
129129

130130
if (!track.propagateTo(x, b)) {
131131
return false;
@@ -155,8 +155,8 @@ bool Propagator::PropagateToXBxByBz(o2::track::TrackParCov& track, float xToGo,
155155
}
156156

157157
//_______________________________________________________________________
158-
bool Propagator::PropagateToXBxByBz(o2::track::TrackPar& track, float xToGo, float maxSnp, float maxStep,
159-
Propagator::MatCorrType matCorr, o2::track::TrackLTIntegral* tofInfo, int signCorr) const
158+
GPUd() bool Propagator::PropagateToXBxByBz(o2::track::TrackPar& track, float xToGo, float maxSnp, float maxStep,
159+
Propagator::MatCorrType matCorr, o2::track::TrackLTIntegral* tofInfo, int signCorr) const
160160
{
161161
//----------------------------------------------------------------
162162
//
@@ -176,15 +176,15 @@ bool Propagator::PropagateToXBxByBz(o2::track::TrackPar& track, float xToGo, flo
176176
signCorr = -dir; // sign of eloss correction is not imposed
177177
}
178178

179-
std::array<float, 3> b;
179+
gpu::gpustd::array<float, 3> b;
180180
while (std::abs(dx) > Epsilon) {
181181
auto step = std::min(std::abs(dx), maxStep);
182182
if (dir < 0) {
183183
step = -step;
184184
}
185185
auto x = track.getX() + step;
186186
auto xyz0 = track.getXYZGlo();
187-
mField->Field(xyz0, b.data());
187+
mField->Field(xyz0, &b[0]);
188188

189189
if (!track.propagateParamTo(x, b)) {
190190
return false;
@@ -213,8 +213,8 @@ bool Propagator::PropagateToXBxByBz(o2::track::TrackPar& track, float xToGo, flo
213213
}
214214

215215
//_______________________________________________________________________
216-
bool Propagator::propagateToX(o2::track::TrackParCov& track, float xToGo, float bZ, float maxSnp, float maxStep,
217-
Propagator::MatCorrType matCorr, o2::track::TrackLTIntegral* tofInfo, int signCorr) const
216+
GPUd() bool Propagator::propagateToX(o2::track::TrackParCov& track, float xToGo, float bZ, float maxSnp, float maxStep,
217+
Propagator::MatCorrType matCorr, o2::track::TrackLTIntegral* tofInfo, int signCorr) const
218218
{
219219
//----------------------------------------------------------------
220220
//
@@ -271,8 +271,8 @@ bool Propagator::propagateToX(o2::track::TrackParCov& track, float xToGo, float
271271
}
272272

273273
//_______________________________________________________________________
274-
bool Propagator::propagateToX(o2::track::TrackPar& track, float xToGo, float bZ, float maxSnp, float maxStep,
275-
Propagator::MatCorrType matCorr, o2::track::TrackLTIntegral* tofInfo, int signCorr) const
274+
GPUd() bool Propagator::propagateToX(o2::track::TrackPar& track, float xToGo, float bZ, float maxSnp, float maxStep,
275+
Propagator::MatCorrType matCorr, o2::track::TrackLTIntegral* tofInfo, int signCorr) const
276276
{
277277
//----------------------------------------------------------------
278278
//
@@ -329,10 +329,10 @@ bool Propagator::propagateToX(o2::track::TrackPar& track, float xToGo, float bZ,
329329
}
330330

331331
//_______________________________________________________________________
332-
bool Propagator::propagateToDCA(const o2::dataformats::VertexBase& vtx, o2::track::TrackParCov& track, float bZ,
333-
float maxStep, Propagator::MatCorrType matCorr,
334-
o2::dataformats::DCA* dca, o2::track::TrackLTIntegral* tofInfo,
335-
int signCorr, float maxD) const
332+
GPUd() bool Propagator::propagateToDCA(const o2::dataformats::VertexBase& vtx, o2::track::TrackParCov& track, float bZ,
333+
float maxStep, Propagator::MatCorrType matCorr,
334+
o2::dataformats::DCA* dca, o2::track::TrackLTIntegral* tofInfo,
335+
int signCorr, float maxD) const
336336
{
337337
// propagate track to DCA to the vertex
338338
float sn, cs, alp = track.getAlpha();
@@ -374,10 +374,10 @@ bool Propagator::propagateToDCA(const o2::dataformats::VertexBase& vtx, o2::trac
374374
}
375375

376376
//_______________________________________________________________________
377-
bool Propagator::propagateToDCABxByBz(const o2::dataformats::VertexBase& vtx, o2::track::TrackParCov& track,
378-
float maxStep, Propagator::MatCorrType matCorr,
379-
o2::dataformats::DCA* dca, o2::track::TrackLTIntegral* tofInfo,
380-
int signCorr, float maxD) const
377+
GPUd() bool Propagator::propagateToDCABxByBz(const o2::dataformats::VertexBase& vtx, o2::track::TrackParCov& track,
378+
float maxStep, Propagator::MatCorrType matCorr,
379+
o2::dataformats::DCA* dca, o2::track::TrackLTIntegral* tofInfo,
380+
int signCorr, float maxD) const
381381
{
382382
// propagate track to DCA to the vertex
383383
float sn, cs, alp = track.getAlpha();
@@ -419,10 +419,10 @@ bool Propagator::propagateToDCABxByBz(const o2::dataformats::VertexBase& vtx, o2
419419
}
420420

421421
//_______________________________________________________________________
422-
bool Propagator::propagateToDCA(const math_utils::Point3D<float>& vtx, o2::track::TrackPar& track, float bZ,
423-
float maxStep, Propagator::MatCorrType matCorr,
424-
std::array<float, 2>* dca, o2::track::TrackLTIntegral* tofInfo,
425-
int signCorr, float maxD) const
422+
GPUd() bool Propagator::propagateToDCA(const math_utils::Point3D<float>& vtx, o2::track::TrackPar& track, float bZ,
423+
float maxStep, Propagator::MatCorrType matCorr,
424+
gpu::gpustd::array<float, 2>* dca, o2::track::TrackLTIntegral* tofInfo,
425+
int signCorr, float maxD) const
426426
{
427427
// propagate track to DCA to the vertex
428428
float sn, cs, alp = track.getAlpha();
@@ -463,10 +463,10 @@ bool Propagator::propagateToDCA(const math_utils::Point3D<float>& vtx, o2::track
463463
}
464464

465465
//_______________________________________________________________________
466-
bool Propagator::propagateToDCABxByBz(const math_utils::Point3D<float>& vtx, o2::track::TrackPar& track,
467-
float maxStep, Propagator::MatCorrType matCorr,
468-
std::array<float, 2>* dca, o2::track::TrackLTIntegral* tofInfo,
469-
int signCorr, float maxD) const
466+
GPUd() bool Propagator::propagateToDCABxByBz(const math_utils::Point3D<float>& vtx, o2::track::TrackPar& track,
467+
float maxStep, Propagator::MatCorrType matCorr,
468+
gpu::gpustd::array<float, 2>* dca, o2::track::TrackLTIntegral* tofInfo,
469+
int signCorr, float maxD) const
470470
{
471471
// propagate track to DCA to the vertex
472472
float sn, cs, alp = track.getAlpha();
@@ -507,7 +507,7 @@ bool Propagator::propagateToDCABxByBz(const math_utils::Point3D<float>& vtx, o2:
507507
}
508508

509509
//____________________________________________________________
510-
MatBudget Propagator::getMatBudget(Propagator::MatCorrType corrType, const math_utils::Point3D<float>& p0, const math_utils::Point3D<float>& p1) const
510+
GPUd() MatBudget Propagator::getMatBudget(Propagator::MatCorrType corrType, const math_utils::Point3D<float>& p0, const math_utils::Point3D<float>& p1) const
511511
{
512512
#ifndef GPUCA_STANDALONE
513513
if (corrType == MatCorrType::USEMatCorrTGeo) {

0 commit comments

Comments
 (0)