[clang] [Clang][HIP] Warn when __AMDGCN_WAVEFRONT_SIZE is used in host code without relying on target-dependent overload resolution (PR #109663)

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 2 12:19:49 PDT 2024


yxsamliu wrote:

One drawback of not defining `__AMDGCN_WAVEFRONT_SIZE__` in host compilation is the impairment of uniformity of source code across host and device sides. Users have to put `#if __HIP_DEVICE_COMPILE__` anywhere they use `__AMDGCN_WAVEFRONT_SIZE__`. Previous experience tells us that this causes bad user experience and clutters source code.

There are valid uses of `__AMDGCN_WAVEFRONT_SIZE__` seen in host compilation. Obviously they can be safely used in device functions or kernels. Even if they are used in file scope, as long as the resulted constants end up in device binary, they are safe to be 'seen' during host compilation. However, if we simply ban `__AMDGCN_WAVEFRONT_SIZE__` in host compilation, we are banning the valid uses of `__AMDGCN_WAVEFRONT_SIZE__` in the source code.

I think we need to balance between usability and safety. That is, we want to diagnose misuse of `__AMDGCN_WAVEFRONT_SIZE__` in host code without impairing too much on single-source-ness of HIP.

https://github.com/llvm/llvm-project/pull/109663


More information about the cfe-commits mailing list