Skip to content

Commit

Permalink
ENH: Update Autoscoper modernizing CUDA integration
Browse files Browse the repository at this point in the history
This commit updates the Autoscoper project by replacing the deprecated
FindCUDA CMake module with the more robust and first-class support for
CUDA language. The changes leverage the following key features introduced
in various CMake versions:

- 3.8: Support by the Makefile Generators and the Ninja generator
  on Linux, macOS, and Windows
  See https://cmake.org/cmake/help/latest/release/3.8.html#cuda\

- 3.9: Support by the Visual Studio Generators for VS 2010 and above.
  See https://cmake.org/cmake/help/latest/release/3.9.html#languages

- 3.17: Introduction of FindCUDAToolkit
  See https://cmake.org/cmake/help/latest/release/3.17.html#modules
  and https://cmake.org/cmake/help/latest/module/FindCUDAToolkit.html#module:FindCUDAToolkit

* 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

List of Autoscoper changes:

```
$ git shortlog 7df4365..22b1a41e0 --no-merges
Jean-Christophe Fillion-Robin (4):
      COMP: Update minimum CMake version from 3.8 to 3.17.5
      COMP: Modernize CUDA integration using FindCUDAToolkit CMake module
      COMP: Update minimum CMake version from 3.17.5 to 3.20.6
      COMP: Initialize list of CUDA architectures for maximum compatibility
```
  • Loading branch information
jcfr committed Feb 13, 2024
1 parent 1b3eaa4 commit f732df9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.13.4)
cmake_minimum_required(VERSION 3.20.6)

project(SlicerAutoscoperM)

Expand Down
29 changes: 24 additions & 5 deletions SuperBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,32 @@ set(${proj}_DEPENDS
)

if(DEFINED ENV{SlicerAutoscoperM_CUDA_PATH})
set(ENV{CUDA_PATH} $ENV{SlicerAutoscoperM_CUDA_PATH})
file(TO_CMAKE_PATH "$ENV{SlicerAutoscoperM_CUDA_PATH}" _cuda_path)
if(CMAKE_GENERATOR MATCHES "Visual Studio")
# https://cmake.org/cmake/help/latest/variable/CMAKE_GENERATOR_TOOLSET.html#visual-studio-toolset-selection
if(NOT "${CMAKE_GENERATOR_TOOLSET}" MATCHES "cuda=")
set(_generator_toolset_key_value "cuda=${_cuda_path}")
if(NOT "${CMAKE_GENERATOR_TOOLSET}" STREQUAL "")
set(CMAKE_GENERATOR_TOOLSET "${CMAKE_GENERATOR_TOOLSET},${_generator_toolset_key_value}")
else()
set(CMAKE_GENERATOR_TOOLSET "${_generator_toolset_key_value}")
endif()
endif()
else()
# See https://cmake.org/cmake/help/latest/envvar/CUDACXX.html#cudacxx
set(ENV{CUDACXX} $ENV{_cuda_path}/bin/nvcc)
endif()
endif()

find_package(CUDA)
if(CUDA_FOUND)
# Variable expected by find_package(CUDA) also used in Autoscoper
mark_as_superbuild(VARS CUDA_TOOLKIT_ROOT_DIR PROJECTS Autoscoper-CUDA)
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
# Variable expected by CUDA language also used in Autoscoper
if(CMAKE_GENERATOR MATCHES "Visual Studio")
mark_as_superbuild(VARS CMAKE_GENERATOR_TOOLSET PROJECTS Autoscoper-CUDA)
else()
mark_as_superbuild(VARS CMAKE_CUDA_COMPILER PROJECTS Autoscoper-CUDA)
endif()
list(APPEND ${proj}_DEPENDS
Autoscoper-CUDA
)
Expand Down
2 changes: 1 addition & 1 deletion SuperBuild/External_Autoscoper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ if(NOT DEFINED ${proj}_DIR AND NOT ${SUPERBUILD_TOPLEVEL_PROJECT}_USE_SYSTEM_${p

ExternalProject_SetIfNotDefined(
Slicer_${proj}_GIT_TAG
"7df4365ecb1919fa10cb3e67a836467db0686f2e"
"22b1a41e0b7b6a2de330f436d8834d1a0b96a3ac"
QUIET
)

Expand Down

0 comments on commit f732df9

Please sign in to comment.