From 22b1a41e0b7b6a2de330f436d8834d1a0b96a3ac Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Tue, 13 Feb 2024 17:53:47 -0500 Subject: [PATCH] COMP: Initialize list of CUDA architectures for maximum compatibility To support building on system without the most recent 11.x toolkit, we specify 80 as upper bound. The changes leverage the following key features introduced in various CMake versions: * 3.18: A CMAKE_CUDA_ARCHITECTURES variable was added to specify CUDA output architectures. See https://cmake.org/cmake/help/latest/release/3.18.html#variables and https://cmake.org/cmake/help/latest/policy/CMP0104.html#policy:CMP0104 * 3.19: If CUDA compiler detection fails with user-specified CMAKE_CUDA_ARCHITECTURES or CMAKE_CUDA_HOST_COMPILER, an error is raised. See https://cmake.org/cmake/help/latest/release/3.19.html#other-changes * 3.20: The CUDAARCHS environment variable was added for initializing CMAKE_CUDA_ARCHITECTURES. Useful in cases where the compiler default is unsuitable for the machine's GPU. See https://cmake.org/cmake/help/latest/release/3.20.html#languages * 3.23: The CMAKE_CUDA_ARCHITECTURES variable and associated CUDA_ARCHITECTURES target property now support the all, and all-major values for CUDA toolkit 7.0+. See https://cmake.org/cmake/help/latest/release/3.23.html#variables References: * https://docs.nvidia.com/cuda/archive/11.8.0/cuda-c-best-practices-guide/index.html#building-for-maximum-compatibility * https://forums.developer.nvidia.com/t/how-should-i-use-correctly-the-sm-xx-and-compute-xx/219160 * https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/ --- libautoscoper/CMakeLists.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libautoscoper/CMakeLists.txt b/libautoscoper/CMakeLists.txt index 725660af..b4ea2a9f 100644 --- a/libautoscoper/CMakeLists.txt +++ b/libautoscoper/CMakeLists.txt @@ -63,6 +63,28 @@ if(Autoscoper_RENDERING_BACKEND STREQUAL "CUDA") # See https://docs.nvidia.com/cuda/archive/10.2/cuda-c-programming-guide/index.html#c-cplusplus-language-support set(CMAKE_CUDA_STANDARD 14) set(CMAKE_CUDA_STANDARD_REQUIRED TRUE) + if("$ENV{CUDAARCHS}" STREQUAL "" AND NOT DEFINED CMAKE_CUDA_ARCHITECTURES) + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.23") + set(_cuda_achitectures "all") + else() + # Adapted from https://github.com/Kitware/CMake/blob/v3.29.0-rc1/Modules/Internal/CMakeCUDAArchitecturesAll.cmake + set(_cuda_achitectures + 50 52 53 + 60 61 62 # >= 8.0 + 70 72 # >= 9.0 + 75 # >= 10.0 + 80 # >= 11.0 + # 86 # >= 11.1 + # 87 # >= 11.4 + # 88 89 # >= 11.8 + ) + # only generate jit code for the newest arch + list(POP_BACK _cuda_achitectures _latest_arch) + list(TRANSFORM _cuda_achitectures APPEND "-real") + list(APPEND _cuda_achitectures ${_latest_arch}) + endif() + set(ENV{CUDAARCHS} "${_cuda_achitectures}") + endif() enable_language(CUDA) find_package(CUDAToolkit REQUIRED) include(${CMAKE_CURRENT_SOURCE_DIR}/src/gpu/cuda/CMakeLists.txt)