[PATCH] D49083: [HIP] Register/unregister device fat binary only once

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 9 08:19:22 PDT 2018


yaxunl created this revision.
yaxunl added reviewers: tra, rjmccall.

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 `_gpubin_handle`. This patch changes the linkage of `_gpubin_handle` to be linkonce
so that they are shared between LLVM modules. Then this patch adds check of value of
`_gpubin_handle` to make sure `__hipRegisterFatBinary` is only called once. The code
is equivalent to

  void *_gpubin_handle;
  void ctor() {
    if (_gpubin_handle == 0) {
      _gpubin_handle = __hipRegisterFatBinary(...);
    }
    // register kernels and variables.
  }

The patch also does similar change to dtors so that `__hipUnregisterFatBinary`
is called once.


https://reviews.llvm.org/D49083

Files:
  lib/CodeGen/CGCUDANV.cpp
  test/CodeGenCUDA/device-stub.cu

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49083.154612.patch
Type: text/x-patch
Size: 6779 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180709/c8e7b0f1/attachment.bin>


More information about the cfe-commits mailing list