Skip to content

Commit 5d5455e

Browse files
committed
GPU: Add gpu::gpustd::array to forward std::array on host / mimic as array on GPU
1 parent 296c38c commit 5d5455e

7 files changed

Lines changed: 71 additions & 35 deletions

File tree

DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrization.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
#include "GPUCommonDef.h"
2929
#include "GPUCommonRtypes.h"
3030
#include "GPUCommonMath.h"
31+
#include "GPUCommonArray.h"
32+
#include "GPUROOTCartesianFwd.h"
3133

3234
#ifndef __OPENCL__
3335
#include <algorithm>
34-
#include <array>
3536
#include <cfloat>
3637
#include <cmath>
3738
#include <cstring>
@@ -50,9 +51,6 @@
5051

5152
#include "ReconstructionDataFormats/TrackUtils.h"
5253

53-
//Forward declarations, since we cannot include the headers if we eventually want to use track.h on GPU
54-
#include "GPUROOTCartesianFwd.h"
55-
5654
namespace o2
5755
{
5856
template <typename T>
@@ -122,9 +120,9 @@ class TrackParametrization
122120

123121
public:
124122
using value_t = value_T;
125-
using dim2_t = std::array<value_t, 2>;
126-
using dim3_t = std::array<value_t, 3>;
127-
using params_t = std::array<value_t, kNParams>;
123+
using dim2_t = gpu::gpustd::array<value_t, 2>;
124+
using dim3_t = gpu::gpustd::array<value_t, 3>;
125+
using params_t = gpu::gpustd::array<value_t, kNParams>;
128126

129127
static_assert(std::is_floating_point_v<value_t>);
130128

@@ -188,7 +186,7 @@ class TrackParametrization
188186
math_utils::Point3D<value_t> getXYZGlo() const;
189187
void getXYZGlo(dim3_t& xyz) const;
190188
bool getPxPyPzGlo(dim3_t& pxyz) const;
191-
bool getPosDirGlo(std::array<value_t, 9>& posdirp) const;
189+
bool getPosDirGlo(gpu::gpustd::array<value_t, 9>& posdirp) const;
192190

193191
// methods for track params estimate at other point
194192
bool getYZAt(value_t xk, value_t b, value_t& y, value_t& z) const;

DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackParametrizationWithError.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ class TrackParametrizationWithError : public TrackParametrization<value_T>
3737
static_assert(std::is_floating_point_v<value_t>);
3838

3939
public:
40-
using covMat_t = std::array<value_t, kCovMatSize>;
40+
using covMat_t = gpu::gpustd::array<value_t, kCovMatSize>;
4141

4242
TrackParametrizationWithError();
43-
TrackParametrizationWithError(value_t x, value_t alpha, const params_t& par, const std::array<value_t, kCovMatSize>& cov, int charge = 1);
43+
TrackParametrizationWithError(value_t x, value_t alpha, const params_t& par, const covMat_t& cov, int charge = 1);
4444
TrackParametrizationWithError(const dim3_t& xyz, const dim3_t& pxpypz,
45-
const std::array<value_t, kLabCovMatSize>& cv, int sign, bool sectorAlpha = true);
45+
const gpu::gpustd::array<value_t, kLabCovMatSize>& cv, int sign, bool sectorAlpha = true);
4646

4747
TrackParametrizationWithError(const TrackParametrizationWithError& src) = default;
4848
TrackParametrizationWithError(TrackParametrizationWithError&& src) = default;
@@ -70,7 +70,7 @@ class TrackParametrizationWithError : public TrackParametrization<value_T>
7070
value_t getCovarElem(int i, int j) const;
7171
value_t getDiagError2(int i) const;
7272

73-
bool getCovXYZPxPyPzGlo(std::array<value_t, kLabCovMatSize>& c) const;
73+
bool getCovXYZPxPyPzGlo(gpu::gpustd::array<value_t, kLabCovMatSize>& c) const;
7474

7575
void print() const;
7676
#ifndef GPUCA_ALIGPUCODE

DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackUtils.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#define INCLUDE_RECONSTRUCTIONDATAFORMATS_TRACKUTILS_H_
1818

1919
#include "GPUCommonRtypes.h"
20+
#include "GPUCommonArray.h"
2021

2122
#ifndef __OPENCL__
22-
#include <array>
2323
#include <cmath>
2424
#endif
2525

