[all-commits] [llvm/llvm-project] 45f2a5: [CUDA][HIP] Support accessing static device variab...

Yaxun (Sam) Liu via All-commits all-commits at lists.llvm.org
Wed Aug 5 04:58:16 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 45f2a56856e29b8cb038b2e559289b91fb98fedf
      https://github.com/llvm/llvm-project/commit/45f2a56856e29b8cb038b2e559289b91fb98fedf
  Author: Yaxun (Sam) Liu <yaxun.liu at amd.com>
  Date:   2020-08-05 (Wed, 05 Aug 2020)

  Changed paths:
    M clang/include/clang/AST/ASTContext.h
    M clang/lib/AST/ASTContext.cpp
    M clang/lib/Sema/SemaExpr.cpp
    M clang/test/CodeGenCUDA/constexpr-variables.cu
    A clang/test/CodeGenCUDA/static-device-var-no-rdc.cu

  Log Message:
  -----------
  [CUDA][HIP] Support accessing static device variable in host code for -fno-gpu-rdc

nvcc supports accessing file-scope static device variables in host code by host APIs
like cudaMemcpyToSymbol etc.

CUDA/HIP let users access device variables in host code by shadow variables. In host compilation,
clang emits a shadow variable for each device variable, and calls __*RegisterVariable to
register it in init function. The address of the shadow variable and the device side mangled
name of the device variable is passed to __*RegisterVariable. Runtime looks up the symbol
by name in the device binary  to find the address of the device variable.

The problem with static device variables is that they have internal linkage, therefore their
name may be changed by the linker if there are multiple symbols with the same name. Also
they end up as local symbols in the elf file, whereas the runtime only looks up the global symbols.

Another reason for making the static device variables external linkage is that they may be
initialized externally by host code and their final value may be accessed by host code
after kernel execution, therefore they actually have external linkage. Giving them internal
linkage will cause incorrect optimizations on them.

To support accessing static device var in host code for -fno-gpu-rdc mode, change the intnernal
linkage to external linkage. The name does not need change since there is only one TU for
-fno-gpu-rdc mode. Also the externalization is done only if the device static var is referenced
by host code.

Differential Revision: https://reviews.llvm.org/D80858




More information about the All-commits mailing list