Skip to content

Commit

Permalink
COMP: Initialize list of CUDA architectures for maximum compatibility
Browse files Browse the repository at this point in the history
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/
  • Loading branch information
jcfr committed Feb 13, 2024
1 parent 0aea242 commit 22b1a41
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions libautoscoper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 22b1a41

Please sign in to comment.