From 83af411ca7c1572c79e4a515bf17a035837aae48 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Tue, 17 Jan 2023 08:55:55 -0600 Subject: [PATCH] [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 --- .../Modules/LibomptargetGetDependencies.cmake | 22 +++++++++++++--------- openmp/libomptarget/test/lit.cfg | 2 +- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake b/openmp/libomptarget/cmake/Modules/LibomptargetGetDependencies.cmake index 60aa9e4..509cbc4 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 e359f9c..a3e0e25 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: -- 2.7.4