This is an archive of the discontinued LLVM Phabricator instance.

[IRLinker] Suppress linker warnings when linking with CUDA libdevice.
ClosedPublic

Authored by tra on Aug 27 2021, 11:31 AM.

Details

Summary

libdevice bitcode provided by NVIDIA is linked with clang/LLVM-generated IR
which uses nvptx*-nvidia-cuda triple. We need to mark them as compatible.

Diff Detail

Event Timeline

tra created this revision.Aug 27 2021, 11:31 AM
tra requested review of this revision.Aug 27 2021, 11:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 27 2021, 11:31 AM
jdoerfert accepted this revision.Aug 27 2021, 12:51 PM

FWIW, with OpenMP we now see 3 warnings:

[ 90%] Building CXX object ...
warning: linking module '/usr/local/cuda-11.0/nvvm/libdevice/libdevice.10.bc': Linking two modules of different data layouts: '/usr/local/cuda-11.0/nvvm/libdevice/libdevice.10.bc' is '' whereas '...' is 'e-i64:64-i128:128-v16:16-v32:32-n16:32:64'
 [-Wlinker-warnings]
warning: linking module '/usr/local/cuda-11.0/nvvm/libdevice/libdevice.10.bc': Linking two modules of different target triples: '/usr/local/cuda-11.0/nvvm/libdevice/libdevice.10.bc' is 'nvptx64-nvidia-gpulibs' whereas '...' is 'nvptx64-nvidia-cuda'
 [-Wlinker-warnings]
warning: linking module '/soft/llvm/main-20210824/lib/libomptarget-nvptx-sm_80.bc': Linking two modules of different target triples: '/soft/llvm/main-20210824/lib/libomptarget-nvptx-sm_80.bc' is 'nvptx64' whereas '...' is 'nvptx64-nvidia-cuda'
 [-Wlinker-warnings]

This patch should fix the middle one. The last one we can fix ourselves by always embedding canonical/full triples. The first one I am not sure about yet.

Long story short, I think this makes sense. LGTM.

This revision is now accepted and ready to land.Aug 27 2021, 12:51 PM
tra added a comment.Aug 27 2021, 1:04 PM

I've checked libdevice in different CUDA versions and the results are rather inconsistent:

For triples, CUDA-10+ uses nvptx64-nvidia-gpulibs, older versions use nvptx-unknown-unknown
Data layout is absent until CUDA-11.1.

Instead of chasing all the variations, I wonder if we should just disable linker warning for libdevice somewhere in clang.

I've checked libdevice in different CUDA versions and the results are rather inconsistent:

For triples, CUDA-10+ uses nvptx64-nvidia-gpulibs, older versions use nvptx-unknown-unknown
Data layout is absent until CUDA-11.1.

Instead of chasing all the variations, I wonder if we should just disable linker warning for libdevice somewhere in clang.

I was initially thinking to have a flag to do so. With this patch I though we could make it work without. If this patch doesn't work,
I agree, linking libdevice should set a "don't look too closely" flag.

jdoerfert requested changes to this revision.Aug 30 2021, 8:35 AM

The warnings we see are most likely caused by D108603, just to have a connection to the discussion.

This revision now requires changes to proceed.Aug 30 2021, 8:35 AM
tra added a comment.Aug 30 2021, 10:33 AM

How is libomptarget-nvptx-sm_80.bc built? Perhaps it should be changed to use a more detailed triple. Perhaps match libdevice's nvptx64-nvidia-gpulibs or have a distinct openmp-specific one?

Do we have to deal with the libomptarget-nvptx-sm_80.bc shipped with the current nvptx64 triple or is it shipped with clang and we don't need to worry about the older versions in the wild?

How is libomptarget-nvptx-sm_80.bc built? Perhaps it should be changed to use a more detailed triple. Perhaps match libdevice's nvptx64-nvidia-gpulibs or have a distinct openmp-specific one?

Do we have to deal with the libomptarget-nvptx-sm_80.bc shipped with the current nvptx64 triple or is it shipped with clang and we don't need to worry about the older versions in the wild?

We do not have to care about older versions and we can change the triple there. I'm not sure changing it to gpulibs is the right thing though.
My plan was to normalize nvptx64 to nvptx-nvidia-cuda in the frontend such that user can use any subset of that normalized triple w/o warning.
Unsure what we gain by having "gpulibs" and special handling there. That said we could certainly do it.

I'm however unsure how that helps us with libdevice, libomptarget-nvptx is in our control so certainly less of a problem.

tra added a comment.Aug 30 2021, 12:43 PM

My plan was to normalize nvptx64 to nvptx-nvidia-cuda in the frontend such that user can use any subset of that normalized triple w/o warning.

SGTM. So, for now I'll just deal with the libdevice-related warnings.

My plan was to normalize nvptx64 to nvptx-nvidia-cuda in the frontend such that user can use any subset of that normalized triple w/o warning.

SGTM. So, for now I'll just deal with the libdevice-related warnings.

Yes, libdevice we need to somehow make work for all the version incl. mismatching/missing target information.

tra updated this revision to Diff 369594.Aug 30 2021, 6:08 PM
tra edited the summary of this revision. (Show Details)

Suppress warnings about triple and DataLayout mismatches related to CUDA's
libdevice. Tested on CUDA versions 8.0-11.3

tra added inline comments.Aug 30 2021, 6:12 PM
llvm/lib/Support/Triple.cpp
1643 ↗(On Diff #369594)

I think this could be incorporated into the SuppressDLWarning calculation above. This way we'll keep this libdevice quirk handling to one place. I'll update the patch tomorrow.

tra updated this revision to Diff 369597.Aug 30 2021, 6:42 PM

Consolidated the checks into IRMover.

tra added a comment.Aug 30 2021, 6:47 PM

OK, this patch no longer produces warnings about Triple and DL when we're linking in libbdevice from CUDA-8.0 through 11.4.
I've tried to make it as specific as I could.

We can actually test this, right?
Commit subject and message needs to be updated too.

tra updated this revision to Diff 369814.Aug 31 2021, 4:00 PM

Added tests.

tra retitled this revision from [NVPTX] consider nvptx-nvidia-gpulibs triple to be compatible with other variants. to [IRLinker] Suppress linker warnings when linking with CUDA libdevice..Aug 31 2021, 4:01 PM
This revision is now accepted and ready to land.Aug 31 2021, 6:07 PM