[libc-commits] [PATCH] D152603: [libc] Add math functions to AMD/NVPTX libm

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Jun 21 11:17:47 PDT 2023


jhuber6 added a subscriber: arsenm.
jhuber6 added inline comments.


================
Comment at: libc/src/math/gpu/cos.cpp:14
 
-extern "C" {
-double __nv_sin(double);
-}
+LLVM_LIBC_FUNCTION(double, cos, (double x)) { return __builtin_cos(x); }
 
----------------
sivachandra wrote:
> I am not sure the GPUs would have instructions to do trignometric functions.
They do not, https://godbolt.org/z/zTWY168a3.


================
Comment at: libc/src/math/gpu/exp2f.cpp:14
 
-extern "C" {
-double __nv_sin(double);
-}
+LLVM_LIBC_FUNCTION(float, exp2f, (float x)) { return __builtin_exp2f(x); }
 
----------------
sivachandra wrote:
> AMD gpus seem to be having `exp2f`. Can we assume other GPUs also have them? Even if they do have, what guarantees and promises they come with? The reason I am asking is to understand how we should set up tests for them.
Seems NVPTX does not support it https://godbolt.org/z/a1jGzeo48. Maybe @arsenm can answer the later questions about the properties.

I'm still not sure how to stand up tests for this math on the GPU. We may need to map it against some host implementation and compare within some ULP. We could potentially have the GPU allocate a table like `arr = (x, f(x))` for that math function and pass it in, letting  the GPU scan it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152603



More information about the libc-commits mailing list