-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Clang][HIP] Warn when __AMDGCN_WAVEFRONT_SIZE is used in host code without relying on target-dependent overload resolution #109663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ritter-x2a
wants to merge
1
commit into
llvm:main
from
ritter-x2a:deeply-integrated-wavefrontsize-warnings
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
clang/test/Driver/hip-wavefront-size-host-diagnostics.hip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| // REQUIRES: amdgpu-registered-target | ||
| // RUN: %clang -xhip --offload-arch=gfx1030 --offload-host-only -pedantic -nogpuinc -nogpulib -nobuiltininc -fsyntax-only -Xclang -verify=onhost %s | ||
| // RUN: %clang -xhip --offload-arch=gfx1030 --offload-device-only -pedantic -nogpuinc -nogpulib -nobuiltininc -fsyntax-only -Xclang -verify=ondevice %s | ||
|
|
||
| // ondevice-no-diagnostics | ||
|
|
||
| #include <type_traits> | ||
|
|
||
| #define WRAPPED __AMDGCN_WAVEFRONT_SIZE__ | ||
|
|
||
| #define DOUBLE_WRAPPED (WRAPPED) | ||
|
|
||
| __attribute__((host, device)) void use(int, const char*); | ||
|
|
||
| template<int N> __attribute__((host, device)) int templatify(int x) { | ||
| return x + N; | ||
| } | ||
|
|
||
| // no warning expected | ||
| #if defined(__HIP_DEVICE_COMPILE__) && (__AMDGCN_WAVEFRONT_SIZE__ == 64) && (__AMDGCN_WAVEFRONT_SIZE == 64) | ||
| int foo(void); | ||
| #endif | ||
|
|
||
| // no warning expected | ||
| __attribute__((device)) int device_var = __AMDGCN_WAVEFRONT_SIZE__; | ||
|
|
||
| __attribute__((device)) | ||
| void device_fun() { | ||
| // no warnings expected | ||
| use(__AMDGCN_WAVEFRONT_SIZE, "device function"); | ||
| use(__AMDGCN_WAVEFRONT_SIZE__, "device function"); | ||
| use(WRAPPED, "device function"); | ||
| use(DOUBLE_WRAPPED, "device function"); | ||
| use(templatify<__AMDGCN_WAVEFRONT_SIZE__>(42), "device function"); | ||
| } | ||
|
|
||
| __attribute__((global)) | ||
| void global_fun() { | ||
| // no warnings expected | ||
| use(__AMDGCN_WAVEFRONT_SIZE, "global function"); | ||
| use(__AMDGCN_WAVEFRONT_SIZE__, "global function"); | ||
| use(WRAPPED, "global function"); | ||
| use(DOUBLE_WRAPPED, "global function"); | ||
| use(templatify<__AMDGCN_WAVEFRONT_SIZE__>(42), "global function"); | ||
| } | ||
|
|
||
| // warning expected | ||
| int host_var = __AMDGCN_WAVEFRONT_SIZE__; // onhost-warning {{device-specific macro __AMDGCN_WAVEFRONT_SIZE__ is not available in a __host__ context}} | ||
| int host_var_alt = __AMDGCN_WAVEFRONT_SIZE; // onhost-warning {{device-specific macro __AMDGCN_WAVEFRONT_SIZE is not available in a __host__ context}} | ||
| int host_var_wrapped = WRAPPED; // onhost-warning {{device-specific macro __AMDGCN_WAVEFRONT_SIZE__ is not available in a __host__ context}} | ||
| int host_var_double_wrapped = DOUBLE_WRAPPED; // onhost-warning {{device-specific macro __AMDGCN_WAVEFRONT_SIZE__ is not available in a __host__ context}} | ||
|
|
||
| __attribute__((host)) | ||
| void host_fun() { | ||
| // warnings expected | ||
| use(__AMDGCN_WAVEFRONT_SIZE, "host function"); // onhost-warning {{device-specific macro __AMDGCN_WAVEFRONT_SIZE is not available in a __host__ context}} | ||
| use(__AMDGCN_WAVEFRONT_SIZE__, "host function"); // onhost-warning {{device-specific macro __AMDGCN_WAVEFRONT_SIZE__ is not available in a __host__ context}} | ||
| use(WRAPPED, "host function"); // onhost-warning {{device-specific macro __AMDGCN_WAVEFRONT_SIZE__ is not available in a __host__ context}} | ||
| use(DOUBLE_WRAPPED, "host function"); // onhost-warning {{device-specific macro __AMDGCN_WAVEFRONT_SIZE__ is not available in a __host__ context}} | ||
| use(templatify<__AMDGCN_WAVEFRONT_SIZE__>(42), "host function"); // onhost-warning {{device-specific macro __AMDGCN_WAVEFRONT_SIZE__ is not available in a __host__ context}} | ||
| } | ||
|
|
||
| __attribute((host, device)) | ||
| void host_device_fun() { | ||
| // warnings expected | ||
| use(__AMDGCN_WAVEFRONT_SIZE__, "host device function"); // onhost-warning {{device-specific macro __AMDGCN_WAVEFRONT_SIZE__ is not available in a __host__ __device__ context}} | ||
| use(WRAPPED, "host device function"); // onhost-warning {{device-specific macro __AMDGCN_WAVEFRONT_SIZE__ is not available in a __host__ __device__ context}} | ||
| use(DOUBLE_WRAPPED, "host device function"); // onhost-warning {{device-specific macro __AMDGCN_WAVEFRONT_SIZE__ is not available in a __host__ __device__ context}} | ||
| use(templatify<__AMDGCN_WAVEFRONT_SIZE__>(42), "host device function"); // onhost-warning {{device-specific macro __AMDGCN_WAVEFRONT_SIZE__ is not available in a __host__ __device__ context}} | ||
| } | ||
|
|
||
| // Variations of this construct are used in rocPRIM and should compile without diagnostics. | ||
| template <unsigned int OuterWarpSize = __AMDGCN_WAVEFRONT_SIZE> | ||
| class FunSelector { | ||
| public: | ||
| template<unsigned int FunWarpSize = OuterWarpSize> | ||
| __attribute__((device)) | ||
| auto fun(void) | ||
| -> typename std::enable_if<(FunWarpSize <= __AMDGCN_WAVEFRONT_SIZE), void>::type | ||
| { | ||
| use(1, "yay!"); | ||
| } | ||
|
|
||
| template<unsigned int FunWarpSize = OuterWarpSize> | ||
| __attribute__((device)) | ||
| auto fun(void) | ||
| -> typename std::enable_if<(FunWarpSize > __AMDGCN_WAVEFRONT_SIZE), void>::type | ||
| { | ||
| use(0, "nay!"); | ||
| } | ||
| }; | ||
|
|
||
| __attribute__((device)) | ||
| void device_fun_selector_user() { | ||
| FunSelector<> f; | ||
| f.fun<>(); | ||
| f.fun<1>(); | ||
| f.fun<1000>(); | ||
|
|
||
| std::enable_if<(1 <= __AMDGCN_WAVEFRONT_SIZE), int>::type x = 42; | ||
| } | ||
|
|
||
| __attribute__((device)) std::enable_if<(1 <= __AMDGCN_WAVEFRONT_SIZE), int>::type DeviceFunTemplateRet(void) { | ||
| return 42; | ||
| } | ||
|
|
||
| __attribute__((device)) int DeviceFunTemplateArg(std::enable_if<(1 <= __AMDGCN_WAVEFRONT_SIZE), int>::type x) { | ||
| return x; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will
constorconstexprhost variables dependent on the macros also produce warnings?E.g. something like this https://godbolt.org/z/1bxnrxrnn may be OK:
The use of
zon the host side would still be wrong, though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this patch, the initializer of
zwould cause a warning. Is that not the intended behavior?The const variable will only have a meaningful value during device compilation and therefore should only be used in a device context, so it should be declared with
__device__to avoid the warning, right?