@@ -33,13 +33,13 @@ namespace track
3333
// helper function
3434
template <typename value_T = float>
3535
value_T BetheBlochSolid(value_T bg, value_T rho = 2.33, value_T kp1 = 0.20, value_T kp2 = 3.00, value_T meanI = 173e-9,
36-
value_T meanZA = 0.49848);
36+
value_T meanZA = 0.49848);
3737
template <typename value_T = float>
38-
void g3helx3(value_T qfield, value_T step, std::array<value_T, 7>& vect);
38+
void g3helx3(value_T qfield, value_T step, gpu::gpustd::array<value_T, 7>& vect);
3939

4040
//____________________________________________________
4141
template <typename value_T>
42-
void g3helx3(value_T qfield, value_T step, std::array<value_T, 7>& vect)
42+
void g3helx3(value_T qfield, value_T step, gpu::gpustd::array<value_T, 7>& vect)
4343
{
4444
/******************************************************************
4545
* *

DataFormats/Reconstruction/src/TrackParametrization.cxx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ bool TrackParametrization<value_T>::getPxPyPzGlo(dim3_t& pxyz) const
130130

131131
//____________________________________________________
132132
template <typename value_T>
133-
bool TrackParametrization<value_T>::getPosDirGlo(std::array<value_t, 9>& posdirp) const
133+
bool TrackParametrization<value_T>::getPosDirGlo(gpu::gpustd::array<value_t, 9>& posdirp) const
134134
{
135135
// fill vector with lab x,y,z,px/p,py/p,pz/p,p,sinAlpha,cosAlpha
136136
value_t ptI = std::fabs(getQ2Pt());
@@ -229,7 +229,7 @@ bool TrackParametrization<value_T>::propagateParamTo(value_t xk, const dim3_t& b
229229
step *= std::sqrt(1.f + getTgl() * getTgl());
230230
//
231231
// get the track x,y,z,px/p,py/p,pz/p,p,sinAlpha,cosAlpha in the Global System
232-
std::array<value_t, 9> vecLab{0.f};
232+
gpu::gpustd::array<value_t, 9> vecLab{0.f};
233233
if (!getPosDirGlo(vecLab)) {
234234
return false;
235235
}
@@ -248,13 +248,13 @@ bool TrackParametrization<value_T>::propagateParamTo(value_t xk, const dim3_t& b
248248
costet = b[2] / bb;
249249
sintet = bt / bb;
250250
}
251-
std::array<value_t, 7> vect{costet * cosphi * vecLab[0] + costet * sinphi * vecLab[1] - sintet * vecLab[2],
252-
-sinphi * vecLab[0] + cosphi * vecLab[1],
253-
sintet * cosphi * vecLab[0] + sintet * sinphi * vecLab[1] + costet * vecLab[2],
254-
costet * cosphi * vecLab[3] + costet * sinphi * vecLab[4] - sintet * vecLab[5],
255-
-sinphi * vecLab[3] + cosphi * vecLab[4],
256-
sintet * cosphi * vecLab[3] + sintet * sinphi * vecLab[4] + costet * vecLab[5],
257-
vecLab[6]};
251+
gpu::gpustd::array<value_t, 7> vect{costet * cosphi * vecLab[0] + costet * sinphi * vecLab[1] - sintet * vecLab[2],
252+
-sinphi * vecLab[0] + cosphi * vecLab[1],
253+
sintet * cosphi * vecLab[0] + sintet * sinphi * vecLab[1] + costet * vecLab[2],
254+
costet * cosphi * vecLab[3] + costet * sinphi * vecLab[4] - sintet * vecLab[5],
255+
-sinphi * vecLab[3] + cosphi * vecLab[4],
256+
sintet * cosphi * vecLab[3] + sintet * sinphi * vecLab[4] + costet * vecLab[5],
257+
vecLab[6]};
258258

259259
// Do the helix step
260260
value_t q = getCharge();

DataFormats/Reconstruction/src/TrackParametrizationWithError.cxx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ bool TrackParametrizationWithError<value_T>::propagateToDCA(const o2::dataformat
262262
//______________________________________________________________
263263
template <typename value_T>
264264
TrackParametrizationWithError<value_T>::TrackParametrizationWithError(const dim3_t& xyz, const dim3_t& pxpypz,
265-
const std::array<value_t, kLabCovMatSize>& cv, int charge, bool sectorAlpha)
265+
const gpu::gpustd::array<value_t, kLabCovMatSize>& cv, int charge, bool sectorAlpha)
266266
{
267267
// construct track param and covariance from kinematics and lab errors
268268

@@ -454,7 +454,7 @@ bool TrackParametrizationWithError<value_T>::propagateTo(value_t xk, const dim3_
454454
step *= std::sqrt(1.f + this->getTgl() * this->getTgl());
455455
//
456456
// get the track x,y,z,px/p,py/p,pz/p,p,sinAlpha,cosAlpha in the Global System
457-
std::array<value_t, 9> vecLab{0.f};
457+
gpu::gpustd::array<value_t, 9> vecLab{0.f};
458458
if (!this->getPosDirGlo(vecLab)) {
459459
return false;
460460
}
@@ -521,13 +521,13 @@ bool TrackParametrizationWithError<value_T>::propagateTo(value_t xk, const dim3_
521521
costet = b[2] / bb;
522522
sintet = bt / bb;
523523
}
524-
std::array<value_t, 7> vect{costet * cosphi * vecLab[0] + costet * sinphi * vecLab[1] - sintet * vecLab[2],
525-
-sinphi * vecLab[0] + cosphi * vecLab[1],
526-
sintet * cosphi * vecLab[0] + sintet * sinphi * vecLab[1] + costet * vecLab[2],
527-
costet * cosphi * vecLab[3] + costet * sinphi * vecLab[4] - sintet * vecLab[5],
528-
-sinphi * vecLab[3] + cosphi * vecLab[4],
529-
sintet * cosphi * vecLab[3] + sintet * sinphi * vecLab[4] + costet * vecLab[5],
530-
vecLab[6]};
524+
gpu::gpustd::array<value_t, 7> vect{costet * cosphi * vecLab[0] + costet * sinphi * vecLab[1] - sintet * vecLab[2],
525+
-sinphi * vecLab[0] + cosphi * vecLab[1],
526+
sintet * cosphi * vecLab[0] + sintet * sinphi * vecLab[1] + costet * vecLab[2],
527+
costet * cosphi * vecLab[3] + costet * sinphi * vecLab[4] - sintet * vecLab[5],
528+
-sinphi * vecLab[3] + cosphi * vecLab[4],
529+
sintet * cosphi * vecLab[3] + sintet * sinphi * vecLab[4] + costet * vecLab[5],
530+
vecLab[6]};
531531

532532
// Do the helix step
533533
value_t sgn = this->getSign();
@@ -1004,7 +1004,7 @@ bool TrackParametrizationWithError<value_T>::correctForMaterial(value_t x2x0, va
10041004

10051005
//______________________________________________________________
10061006
template <typename value_T>
1007-
bool TrackParametrizationWithError<value_T>::getCovXYZPxPyPzGlo(std::array<value_t, kLabCovMatSize>& cv) const
1007+
bool TrackParametrizationWithError<value_T>::getCovXYZPxPyPzGlo(gpu::gpustd::array<value_t, kLabCovMatSize>& cv) const
10081008
{
10091009
//---------------------------------------------------------------------
10101010
// This function returns the global covariance matrix of the track params

GPU/Common/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set(HDRS_INSTALL
1818
GPUCommonLogger.h
1919
GPUCommonMath.h
2020
GPUCommonRtypes.h
21+
GPUCommonArray.h
2122
GPUCommonTransform3D.h
2223
GPUDef.h
2324
GPUDefConstantsAndSettings.h

GPU/Common/GPUCommonArray.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// \file GPUCommonArray.h
12+
/// \author David Rohr
13+
14+
#ifndef GPUCOMMONFAIRARRAY_H
15+
#define GPUCOMMONFAIRARRAY_H
16+
17+
#ifndef GPUCA_GPUCODE_DEVICE
18+
#include <array>
19+
#endif
20+
21+
#include "GPUCommonDef.h"
22+
namespace o2::gpu::gpustd
23+
{
24+
#ifdef GPUCA_GPUCODE_DEVICE
25+
template <typename T, size_t N>
26+
struct array {
27+
GPUd() T& operator[](size_t i) { return m_internal_V__[i]; }
28+
GPUd() const T& operator[](size_t i) const { return m_internal_V__[i]; }
29+
T m_internal_V__[N];
30+
};
31+
#else
32+
template <typename T, size_t N>
33+
using array = std::array<T, N>;
34+
#endif
35+
} // namespace o2::gpu::gpustd
36+
37+
#endif

0 commit comments

Comments
 (0)