[Openmp-commits] [openmp] ea0eee8 - [Libomptarget] Only build GPU tests if a GPU is found on the system
Joseph Huber via Openmp-commits
openmp-commits at lists.llvm.org
Wed Jan 18 08:35:45 PST 2023
Author: Joseph Huber
Date: 2023-01-18T10:35:37-06:00
New Revision: ea0eee80d8988d16133bcb858874a1d95ede1a32
URL: https://github.com/llvm/llvm-project/commit/ea0eee80d8988d16133bcb858874a1d95ede1a32
DIFF: https://github.com/llvm/llvm-project/commit/ea0eee80d8988d16133bcb858874a1d95ede1a32.diff
LOG: [Libomptarget] Only build GPU tests if a GPU is found on the system
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.
Reviewed By: tianshilei1992
Differential Revision: https://reviews.llvm.org/D142018
Added:
Modified:
openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
openmp/libomptarget/plugins/cuda/CMakeLists.txt
Removed:
################################################################################
diff --git a/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake b/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
index 509cbc4b6e273..8677b4f1016a4 100644
--- a/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
+++ b/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
@@ -118,6 +118,7 @@ if(LIBOMPTARGET_NVPTX_ARCH)
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 @@ find_package_handle_standard_args(
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...
################################################################################
diff --git a/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt b/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
index 2c8aed883feca..4d8f9050fd004 100644
--- a/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
+++ b/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
@@ -111,7 +111,8 @@ set_target_properties(omptarget.rtl.amdgpu PROPERTIES
# 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)
diff --git a/openmp/libomptarget/plugins/cuda/CMakeLists.txt b/openmp/libomptarget/plugins/cuda/CMakeLists.txt
index 796ff690abbff..520c6b0365de2 100644
--- a/openmp/libomptarget/plugins/cuda/CMakeLists.txt
+++ b/openmp/libomptarget/plugins/cuda/CMakeLists.txt
@@ -98,7 +98,8 @@ target_include_directories(omptarget.rtl.cuda PRIVATE
# 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)
More information about the Openmp-commits
mailing list