[libc-commits] [PATCH] D140422: [libc] Add check for locally installed GPUs

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Dec 20 11:14:45 PST 2022


jhuber6 created this revision.
jhuber6 added reviewers: lntue, michaelrj, sivachandra.
Herald added subscribers: libc-commits, kosarev, ecnelises, tschuett, tpr.
Herald added projects: libc-project, All.
jhuber6 requested review of this revision.

We need to know which, if any, GPUs the user has on their system if we
want to be able to test the `libc` source code for the GPU. This patch
adds a basic check using the `amdgpu-arch` utility which is provided by
`clang`.

Checking for NVIDIA GPUs will be done later as this is a little
problematic right now. CMake provides a method that we use for Clang but
it will soon be deprecated, the replacement requires a newer CMake
version that we will have in the LLVM 17 branch in the future. CUDA also
provides `__nvcc_device_query` but it's very new so I'm not sure if we
should rely on it. I may introduce a new tool to do it similar to
`amdgpu-arch`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140422

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,18 +29,20 @@
                       "GPU.")
 endif()
 
+# Identify any locally installed GPUs to use for testing.
 find_program(LIBC_AMDGPU_ARCH
              NAMES amdgpu-arch
              PATHS ${LLVM_BINARY_DIR}/bin /opt/rocm/llvm/bin/)
-if (LIBC_AMDGPU_ARCH)
+if(LIBC_AMDGPU_ARCH)
   execute_process(COMMAND ${LIBC_AMDGPU_ARCH}
                   OUTPUT_VARIABLE LIBC_AMDGPU_ARCH_OUTPUT
                   OUTPUT_STRIP_TRAILING_WHITESPACE)
-  string(REPLACE "\n" ";" LIBC_AMDGPU_ARCH_OUTPUT "${LIBC_AMDGPU_ARCH_OUTPUT}")
-
-  list(LENGTH "${LIBC_AMDGPU_ARCH_OUTPUT}" LEN)
-  message(WARNING ${LEN})
-  message(WARNING ${LIBC_AMDGPU_ARCH_OUTPUT})
-  list(POP_BACK ${LIBC_AMDGPU_ARCH_OUTPUT} OUT)
-  message(WARNING ${OUT})
+  string(FIND "${LIBC_AMDGPU_ARCH_OUTPUT}" "\n" first_arch_string)
+  string(SUBSTRING "${LIBC_AMDGPU_ARCH_OUTPUT}" 0 ${first_arch_string}
+         arch_string)
+  if(arch_string)
+    set(LIBC_GPU_TARGET_TRIPLE "amdgcn-amd-amdhsa")
+    set(LIBC_GPU_TARGET_ARCHITECTURE "${arch_string}")
+  endif()
 endif()
+# TODO: Check for Nvidia GPUs.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140422.484331.patch
Type: text/x-patch
Size: 1304 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20221220/b18a2826/attachment.bin>


More information about the libc-commits mailing list