[Openmp-commits] [openmp] 83af411 - [Libomptarget] Replace Nvidia arch lookup with 'nvptx-arch'

Joseph Huber via Openmp-commits openmp-commits at lists.llvm.org
Tue Jan 17 10:38:44 PST 2023


Author: Joseph Huber
Date: 2023-01-17T12:38:34-06:00
New Revision: 83af411ca7c1572c79e4a515bf17a035837aae48

URL: https://github.com/llvm/llvm-project/commit/83af411ca7c1572c79e4a515bf17a035837aae48
DIFF: https://github.com/llvm/llvm-project/commit/83af411ca7c1572c79e4a515bf17a035837aae48.diff

LOG: [Libomptarget] Replace Nvidia arch lookup with 'nvptx-arch'

This method to look up the CUDA architecture is deprecated in newer
versions of CMake. We also have our own way to query this information
that we control now via the `nvptx-arch` program, which should always be
present in LLVM builds with clang going forward. This is currently only
used for testing so I think we should be okay with the dependency.

Reviewed By: tianshilei1992

Differential Revision: https://reviews.llvm.org/D141933

Added: 
    

Modified: 
    openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
    openmp/libomptarget/test/lit.cfg

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake b/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
index 60aa9e4de9331..509cbc4b6e273 100644
--- a/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
+++ b/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
@@ -106,15 +106,19 @@ if (CUDA_TOOLKIT_ROOT_DIR)
 endif()
 find_package(CUDA QUIET)
 
-# Try to get the highest Nvidia GPU architecture the system supports
-if (CUDA_FOUND)
-  cuda_select_nvcc_arch_flags(CUDA_ARCH_FLAGS)
-  string(REGEX MATCH "sm_([0-9]+)" CUDA_ARCH_MATCH_OUTPUT ${CUDA_ARCH_FLAGS})
-  if (NOT DEFINED CUDA_ARCH_MATCH_OUTPUT OR "${CMAKE_MATCH_1}" LESS 35)
-    libomptarget_warning_say("Setting Nvidia GPU architecture support for OpenMP target runtime library to sm_35 by default")
-    set(LIBOMPTARGET_DEP_CUDA_ARCH "35")
-  else()
-    set(LIBOMPTARGET_DEP_CUDA_ARCH "${CMAKE_MATCH_1}")
+# Identify any locally installed GPUs to use for testing.
+set(LIBOMPTARGET_DEP_CUDA_ARCH "sm_35")
+
+find_program(LIBOMPTARGET_NVPTX_ARCH NAMES nvptx-arch PATHS ${LLVM_BINARY_DIR}/bin)
+if(LIBOMPTARGET_NVPTX_ARCH)
+  execute_process(COMMAND ${LIBOMPTARGET_NVPTX_ARCH}
+                  OUTPUT_VARIABLE LIBOMPTARGET_NVPTX_ARCH_OUTPUT
+                  OUTPUT_STRIP_TRAILING_WHITESPACE)
+  string(FIND "${LIBOMPTARGET_NVPTX_ARCH_OUTPUT}" "\n" first_arch_string)
+  string(SUBSTRING "${LIBOMPTARGET_NVPTX_ARCH_OUTPUT}" 0 ${first_arch_string}
+         arch_string)
+  if(arch_string)
+    set(LIBOMPTARGET_DEP_CUDA_ARCH "${arch_string}")
   endif()
 endif()
 

diff  --git a/openmp/libomptarget/test/lit.cfg b/openmp/libomptarget/test/lit.cfg
index e359f9c798f0f..a3e0e25db5aae 100644
--- a/openmp/libomptarget/test/lit.cfg
+++ b/openmp/libomptarget/test/lit.cfg
@@ -85,7 +85,7 @@ config.available_features.add(config.libomptarget_current_target)
 supports_unified_shared_memory = True
 if config.libomptarget_current_target.startswith('nvptx'):
   try:
-    cuda_arch = int(config.cuda_test_arch)
+    cuda_arch = int(config.cuda_test_arch[:3])
     if cuda_arch < 70:
       supports_unified_shared_memory = False
   except ValueError:


        


More information about the Openmp-commits mailing list