]> granicus.if.org Git - clang/commit
[HIP] Register/unregister device fat binary only once
authorYaxun Liu <Yaxun.Liu@amd.com>
Fri, 20 Jul 2018 22:45:24 +0000 (22:45 +0000)
committerYaxun Liu <Yaxun.Liu@amd.com>
Fri, 20 Jul 2018 22:45:24 +0000 (22:45 +0000)
commit67428b72eda39d9b712a128e5c6f3a6c9d6cc264
treef0c79d00352d1d5fed8f68540e3f80207f7fd15d
parentf6ec322ffdc0227034876d73801b95b338d100b0
[HIP] Register/unregister device fat binary only once

HIP generates one fat binary for all devices after linking. However, for each compilation
unit a ctor function is emitted which register the same fat binary. Measures need to be
taken to make sure the fat binary is only registered once.

Currently each ctor function calls __hipRegisterFatBinary and stores the returned value
to __hip_gpubin_handle. This patch changes the linkage of __hip_gpubin_handle to be linkonce
so that they are shared between LLVM modules. Then this patch adds check of value of
__hip_gpubin_handle to make sure __hipRegisterFatBinary is only called once. The code
is equivalent to

void *_gpubin_handle;
void ctor() {
  if (__hip_gpubin_handle == 0) {
    __hip_gpubin_handle = __hipRegisterFatBinary(...);
  }
  // register kernels and variables.
}
The patch also does similar change to dtors so that __hipUnregisterFatBinary
is called once.

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337631 91177308-0d34-0410-b5e6-96231b3b80d8
lib/CodeGen/CGCUDANV.cpp
test/CodeGenCUDA/device-stub.cu