Skip to content

Commit e5c6d1f

Browse files
authored
[Clang][HIP] Deprecate the AMDGCN_WAVEFRONT_SIZE macros (#112849)
So far, these macros can be used in contexts where no meaningful wavefront size is available. We therefore deprecate these macros, to replace them with a more resilient interface to access wavefront size information where it is available. For SWDEV-491529.
1 parent 231e03b commit e5c6d1f

File tree

5 files changed

+127
-7
lines changed

5 files changed

+127
-7
lines changed

clang/docs/AMDGPUSupport.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ Predefined Macros
5050
* - ``__AMDGCN_UNSAFE_FP_ATOMICS__``
5151
- Defined if unsafe floating-point atomics are allowed.
5252
* - ``__AMDGCN_WAVEFRONT_SIZE__``
53-
- Defines the wavefront size. Allowed values are 32 and 64.
53+
- Defines the wavefront size. Allowed values are 32 and 64 (deprecated).
5454
* - ``__AMDGCN_WAVEFRONT_SIZE``
55-
- Alias to ``__AMDGCN_WAVEFRONT_SIZE__``. To be deprecated.
55+
- Alias to ``__AMDGCN_WAVEFRONT_SIZE__`` (deprecated).
5656
* - ``__HAS_FMAF__``
5757
- Defined if FMAF instruction is available (deprecated).
5858
* - ``__HAS_LDEXPF__``

clang/docs/HIPSupport.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ Predefined Macros
178178

179179
Note that some architecture specific AMDGPU macros will have default values when
180180
used from the HIP host compilation. Other :doc:`AMDGPU macros <AMDGPUSupport>`
181-
like ``__AMDGCN_WAVEFRONT_SIZE__`` will default to 64 for example.
181+
like ``__AMDGCN_WAVEFRONT_SIZE__`` (deprecated) will default to 64 for example.
182182

183183
Compilation Modes
184184
=================

clang/include/clang/Basic/MacroBuilder.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ class MacroBuilder {
2626
MacroBuilder(raw_ostream &Output) : Out(Output) {}
2727

2828
/// Append a \#define line for macro of the form "\#define Name Value\n".
29-
void defineMacro(const Twine &Name, const Twine &Value = "1") {
29+
/// If DeprecationMsg is provided, also append a pragma to deprecate the
30+
/// defined macro.
31+
void defineMacro(const Twine &Name, const Twine &Value = "1",
32+
Twine DeprecationMsg = "") {
3033
Out << "#define " << Name << ' ' << Value << '\n';
34+
if (!DeprecationMsg.isTriviallyEmpty())
35+
Out << "#pragma clang deprecated(" << Name << ", \"" << DeprecationMsg
36+
<< "\")\n";
3137
}
3238

3339
/// Append a \#undef line for Name. Name should be of the form XXX

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,12 @@ void AMDGPUTargetInfo::getTargetDefines(const LangOptions &Opts,
337337
if (hasFastFMA())
338338
Builder.defineMacro("FP_FAST_FMA");
339339

340-
Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE__", Twine(WavefrontSize));
341-
// ToDo: deprecate this macro for naming consistency.
342-
Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE", Twine(WavefrontSize));
340+
Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE__", Twine(WavefrontSize),
341+
"compile-time-constant access to the wavefront size will "
342+
"be removed in a future release");
343+
Builder.defineMacro("__AMDGCN_WAVEFRONT_SIZE", Twine(WavefrontSize),
344+
"compile-time-constant access to the wavefront size will "
345+
"be removed in a future release");
343346
Builder.defineMacro("__AMDGCN_CUMODE__", Twine(CUMode));
344347
}
345348

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// REQUIRES: amdgpu-registered-target
2+
// RUN: %clang -xhip --offload-arch=gfx1030 --offload-host-only -pedantic -nogpuinc -nogpulib -nobuiltininc -fsyntax-only -Xclang -verify %s
3+
// RUN: %clang -xhip --offload-arch=gfx1030 --offload-device-only -pedantic -nogpuinc -nogpulib -nobuiltininc -fsyntax-only -Xclang -verify %s
4+
5+
// Test that deprecation warnings for the wavefront size macro are emitted properly.
6+
7+
#include <type_traits>
8+
9+
#define WRAPPED __AMDGCN_WAVEFRONT_SIZE__
10+
11+
#define DOUBLE_WRAPPED (WRAPPED)
12+
13+
__attribute__((host, device)) void use(int, const char*);
14+
15+
template<int N> __attribute__((host, device)) int templatify(int x) {
16+
return x + N;
17+
}
18+
19+
__attribute__((device)) const int GlobalConst = __AMDGCN_WAVEFRONT_SIZE__; // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
20+
constexpr int GlobalConstExpr = __AMDGCN_WAVEFRONT_SIZE__; // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
21+
22+
#if defined(__HIP_DEVICE_COMPILE__) && (__AMDGCN_WAVEFRONT_SIZE__ == 64) // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
23+
int foo(void);
24+
#endif
25+
26+
__attribute__((device)) int device_var = __AMDGCN_WAVEFRONT_SIZE__; // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
27+
28+
__attribute__((device))
29+
void device_fun() {
30+
use(__AMDGCN_WAVEFRONT_SIZE, "device function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE' has been marked as deprecated}}
31+
use(__AMDGCN_WAVEFRONT_SIZE__, "device function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
32+
use(WRAPPED, "device function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
33+
use(DOUBLE_WRAPPED, "device function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
34+
use(templatify<__AMDGCN_WAVEFRONT_SIZE__>(42), "device function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
35+
use(GlobalConst, "device function");
36+
use(GlobalConstExpr, "device function");
37+
}
38+
39+
__attribute__((global))
40+
void global_fun() {
41+
// no warnings expected
42+
use(__AMDGCN_WAVEFRONT_SIZE, "global function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE' has been marked as deprecated}}
43+
use(__AMDGCN_WAVEFRONT_SIZE__, "global function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
44+
use(WRAPPED, "global function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
45+
use(DOUBLE_WRAPPED, "global function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
46+
use(templatify<__AMDGCN_WAVEFRONT_SIZE__>(42), "global function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
47+
}
48+
49+
int host_var = __AMDGCN_WAVEFRONT_SIZE__; // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
50+
int host_var_alt = __AMDGCN_WAVEFRONT_SIZE; // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE' has been marked as deprecated}}
51+
int host_var_wrapped = WRAPPED; // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
52+
int host_var_double_wrapped = DOUBLE_WRAPPED; // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
53+
54+
__attribute__((host))
55+
void host_fun() {
56+
use(__AMDGCN_WAVEFRONT_SIZE, "host function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE' has been marked as deprecated}}
57+
use(__AMDGCN_WAVEFRONT_SIZE__, "host function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
58+
use(WRAPPED, "host function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
59+
use(DOUBLE_WRAPPED, "host function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
60+
use(templatify<__AMDGCN_WAVEFRONT_SIZE__>(42), "host function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
61+
use(GlobalConst, "host function");
62+
use(GlobalConstExpr, "host function");
63+
}
64+
65+
__attribute((host, device))
66+
void host_device_fun() {
67+
use(__AMDGCN_WAVEFRONT_SIZE__, "host device function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
68+
use(WRAPPED, "host device function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
69+
use(DOUBLE_WRAPPED, "host device function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
70+
use(templatify<__AMDGCN_WAVEFRONT_SIZE__>(42), "host device function"); // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
71+
}
72+
73+
template <unsigned int OuterWarpSize = __AMDGCN_WAVEFRONT_SIZE__> // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
74+
class FunSelector {
75+
public:
76+
template<unsigned int FunWarpSize = OuterWarpSize>
77+
__attribute__((device))
78+
auto fun(void)
79+
-> typename std::enable_if<(FunWarpSize <= __AMDGCN_WAVEFRONT_SIZE__), void>::type // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
80+
{
81+
use(1, "yay!");
82+
}
83+
84+
template<unsigned int FunWarpSize = OuterWarpSize>
85+
__attribute__((device))
86+
auto fun(void)
87+
-> typename std::enable_if<(FunWarpSize > __AMDGCN_WAVEFRONT_SIZE__), void>::type // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
88+
{
89+
use(0, "nay!");
90+
}
91+
};
92+
93+
__attribute__((device))
94+
void device_fun_selector_user() {
95+
FunSelector<> f;
96+
f.fun<>();
97+
f.fun<1>();
98+
f.fun<1000>();
99+
100+
std::enable_if<(1 <= __AMDGCN_WAVEFRONT_SIZE__), int>::type x = 42; // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
101+
}
102+
103+
__attribute__((device)) std::enable_if<(1 <= __AMDGCN_WAVEFRONT_SIZE__), int>::type DeviceFunTemplateRet(void) { // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
104+
return 42;
105+
}
106+
107+
__attribute__((device)) int DeviceFunTemplateArg(std::enable_if<(1 <= __AMDGCN_WAVEFRONT_SIZE__), int>::type x) { // expected-warning {{macro '__AMDGCN_WAVEFRONT_SIZE__' has been marked as deprecated}}
108+
return x;
109+
}
110+
111+
// expected-note@* 0+ {{macro marked 'deprecated' here}}

0 commit comments

Comments
 (0)