From: Joseph Huber Date: Tue, 20 Dec 2022 19:06:40 +0000 (-0600) Subject: [libc] Add check for locally installed GPUs X-Git-Tag: upstream/17.0.6~23060 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ae20ff7526212598f4bbe193575560e435ab2707;p=platform%2Fupstream%2Fllvm.git [libc] Add check for locally installed GPUs 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`. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D140422 --- diff --git a/libc/cmake/modules/prepare_libc_gpu_build.cmake b/libc/cmake/modules/prepare_libc_gpu_build.cmake index 20fa57f..fa65b9a 100644 --- a/libc/cmake/modules/prepare_libc_gpu_build.cmake +++ b/libc/cmake/modules/prepare_libc_gpu_build.cmake @@ -28,3 +28,22 @@ if(NOT LLVM_LIBC_FULL_BUILD) message(FATAL_ERROR "LLVM_LIBC_FULL_BUILD must be enabled to build libc for " "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) + execute_process(COMMAND ${LIBC_AMDGPU_ARCH} + OUTPUT_VARIABLE LIBC_AMDGPU_ARCH_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE) + 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_ARCHITECTURE_IS_AMDGPU TRUE) + set(LIBC_GPU_TARGET_TRIPLE "amdgcn-amd-amdhsa") + set(LIBC_GPU_TARGET_ARCHITECTURE "${arch_string}") + endif() +endif() +# TODO: Check for Nvidia GPUs.