This is an archive of the discontinued LLVM Phabricator instance.

[HIP] Fix -fgpu-rdc for Windows
ClosedPublic

Authored by yaxunl on Dec 3 2021, 6:45 AM.

Details

Summary

This patch fixes issues for -fgpu-rdc for Windows MSVC
toolchain:

Fix COFF specific section flags and remove section types
in llvm-mc input file for Windows.

Escape fatbin path in llvm-mc input file.

Add -triple option to llvm-mc.

Put __hip_gpubin_handle in comdat when it has linkonce_odr
linkage.

Diff Detail

Event Timeline

yaxunl requested review of this revision.Dec 3 2021, 6:45 AM
yaxunl created this revision.
tra added a comment.Dec 6 2021, 10:40 AM

Put __hip_gpubin_handle in comdat when it has linkonce_odr linkage.

I wonder when would this happen? I'm not sure we ever want gpubin handles from different TUs merged. I think it may result in different TUs attempting to load/init the same GPU binary multiple times.

yaxunl added a comment.EditedDec 6 2021, 12:11 PM

Put __hip_gpubin_handle in comdat when it has linkonce_odr linkage.

I wonder when would this happen? I'm not sure we ever want gpubin handles from different TUs merged. I think it may result in different TUs attempting to load/init the same GPU binary multiple times.

For -fgpu-rdc case, __hip_gpubin_handle is a global variable shared by all TU. This is because in the global ctor function for each TU there is logic like

void init_fun() {
  if (!__hip_gpubin_handle)
     __hip_gpubin_handle = __hipRegisterFatbinary(__hip_fatbin);
}

Since all TU share the same __hip_fatbin, we need this to avoid duplicate registration of __hip_fatbin. Since __hip_gpubin_handle needs to be defined in each TU, we let them have linkonce_odr linkage to force them merged. On Windows, this also requires comdat.

tra accepted this revision.Dec 6 2021, 12:44 PM
This revision is now accepted and ready to land.Dec 6 2021, 12:44 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptDec 6 2021, 1:42 PM