From f8563a2545416df90e41b4345ccb81f9ca9b7835 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Mon, 6 Feb 2023 09:14:20 -0600 Subject: [PATCH] [libc] Add `LIBC_GPU_TEST_ARCHITECTURE` option to set architecture Currently, the plan is to support testing on a single GPU architecture. We query the supported architectures from the user's system. However, there are times when the user would want to override this. This patch adds the `LIBC_GPU_TEST_ARCHITECTURE` option, which allows users to specify which GPU architecture to build for. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D143400 --- libc/cmake/modules/prepare_libc_gpu_build.cmake | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libc/cmake/modules/prepare_libc_gpu_build.cmake b/libc/cmake/modules/prepare_libc_gpu_build.cmake index 8bd7d9d..beea99d 100644 --- a/libc/cmake/modules/prepare_libc_gpu_build.cmake +++ b/libc/cmake/modules/prepare_libc_gpu_build.cmake @@ -42,6 +42,25 @@ if(NOT LIBC_CLANG_OFFLOAD_PACKAGER) "build") endif() +set(LIBC_GPU_TEST_ARCHITECTURE "" CACHE STRING "Architecture for the GPU tests") +if(LIBC_GPU_TEST_ARCHITECTURE) + message(STATUS "Using user-specified GPU architecture for testing " + "'${LIBC_GPU_TARGET_ARCHITECTURE}'") + if("${LIBC_GPU_TARGET_ARCHITECTURE}" IN_LIST all_amdgpu_architectures) + set(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU TRUE) + set(LIBC_GPU_TARGET_TRIPLE "amdgcn-amd-amdhsa") + set(LIBC_GPU_TARGET_ARCHITECTURE "${LIBC_GPU_TEST_ARCHITECTURE}") + elseif("${LIBC_GPU_TARGET_ARCHITECTURE}" IN_LIST all_nvptx_architectures) + set(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX TRUE) + set(LIBC_GPU_TARGET_TRIPLE "nvptx64-nvidia-cuda") + set(LIBC_GPU_TARGET_ARCHITECTURE "${LIBC_GPU_TEST_ARCHITECTURE}") + else() + message(FATAL_ERROR + "Unknown GPU architecture '${LIBC_GPU_TARGET_ARCHITECTURE}'") + endif() + return() +endif() + # Identify any locally installed AMD GPUs on the system to use for testing. find_program(LIBC_AMDGPU_ARCH NAMES amdgpu-arch -- 2.7.4