Skip to content

Commit 7d75d71

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 these gains a constant-qualified overload next to the existing one, alongside the copy constructor and the OpenCL __constant one that are already there for the same reason. Only the members actually called on a constant object need it.
1 parent c8ce55e commit 7d75d71

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎GPU/GPUTracking/TPCClusterFinder/CfChargePos.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ struct CfChargePos {
3434
: gpad(tpcGlobalPadIdx(row, pad)), timePadded(t + GPUCF_PADDING_TIME)
3535
{
3636
}
37+
#ifdef __METAL__
38+
// INVALID_CHARGE_POS below lives in the constant address space, which a
39+
// generic `this` does not reach in MSL.
40+
constexpr GPUhdi() CfChargePos(tpccf::Row row, tpccf::Pad pad, tpccf::TPCFragmentTime t) constant
41+
: gpad(tpcGlobalPadIdx(row, pad)), timePadded(t + GPUCF_PADDING_TIME)
42+
{
43+
}
44+
#endif
3745

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

‎GPU/Utils/GPUCommonBitSet.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ 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+
// Objects in the constant address space are built and read through their own
52+
// overloads: a generic `this` does not reach constant memory in MSL.
53+
GPUd() constexpr bitset(uint32_t vv) constant : v(vv) {};
54+
#endif
5055
static GPUglobalconstexpr() uint32_t full_set = ((1ul << N) - 1ul);
5156

5257
GPUd() constexpr bool all() const { return (v & full_set) == full_set; }
@@ -83,6 +88,13 @@ class bitset
8388
GPUd() constexpr bool operator!=(const bitset b) const { return v != b.v; }
8489

8590
GPUd() constexpr bool operator[](uint32_t i) const { return (v >> i) & 1u; }
91+
#ifdef __METAL__
92+
GPUd() constexpr bitset operator|(const bitset b) constant { return v | b.v; }
93+
GPUd() constexpr bitset operator&(const bitset b) constant { return v & b.v; }
94+
GPUd() constexpr bool operator[](uint32_t i) constant { return (v >> i) & 1u; }
95+
GPUd() constexpr bool any() constant { return v & full_set; }
96+
GPUd() constexpr uint32_t to_ulong() constant { return v; }
97+
#endif
8698

8799
GPUd() constexpr uint32_t to_ulong() const { return v; }
88100

0 commit comments

Comments
 (0)