[libc] [llvm] [libc] Repurpose `LIBC_GPU_BUILD` option to enable the new format (PR #82848)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 23 16:01:51 PST 2024


https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/82848

Summary:
We previously used the `LIBC_GPU_BUILD` option to control whether or not
the GPU build was enabled. This was recently replaced with a new format
that allows treating the GPU targets more directly. However, the new
format is somewhat difficult to use for people unfamiliar with the
runtimes builds, and the removal of this option somewhat broke backward
compatibility. This patch seeks to simplify enabling the GPU build by
repurposing the old enabling option and convert it to the new interface.

Unsure what the rules are here, since this is technically a `LIBC`
option living in the LLVM location.


>From f60d5437fcdd02e39c10385c949284cce6d27785 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Fri, 23 Feb 2024 17:53:16 -0600
Subject: [PATCH] [libc] Repurpose `LIBC_GPU_BUILD` option to enable the new
 format

Summary:
We previously used the `LIBC_GPU_BUILD` option to control whether or not
the GPU build was enabled. This was recently replaced with a new format
that allows treating the GPU targets more directly. However, the new
format is somewhat difficult to use for people unfamiliar with the
runtimes builds, and the removal of this option somewhat broke backward
compatibility. This patch seeks to simplify enabling the GPU build by
repurposing the old enabling option and convert it to the new interface.

Unsure what the rules are here, since this is technically a `LIBC`
option living in the LLVM location.
---
 libc/CMakeLists.txt |  3 +--
 llvm/CMakeLists.txt | 12 ++++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 75fcc91757b807..e5f8755a100dbf 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -131,7 +131,6 @@ option(LLVM_LIBC_FULL_BUILD "Build and test LLVM libc as if it is the full libc"
 option(LLVM_LIBC_IMPLEMENTATION_DEFINED_TEST_BEHAVIOR "Build LLVM libc tests assuming our implementation-defined behavior" ON)
 option(LLVM_LIBC_ENABLE_LINTING "Enables linting of libc source files" OFF)
 
-option(LIBC_GPU_BUILD "Build libc for the GPU. All CPU build options will be ignored." OFF)
 set(LIBC_TARGET_TRIPLE "" CACHE STRING "The target triple for the libc build.")
 
 option(LIBC_CONFIG_PATH "The path to user provided folder that configures the build for the target system." OFF)
@@ -240,7 +239,7 @@ endif()
 
 if(LIBC_TARGET_TRIPLE)
   set(LIBC_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LIBC_TARGET_TRIPLE})
-elseif(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT LIBC_GPU_BUILD)
+elseif(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
   set(LIBC_INSTALL_LIBRARY_DIR
       lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE})
 else()
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index f5f7d3f3253fd3..b326b059705c10 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -168,6 +168,18 @@ foreach(proj IN LISTS LLVM_ENABLE_RUNTIMES)
   endif()
 endforeach()
 
+# Set a shorthand option to enable the GPU build of the 'libc' project.
+option(LIBC_GPU_BUILD "Enable the 'libc' project targeting the GPU" OFF)
+if(LIBC_GPU_BUILD)
+  if(LLVM_RUNTIME_TARGETS)
+    list(APPEND LLVM_RUNTIME_TARGETS "nvptx64-nvidia-cuda" "amdgcn-amd-amdhsa")
+  else()
+    set(LLVM_RUNTIME_TARGETS "default;nvptx64-nvidia-cuda;amdgcn-amd-amdhsa")
+  endif()
+  list(APPEND RUNTIMES_nvptx64-nvidia-cuda_LLVM_ENABLE_RUNTIMES "libc")
+  list(APPEND RUNTIMES_amdgcn-amd-amdhsa_LLVM_ENABLE_RUNTIMES "libc")
+endif()
+
 set(NEED_LIBC_HDRGEN FALSE)
 if("libc" IN_LIST LLVM_ENABLE_RUNTIMES)
   set(NEED_LIBC_HDRGEN TRUE)



More information about the llvm-commits mailing list