[libc-commits] [libc] fd059ea - [libc] Simplify enabling the GPU build for libc

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Mon Mar 27 11:22:37 PDT 2023


Author: Joseph Huber
Date: 2023-03-27T13:22:28-05:00
New Revision: fd059ea7ec044198fd75bb2b3aa30734bcace33e

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

LOG: [libc] Simplify enabling the GPU build for libc

Currently the GPU build requires the `LLVM_LIBC_FULL_BUILD` option to be
set. This patch changes the logic so that it is always enabled when
targeting the GPU. Also, this patch allows `LIBC_GPU_BUILD` and
`LIBC_GPU_ARCHITECTURES` to both enable a GPU build. Now, enabling the
GPU support should only require the following CMake:

```
  -DLLVM_ENABLE_RUNTIMES=libc -DLIBC_GPU_ARCHITECTURES=gfx1030
```

Reviewed By: jdoerfert, sivachandra

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

Added: 
    

Modified: 
    libc/CMakeLists.txt
    libc/cmake/modules/LLVMLibCArchitectures.cmake
    libc/cmake/modules/prepare_libc_gpu_build.cmake
    llvm/runtimes/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 0a9627246d0f5..958de3b30ad20 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -18,7 +18,7 @@ set(LIBC_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
 # The top-level directory in which libc is being built.
 set(LIBC_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR})
 
-if(LLVM_LIBC_FULL_BUILD)
+if(LLVM_LIBC_FULL_BUILD OR LIBC_GPU_BUILD OR LIBC_GPU_ARCHITECTURES)
   if(NOT LIBC_HDRGEN_EXE)
     # We need to set up hdrgen first since other targets depend on it.
     add_subdirectory(utils/LibcTableGenUtil)

diff  --git a/libc/cmake/modules/LLVMLibCArchitectures.cmake b/libc/cmake/modules/LLVMLibCArchitectures.cmake
index 27e17cd6a2aa4..63ec2ef7a286a 100644
--- a/libc/cmake/modules/LLVMLibCArchitectures.cmake
+++ b/libc/cmake/modules/LLVMLibCArchitectures.cmake
@@ -6,7 +6,7 @@
 # platform.
 # ------------------------------------------------------------------------------
 
-if(LIBC_GPU_BUILD)
+if(LIBC_GPU_BUILD OR LIBC_GPU_ARCHITECTURES)
   # We set the generic target and OS to "gpu" here. More specific defintions
   # for the exact target GPU are set up in prepare_libc_gpu_build.cmake.
   set(LIBC_TARGET_OS "gpu")

diff  --git a/libc/cmake/modules/prepare_libc_gpu_build.cmake b/libc/cmake/modules/prepare_libc_gpu_build.cmake
index fe0f4ef4826d5..c6263aeb458b7 100644
--- a/libc/cmake/modules/prepare_libc_gpu_build.cmake
+++ b/libc/cmake/modules/prepare_libc_gpu_build.cmake
@@ -29,8 +29,9 @@ if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" AND
                       " is not `Clang ${req_ver}.")
 endif()
 if(NOT LLVM_LIBC_FULL_BUILD)
-  message(FATAL_ERROR "LLVM_LIBC_FULL_BUILD must be enabled to build libc for "
-                      "GPU.")
+  message(STATUS "LLVM_LIBC_FULL_BUILD must be enabled to build libc for GPU. "
+                 "Overriding LLVM_LIBC_FULL_BUILD to ON.")
+  set(LLVM_LIBC_FULL_BUILD ON FORCE)
 endif()
 
 # Identify the program used to package multiple images into a single binary.

diff  --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
index 195dba9d2989a..f9766286bbbc2 100644
--- a/llvm/runtimes/CMakeLists.txt
+++ b/llvm/runtimes/CMakeLists.txt
@@ -385,7 +385,8 @@ if(runtimes)
       list(APPEND extra_deps llvm-link)
     endif()
   endif()
-  if("libc" IN_LIST LLVM_ENABLE_RUNTIMES AND LLVM_LIBC_FULL_BUILD)
+  if("libc" IN_LIST LLVM_ENABLE_RUNTIMES AND 
+      (LLVM_LIBC_FULL_BUILD OR LIBC_GPU_BUILD OR LIBC_GPU_ARCHITECTURES))
     if(TARGET libc-hdrgen)
       set(libc_tools libc-hdrgen)
       set(libc_cmake_args "-DLIBC_HDRGEN_EXE=$<TARGET_FILE:libc-hdrgen>"


        


More information about the libc-commits mailing list