yaxunl added a comment.

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

> > The problem is that even though the static variable is registered through 
> > `__hipRigisterVariable`, the runtime still relies on looking up symbol name 
> > to get the address of the device variable. That's why we need to 
> > externalize the static variable.
>
> If so, the runtime should be fixed as the variable name. I remembered I fixed 
> the global one so that each one is uniquely identified by module id plus the 
> name. For runtime APIs, all host-side references to device variables should 
> look through the host stub variables instead of its name. If runtime or API 
> doesn't follow that, we should fix them instead of asking the compiler to do 
> the favor.


For runtime APIs, we do reference device variables through host stub variable 
instead of its name. However, how does runtime implements that internally?

In host compilation, clang emits call of `__hipRegisterVariable(shadow_var, 
device_var_name)` in init functions.

runtime builds a map of each shadow var to a device var name. then runtime 
looks up device var name in code object to get the real address of a device var.

Note: `__hipRegisterVariable` does not really associate a shadow var with the 
address of a device var, since in host compilation there is no way to know the 
address of a device var. It only associates a shadow var with the name of a 
device var.

So eventually, runtime still needs to look up the device var symbol in code 
objects. Since ROCm runtime does not look up local symbols, it cannot find the 
static device var in code objects, unless we externalize it.


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