Skip to content

Commit feedb4a

Browse files
committed
[libc] Add code for detecting NVIDIA GPUs as well
Recently the `nvptx-arch` tool was added to address the lack of a similar tool for detecting locally installed NVIDIA GPUs. This patch adds similar functionality for the already existing `amdgpu-arch` tool in libc. These will be used to run tests on the user's system in the future. On a system with both GPUs installed we will just go with the first GPU detected. In the future we may want to configure the tests to run on both of them. Reviewed By: sivachandra, lntue Differential Revision: https://reviews.llvm.org/D142776
1 parent 8583291 commit feedb4a

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

libc/cmake/modules/prepare_libc_gpu_build.cmake

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if(NOT LLVM_LIBC_FULL_BUILD)
2929
"GPU.")
3030
endif()
3131

32-
# Identify any locally installed GPUs to use for testing.
32+
# Identify any locally installed AMD GPUs on the system to use for testing.
3333
find_program(LIBC_AMDGPU_ARCH
3434
NAMES amdgpu-arch
3535
PATHS ${LLVM_BINARY_DIR}/bin /opt/rocm/llvm/bin/)
@@ -46,4 +46,33 @@ if(LIBC_AMDGPU_ARCH)
4646
set(LIBC_GPU_TARGET_ARCHITECTURE "${arch_string}")
4747
endif()
4848
endif()
49-
# TODO: Check for Nvidia GPUs.
49+
50+
if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU)
51+
message(STATUS "Found an installed AMD GPU on the system with target "
52+
"architecture ${LIBC_GPU_TARGET_ARCHITECTURE} ")
53+
return()
54+
endif()
55+
56+
# Identify any locally installed NVIDIA GPUs on the system to use for testing.
57+
find_program(LIBC_NVPTX_ARCH
58+
NAMES nvptx-arch
59+
PATHS ${LLVM_BINARY_DIR}/bin)
60+
if(LIBC_NVPTX_ARCH)
61+
execute_process(COMMAND ${LIBC_NVPTX_ARCH}
62+
OUTPUT_VARIABLE LIBC_NVPTX_ARCH_OUTPUT
63+
OUTPUT_STRIP_TRAILING_WHITESPACE)
64+
string(FIND "${LIBC_NVPTX_ARCH_OUTPUT}" "\n" first_arch_string)
65+
string(SUBSTRING "${LIBC_NVPTX_ARCH_OUTPUT}" 0 ${first_arch_string}
66+
arch_string)
67+
if(arch_string)
68+
set(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX TRUE)
69+
set(LIBC_GPU_TARGET_TRIPLE "nvptx64-nvidia-cuda")
70+
set(LIBC_GPU_TARGET_ARCHITECTURE "${arch_string}")
71+
endif()
72+
endif()
73+
74+
if(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
75+
message(STATUS "Found an installed NVIDIA GPU on the system with target "
76+
"architecture ${LIBC_GPU_TARGET_ARCHITECTURE} ")
77+
return()
78+
endif()

0 commit comments

Comments
 (0)