Skip to content

Commit b7c157b

Browse files
committed
GPU: let the constant-address-space constants be built on Metal
A constructor's implicit `this` is generic in MSL 4.1, and a generic pointer does not reach the constant address space, so a class-type constant at program scope could not be constructed at all: gpustd::bitset for the DetID and GlobalTrackID masks, CfChargePos for INVALID_CHARGE_POS. MSL lets a member function be qualified with the address space of its `this`, so each of the two constructors gains a constant-qualified overload next to the existing one; for bitset that sits next to the __constant copy constructor OpenCL already needs for the same reason. Reading those constants back needs nothing further, with one exception: sTrackSources is derived with operator| from the constant sMasks and then indexed by isTrackSource. Rather than give bitset constant-qualified accessors as well, that pair is left out of device code on Metal exactly as it already is on OpenCL; its only caller is on the host.
1 parent 45693c5 commit b7c157b

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎DataFormats/Reconstruction/include/ReconstructionDataFormats/GlobalTrackID.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ GPUconstexpr() GlobalTrackID::mask_t sMasks[GlobalTrackID::NSources] = ///< dete
165165
GlobalTrackID::mask_t(math_utils::bit2Mask(GlobalTrackID::MCHMID)) // Temporary ordering
166166
};
167167

168-
#ifndef __OPENCL__
168+
#if !defined(__OPENCL__) && !defined(__METAL__)
169169
GPUconstexpr() GlobalTrackID::mask_t sTrackSources =
170170
sMasks[GlobalTrackID::ITS] | sMasks[GlobalTrackID::TPC] | sMasks[GlobalTrackID::MFT] | sMasks[GlobalTrackID::MCH] | sMasks[GlobalTrackID::ITSTPC] | sMasks[GlobalTrackID::TPCTOF] |
171171
sMasks[GlobalTrackID::TPCTRD] | sMasks[GlobalTrackID::MFTMCH] | sMasks[GlobalTrackID::ITSTPCTRD] | sMasks[GlobalTrackID::ITSTPCTOF] | sMasks[GlobalTrackID::TPCTRDTOF] |
@@ -177,7 +177,7 @@ GPUconstexpr() GlobalTrackID::mask_t sTrackSources =
177177
GPUdi() constexpr GlobalTrackID::DetID::mask_t GlobalTrackID::getSourceDetectorsMask(int i) { return globaltrackid_internal::SourceDetectorsMasks[i]; }
178178
GPUdi() constexpr GlobalTrackID::mask_t GlobalTrackID::getSourceMask(int s) { return globaltrackid_internal::sMasks[s]; }
179179

180-
#ifndef __OPENCL__
180+
#if !defined(__OPENCL__) && !defined(__METAL__)
181181
GPUdi() bool GlobalTrackID::isTrackSource(int s)
182182
{
183183
return globaltrackid_internal::sTrackSources[s];

‎GPU/GPUTracking/TPCClusterFinder/CfChargePos.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ struct CfChargePos {
3434
: gpad(tpcGlobalPadIdx(row, pad)), timePadded(t + GPUCF_PADDING_TIME)
3535
{
3636
}
37+
#ifdef __METAL__
38+
constexpr GPUhdi() CfChargePos(tpccf::Row row, tpccf::Pad pad, tpccf::TPCFragmentTime t) constant : gpad(tpcGlobalPadIdx(row, pad)), timePadded(t + GPUCF_PADDING_TIME) {}
39+
#endif
3740

3841
GPUdi() CfChargePos(const tpccf::GlobalPad& p, const tpccf::TPCFragmentTime& t) : gpad(p), timePadded(t) {}
3942

‎GPU/Utils/GPUCommonBitSet.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class bitset
4747
GPUdDefault() constexpr bitset(const __constant bitset&) = default;
4848
#endif // __OPENCL__
4949
GPUd() constexpr bitset(uint32_t vv) : v(vv) {};
50+
#ifdef __METAL__
51+
GPUd() constexpr bitset(uint32_t vv) constant : v(vv) {};
52+
#endif
5053
static GPUglobalconstexpr() uint32_t full_set = ((1ul << N) - 1ul);
5154

5255
GPUd() constexpr bool all() const { return (v & full_set) == full_set; }

0 commit comments

Comments
 (0)