[libc] Add `LIBC_GPU_TEST_ARCHITECTURE` option to set architecture
authorJoseph Huber <jhuber6@vols.utk.edu>
Mon, 6 Feb 2023 15:14:20 +0000 (09:14 -0600)
committerJoseph Huber <jhuber6@vols.utk.edu>
Mon, 6 Feb 2023 17:02:07 +0000 (11:02 -0600)
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

index 8bd7d9d..beea99d 100644 (file)
@@ -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