Skip to content

Commit c47a6d2

Browse files
committed
CMake: 3.25+
We already use features of `FindCUDAToolkit` for nvtx3 that are CMake 3.25+. Modernize and remove pre CMake 3.20 CUDA logic.
1 parent e727197 commit c47a6d2

File tree

9 files changed

+30
-225
lines changed

9 files changed

+30
-225
lines changed

CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.18)
1+
cmake_minimum_required(VERSION 3.25)
22

33
#
44
# Setting a cmake_policy to OLD is deprecated by definition and will raise a
@@ -106,9 +106,6 @@ include( AMReXOptions )
106106
#
107107
if (AMReX_CUDA)
108108
enable_language(CUDA)
109-
if(CMAKE_VERSION VERSION_LESS 3.20)
110-
include(AMReX_SetupCUDA)
111-
endif()
112109
endif ()
113110

114111
#

Docs/sphinx_documentation/source/GPU.rst

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,7 @@ the following code into the appropriate CMakeLists.txt file:
323323

324324

325325
If instead of using an external installation of AMReX you prefer to include AMReX as a subproject
326-
in your CMake setup, we strongly encourage you to use the ``AMReX_SetupCUDA`` module as shown below
327-
if the CMake version is less than 3.20:
326+
in your CMake setup (i.e., build AMReX on the fly), do this:
328327

329328
.. highlight:: console
330329

@@ -333,12 +332,7 @@ if the CMake version is less than 3.20:
333332
# Enable CUDA in your CMake project
334333
enable_language(CUDA)
335334

336-
# Include the AMReX-provided CUDA setup module -- OBSOLETE with CMake >= 3.20
337-
if(CMAKE_VERSION VERSION_LESS 3.20)
338-
include(AMReX_SetupCUDA)
339-
endif()
340-
341-
# Include AMReX source directory ONLY AFTER the two steps above
335+
# Include AMReX source directory ONLY AFTER enable_language
342336
add_subdirectory(/path/to/amrex/source/dir)
343337

344338

Tests/CMakeTestInstall/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# building and running the code
44
# in Tests/Amr/Advection_AmrCore/
55
#
6-
cmake_minimum_required(VERSION 3.18)
6+
cmake_minimum_required(VERSION 3.25)
77

88
project(amrex-test-install)
99

Tests/SpackSmokeTest/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# against a currently installed version of AMReX. The resulting
77
# executable can then be ran to test functionality.
88

9-
cmake_minimum_required(VERSION 3.18)
9+
cmake_minimum_required(VERSION 3.25)
1010

1111
project(amrex-test-install)
1212

@@ -26,9 +26,6 @@ if (AMReX_GPU_BACKEND STREQUAL "CUDA")
2626
find_package(AMReX REQUIRED CUDA)
2727

2828
elseif(AMReX_GPU_BACKEND STREQUAL "HIP")
29-
if(CMAKE_VERSION VERSION_LESS 3.20)
30-
message(FATAL_ERROR "HIP requires CMake version 3.20 or newer")
31-
endif()
3229
find_package(AMReX REQUIRED HIP)
3330
find_package(rocrand REQUIRED CONFIG)
3431
find_package(rocprim REQUIRED CONFIG)

Tools/CMake/AMReXConfig.cmake.in

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,7 @@ endif ()
256256
#
257257
# AMReX 21.06+ supports CUDA_ARCHITECTURES
258258
if (@AMReX_CUDA@)
259-
if (CMAKE_VERSION VERSION_LESS 3.20)
260-
include(AMReX_SetupCUDA)
261-
else ()
262-
find_dependency(CUDAToolkit REQUIRED)
263-
endif ()
259+
find_dependency(CUDAToolkit REQUIRED)
264260
endif ()
265261

266262
# CMake targets
@@ -275,7 +271,7 @@ if (NOT TARGET AMReX::amrex) # protection in case of multiple inclusions
275271
endif()
276272

277273
# More Modern CUDA CMake
278-
if (@CMAKE_VERSION@ VERSION_GREATER_EQUAL 3.20 AND @AMReX_CUDA@)
274+
if (@AMReX_CUDA@)
279275
foreach(D IN LISTS AMReX_SPACEDIM)
280276
# CUDA architectures amrex was built for -- should we make
281277
set(AMREX_CUDA_ARCHS @AMREX_CUDA_ARCHS@ CACHE INTERNAL "CUDA archs AMReX is built for")

