[libc-commits] [PATCH] D142776: [libc] Add code for detecting NVIDIA GPUs as well
Joseph Huber via Phabricator via libc-commits
libc-commits at lists.llvm.org
Fri Jan 27 11:06:52 PST 2023
jhuber6 created this revision.
jhuber6 added reviewers: michaelrj, sivachandra, lntue.
Herald added subscribers: libc-commits, kosarev, ecnelises, tschuett, tpr.
Herald added projects: libc-project, All.
jhuber6 requested review of this revision.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D142776
Files:
libc/cmake/modules/prepare_libc_gpu_build.cmake
Index: libc/cmake/modules/prepare_libc_gpu_build.cmake
===================================================================
--- libc/cmake/modules/prepare_libc_gpu_build.cmake
+++ libc/cmake/modules/prepare_libc_gpu_build.cmake
@@ -29,7 +29,7 @@
"GPU.")
endif()
-# Identify any locally installed GPUs to use for testing.
+# Identify any locally installed AMD GPUs on the system to use for testing.
find_program(LIBC_AMDGPU_ARCH
NAMES amdgpu-arch
PATHS ${LLVM_BINARY_DIR}/bin /opt/rocm/llvm/bin/)
@@ -46,4 +46,33 @@
set(LIBC_GPU_TARGET_ARCHITECTURE "${arch_string}")
endif()
endif()
-# TODO: Check for Nvidia GPUs.
+
+if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU)
+ message(STATUS "Found an installed AMD GPU on the system with target "
+ "architecture ${LIBC_GPU_TARGET_ARCHITECTURE} ")
+ return()
+endif()
+
+# Identify any locally installed NVIDIA GPUs on the system to use for testing.
+find_program(LIBC_NVPTX_ARCH
+ NAMES nvptx-arch
+ PATHS ${LLVM_BINARY_DIR}/bin)
+if(LIBC_NVPTX_ARCH)
+ execute_process(COMMAND ${LIBC_NVPTX_ARCH}
+ OUTPUT_VARIABLE LIBC_NVPTX_ARCH_OUTPUT
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ string(FIND "${LIBC_NVPTX_ARCH_OUTPUT}" "\n" first_arch_string)
+ string(SUBSTRING "${LIBC_NVPTX_ARCH_OUTPUT}" 0 ${first_arch_string}
+ arch_string)
+ if(arch_string)
+ set(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX TRUE)
+ set(LIBC_GPU_TARGET_TRIPLE "nvptx64-nvidia-cuda")
+ set(LIBC_GPU_TARGET_ARCHITECTURE "${arch_string}")
+ endif()
+endif()
+
+if(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
+ message(STATUS "Found an installed NVIDIA GPU on the system with target "
+ "architecture ${LIBC_GPU_TARGET_ARCHITECTURE} ")
+ return()
+endif()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142776.492850.patch
Type: text/x-patch
Size: 1824 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230127/c105965a/attachment-0001.bin>
More information about the libc-commits
mailing list