[PATCH] D123441: [CUDA][HIP] Fix host used external kernel in archive

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 12 12:31:11 PDT 2022


yaxunl added a comment.

In D123441#3446408 <https://reviews.llvm.org/D123441#3446408>, @tra wrote:

> LGTM in principle. This will keep around the GPU code we do need.
>
> That said, it seems to be a rather blunt hammer. I think we'll end up linking almost everything in an archive into the final executable as we'll likely have a host-visible symbol in most of the GPU objects (e.g. most of them would have a kernel).
> Device-side linking would also be unaware of which objects were actually linked into the host executable and thus would link in more objects than necessary. We could have achieved about the same result by linking with `--whole-archive`.
>
> The root of the problem here is that in isolation GPU-side linking does not know what will really be needed by the host and thus has to link in everything, except, maybe, object files where we may have `__device__` functions only.
> Ideally, the linking should be a two-phase process -- link CPU side, extract references to the GPU symbols (host-side compilation would have to be augmented to place them in a well known location) and pass them to the GPU-side linker which would then have all the info necessary to pull in relevant GPU-side objects without compiler having to force having nearly all of them linked in.
>
> I realize that this would be a nontrivial change to the compilation pipeline. As a short-to-medium term solution, this patch may do, though I'd probably prefer just linking with `--whole-archive` as it would, in theory, be simpler.

This approach will only link in kernels and device variables used by host code, whereas --whole-archive will keep everything in the archive. There are use cases where the archive contains a large amount of kernels that the application only use a few of them.

Also, --whole-archive will require users to carefully arrange --whole-archive and --no-whole-archive options for the archives they use. This approach avoids that.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123441/new/

https://reviews.llvm.org/D123441



More information about the cfe-commits mailing list