Skip to content

Commit

Permalink
[libc] Correctly find LLVM binaries when built in projects mode for GPU
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jhuber6 committed Jun 3, 2024
1 parent 2bc098b commit 2ee7f49
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions libc/cmake/modules/prepare_libc_gpu_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 2ee7f49

Please sign in to comment.