[libc-commits] [libc] 2ee7f49 - [libc] Correctly find LLVM binaries when built in projects mode for GPU
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Mon Jun 3 11:09:04 PDT 2024
Author: Joseph Huber
Date: 2024-06-03T13:08:51-05:00
New Revision: 2ee7f49addb60f100929d10ad24ebf1743943b0d
URL: https://github.com/llvm/llvm-project/commit/2ee7f49addb60f100929d10ad24ebf1743943b0d
DIFF: https://github.com/llvm/llvm-project/commit/2ee7f49addb60f100929d10ad24ebf1743943b0d.diff
LOG: [libc] Correctly find LLVM binaries when built in projects mode for GPU
Summary:
You can build the GPU libc support in projects mode. There were some
issues with it not finding the correct binaries. This patch fixes that.
Added:
Modified:
libc/cmake/modules/prepare_libc_gpu_build.cmake
Removed:
################################################################################
diff --git a/libc/cmake/modules/prepare_libc_gpu_build.cmake b/libc/cmake/modules/prepare_libc_gpu_build.cmake
index 88538caaa3bc5..dc8beb14fd7f4 100644
--- a/libc/cmake/modules/prepare_libc_gpu_build.cmake
+++ b/libc/cmake/modules/prepare_libc_gpu_build.cmake
@@ -18,20 +18,28 @@ endif()
# Identify the program used to package multiple images into a single binary.
get_filename_component(compiler_path ${CMAKE_CXX_COMPILER} DIRECTORY)
-find_program(LIBC_CLANG_OFFLOAD_PACKAGER
- NAMES clang-offload-packager NO_DEFAULT_PATH
- PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
-if(NOT LIBC_CLANG_OFFLOAD_PACKAGER)
- message(FATAL_ERROR "Cannot find the 'clang-offload-packager' for the GPU "
- "build")
+if(TARGET clang-offload-packager)
+ get_target_property(LIBC_CLANG_OFFLOAD_PACKAGER clang-offload-packager LOCATION)
+else()
+ find_program(LIBC_CLANG_OFFLOAD_PACKAGER
+ NAMES clang-offload-packager NO_DEFAULT_PATH
+ PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
+ if(NOT LIBC_CLANG_OFFLOAD_PACKAGER)
+ message(FATAL_ERROR "Cannot find the 'clang-offload-packager' for the GPU "
+ "build")
+ endif()
endif()
# Identify llvm-link program so we can merge the output IR into a single blob.
-find_program(LIBC_LLVM_LINK
- NAMES llvm-link NO_DEFAULT_PATH
- PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
-if(NOT LIBC_LLVM_LINK)
- message(FATAL_ERROR "Cannot find 'llvm-link' for the GPU build")
+if(TARGET llvm-link)
+ get_target_property(LIBC_LLVM_LINK llvm-link LOCATION)
+else()
+ find_program(LIBC_LLVM_LINK
+ NAMES llvm-link NO_DEFAULT_PATH
+ PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
+ if(NOT LIBC_LLVM_LINK)
+ message(FATAL_ERROR "Cannot find 'llvm-link' for the GPU build")
+ endif()
endif()
# Optionally set up a job pool to limit the number of GPU tests run in parallel.
@@ -48,10 +56,14 @@ endif()
set(LIBC_GPU_TEST_ARCHITECTURE "" CACHE STRING "Architecture for the GPU tests")
if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
- # Identify any locally installed NVIDIA GPUs on the system using 'nvptx-arch'.
- find_program(LIBC_AMDGPU_ARCH
- NAMES amdgpu-arch NO_DEFAULT_PATH
- PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
+ # Identify any locally installed AMD GPUs on the system using 'amdgpu-arch'.
+ if(TARGET amdgpu-arch)
+ get_target_property(LIBC_AMDGPU_ARCH amdgpu-arch LOCATION)
+ else()
+ find_program(LIBC_AMDGPU_ARCH
+ NAMES amdgpu-arch NO_DEFAULT_PATH
+ PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
+ endif()
if(LIBC_AMDGPU_ARCH)
execute_process(COMMAND ${LIBC_AMDGPU_ARCH}
OUTPUT_VARIABLE arch_tool_output
@@ -62,9 +74,13 @@ if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
endif()
elseif(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
# Identify any locally installed NVIDIA GPUs on the system using 'nvptx-arch'.
- find_program(LIBC_NVPTX_ARCH
- NAMES nvptx-arch NO_DEFAULT_PATH
- PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
+ if(TARGET nvptx-arch)
+ get_target_property(LIBC_NVPTX_ARCH nvptx-arch LOCATION)
+ else()
+ find_program(LIBC_NVPTX_ARCH
+ NAMES nvptx-arch NO_DEFAULT_PATH
+ PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
+ endif()
if(LIBC_NVPTX_ARCH)
execute_process(COMMAND ${LIBC_NVPTX_ARCH}
OUTPUT_VARIABLE arch_tool_output
More information about the libc-commits
mailing list