[PATCH] D95901: [CUDA][HIP] Fix device variable linkage

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 3 10:25:07 PST 2021


yaxunl added a comment.

In D95901#2539663 <https://reviews.llvm.org/D95901#2539663>, @tra wrote:

>> For -fgpu-rdc, shadow variables should not be internalized, otherwise they cannot be accessed by other TUs. 
>> This is necessary because the shadow variable of external device variables are always emitted as undefined symbols, which need to resolve to a global symbols.
>
> Does it mean that we always internalize shadows *now*, before this patch? That would indeed be wrong. Shadow's visibility should be the same as that of a variable without a `__device__`.

Yes before this patch we always internalize shadow vars.

> Next question is whether the behavior should be different for `-fgpu-rdc` vs non-RDC.  I think shadows should behave the same regardless of RDC mode and make things work closer to what users would expect from regular C++ code. We already have mechanisms to uniquify the variables, if necessary, so we don't need to use visibility to avoid cross-TU linking conflicts.

For -fno-gpu-rdc, two TU's can have global device variables with the same name, therefore the shadow variables need to be internalized, which is fine since -fno-gpu-rdc is not supposed to access device variables across TU's. So far users did not report issues about shadow var linkage for -fno-gpu-rdc (they reported shadow var linkage issues for -fgpu-rdc only). Let the shadow vars keep original linkage and use CUID to make them unique would be unnecessary and clutter the IR.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95901/new/

https://reviews.llvm.org/D95901



More information about the cfe-commits mailing list