[Openmp-commits] [PATCH] D142018: [Libomptarget] Only build GPU tests if a GPU is found on the system

Joseph Huber via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Jan 18 06:58:23 PST 2023


jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, ye-luo, tianshilei1992, JonChesterfield.
jhuber6 added a project: OpenMP.
Herald added subscribers: kosarev, kerbowa, tpr, jvesely.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: openmp-commits, sstefan1.

  Currently we build tests as long as the libraries are found on the
  machine. This doesn't necessarily mean there is a GPU to use though.
  This patch changes it to where we only will build the tests if we found
  a compatible GPU via `nvptx-arch` or `amdgpu-arch`.
  
  The only downside to this I could see if someone were to build LLVM on a
  home node of a cluster and then wished to run the tests after switching
  to a compute node. For this I think we should allow it to be overridden.
  I think that's better than allowing us to run tests that will fail by
  default.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142018

Files:
  openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
  openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
  openmp/libomptarget/plugins/cuda/CMakeLists.txt


Index: openmp/libomptarget/plugins/cuda/CMakeLists.txt
===================================================================
--- openmp/libomptarget/plugins/cuda/CMakeLists.txt
+++ openmp/libomptarget/plugins/cuda/CMakeLists.txt
@@ -98,7 +98,8 @@
 # This controls whether tests are run for the nvptx offloading target
 # Run them if libcuda is available, or if the user explicitly asked for dlopen
 # Otherwise this plugin is being built speculatively and there may be no cuda available
-if (LIBOMPTARGET_CAN_LINK_LIBCUDA OR LIBOMPTARGET_FORCE_DLOPEN_LIBCUDA)
+option(LIBOMPTARGET_FORCE_NVIDIA_TESTS "Build NVIDIA libomptarget tests" OFF)
+if (LIBOMPTARGET_FOUND_NVIDIA_GPU OR LIBOMPTARGET_FORCE_NVIDIA_TESTS)
   libomptarget_say("Enable tests using CUDA plugin")
   set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS} nvptx64-nvidia-cuda nvptx64-nvidia-cuda-oldDriver" PARENT_SCOPE)
   set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS} nvptx64-nvidia-cuda nvptx64-nvidia-cuda-LTO" PARENT_SCOPE)
Index: openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
===================================================================
--- openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
+++ openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
@@ -111,7 +111,8 @@
 # This controls whether tests are run for the nvptx offloading target
 # Run them if libhsa is available, or if the user explicitly asked for dlopen
 # Otherwise this plugin is being built speculatively and there may be no hsa available
-if (${hsa-runtime64_FOUND} OR LIBOMPTARGET_FORCE_DLOPEN_LIBHSA)
+option(LIBOMPTARGET_FORCE_AMDGPU_TESTS "Build AMDGPU libomptarget tests" OFF)
+if (LIBOMPTARGET_FOUND_AMDGPU_GPU OR LIBOMPTARGET_FORCE_AMDGPU_TESTS)
   # Report to the parent scope that we are building a plugin for amdgpu
   set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS} amdgcn-amd-amdhsa amdgcn-amd-amdhsa-oldDriver" PARENT_SCOPE)
   set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS} amdgcn-amd-amdhsa amdgcn-amd-amdhsa-LTO" PARENT_SCOPE)
Index: openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
===================================================================
--- openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
+++ openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
@@ -118,6 +118,7 @@
   string(SUBSTRING "${LIBOMPTARGET_NVPTX_ARCH_OUTPUT}" 0 ${first_arch_string}
          arch_string)
   if(arch_string)
+    set(LIBOMPTARGET_FOUND_NVIDIA_GPU TRUE)
     set(LIBOMPTARGET_DEP_CUDA_ARCH "${arch_string}")
   endif()
 endif()
@@ -158,6 +159,25 @@
 
 mark_as_advanced(LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES)
 
+################################################################################
+# Looking for AMD GPUs...
+################################################################################
+
+find_program(LIBOMPTARGET_AMDGPU_ARCH NAMES amdgpu-arch PATHS ${LLVM_BINARY_DIR}/bin)
+if(LIBOMPTARGET_AMDGPU_ARCH)
+  execute_process(COMMAND ${LIBOMPTARGET_AMDGPU_ARCH}
+                  OUTPUT_VARIABLE LIBOMPTARGET_AMDGPU_ARCH_OUTPUT
+                  OUTPUT_STRIP_TRAILING_WHITESPACE)
+  string(FIND "${LIBOMPTARGET_AMDGPU_ARCH_OUTPUT}" "\n" first_arch_string)
+  string(SUBSTRING "${LIBOMPTARGET_AMDGPU_ARCH_OUTPUT}" 0 ${first_arch_string}
+         arch_string)
+  if(arch_string)
+    set(LIBOMPTARGET_FOUND_AMDGPU_GPU TRUE)
+    set(LIBOMPTARGET_DEP_AMDGPU_ARCH "${arch_string}")
+  endif()
+endif()
+
+
 ################################################################################
 # Looking for VEO...
 ################################################################################


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142018.490140.patch
Type: text/x-patch
Size: 3673 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20230118/69a9ad20/attachment-0001.bin>


More information about the Openmp-commits mailing list