Tools/CMake/AMReXFlagsTargets.cmake

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,42 +25,21 @@ include_guard(GLOBAL)
2525
# <lang> = cxx,fortran,cuda
2626
# <id> = gnu,intel,pgi,cray,clang,appleclang,crayclang,ibmclang,intelllvm,msvc,nvidia,nvhpc,xlclang
2727
#
28-
if (CMAKE_VERSION VERSION_LESS 3.20)
29-
foreach (_language CXX Fortran CUDA )
30-
set(_comp_lang "$<COMPILE_LANGUAGE:${_language}>")
31-
string(TOLOWER "${_language}" _lang)
32-
33-
foreach (_comp GNU Intel PGI Cray Clang AppleClang CrayClang IBMClang IntelLLVM MSVC NVIDIA NVHPC XLClang )
34-
string(TOLOWER "${_comp}" _id)
35-
# Define variables
36-
set(_comp_id "$<${_language}_COMPILER_ID:${_comp}>")
37-
set(_${_lang}_${_id} "$<AND:${_comp_lang},${_comp_id}>")
38-
set(_${_lang}_${_id}_dbg "$<AND:${_comp_lang},${_comp_id},$<CONFIG:Debug>>")
39-
set(_${_lang}_${_id}_rel "$<AND:${_comp_lang},${_comp_id},$<CONFIG:Release>>")
40-
set(_${_lang}_${_id}_rwdbg "$<AND:${_comp_lang},${_comp_id},$<CONFIG:RelWithDebInfo>>")
41-
unset(_comp_id)
42-
endforeach ()
43-
44-
unset(_comp_lang)
45-
unset(_lang)
46-
endforeach ()
47-
else ()
48-
foreach (_language CXX Fortran CUDA )
49-
string(TOLOWER "${_language}" _lang)
50-
51-
foreach (_comp GNU Intel PGI Cray Clang AppleClang CrayClang IBMClang IntelLLVM MSVC NVIDIA NVHPC XLClang )
52-
string(TOLOWER "${_comp}" _id)
53-
# Define variables
54-
set(_${_lang}_${_id} "$<COMPILE_LANG_AND_ID:${_language},${_comp}>")
55-
set(_${_lang}_${_id}_dbg "$<AND:${_${_lang}_${_id}},$<CONFIG:Debug>>")
56-
set(_${_lang}_${_id}_rel "$<AND:${_${_lang}_${_id}},$<CONFIG:Release>>")
57-
set(_${_lang}_${_id}_rwdbg "$<AND:${_${_lang}_${_id}},$<CONFIG:RelWithDebInfo>>")
58-
unset(_id)
59-
endforeach ()
60-
61-
unset(_lang)
62-
endforeach ()
63-
endif ()
28+
foreach (_language CXX Fortran CUDA )
29+
string(TOLOWER "${_language}" _lang)
30+
31+
foreach (_comp GNU Intel PGI Cray Clang AppleClang CrayClang IBMClang IntelLLVM MSVC NVIDIA NVHPC XLClang )
32+
string(TOLOWER "${_comp}" _id)
33+
# Define variables
34+
set(_${_lang}_${_id} "$<COMPILE_LANG_AND_ID:${_language},${_comp}>")
35+
set(_${_lang}_${_id}_dbg "$<AND:${_${_lang}_${_id}},$<CONFIG:Debug>>")
36+
set(_${_lang}_${_id}_rel "$<AND:${_${_lang}_${_id}},$<CONFIG:Release>>")
37+
set(_${_lang}_${_id}_rwdbg "$<AND:${_${_lang}_${_id}},$<CONFIG:RelWithDebInfo>>")
38+
unset(_id)
39+
endforeach ()
40+
41+
unset(_lang)
42+
endforeach ()
6443

6544

6645
#

Tools/CMake/AMReXParallelBackends.cmake

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ endif ()
7070
#
7171
#
7272
#
73-
if ( AMReX_GPU_BACKEND STREQUAL "CUDA"
74-
AND
75-
CMAKE_VERSION VERSION_GREATER_EQUAL 3.20 )
73+
if (AMReX_GPU_BACKEND STREQUAL "CUDA")
7674

7775
find_package(CUDAToolkit REQUIRED)
7876
foreach(D IN LISTS AMReX_SPACEDIM)
@@ -82,11 +80,9 @@ if ( AMReX_GPU_BACKEND STREQUAL "CUDA"
8280
target_link_libraries(amrex_${D}d PUBLIC CUDA::cusparse)
8381
endif ()
8482

85-
if(CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 11.2)
86-
# nvToolsExt: if tiny profiler or base profiler are on.
87-
if (AMReX_TINY_PROFILE OR AMReX_BASE_PROFILE)
88-
target_link_libraries(amrex_${D}d PUBLIC CUDA::nvToolsExt)
89-
endif ()
83+
# if tiny profiler or base profiler are on we add range annotations
84+
if (AMReX_TINY_PROFILE OR AMReX_BASE_PROFILE)
85+
target_link_libraries(amrex_${D}d PUBLIC CUDA::nvtx3)
9086
endif ()
9187
endforeach()
9288

@@ -378,14 +374,9 @@ if (AMReX_HIP)
378374
foreach(D IN LISTS AMReX_SPACEDIM)
379375
target_compile_options(amrex_${D}d PUBLIC
380376
$<$<COMPILE_LANGUAGE:CXX>:-fgpu-rdc> )
381-
if(CMAKE_VERSION VERSION_LESS 3.18)
382-
target_link_options(amrex_${D}d PUBLIC
383-
-fgpu-rdc)
384-
else()
385-
target_link_options(amrex_${D}d PUBLIC
386-
"$<$<LINK_LANGUAGE:HIP>:-fgpu-rdc>"
387-
"$<$<LINK_LANGUAGE:CXX>:-fgpu-rdc>")
388-
endif()
377+
target_link_options(amrex_${D}d PUBLIC
378+
"$<$<LINK_LANGUAGE:HIP>:-fgpu-rdc>"
379+
"$<$<LINK_LANGUAGE:CXX>:-fgpu-rdc>")
389380
endforeach()
390381
endif()
391382
endif ()

Tools/CMake/AMReXTargetHelpers.cmake

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,7 @@ function (setup_target_for_cuda_compilation _target)
126126
set_target_properties( ${_target}
127127
PROPERTIES
128128
CUDA_SEPARABLE_COMPILATION ${AMReX_GPU_RDC} # This adds -dc
129+
CUDA_ARCHITECTURES "${AMREX_CUDA_ARCHS}"
129130
)
130131
set_cpp_sources_to_cuda_language(${_target})
131-
132-
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.20)
133-
set_target_properties( ${_target}
134-
PROPERTIES
135-
CUDA_ARCHITECTURES "${AMREX_CUDA_ARCHS}"
136-
)
137-
endif ()
138132
endfunction ()

Tools/CMake/AMReX_SetupCUDA.cmake

Lines changed: 0 additions & 143 deletions
This file was deleted.

0 commit comments

Comments
 (0)