clang 23.0.0git
__clang_gpu_builtin_vars.h
Go to the documentation of this file.
1//===---- __clang_gpu_builtin_vars.h - GPU built-in variables --------------===
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===-----------------------------------------------------------------------===
8
9#ifndef __CLANG_GPU_BUILTIN_VARS_H__
10#define __CLANG_GPU_BUILTIN_VARS_H__
11
12#if defined(__HIP__) || defined(__CUDA__)
13
14#include <gpuintrin.h>
15
16// The warpSize is a runtime value rather than a compile-time constant.
17static inline __attribute__((device)) const struct {
18 __attribute__((device, always_inline, const)) operator int() const noexcept {
19 return __gpu_num_lanes();
20 }
21} warpSize{};
22
23// Make sure nobody can create instances of the coordinate types, take their
24// address, copy, or assign them.
25#pragma push_macro("__GPU_DISALLOW_BUILTINVAR_ACCESS")
26#define __GPU_DISALLOW_BUILTINVAR_ACCESS(__tag) \
27 __attribute__((device)) __tag() = delete; \
28 __attribute__((device)) __tag(const __tag &) = delete; \
29 __attribute__((device)) void operator=(const __tag &) const = delete; \
30 __attribute__((device)) __tag *operator&() const = delete
31
32#pragma push_macro("__GPU_COORD_BUILTIN")
33#define __GPU_COORD_BUILTIN(__tag, __fx, __fy, __fz) \
34 struct __tag { \
35 __declspec(property(get = __get_x)) unsigned int x; \
36 __declspec(property(get = __get_y)) unsigned int y; \
37 __declspec(property(get = __get_z)) unsigned int z; \
38 __attribute__((device, always_inline)) unsigned int __get_x() const { \
39 return __fx; \
40 } \
41 __attribute__((device, always_inline)) unsigned int __get_y() const { \
42 return __fy; \
43 } \
44 __attribute__((device, always_inline)) unsigned int __get_z() const { \
45 return __fz; \
46 } \
47 \
48 private: \
49 __GPU_DISALLOW_BUILTINVAR_ACCESS(__tag); \
50 }
51
52__GPU_COORD_BUILTIN(__gpu_builtin_threadIdx_t, __gpu_thread_id_x(),
54__GPU_COORD_BUILTIN(__gpu_builtin_blockIdx_t, __gpu_block_id_x(),
56__GPU_COORD_BUILTIN(__gpu_builtin_blockDim_t, __gpu_num_threads_x(),
58__GPU_COORD_BUILTIN(__gpu_builtin_gridDim_t, __gpu_num_blocks_x(),
60
61#pragma pop_macro("__GPU_COORD_BUILTIN")
62#pragma pop_macro("__GPU_DISALLOW_BUILTINVAR_ACCESS")
63
64static inline const
65 __attribute__((device)) __gpu_builtin_threadIdx_t threadIdx{};
66static inline const __attribute__((device)) __gpu_builtin_blockIdx_t blockIdx{};
67static inline const __attribute__((device)) __gpu_builtin_blockDim_t blockDim{};
68static inline const __attribute__((device)) __gpu_builtin_gridDim_t gridDim{};
69
70#endif // device compile
71#endif // __CLANG_GPU_BUILTIN_VARS_H__
__CUDA_BUILTIN_VAR __cuda_builtin_blockDim_t blockDim
__CUDA_BUILTIN_VAR __cuda_builtin_gridDim_t gridDim
__CUDA_BUILTIN_VAR __cuda_builtin_blockIdx_t blockIdx
__CUDA_BUILTIN_VAR __cuda_builtin_threadIdx_t threadIdx
_Float16 __2f16 __attribute__((ext_vector_type(2)))
Zeroes the upper 128 bits (bits 255:128) of all YMM registers.
static _DEFAULT_FN_ATTRS __inline__ uint32_t __gpu_thread_id_x(void)
static _DEFAULT_FN_ATTRS __inline__ uint32_t __gpu_num_threads_z(void)
static _DEFAULT_FN_ATTRS __inline__ uint32_t __gpu_block_id_y(void)
static _DEFAULT_FN_ATTRS __inline__ uint32_t __gpu_thread_id_z(void)
static _DEFAULT_FN_ATTRS __inline__ uint32_t __gpu_num_blocks_x(void)
static _DEFAULT_FN_ATTRS __inline__ uint32_t __gpu_block_id_z(void)
static _DEFAULT_FN_ATTRS __inline__ uint32_t __gpu_num_threads_y(void)
static _DEFAULT_FN_ATTRS __inline__ uint32_t __gpu_num_threads_x(void)
static _DEFAULT_FN_ATTRS __inline__ uint32_t __gpu_num_lanes(void)
static _DEFAULT_FN_ATTRS __inline__ uint32_t __gpu_thread_id_y(void)
static _DEFAULT_FN_ATTRS __inline__ uint32_t __gpu_num_blocks_z(void)
static _DEFAULT_FN_ATTRS __inline__ uint32_t __gpu_block_id_x(void)
static _DEFAULT_FN_ATTRS __inline__ uint32_t __gpu_num_blocks_y(void)