[Openmp-commits] [PATCH] D141933: [Libomptarget] Replace Nvidia arch lookup with 'nvptx-arch'

Joseph Huber via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Tue Jan 17 07:00:47 PST 2023


jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tianshilei1992, JonChesterfield, ye-luo.
Herald added subscribers: mattd, gchakrabarti, asavonic.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141933

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


Index: openmp/libomptarget/test/lit.cfg
===================================================================
--- openmp/libomptarget/test/lit.cfg
+++ openmp/libomptarget/test/lit.cfg
@@ -85,7 +85,7 @@
 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:
Index: openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
===================================================================
--- openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
+++ openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake
@@ -106,15 +106,19 @@
 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")
+# Identify any locally installed GPUs to use for testing.
+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}")
   else()
-    set(LIBOMPTARGET_DEP_CUDA_ARCH "${CMAKE_MATCH_1}")
+    set(LIBOMPTARGET_DEP_CUDA_ARCH "sm_35")
   endif()
 endif()
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141933.489809.patch
Type: text/x-patch
Size: 2024 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20230117/66fe51a5/attachment-0001.bin>


More information about the Openmp-commits mailing list