Skip to content

Commit 5aba39f

Browse files
committed
CommonConstants: place shared constants in the constant address space
MSL requires every variable at program scope to name an address space and diagnoses it at the declaration, so these headers broke any device translation unit that included them. GPUglobalconstexpr() expands to constexpr everywhere except Metal, where it adds constant. Preprocessed declarations are unchanged for host, CUDA, HIP and cling.
1 parent 34ddccd commit 5aba39f

2 files changed

Lines changed: 22 additions & 18 deletions

File tree

‎Common/Constants/include/CommonConstants/LHCConstants.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#ifndef ALICEO2_LHCCONSTANTS_H_
1717
#define ALICEO2_LHCCONSTANTS_H_
1818

19+
#include "GPUCommonDef.h"
20+
1921
namespace o2
2022
{
2123
namespace constants
@@ -28,17 +30,17 @@ enum BeamDirection : int { BeamA, // beamA = beam 0,
2830
NBeamDirections,
2931
InteractingBC = -1 // as used in the BunchFilling class
3032
};
31-
constexpr int LHCMaxBunches = 3564; // max N bunches
33+
GPUglobalconstexpr() int LHCMaxBunches = 3564; // max N bunches
3234
constexpr double LHCRFFreq = 400.789e6; // LHC RF frequency in Hz
3335
constexpr double LHCBunchSpacingNS = 10 * 1.e9 / LHCRFFreq; // bunch spacing in ns (10 RFbuckets)
3436
constexpr double LHCOrbitNS = LHCMaxBunches * LHCBunchSpacingNS; // orbit duration in ns
3537
constexpr double LHCRevFreq = 1.e9 / LHCOrbitNS; // revolution frequency
3638
constexpr double LHCBunchSpacingMUS = LHCBunchSpacingNS * 1e-3; // bunch spacing in \mus (10 RFbuckets)
3739
constexpr double LHCOrbitMUS = LHCOrbitNS * 1e-3; // orbit duration in \mus
38-
constexpr unsigned int MaxNOrbits = 0xffffffff;
40+
GPUglobalconstexpr() unsigned int MaxNOrbits = 0xffffffff;
3941

4042
// Offsets of A, C beam bunches at P2
41-
constexpr int BunchOffsetsP2[2] = {344, 3017};
43+
GPUglobalconstexpr() int BunchOffsetsP2[2] = {344, 3017};
4244

4345
// convert LHC bunch ID to BC for 2 beam directions
4446
constexpr int LHCBunch2P2BC(int bunch, BeamDirection dir)

‎Common/Constants/include/CommonConstants/MathConstants.h‎

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,33 @@
1616
#ifndef ALICEO2_COMMON_MATH_CONSTANTS_
1717
#define ALICEO2_COMMON_MATH_CONSTANTS_
1818

19+
#include "GPUCommonDef.h"
20+
1921
namespace o2
2022
{
2123
namespace constants
2224
{
2325
namespace math
2426
{
25-
constexpr float Almost0 = 0x1.0p-126f; // smallest non-denormal float
26-
constexpr float Epsilon = 0x0.000002p0f; // smallest float such that 1 != 1 + Epsilon
27-
constexpr float Almost1 = 1.f - 1.0e-6f;
28-
constexpr float VeryBig = 1.f / Almost0;
27+
GPUglobalconstexpr() float Almost0 = 0x1.0p-126f; // smallest non-denormal float
28+
GPUglobalconstexpr() float Epsilon = 0x0.000002p0f; // smallest float such that 1 != 1 + Epsilon
29+
GPUglobalconstexpr() float Almost1 = 1.f - 1.0e-6f;
30+
GPUglobalconstexpr() float VeryBig = 1.f / Almost0;
2931

30-
constexpr float PI = 3.14159274101257324e+00f;
31-
constexpr float TwoPI = 2.f * PI;
32-
constexpr float PIHalf = 0.5f * PI;
33-
constexpr float PIThird = PI / 3.0f;
34-
constexpr float PIQuarter = 0.25f * PI;
35-
constexpr float Rad2Deg = 180.f / PI;
36-
constexpr float Deg2Rad = PI / 180.f;
32+
GPUglobalconstexpr() float PI = 3.14159274101257324e+00f;
33+
GPUglobalconstexpr() float TwoPI = 2.f * PI;
34+
GPUglobalconstexpr() float PIHalf = 0.5f * PI;
35+
GPUglobalconstexpr() float PIThird = PI / 3.0f;
36+
GPUglobalconstexpr() float PIQuarter = 0.25f * PI;
37+
GPUglobalconstexpr() float Rad2Deg = 180.f / PI;
38+
GPUglobalconstexpr() float Deg2Rad = PI / 180.f;
3739

38-
constexpr int NSectors = 18;
39-
constexpr float SectorSpanDeg = 360. / NSectors;
40-
constexpr float SectorSpanRad = SectorSpanDeg * Deg2Rad;
40+
GPUglobalconstexpr() int NSectors = 18;
41+
GPUglobalconstexpr() float SectorSpanDeg = 360. / NSectors;
42+
GPUglobalconstexpr() float SectorSpanRad = SectorSpanDeg * Deg2Rad;
4143

4244
// conversion from B(kGaus) to curvature for 1GeV pt
43-
constexpr float B2C = -0.299792458e-3;
45+
GPUglobalconstexpr() float B2C = -0.299792458e-3;
4446
} // namespace math
4547
} // namespace constants
4648
} // namespace o2

0 commit comments

Comments
 (0)