yaxunl added a comment.

In D80858#2171266 <https://reviews.llvm.org/D80858#2171266>, @hliao wrote:

> We may try to solve the issue without RDC firstly, where we don't need to 
> change that static variable name (if the runtime maintains the device 
> binaries correctly.) We only need to ensure the linker won't remove their 
> symbols.


This is essentially externalizing it in linker. However, it may not work.

Consider a static device var was accessed in host code through 
hipMemCpyToSymbol or hipMemCpyFromSymbol. In device code, this static var may 
be initialized through host code, or its final value may be read by host code 
after kernel execution. The existence of these operations mean that this static 
device variable `is` actually having `external` linkage, instead of `internal` 
linkage, since it is accessed by external modules. Fail to reflect this truth 
in IR will cause optimization passes to make incorrect assumptions about this 
variable and perform incorrect optimizations on it. e.g. the llvm passes can 
assume the value in this static var never changes, or its final value will not 
be used, then the llvm passes may simply remove it. Marking it as `used` will 
not solve the issue, since the llvm passes may still assume its value never 
changes after initialization, whereas in reality it may be changed by 
hipMemCpyToSymbol before kernel execution.


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

https://reviews.llvm.org/D80858



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to