[libc-commits] [PATCH] D152486: [libc] Begin implementing a 'libmgpu.a' for math on the GPU

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Fri Jun 9 15:12:26 PDT 2023


jhuber6 added a comment.

In D152486#4410189 <https://reviews.llvm.org/D152486#4410189>, @sivachandra wrote:

> Couple of questions:
>
> 1. If all that `libmgpu.a` is doing is to route to the vendor specific implementations, what exactly is the benefit provided by `libmgpu.a`?

The vendor libraries provide math functions that have different names and the format they are provided in presents unfortunate design challenges. This allows us to  provide math functions as a library using a more convenient format and it allows us to only resolve these to the vendor versions at (LTO) link time. The primary benefit of this is that LLVM generally understands what a `sin` call is, but does not understand what an `__nv_sin` call is. To that end, keeping the calls until the link job and using our `libm.a` should allow more optimizations. Additionally, this remaps the vendor library into something that's more usable with our interface.

> 2. How do GPU applications use and link to the math functions today without `libmgpu.a`?
>
> Based on the answers to the above questions, I might have more questions and/or comments.

The current solution is to use a wrapper header that's forcibly included before each offloading compilation that maps for example `sin` to `__nv_sin` on the GPU. This is then resolved per-TU by the `-mlink-builtin-bitcode` option that you see used in this patch in a similar way. There is no linking per-se currently, a lot of the work I did last year was to allow GPUs to have more traditional linking steps when using offloading languages.

@jdoerfert or @tra will probably be able to give you a more detailed answer, I remember there being some talks a long time ago about making this `libm`. There's also an implementation of it in AMD's downstream fork for use with OpenMP offloading to Fortran so this is a way to bring that upstream.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152486



More information about the libc-commits mailing list