diff --git a/.clang-tidy b/.clang-tidy
index 789c891ab1..a996e64c0a 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -9,6 +9,7 @@ Checks: |
-bugprone-easily-swappable-parameters,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-macro-parentheses,
+ -bugprone-reserved-identifier,
clang-analyzer-alpha.*,
modernize-deprecated-headers,
modernize-make-shared,
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index c0789c2a4c..462961f962 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -196,9 +196,9 @@ clang-sanitizer:
variables:
CC: 'clang-14'
CXX: 'clang++-14'
+ CUDAXX: 'clang++-14'
myconfig: 'maxset'
with_cuda: 'true'
- with_cuda_compiler: 'clang'
with_coverage: 'false'
with_static_analysis: 'true'
check_skip_long: 'true'
@@ -427,9 +427,9 @@ empty:
variables:
CC: 'clang-14'
CXX: 'clang++-14'
+ CUDAXX: 'clang++-14'
myconfig: 'empty'
with_cuda: 'true'
- with_cuda_compiler: 'clang'
with_static_analysis: 'true'
with_scafacos: 'false'
with_stokesian_dynamics: 'false'
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d66955f672..1a60aaece9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -177,17 +177,49 @@ endforeach()
# CUDA compiler
if(ESPRESSO_BUILD_WITH_CUDA)
+ set(ESPRESSO_DEFINE_CUDA_ARCHITECTURES OFF)
+ if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
+ set(ESPRESSO_DEFINE_CUDA_ARCHITECTURES ON)
+ endif()
+ include(CheckLanguage)
enable_language(CUDA)
+ check_language(CUDA)
set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD})
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
set(ESPRESSO_MINIMAL_CUDA_VERSION 11.0)
find_package(CUDAToolkit ${ESPRESSO_MINIMAL_CUDA_VERSION} REQUIRED)
- espresso_option_enum(
- varname "ESPRESSO_CUDA_COMPILER" help_text "CUDA compiler" default_value
- "nvcc" possible_values "nvcc;clang")
- if(ESPRESSO_CUDA_COMPILER STREQUAL "nvcc")
+ if(ESPRESSO_DEFINE_CUDA_ARCHITECTURES)
+ unset(ESPRESSO_CUDA_ARCHITECTURES)
+ # 1. sm_75: RTX-2000 series (Turing)
+ # 2. sm_61: GTX-1000 series (Pascal)
+ # 3. sm_52: GTX-900 series (Maxwell)
+ if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
+ list(APPEND ESPRESSO_CUDA_ARCHITECTURES 75)
+ list(APPEND ESPRESSO_CUDA_ARCHITECTURES 61)
+ elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang")
+ # GTX-900 series (Maxwell)
+ if(CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 12)
+ list(APPEND ESPRESSO_CUDA_ARCHITECTURES 52)
+ endif()
+ if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 10)
+ list(APPEND ESPRESSO_CUDA_ARCHITECTURES 61)
+ # With Clang 14+, architectures sm_70+ are only supported with Thrust
+ # 1.11+ from CUDA 11.3+, for details see
+ # https://github.com/NVIDIA/cub/pull/170
+ if((CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 14)
+ OR (CUDAToolkit_VERSION VERSION_GREATER_EQUAL 11.3.0))
+ list(APPEND ESPRESSO_CUDA_ARCHITECTURES 75)
+ endif()
+ endif()
+ endif()
+ # only override CMAKE_CUDA_ARCHITECTURES when dependencies are satisfied
+ if(DEFINED ESPRESSO_CUDA_ARCHITECTURES)
+ set(CMAKE_CUDA_ARCHITECTURES ${ESPRESSO_CUDA_ARCHITECTURES})
+ endif()
+ endif()
+ if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
find_package(CUDACompilerNVCC ${ESPRESSO_MINIMAL_CUDA_VERSION} REQUIRED)
- elseif(ESPRESSO_CUDA_COMPILER STREQUAL "clang")
+ elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang")
if(ESPRESSO_BUILD_WITH_COVERAGE)
message(
FATAL_ERROR
@@ -195,7 +227,7 @@ if(ESPRESSO_BUILD_WITH_CUDA)
endif()
find_package(CUDACompilerClang 9.0 REQUIRED)
else()
- message(FATAL_ERROR "Unknown CUDA compiler '${ESPRESSO_CUDA_COMPILER}'")
+ message(FATAL_ERROR "Unknown CUDA compiler '${CMAKE_CUDA_COMPILER_ID}'")
endif()
endif()
diff --git a/cmake/FindCUDACompilerClang.cmake b/cmake/FindCUDACompilerClang.cmake
index 5f69984e10..113eefde46 100644
--- a/cmake/FindCUDACompilerClang.cmake
+++ b/cmake/FindCUDACompilerClang.cmake
@@ -19,69 +19,74 @@
# along with this program. If not, see .
#
-# Find the Clang compiler, include its libraries and declare a custom
-# `add_library()` wrapper function named `add_gpu_library()`.
+# Verify the Clang compiler matches the NVIDIA toolkit,
+# include the toolkit libraries and declare a custom
+# `add_library()` wrapper function named `espresso_add_gpu_library()`.
-if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+if(NOT CMAKE_CXX_COMPILER_ID STREQUAL CMAKE_CUDA_COMPILER_ID)
message(
FATAL_ERROR
- "To compile CUDA code with Clang, the C++ compiler must be Clang, not ${CMAKE_CXX_COMPILER_ID}."
+ "To compile CUDA code with ${CMAKE_CUDA_COMPILER_ID}, the C++ compiler must be ${CMAKE_CUDA_COMPILER_ID}, not ${CMAKE_CXX_COMPILER_ID}."
)
endif()
add_library(espresso_cuda_flags INTERFACE)
add_library(espresso::cuda_flags ALIAS espresso_cuda_flags)
-function(detect_clang_cuda_path)
- execute_process(COMMAND ${CMAKE_CUDA_COMPILER} ${CMAKE_CXX_FLAGS} --verbose
- ERROR_VARIABLE CLANG_VERBOSE_OUTPUT)
- if(CLANG_VERBOSE_OUTPUT MATCHES "Found CUDA installation")
- set(CLANG_VERBOSE_OUTPUT ${CLANG_VERBOSE_OUTPUT} PARENT_SCOPE)
- return()
- endif()
- if(NOT CMAKE_CXX_FLAGS MATCHES "--cuda-path")
- foreach(unix_cuda_path /usr/lib/cuda /usr/local/cuda)
- if(EXISTS ${unix_cuda_path})
- execute_process(COMMAND ${CMAKE_CUDA_COMPILER} ${CMAKE_CXX_FLAGS}
- "--cuda-path=${unix_cuda_path}" --verbose
- ERROR_VARIABLE CLANG_VERBOSE_OUTPUT)
- if(CLANG_VERBOSE_OUTPUT MATCHES "Found CUDA installation")
- set(CLANG_VERBOSE_OUTPUT ${CLANG_VERBOSE_OUTPUT} PARENT_SCOPE)
- message(STATUS "Clang did not automatically detect a compatible CUDA library; adding compiler flag --cuda-path=${unix_cuda_path}")
- target_compile_options(espresso_cuda_flags INTERFACE "--cuda-path=${unix_cuda_path}")
- return()
+function(espresso_detect_clang_cuda_path)
+ separate_arguments(ESPRESSO_CMAKE_CUDA_FLAGS_LIST NATIVE_COMMAND "${CMAKE_CUDA_FLAGS}")
+ execute_process(COMMAND ${CMAKE_CUDA_COMPILER} ${ESPRESSO_CMAKE_CUDA_FLAGS_LIST} ${ARGV} --verbose
+ ERROR_VARIABLE ESPRESSO_CLANG_VERBOSE_OUTPUT)
+ set(ESPRESSO_CLANG_VERBOSE_OUTPUT ${ESPRESSO_CLANG_VERBOSE_OUTPUT} PARENT_SCOPE)
+endfunction()
+
+espresso_detect_clang_cuda_path()
+if(NOT ESPRESSO_CLANG_VERBOSE_OUTPUT MATCHES "Found CUDA installation")
+ unset(ESPRESSO_CLANG_HINT_CUDA_PATHS)
+ if(NOT CMAKE_CUDA_FLAGS MATCHES "--cuda-path")
+ foreach(ESPRESSO_UNIX_CUDA_PATH ${CUDAToolkit_ROOT} /usr/lib/cuda /usr/local/cuda)
+ if(EXISTS ${ESPRESSO_UNIX_CUDA_PATH})
+ espresso_detect_clang_cuda_path("--cuda-path=${ESPRESSO_UNIX_CUDA_PATH}")
+ if(ESPRESSO_CLANG_VERBOSE_OUTPUT MATCHES "Found CUDA installation")
+ list(APPEND ESPRESSO_CLANG_HINT_CUDA_PATHS "${ESPRESSO_UNIX_CUDA_PATH}")
endif()
endif()
endforeach()
endif()
-endfunction()
-
-set(CMAKE_CUDA_COMPILER ${CMAKE_CXX_COMPILER})
-set(CMAKE_CUDA_COMPILER_VERSION ${CMAKE_CXX_COMPILER_VERSION})
+ set(ESPRESSO_CLANG_HINT_CUDA_PATHS_STR "")
+ if(DEFINED ESPRESSO_CLANG_HINT_CUDA_PATHS)
+ list(JOIN ESPRESSO_CLANG_HINT_CUDA_PATHS " " ESPRESSO_CLANG_HINT_CUDA_PATHS_STR)
+ set(ESPRESSO_CLANG_HINT_CUDA_PATHS_STR " (possible paths: ${ESPRESSO_CLANG_HINT_CUDA_PATHS_STR})")
+ endif()
+ message(FATAL_ERROR "${CMAKE_CUDA_COMPILER_ID} could not automatically detect a compatible CUDA library; try hinting one with both '-D CUDAToolkit_ROOT=\"...\"' and '-D CMAKE_CUDA_FLAGS=\"--cuda-path=...\"'${ESPRESSO_CLANG_HINT_CUDA_PATHS_STR}.")
+endif()
-detect_clang_cuda_path()
-string(REGEX REPLACE "^.*Found CUDA installation: ([^,]+).*\$" "\\1" CUDA_DIR
- "${CLANG_VERBOSE_OUTPUT}")
+string(REGEX REPLACE "^.*Found CUDA installation: ([^,]+).*\$" "\\1"
+ ESPRESSO_CLANG_DETECTED_CUDA_DIR "${ESPRESSO_CLANG_VERBOSE_OUTPUT}")
string(REGEX REPLACE "^.*Found CUDA installation: .* version ([0-9\.]+|unknown).*\$"
- "\\1" CUDA_VERSION "${CLANG_VERBOSE_OUTPUT}")
-message(STATUS "Found CUDA-capable host compiler: ${CMAKE_CUDA_COMPILER}")
-if(NOT CLANG_VERBOSE_OUTPUT MATCHES "Found CUDA installation" OR CUDA_VERSION STREQUAL "unknown")
- message(STATUS "Clang did not automatically detect a compatible CUDA library; adding compiler flag -Wno-unknown-cuda-version")
- target_compile_options(espresso_cuda_flags INTERFACE -Wno-unknown-cuda-version)
- message(STATUS "Found CUDA version: ${CUDAToolkit_VERSION}")
- message(STATUS "Found CUDA installation: ${CUDAToolkit_LIBRARY_DIR}")
-else()
- if(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "12.0.0" AND
- CMAKE_CUDA_COMPILER_VERSION VERSION_LESS "13.0.0" AND
- CUDA_VERSION VERSION_GREATER_EQUAL "11.0" AND
- CUDA_VERSION VERSION_LESS "12.0")
- message(STATUS "Clang ${CMAKE_CXX_COMPILER_VERSION} doesn't natively support CUDA ${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}; adding compiler flag -Wno-unknown-cuda-version")
+ "\\1" ESPRESSO_CLANG_DETECTED_CUDA_VERSION "${ESPRESSO_CLANG_VERBOSE_OUTPUT}")
+
+if(NOT "${ESPRESSO_CLANG_DETECTED_CUDA_DIR}" STREQUAL "${CUDAToolkit_ROOT}")
+ set(ESPRESSO_CUDA_TOOLKIT_MISMATCH_WARN "${CMAKE_CUDA_COMPILER_ID} CUDA toolkit directory (${ESPRESSO_CLANG_DETECTED_CUDA_DIR}) and NVIDIA CUDA toolkit directory (${CUDAToolkit_ROOT}) don't match")
+ if("${CUDAToolkit_ROOT}" STREQUAL "")
+ message(WARNING "${ESPRESSO_CUDA_TOOLKIT_MISMATCH_WARN}; try hinting it with '-D CUDAToolkit_ROOT=\"${ESPRESSO_CLANG_DETECTED_CUDA_DIR}\"'.")
+ else()
+ message(WARNING "${ESPRESSO_CUDA_TOOLKIT_MISMATCH_WARN}; try hinting it with '-D CMAKE_CUDA_FLAGS=\"--cuda-path=${CUDAToolkit_ROOT}\"'.")
+ endif()
+endif()
+
+if(NOT CMAKE_CUDA_FLAGS MATCHES "-Wno-unknown-cuda-version")
+ set(ESPRESSO_CUDA_TOOLKIT_UNKNOWN_WARN "use '-D CMAKE_CUDA_FLAGS=\"-Wno-unknown-cuda-version\"' to override this check")
+ if(ESPRESSO_CLANG_DETECTED_CUDA_VERSION STREQUAL "unknown")
+ message(FATAL_ERROR "${CMAKE_CUDA_COMPILER_ID} could not detect the version of the CUDA toolkit library; ${ESPRESSO_CUDA_TOOLKIT_UNKNOWN_WARN}")
+ elseif(CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL "12.0.0" AND
+ CMAKE_CUDA_COMPILER_VERSION VERSION_LESS "13.0.0" AND
+ ESPRESSO_CLANG_DETECTED_CUDA_VERSION VERSION_LESS "12.0")
+ message(WARNING "${CMAKE_CUDA_COMPILER_ID} ${CMAKE_CUDA_COMPILER_VERSION} doesn't natively support CUDA ${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}; ${ESPRESSO_CUDA_TOOLKIT_UNKNOWN_WARN}.")
target_compile_options(espresso_cuda_flags INTERFACE -Wno-unknown-cuda-version)
endif()
- message(STATUS "Found CUDA version: ${CUDAToolkit_VERSION} (recognized by Clang as ${CUDA_VERSION})")
- message(STATUS "Found CUDA installation: ${CUDA_DIR}")
endif()
-set(CUDA_VERSION ${CUDAToolkit_VERSION})
+message(STATUS "Found CUDA toolkit installation: ${ESPRESSO_CLANG_DETECTED_CUDA_DIR} (recognized by ${CMAKE_CUDA_COMPILER_ID} as CUDA ${ESPRESSO_CLANG_DETECTED_CUDA_VERSION})")
target_compile_options(
espresso_cuda_flags
@@ -92,14 +97,6 @@ target_compile_options(
$<$:-O2 -g -DNDEBUG>
$<$:-O3 -g>
$<$:-O3 -g>
- # GTX-900 series (Maxwell)
- $<$:--cuda-gpu-arch=sm_52>
- # GTX-1000 series (Pascal)
- $<$:--cuda-gpu-arch=sm_61>
- # RTX-2000 series (Turing)
- # With Clang 14+, architectures sm_70+ are only supported with Thrust 1.11+
- # from CUDA 11.3+, for details see https://github.com/NVIDIA/cub/pull/170
- $<$,$,$>>:--cuda-gpu-arch=sm_75>
)
function(espresso_add_gpu_library)
@@ -110,7 +107,7 @@ function(espresso_add_gpu_library)
list(GET ARG_UNPARSED_ARGUMENTS 0 TARGET_NAME)
list(REMOVE_AT ARG_UNPARSED_ARGUMENTS 0)
set(TARGET_SOURCES ${ARG_UNPARSED_ARGUMENTS})
- set_source_files_properties(${TARGET_SOURCES} PROPERTIES LANGUAGE "CXX")
+ set_source_files_properties(${TARGET_SOURCES} PROPERTIES LANGUAGE "CUDA")
add_library(${ARGV})
set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE "CXX")
target_link_libraries(${TARGET_NAME} PRIVATE espresso::cuda_flags)
diff --git a/cmake/FindCUDACompilerNVCC.cmake b/cmake/FindCUDACompilerNVCC.cmake
index 92dddbfdd2..e994127294 100644
--- a/cmake/FindCUDACompilerNVCC.cmake
+++ b/cmake/FindCUDACompilerNVCC.cmake
@@ -19,32 +19,23 @@
# along with this program. If not, see .
#
-# Find the NVCC compiler, include its libraries and declare a custom
-# `add_library()` wrapper function named `add_gpu_library()`.
+# Verify the NVCC compiler matches the NVIDIA toolkit,
+# include the toolkit libraries and declare a custom
+# `add_library()` wrapper function named `espresso_add_gpu_library()`.
-set(CMAKE_CUDA_COMPILER ${CUDAToolkit_NVCC_EXECUTABLE})
-
-execute_process(COMMAND ${CMAKE_CUDA_COMPILER} --version
- OUTPUT_VARIABLE NVCC_VERSION_STRING)
-
-string(REGEX
- REPLACE "^.*Cuda compilation tools, release [0-9\.]+, V([0-9\.]+).*\$"
- "\\1" CMAKE_CUDA_COMPILER_VERSION "${NVCC_VERSION_STRING}")
-
-get_filename_component(CMAKE_CUDA_COMPILER_TOOLKIT "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc" REALPATH)
-get_filename_component(CMAKE_CUDA_COMPILER_RESOLVED "${CMAKE_CUDA_COMPILER}" REALPATH)
-if(NOT "${CMAKE_CUDA_COMPILER_TOOLKIT}" STREQUAL "${CMAKE_CUDA_COMPILER_RESOLVED}"
+get_filename_component(ESPRESO_CUDAToolkit_ROOT_RESOLVED "${CUDAToolkit_ROOT}/bin/nvcc" REALPATH)
+get_filename_component(ESPRESO_CMAKE_CUDA_COMPILER_RESOLVED "${CMAKE_CUDA_COMPILER}" REALPATH)
+if(NOT "${ESPRESO_CUDAToolkit_ROOT_RESOLVED}" STREQUAL "${ESPRESO_CMAKE_CUDA_COMPILER_RESOLVED}"
AND NOT ESPRESSO_INSIDE_DOCKER)
- get_filename_component(NVCC_EXECUTABLE_DIRNAME "${CMAKE_CUDA_COMPILER}" DIRECTORY)
- get_filename_component(NVCC_EXECUTABLE_DIRNAME "${NVCC_EXECUTABLE_DIRNAME}" DIRECTORY)
+ get_filename_component(ESPRESSO_NVCC_EXECUTABLE_DIRNAME "${CMAKE_CUDA_COMPILER}" DIRECTORY)
+ get_filename_component(ESPRESSO_NVCC_EXECUTABLE_DIRNAME "${ESPRESSO_NVCC_EXECUTABLE_DIRNAME}" DIRECTORY)
message(
WARNING
- "Your nvcc (${CMAKE_CUDA_COMPILER}) does not appear to match your CUDA libraries (in ${CUDA_TOOLKIT_ROOT_DIR}). While ESPResSo will still compile, you might get unexpected crashes. Please point CUDA_TOOLKIT_ROOT_DIR to your CUDA toolkit path, e.g. by adding -DCUDA_TOOLKIT_ROOT_DIR='${NVCC_EXECUTABLE_DIRNAME}' to your cmake command."
+ "Your nvcc compiler (${CMAKE_CUDA_COMPILER}) does not appear to match your CUDA toolkit installation (${CUDAToolkit_ROOT}). While ESPResSo will still compile, you might get unexpected crashes. Try hinting it with '-D CUDAToolkit_ROOT=\"${ESPRESSO_NVCC_EXECUTABLE_DIRNAME}\"'."
)
endif()
set(CUDA_LINK_LIBRARIES_KEYWORD PUBLIC)
-
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
add_library(espresso_cuda_flags INTERFACE)
@@ -58,7 +49,6 @@ target_compile_options(
$<$:-Xptxas=-O2 -Xcompiler=-O2,-g -DNDEBUG>
$<$:-Xptxas=-O3 -Xcompiler=-Og,-g>
$<$:-Xptxas=-O3 -Xcompiler=-O3,-g>
- "--compiler-bindir=${CMAKE_CXX_COMPILER}"
$<$:-Xcompiler=-Werror;-Xptxas=-Werror>
$<$:-Xcompiler=-isysroot;-Xcompiler=${CMAKE_OSX_SYSROOT}>
)
@@ -68,12 +58,6 @@ function(espresso_add_gpu_library)
set(TARGET_NAME ${ARGV0})
set_target_properties(${TARGET_NAME} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(${TARGET_NAME} PRIVATE espresso::cuda_flags)
- list(APPEND cuda_archs 75) # RTX-2000 series (Turing)
- list(APPEND cuda_archs 61) # GTX-1000 series (Pascal)
- if(CMAKE_CUDA_COMPILER_VERSION LESS 11)
- list(APPEND cuda_archs 52) # GTX-900 series (Maxwell)
- endif()
- set_target_properties(${TARGET_NAME} PROPERTIES CUDA_ARCHITECTURES "${cuda_archs}")
endfunction()
include(FindPackageHandleStandardArgs)
diff --git a/doc/sphinx/installation.rst b/doc/sphinx/installation.rst
index ada9255942..dd5a541e0f 100644
--- a/doc/sphinx/installation.rst
+++ b/doc/sphinx/installation.rst
@@ -129,35 +129,42 @@ Later in the installation instructions, you will see CMake commands of the form
to activate CUDA. These commands may need to be adapted depending on which
operating system and CUDA version you are using.
+You can control the list of CUDA architectures to generate device code for.
+For example, ``-D CMAKE_CUDA_ARCHITECTURES=61;75`` will generate device code
+for both sm_61 and sm_75 architectures.
+
On Ubuntu 22.04, the default GCC compiler is too recent for nvcc and will fail
to compile sources that rely on ``std::function``. You can either use GCC 10:
.. code-block:: bash
- CC=gcc-10 CXX=g++-10 cmake .. -D ESPRESSO_BUILD_WITH_CUDA=ON
-
-or alternatively install Clang 12 as a replacement for nvcc and GCC:
-
-.. code-block:: bash
-
- CC=clang-12 CXX=clang++-12 cmake .. \
- -D ESPRESSO_BUILD_WITH_CUDA=ON -D ESPRESSO_CUDA_COMPILER=clang
-
-On systems with multiple CUDA releases installed, it is possible to select a
-specific one by providing custom paths to the compiler and toolkit:
-
-.. code-block:: bash
-
- CUDACXX=/usr/local/cuda-11.5/bin/nvcc \
- cmake .. -D ESPRESSO_BUILD_WITH_CUDA=ON -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-11.5
+ CC=gcc-10 CXX=g++-10 CUDACXX=/usr/local/cuda-11.5/bin/nvcc cmake .. \
+ -D ESPRESSO_BUILD_WITH_CUDA=ON \
+ -D CUDAToolkit_ROOT=/usr/local/cuda-11.5 \
+ -D CMAKE_CUDA_FLAGS="--compiler-bindir=/usr/bin/g++-10"
-Alternatively for Clang:
+or alternatively install Clang 14 as a replacement for nvcc and GCC:
.. code-block:: bash
- CC=clang-12 CXX=clang++-12 CUDACXX=clang++-12 CUDAToolkit_ROOT=/usr/local/cuda-11.5 \
- cmake .. -D ESPRESSO_BUILD_WITH_CUDA=ON -D ESPRESSO_CUDA_COMPILER=clang \
- -D CMAKE_CXX_FLAGS=--cuda-path=/usr/local/cuda-11.5
+ CC=clang-14 CXX=clang++-14 CUDACXX=clang++-14 cmake .. \
+ -D ESPRESSO_BUILD_WITH_CUDA=ON \
+ -D CUDAToolkit_ROOT=/usr/local/cuda-11.5 \
+ -D CMAKE_CXX_FLAGS="-I/usr/include/x86_64-linux-gnu/c++/10 -I/usr/include/c++/10 --cuda-path=/usr/local/cuda-11.5" \
+ -D CMAKE_CUDA_FLAGS="-I/usr/include/x86_64-linux-gnu/c++/10 -I/usr/include/c++/10 --cuda-path=/usr/local/cuda-11.5"
+
+Please note that all CMake options and compiler flags that involve
+``/usr/local/cuda-*`` need to be adapted to your CUDA environment.
+But they are only necessary on systems with multiple CUDA releases installed,
+and can be safely removed if you have only one CUDA release installed.
+
+Please also note that with Clang, you still need the GCC 10 toolchain,
+which can be set up with ``apt install gcc-10 g++-10 libstdc++-10-dev``.
+The extra compiler flags in the Clang CMake command above are needed to pin
+the search paths of Clang. By default, it searches trough the most recent
+GCC version, which is GCC 12 on Ubuntu 22.04. It is not possible to install
+the NVIDIA driver without GCC 12 due to a dependency resolution issue
+(``nvidia-dkms`` depends on ``dkms`` which depends on ``gcc-12``).
.. _Requirements for building the documentation:
@@ -770,7 +777,6 @@ The following options control how the project is built and tested:
* ``ESPRESSO_BUILD_WITH_CCACHE``: Enable compiler cache for faster rebuilds.
* ``ESPRESSO_BUILD_TESTS``: Enable C++ and Python tests.
* ``ESPRESSO_BUILD_BENCHMARKS``: Enable benchmarks.
-* ``ESPRESSO_CUDA_COMPILER`` (string): Select the CUDA compiler.
* ``ESPRESSO_CTEST_ARGS`` (string): Arguments passed to the ``ctest`` command.
* ``ESPRESSO_TEST_TIMEOUT``: Test timeout.
* ``ESPRESSO_ADD_OMPI_SINGLETON_WARNING``: Add a runtime warning in the
@@ -780,9 +786,11 @@ The following options control how the project is built and tested:
* ``ESPRESSO_MYCONFIG_NAME`` (string): Filename of the user-provided config file
* ``MPIEXEC_PREFLAGS``, ``MPIEXEC_POSTFLAGS`` (strings): Flags passed to the
``mpiexec`` command in MPI-parallel tests and benchmarks.
-* ``CMAKE_CXX_FLAGS`` (string): Flags passed to the compilers.
* ``CMAKE_BUILD_TYPE`` (string): Build type. Default is ``Release``.
-* ``CUDA_TOOLKIT_ROOT_DIR`` (string): Path to the CUDA toolkit directory.
+* ``CMAKE_CXX_FLAGS`` (string): Flags passed to the C++ compiler.
+* ``CMAKE_CUDA_FLAGS`` (string): Flags passed to the CUDA compiler.
+* ``CMAKE_CUDA_ARCHITECTURES`` (list): Semicolon-separated list of architectures to generate device code for.
+* ``CUDAToolkit_ROOT`` (string): Path to the CUDA toolkit directory.
Most of these options are opt-in, meaning their default value is set to
``OFF`` in the :file:`CMakeLists.txt` file. These options can be modified
@@ -793,16 +801,15 @@ by calling ``cmake`` with the command line argument ``-D``:
cmake -D ESPRESSO_BUILD_WITH_HDF5=OFF ..
When an option is enabled, additional options may become available.
-For example with ``-D ESPRESSO_BUILD_WITH_CUDA=ON``, one can choose the CUDA
-compiler with ``-D ESPRESSO_CUDA_COMPILER=``, where
-```` can be ``nvcc`` (default) or ``clang``.
+For example with ``-D ESPRESSO_BUILD_TESTS=ON``, one can specify
+the CTest parameters with ``-D ESPRESSO_CTEST_ARGS=-j$(nproc)``.
Environment variables can be passed to CMake. For example, to select Clang, use
-``CC=clang CXX=clang++ cmake .. -D ESPRESSO_BUILD_WITH_CUDA=ON -D ESPRESSO_CUDA_COMPILER=clang``.
+``CC=clang CXX=clang++ CUDACXX=clang++ cmake .. -D ESPRESSO_BUILD_WITH_CUDA=ON``.
If you have multiple versions of the CUDA library installed, you can select the
correct one with ``CUDA_BIN_PATH=/usr/local/cuda-11.5 cmake .. -D ESPRESSO_BUILD_WITH_CUDA=ON``
(with Clang as the CUDA compiler, you also need to override its default CUDA
-path with ``-D CMAKE_CXX_FLAGS=--cuda-path=/usr/local/cuda-11.5``).
+path with ``-D CMAKE_CUDA_FLAGS=--cuda-path=/usr/local/cuda-11.5``).
.. _Build types and compiler flags:
diff --git a/maintainer/CI/build_cmake.sh b/maintainer/CI/build_cmake.sh
index a84cd6096e..65d035467e 100755
--- a/maintainer/CI/build_cmake.sh
+++ b/maintainer/CI/build_cmake.sh
@@ -213,7 +213,10 @@ else
fi
if [ "${with_cuda}" = true ]; then
- cmake_params="-D ESPRESSO_BUILD_WITH_CUDA=ON -D ESPRESSO_CUDA_COMPILER=${with_cuda_compiler} ${cmake_params}"
+ cmake_params="-D ESPRESSO_BUILD_WITH_CUDA=ON -D CUDAToolkit_ROOT=/usr/lib/cuda ${cmake_params}"
+ if [ "${CUDACXX}" = "" ]; then
+ cmake_params="-D CMAKE_CUDA_FLAGS='--compiler-bindir=/usr/bin/g++-10' ${cmake_params}"
+ fi
else
cmake_params="-D ESPRESSO_BUILD_WITH_CUDA=OFF ${cmake_params}"
fi