[clang] [Clang][HIP] Add LLVM vendored device headers for `*-llvm` triple (PR #203980)
Joseph Huber via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 6 11:47:18 PDT 2026
================
@@ -0,0 +1,71 @@
+//===---- __clang_gpu_builtin_vars.h - GPU built-in variables --------------===
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===-----------------------------------------------------------------------===
+
+#ifndef __CLANG_GPU_BUILTIN_VARS_H__
+#define __CLANG_GPU_BUILTIN_VARS_H__
+
+#if defined(__HIP__) || defined(__CUDA__)
+
+#include <gpuintrin.h>
+
+// The warpSize is a runtime value rather than a compile-time constant.
+inline __attribute__((device)) const struct {
+ __attribute__((device, always_inline, const)) operator int() const noexcept {
+ return __gpu_num_lanes();
+ }
+} warpSize{};
+
+// Make sure nobody can create instances of the coordinate types, take their
+// address, copy, or assign them.
+#pragma push_macro("__GPU_DISALLOW_BUILTINVAR_ACCESS")
+#define __GPU_DISALLOW_BUILTINVAR_ACCESS(__tag) \
+ __attribute__((device)) __tag() = delete; \
+ __attribute__((device)) __tag(const __tag &) = delete; \
+ __attribute__((device)) void operator=(const __tag &) const = delete; \
+ __attribute__((device)) __tag *operator&() const = delete
+
+#pragma push_macro("__GPU_COORD_BUILTIN")
+#define __GPU_COORD_BUILTIN(__tag, __fx, __fy, __fz) \
+ struct __tag { \
+ __declspec(property(get = __get_x)) unsigned int x; \
+ __declspec(property(get = __get_y)) unsigned int y; \
+ __declspec(property(get = __get_z)) unsigned int z; \
+ __attribute__((device, always_inline)) unsigned int __get_x() const { \
+ return __fx; \
+ } \
+ __attribute__((device, always_inline)) unsigned int __get_y() const { \
+ return __fy; \
+ } \
+ __attribute__((device, always_inline)) unsigned int __get_z() const { \
+ return __fz; \
----------------
jhuber6 wrote:
They're struct members so I actually wasn't sure if they needed it. I'll double check.
https://github.com/llvm/llvm-project/pull/203980
More information about the cfe-commits
mailing list