Skip to content

Commit 2ee7f49

Browse files
committed
[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.
1 parent 2bc098b commit 2ee7f49

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

libc/cmake/modules/prepare_libc_gpu_build.cmake

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,28 @@ endif()
1818

1919
# Identify the program used to package multiple images into a single binary.
2020
get_filename_component(compiler_path ${CMAKE_CXX_COMPILER} DIRECTORY)
21-
find_program(LIBC_CLANG_OFFLOAD_PACKAGER
22-
NAMES clang-offload-packager NO_DEFAULT_PATH
23-
PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
24-
if(NOT LIBC_CLANG_OFFLOAD_PACKAGER)
25-
message(FATAL_ERROR "Cannot find the 'clang-offload-packager' for the GPU "
26-
"build")
21+
if(TARGET clang-offload-packager)
22+
get_target_property(LIBC_CLANG_OFFLOAD_PACKAGER clang-offload-packager LOCATION)
23+
else()
24+
find_program(LIBC_CLANG_OFFLOAD_PACKAGER
25+
NAMES clang-offload-packager NO_DEFAULT_PATH
26+
PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
27+
if(NOT LIBC_CLANG_OFFLOAD_PACKAGER)
28+
message(FATAL_ERROR "Cannot find the 'clang-offload-packager' for the GPU "
29+
"build")
30+
endif()
2731
endif()
2832

2933
# Identify llvm-link program so we can merge the output IR into a single blob.
30-
find_program(LIBC_LLVM_LINK
31-
NAMES llvm-link NO_DEFAULT_PATH
32-
PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
33-
if(NOT LIBC_LLVM_LINK)
34-
message(FATAL_ERROR "Cannot find 'llvm-link' for the GPU build")
34+
if(TARGET llvm-link)
35+
get_target_property(LIBC_LLVM_LINK llvm-link LOCATION)
36+
else()
37+
find_program(LIBC_LLVM_LINK
38+
NAMES llvm-link NO_DEFAULT_PATH
39+
PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
40+
if(NOT LIBC_LLVM_LINK)
41+
message(FATAL_ERROR "Cannot find 'llvm-link' for the GPU build")
42+
endif()
3543
endif()
3644

3745
# Optionally set up a job pool to limit the number of GPU tests run in parallel.
@@ -48,10 +56,14 @@ endif()
4856

4957
set(LIBC_GPU_TEST_ARCHITECTURE "" CACHE STRING "Architecture for the GPU tests")
5058
if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
51-
# Identify any locally installed NVIDIA GPUs on the system using 'nvptx-arch'.
52-
find_program(LIBC_AMDGPU_ARCH
53-
NAMES amdgpu-arch NO_DEFAULT_PATH
54-
PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
59+
# Identify any locally installed AMD GPUs on the system using 'amdgpu-arch'.
60+
if(TARGET amdgpu-arch)
61+
get_target_property(LIBC_AMDGPU_ARCH amdgpu-arch LOCATION)
62+
else()
63+
find_program(LIBC_AMDGPU_ARCH
64+
NAMES amdgpu-arch NO_DEFAULT_PATH
65+
PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
66+
endif()
5567
if(LIBC_AMDGPU_ARCH)
5668
execute_process(COMMAND ${LIBC_AMDGPU_ARCH}
5769
OUTPUT_VARIABLE arch_tool_output
@@ -62,9 +74,13 @@ if(LIBC_TARGET_ARCHITECTURE_IS_AMDGPU)
6274
endif()
6375
elseif(LIBC_TARGET_ARCHITECTURE_IS_NVPTX)
6476
# Identify any locally installed NVIDIA GPUs on the system using 'nvptx-arch'.
65-
find_program(LIBC_NVPTX_ARCH
66-
NAMES nvptx-arch NO_DEFAULT_PATH
67-
PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
77+
if(TARGET nvptx-arch)
78+
get_target_property(LIBC_NVPTX_ARCH nvptx-arch LOCATION)
79+
else()
80+
find_program(LIBC_NVPTX_ARCH
81+
NAMES nvptx-arch NO_DEFAULT_PATH
82+
PATHS ${LLVM_BINARY_DIR}/bin ${compiler_path})
83+
endif()
6884
if(LIBC_NVPTX_ARCH)
6985
execute_process(COMMAND ${LIBC_NVPTX_ARCH}
7086
OUTPUT_VARIABLE arch_tool_output

0 commit comments

Comments
 (0)