clang 24.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#pragma push_macro("__GPU_DISALLOW_BUILTINVAR_ACCESS")
17#define __GPU_DISALLOW_BUILTINVAR_ACCESS(__tag) \
18 __attribute__((device)) __tag() = delete; \
19 __attribute__((device)) __tag(const __tag &) = delete; \
20 __attribute__((device)) void operator=(const __tag &) const = delete; \
21 __attribute__((device)) __tag *operator&() const = delete
22
23#pragma push_macro("__GPU_COORD_BUILTIN")
24#define __GPU_COORD_BUILTIN(__tag, __fx, __fy, __fz) \
25 struct __tag { \
26 __declspec(property(get = __get_x)) unsigned int x; \
27 __declspec(property(get = __get_y)) unsigned int y; \
28 __declspec(property(get = __get_z)) unsigned int z; \
29 __attribute__((device, always_inline)) unsigned int __get_x() const { \
30 return __fx; \
31 } \
32 __attribute__((device, always_inline)) unsigned int __get_y() const { \
33 return __fy; \
34 } \
35 __attribute__((device, always_inline)) unsigned int __get_z() const { \
36 return __fz; \
37 } \
38 \
39 private: \
40 __GPU_DISALLOW_BUILTINVAR_ACCESS(__tag); \
41 }
42
43__GPU_COORD_BUILTIN(__gpu_builtin_threadIdx_t, __gpu_thread_id_x(),
45__GPU_COORD_BUILTIN(__gpu_builtin_blockIdx_t, __gpu_block_id_x(),
47__GPU_COORD_BUILTIN(__gpu_builtin_blockDim_t, __gpu_num_threads_x(),
49__GPU_COORD_BUILTIN(__gpu_builtin_gridDim_t, __gpu_num_blocks_x(),
51
52#pragma pop_macro("__GPU_COORD_BUILTIN")
53#pragma pop_macro("__GPU_DISALLOW_BUILTINVAR_ACCESS")
54
55static inline const
56 __attribute__((device)) __gpu_builtin_threadIdx_t threadIdx{};
57static inline const __attribute__((device)) __gpu_builtin_blockIdx_t blockIdx{};
58static inline const __attribute__((device)) __gpu_builtin_blockDim_t blockDim{};
59static inline const __attribute__((device)) __gpu_builtin_gridDim_t gridDim{};
60
61#endif // device compile
62#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_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)