[libc-commits] [libc] 72bfe2c - [libc] Support the string conversion methods on the GPU

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Thu Apr 27 18:32:09 PDT 2023


Author: Joseph Huber
Date: 2023-04-27T20:31:58-05:00
New Revision: 72bfe2c05a09e39c6e9c8f35fcbbd9322ed56432

URL: https://github.com/llvm/llvm-project/commit/72bfe2c05a09e39c6e9c8f35fcbbd9322ed56432
DIFF: https://github.com/llvm/llvm-project/commit/72bfe2c05a09e39c6e9c8f35fcbbd9322ed56432.diff

LOG: [libc] Support the string conversion methods on the GPU

This patch enables us to use the existing `libc` support for string
conversion functions on the GPU. This required setting the `fenv_t` and
long double configuration. As far as I am aware, long doubles are
converted to doubles on the GPU and the floating point environment is
just an `uint32_t`.

This code is still untested as we are still working out how to run the
unit tests on the GPU.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D149306

Added: 
    

Modified: 
    libc/config/gpu/api.td
    libc/config/gpu/entrypoints.txt
    libc/config/gpu/headers.txt
    libc/docs/gpu/support.rst
    libc/include/llvm-libc-types/fenv_t.h
    libc/src/__support/FPUtil/PlatformDefs.h

Removed: 
    


################################################################################
diff  --git a/libc/config/gpu/api.td b/libc/config/gpu/api.td
index 3e6927de94634..c5f555c90178c 100644
--- a/libc/config/gpu/api.td
+++ b/libc/config/gpu/api.td
@@ -12,3 +12,7 @@ def StdlibAPI : PublicAPI<"stdlib.h"> {
     "__atexithandler_t",
   ];
 }
+
+def FenvAPI: PublicAPI<"fenv.h"> {
+  let Types = ["fenv_t"];
+}

diff  --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt
index c5ed1e3dd4764..13d70f97363f8 100644
--- a/libc/config/gpu/entrypoints.txt
+++ b/libc/config/gpu/entrypoints.txt
@@ -56,7 +56,17 @@ set(TARGET_LIBC_ENTRYPOINTS
 
     # stdlib.h entrypoints
     libc.src.stdlib.atoi
+    libc.src.stdlib.atof
+    libc.src.stdlib.atol
+    libc.src.stdlib.atoll
     libc.src.stdlib.atexit
+    libc.src.stdlib.strtod
+    libc.src.stdlib.strtof
+    libc.src.stdlib.strtol
+    libc.src.stdlib.strtold
+    libc.src.stdlib.strtoll
+    libc.src.stdlib.strtoul
+    libc.src.stdlib.strtoull
 
     # Only implemented in the test suite
     libc.src.stdlib.malloc

diff  --git a/libc/config/gpu/headers.txt b/libc/config/gpu/headers.txt
index 1b77c97b00d8d..608ff42cbdbc5 100644
--- a/libc/config/gpu/headers.txt
+++ b/libc/config/gpu/headers.txt
@@ -1,6 +1,7 @@
 set(TARGET_PUBLIC_HEADERS
     libc.include.ctype
     libc.include.string
+    libc.include.fenv
     libc.include.errno
     libc.include.stdlib
 )

diff  --git a/libc/docs/gpu/support.rst b/libc/docs/gpu/support.rst
index 59fdb61966838..5638e51dd53f2 100644
--- a/libc/docs/gpu/support.rst
+++ b/libc/docs/gpu/support.rst
@@ -85,4 +85,15 @@ stdlib.h
 Function Name  Available  RPC Required
 =============  =========  ============
 atoi           |check|
+atof           |check|
+atol           |check|
+atoll          |check|
+atexit         |check|
+strtod         |check|
+strtof         |check|
+strtol         |check|
+strtold        |check|
+strtoll        |check|
+strtoul        |check|
+strtoull       |check|
 =============  =========  ============

diff  --git a/libc/include/llvm-libc-types/fenv_t.h b/libc/include/llvm-libc-types/fenv_t.h
index 6d2bea74560db..86fcf2e49a7ff 100644
--- a/libc/include/llvm-libc-types/fenv_t.h
+++ b/libc/include/llvm-libc-types/fenv_t.h
@@ -25,6 +25,10 @@ typedef struct {
 } fenv_t;
 #elif defined(__riscv)
 typedef unsigned int fenv_t;
+#elif defined(__AMDGPU__) || defined(__NVPTX__)
+typedef struct {
+  unsigned int __fpc;
+} fenv_t;
 #else
 #error "fenv_t not defined for your platform"
 #endif

diff  --git a/libc/src/__support/FPUtil/PlatformDefs.h b/libc/src/__support/FPUtil/PlatformDefs.h
index 488bfc3bbd96a..175a62a1c930e 100644
--- a/libc/src/__support/FPUtil/PlatformDefs.h
+++ b/libc/src/__support/FPUtil/PlatformDefs.h
@@ -17,8 +17,9 @@
 
 // https://developer.arm.com/documentation/dui0491/i/C-and-C---Implementation-Details/Basic-data-types
 // https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms
-#if defined(_WIN32) || defined(__arm__) ||                                     \
-    (defined(__APPLE__) && defined(__aarch64__))
+// https://docs.amd.com/bundle/HIP-Programming-Guide-v5.1/page/Programming_with_HIP.html
+#if defined(_WIN32) || defined(__arm__) || defined(__NVPTX__) ||               \
+    defined(__AMDGPU__) || (defined(__APPLE__) && defined(__aarch64__))
 #define LONG_DOUBLE_IS_DOUBLE
 #endif
 


        


More information about the libc-commits mailing list