Skip to content

Commit 99542dd

Browse files
committed
GPU: do not place anything in the Metal constant address space
The MSL generic address space covers device, threadgroup and thread but not constant, so a generic member function cannot be called on an object that lives in constant memory: 'cannot initialize object parameter of type X with an expression of type constant X'. The shared code is generic throughout, so constant memory is simply not usable on this backend. Metal therefore implies GPUCA_NO_CONSTANT_MEMORY, which already exists for the other backends and redirects GPUconstant() to GPUglobal(). GPUconstantref() has to follow it, exactly as the OpenCL block already arranges; the Metal block hardcoded 'constant' and so kept handing out constant references whatever the setting. It now falls through to the unannotated, and therefore generic, fallback. Macro expansions are unchanged for host, CUDA, HIP, OpenCL and cling. Takes the Metal translation unit from 333 errors to 235, of which the constant-versus-generic diagnostics drop from 91 to 14.
1 parent 4efc17b commit 99542dd

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎GPU/Common/GPUCommonDef.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@
5858
#define GPUCA_ALIGPUCODE // Part of GPUTracking library but not of interface
5959
#endif
6060

61-
#if (defined(__CUDACC__) && defined(GPUCA_CUDA_NO_CONSTANT_MEMORY)) || (defined(__HIPCC__) && defined(GPUCA_HIP_NO_CONSTANT_MEMORY)) || (defined(__OPENCL__) && defined(GPUCA_OPENCL_NO_CONSTANT_MEMORY))
61+
// __METAL__ unconditionally: the MSL generic address space does not span
62+
// `constant`, so a generic member function cannot be called on an object living
63+
// there, and the shared code is generic throughout.
64+
#if (defined(__CUDACC__) && defined(GPUCA_CUDA_NO_CONSTANT_MEMORY)) || (defined(__HIPCC__) && defined(GPUCA_HIP_NO_CONSTANT_MEMORY)) || (defined(__OPENCL__) && defined(GPUCA_OPENCL_NO_CONSTANT_MEMORY)) || defined(__METAL__)
6265
#define GPUCA_NO_CONSTANT_MEMORY
6366
#elif (defined(__CUDACC__) || defined(__HIPCC__)) && !defined(GPUCA_GPUCODE_HOSTONLY)
6467
#define GPUCA_HAS_GLOBAL_SYMBOL_CONSTANT_MEM

‎GPU/Common/GPUCommonDefAPI.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@
167167
#define GPUglobalref() device
168168
#define GPUsharedref() threadgroup
169169
#define GPUprivateref() thread
170-
#define GPUconstantref() constant
170+
#if !defined(GPUCA_NO_CONSTANT_MEMORY)
171+
#define GPUconstantref() constant
172+
#endif
171173
#define GPUconstexprref() GPUconstexpr()
172174
#define GPUdouble() float
173175
#define GPUbarrier() threadgroup_barrier(mem_flags::mem_device | mem_flags::mem_threadgroup)

0 commit comments

Comments
 (0)