[PATCH] [CUDA] Support for built-in cuda variables (threadIdx and its friends).

Artem Belevich tra at google.com
Mon Apr 20 13:26:04 PDT 2015


================
Comment at: lib/Headers/cuda/cuda_builtin_vars.h:89
@@ +88,3 @@
+// architectures have a WARP_SZ value of 32'.
+__CUDA_BUILTIN_VAR int warpSize = 32;
+
----------------
rsmith wrote:
> This is a (strong) definition due to the `extern` in the `__CUDA_BUILTIN_VAR` macro, and will cause a link error if this file is `#include`d into multiple objects in the same binary. You could solve this by removing the `extern` (that'd give the variable internal linkage) or by using `enum { warpSize = 32 };` or similar. I'm not sure exactly what the CUDA spec requires here.
Those have to be extern because no instances of those special variables can ever exist, yet they are referred to as if they do. 'extern' matches this functionality best. I've added a weak attribute to make linking work. That is, if/when we'll get to do any linking on the GPU code. Currently we produce PTX assembly and we don't ever link one PTX file with another.

I've reworked warpSize into a class with the same restrictions on construction and access as the other built-in variables.

As for CUDA spec, it does not say much -- 'They [built-in variables] are only valid within functions that are executed on the device. [warpSize] is of type int and contains the warp size in threads.'



================
Comment at: lib/Headers/cuda/cuda_builtin_vars.h:11
@@ +10,3 @@
+
+struct __cuda_builtin_threadIdx_t {
+  __CUDA_DEVICE_BUILTIN(x,__builtin_ptx_read_tid_x());
----------------
rsmith wrote:
> Should these types also have deleted copy constructors and copy assignment operators? I'd imagine these should both be ill-formed:
> 
>   auto x = threadIdx;
>   threadIdx = threadIdx;
I've disabled constructors for the special variables and also disabled address-of operator as nvcc does not allow taking their address.

http://reviews.llvm.org/D9064

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list