[libc-commits] [PATCH] D153395: Populating 'libmgpu.a' for math on the GPU

Anton Rydahl via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Jun 20 20:29:42 PDT 2023


AntonRydahl created this revision.
AntonRydahl added reviewers: jdoerfert, jhuber6, elmcdonough, sivachandra.
Herald added subscribers: libc-commits, mattd, asavonic, kerbowa, jvesely.
Herald added projects: libc-project, All.
AntonRydahl requested review of this revision.

This commit adresses the discussions from patch D152575 <https://reviews.llvm.org/D152575>. From previous discussions, we agreed that `__builtin` math functions should be used as 
long as they would compile to NVPTX and AMD-GCN/AMD-HSA targets. I found that the `__builtin` functions compiled to GPU code in all cases. That was tested in the following way:

  bash 
  clang++ -O3 -pthread -fno-dwarf2-cfi-asm -fno-asynchronous-unwind-tables -mcpu=gfx1100 --target=amdgcn-amd-amdhsa -nogpulib -I../llvm-project/libc -fno-pie -emit-llvm -S 
  <file>.cpp -o <file>.ll
  llvm-as <file>.ll -o <file>.bc
  llc -mcpu=gfx1100 -filetype=obj -relocation-model=pic <file>.bc -o <file>.o

However, I have not tested if the code performed well on the GPU target or if it compiles to NVPTX.

`__bulitin` Functions
---------------------

The following `__builtin` functions were added.

- Added modf, modff, and modl.
- Added nearbyint, nearbyintf, and naerbyintl.
- Added nextafter, nextafterf, and nextafterl.
- Added remainder, remainderf, and remainderl.
- Added remquo, remquof, and remquol.
- Added rint, rintf, and rintl.
- Added scalbn, scalbnf, and scalbnl.
- Added sinh, sinhf, and sinhl.
- Added sqrt, sqrtf, and sqrtl.
- Added tan, tanf, and tanl.
- Added tanh, tanhf, tanhl.
- Added trunc, truncf, and truncl.

Vendor Functions
----------------

The following vendor functions were added, because the `__builtin` versions do not exist in the LLVM project, as far as I am aware.

- Added sincos and sincosf.

Further, the patch D152486 <https://reviews.llvm.org/D152486> did only include the 64-bit version of sine. Therefore, I added the 32-bit version, sinf.

`libc` Header Files
-------------------

The following header files were introduced to libc:

- sinh and sinhl.
- tanl.
- tanh and tanhl.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153395

Files:
  libc/config/gpu/entrypoints.txt
  libc/src/math/CMakeLists.txt
  libc/src/math/gpu/CMakeLists.txt
  libc/src/math/gpu/modf.cpp
  libc/src/math/gpu/modff.cpp
  libc/src/math/gpu/modfl.cpp
  libc/src/math/gpu/nearbyint.cpp
  libc/src/math/gpu/nearbyintf.cpp
  libc/src/math/gpu/nearbyintl.cpp
  libc/src/math/gpu/nextafter.cpp
  libc/src/math/gpu/nextafterf.cpp
  libc/src/math/gpu/nextafterl.cpp
  libc/src/math/gpu/remainder.cpp
  libc/src/math/gpu/remainderf.cpp
  libc/src/math/gpu/remainderl.cpp
  libc/src/math/gpu/remquo.cpp
  libc/src/math/gpu/remquof.cpp
  libc/src/math/gpu/remquol.cpp
  libc/src/math/gpu/rint.cpp
  libc/src/math/gpu/rintf.cpp
  libc/src/math/gpu/rintl.cpp
  libc/src/math/gpu/scalbn.cpp
  libc/src/math/gpu/scalbnf.cpp
  libc/src/math/gpu/scalbnl.cpp
  libc/src/math/gpu/sinh.cpp
  libc/src/math/gpu/sinhf.cpp
  libc/src/math/gpu/sinhl.cpp
  libc/src/math/gpu/sqrt.cpp
  libc/src/math/gpu/sqrtf.cpp
  libc/src/math/gpu/sqrtl.cpp
  libc/src/math/gpu/tan.cpp
  libc/src/math/gpu/tanf.cpp
  libc/src/math/gpu/tanh.cpp
  libc/src/math/gpu/tanhf.cpp
  libc/src/math/gpu/tanhl.cpp
  libc/src/math/gpu/tanl.cpp
  libc/src/math/gpu/trunc.cpp
  libc/src/math/gpu/truncf.cpp
  libc/src/math/gpu/truncl.cpp
  libc/src/math/gpu/vendor/CMakeLists.txt
  libc/src/math/gpu/vendor/amdgpu/amdgpu.h
  libc/src/math/gpu/vendor/amdgpu/declarations.h
  libc/src/math/gpu/vendor/nvptx/declarations.h
  libc/src/math/gpu/vendor/nvptx/nvptx.h
  libc/src/math/gpu/vendor/sincos.cpp
  libc/src/math/gpu/vendor/sincosf.cpp
  libc/src/math/gpu/vendor/sinf.cpp
  libc/src/math/sinh.h
  libc/src/math/sinhl.h
  libc/src/math/tanh.h
  libc/src/math/tanhl.h
  libc/src/math/tanl.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153395.533113.patch
Type: text/x-patch
Size: 55041 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230621/cab5de40/attachment-0001.bin>


More information about the libc-commits mailing list