diff options
author | Joseph Huber <huberjn@outlook.com> | 2024-07-22 18:20:14 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-22 18:20:14 -0500 |
commit | 37d0568a6593adfe791c1327d99731050540e97a (patch) | |
tree | 3ced266743fd84a39a1bfd4c06e87b6bc4ef2f16 /clang/lib/Frontend/CompilerInvocation.cpp | |
parent | 40954d7f9bb38b2407fe48a524befc5216f13ccc (diff) | |
download | llvm-37d0568a6593adfe791c1327d99731050540e97a.zip llvm-37d0568a6593adfe791c1327d99731050540e97a.tar.gz llvm-37d0568a6593adfe791c1327d99731050540e97a.tar.bz2 |
[Clang] Introduce 'clang-nvlink-wrapper' to work around 'nvlink' (#96561)
Summary:
The `clang-nvlink-wrapper` is a utility that I removed awhile back
during the transition to the new driver. This patch adds back in a new,
upgraded version that does LTO + archive linking. It's not an easy
choice to reintroduce something I happily deleted, but this is the only
way to move forward with improving GPU support in LLVM.
While NVIDIA provides a linker called 'nvlink', its main interface is
very difficult to work with. It does not provide LTO, or static linking,
requires all files to be named a non-standard `.cubin`, and rejects link
jobs that other linkers would be fine with (i.e empty). I have spent a
great deal of time hacking around this in the GPU `libc` implementation,
where I deliberately avoid LTO and static linking and have about 100
lines of hacky CMake dedicated to storing these files in a format that
the clang-linker-wrapper accepts to avoid this limitation.
The main reason I want to re-intorudce this tool is because I am
planning on creating a more standard C/C++ toolchain for GPUs to use.
This will install files like the following.
```
<install>/lib/nvptx64-nvidia-cuda/libc.a
<install>/lib/nvptx64-nvidia-cuda/libc++.a
<install>/lib/nvptx64-nvidia-cuda/libomp.a
<install>/lib/clang/19/lib/nvptx64-nvidia-cuda/libclang_rt.builtins.a
```
Linking in these libraries will then simply require passing `-lc` like
is already done for non-GPU toolchains. However, this doesn't work with
the currently deficient `nvlink` linker, so I consider this a blocking
issue to massively improving the state of building GPU libraries.
In the future we may be able to convince NVIDIA to port their linker to
`ld.lld`, but for now this is the only workable solution that allows us
to hack around the weird behavior of their closed-source software.
This also copies some amount of logic from the clang-linker-wrapper,
but not enough for it to be worthwhile to merge them I feel. In the
future it may be possible to delete that handling from there entirely.
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
0 files changed, 0 insertions, 0 deletions