| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | #ifndef __CUDA_BUILTIN_VARS_H |
| 25 | #define __CUDA_BUILTIN_VARS_H |
| 26 | |
| 27 | |
| 28 | struct uint3; |
| 29 | struct dim3; |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | #define __CUDA_DEVICE_BUILTIN(FIELD, INTRINSIC) \ |
| 45 | __declspec(property(get = __fetch_builtin_##FIELD)) unsigned int FIELD; \ |
| 46 | static inline __attribute__((always_inline)) \ |
| 47 | __attribute__((device)) unsigned int __fetch_builtin_##FIELD(void) { \ |
| 48 | return INTRINSIC; \ |
| 49 | } |
| 50 | |
| 51 | #if __cplusplus >= 201103L |
| 52 | #define __DELETE =delete |
| 53 | #else |
| 54 | #define __DELETE |
| 55 | #endif |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | #define __CUDA_DISALLOW_BUILTINVAR_ACCESS(TypeName) \ |
| 61 | __attribute__((device)) TypeName() __DELETE; \ |
| 62 | __attribute__((device)) TypeName(const TypeName &) __DELETE; \ |
| 63 | __attribute__((device)) void operator=(const TypeName &) const __DELETE; \ |
| 64 | __attribute__((device)) TypeName *operator&() const __DELETE |
| 65 | |
| 66 | struct __cuda_builtin_threadIdx_t { |
| 67 | __CUDA_DEVICE_BUILTIN(x,__nvvm_read_ptx_sreg_tid_x()); |
| 68 | __CUDA_DEVICE_BUILTIN(y,__nvvm_read_ptx_sreg_tid_y()); |
| 69 | __CUDA_DEVICE_BUILTIN(z,__nvvm_read_ptx_sreg_tid_z()); |
| 70 | |
| 71 | |
| 72 | __attribute__((device)) operator uint3() const; |
| 73 | private: |
| 74 | __CUDA_DISALLOW_BUILTINVAR_ACCESS(__cuda_builtin_threadIdx_t); |
| 75 | }; |
| 76 | |
| 77 | struct __cuda_builtin_blockIdx_t { |
| 78 | __CUDA_DEVICE_BUILTIN(x,__nvvm_read_ptx_sreg_ctaid_x()); |
| 79 | __CUDA_DEVICE_BUILTIN(y,__nvvm_read_ptx_sreg_ctaid_y()); |
| 80 | __CUDA_DEVICE_BUILTIN(z,__nvvm_read_ptx_sreg_ctaid_z()); |
| 81 | |
| 82 | |
| 83 | __attribute__((device)) operator uint3() const; |
| 84 | private: |
| 85 | __CUDA_DISALLOW_BUILTINVAR_ACCESS(__cuda_builtin_blockIdx_t); |
| 86 | }; |
| 87 | |
| 88 | struct __cuda_builtin_blockDim_t { |
| 89 | __CUDA_DEVICE_BUILTIN(x,__nvvm_read_ptx_sreg_ntid_x()); |
| 90 | __CUDA_DEVICE_BUILTIN(y,__nvvm_read_ptx_sreg_ntid_y()); |
| 91 | __CUDA_DEVICE_BUILTIN(z,__nvvm_read_ptx_sreg_ntid_z()); |
| 92 | |
| 93 | |
| 94 | __attribute__((device)) operator dim3() const; |
| 95 | private: |
| 96 | __CUDA_DISALLOW_BUILTINVAR_ACCESS(__cuda_builtin_blockDim_t); |
| 97 | }; |
| 98 | |
| 99 | struct __cuda_builtin_gridDim_t { |
| 100 | __CUDA_DEVICE_BUILTIN(x,__nvvm_read_ptx_sreg_nctaid_x()); |
| 101 | __CUDA_DEVICE_BUILTIN(y,__nvvm_read_ptx_sreg_nctaid_y()); |
| 102 | __CUDA_DEVICE_BUILTIN(z,__nvvm_read_ptx_sreg_nctaid_z()); |
| 103 | |
| 104 | |
| 105 | __attribute__((device)) operator dim3() const; |
| 106 | private: |
| 107 | __CUDA_DISALLOW_BUILTINVAR_ACCESS(__cuda_builtin_gridDim_t); |
| 108 | }; |
| 109 | |
| 110 | #define __CUDA_BUILTIN_VAR \ |
| 111 | extern const __attribute__((device)) __attribute__((weak)) |
| 112 | __CUDA_BUILTIN_VAR __cuda_builtin_threadIdx_t threadIdx; |
| 113 | __CUDA_BUILTIN_VAR __cuda_builtin_blockIdx_t blockIdx; |
| 114 | __CUDA_BUILTIN_VAR __cuda_builtin_blockDim_t blockDim; |
| 115 | __CUDA_BUILTIN_VAR __cuda_builtin_gridDim_t gridDim; |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | __attribute__((device)) const int warpSize = 32; |
| 121 | |
| 122 | #undef __CUDA_DEVICE_BUILTIN |
| 123 | #undef __CUDA_BUILTIN_VAR |
| 124 | #undef __CUDA_DISALLOW_BUILTINVAR_ACCESS |
| 125 | |
| 126 | #endif |
| 127 | |