From 2d1f600f1a6bc8f697bf18482ccc6f0d7b290525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 11 Mar 2020 12:01:45 +0100 Subject: [PATCH 01/35] Define C++ version and load CUDA first Fixes a regression from 1e3fc3b183d: the Boost version depends on the CUDA version for Intel, therefore CUDA must be loaded first, but the CUDA version depends on the C++ version, so C++14 must be defined at the top of the file. --- CMakeLists.txt | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c2d3789cc5..31b8dceddcb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,11 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.12") cmake_policy(SET CMP0074 NEW) endif() +# C++ standard enable_language(CXX) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) set(PROJECT_VERSION "4.2-dev") @@ -123,6 +127,11 @@ endforeach(func_name __PRETTY_FUNCTION__ __FUNCTION__) # Libraries # +# CUDA compiler +if(WITH_CUDA) + find_package(CUDACompiler REQUIRED) +endif(WITH_CUDA) + find_package(PythonInterp 3.5 REQUIRED) if(WITH_PYTHON) @@ -279,16 +288,6 @@ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTDIR}/espressomd") # Flags # -# C++ standard -set(CMAKE_CXX_STANDARD 14) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - -# CUDA compiler -if(WITH_CUDA) - find_package(CUDACompiler REQUIRED) -endif(WITH_CUDA) - # drop 'lib' prefix from all libraries set(CMAKE_SHARED_LIBRARY_PREFIX "") From c271344f2a091192aac64e1ddcf5859f130ab117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 11 Mar 2020 20:53:49 +0100 Subject: [PATCH 02/35] Load the CUDA compiler selected by the user The user can now provide the name of the CUDA compiler as a CMake flag instead of modifying CMake variables to bypass the guessing mechanism. CMake fails if the selected compiler is not found. The FindCUDACompiler helper file was split into separate .cmake files. --- CMakeLists.txt | 15 +++- cmake/FindCUDACompiler.cmake | 126 ------------------------------ cmake/FindCUDACompilerClang.cmake | 81 +++++++++++++++++++ cmake/FindCUDACompilerHIP.cmake | 45 +++++++++++ cmake/FindCUDACompilerNVCC.cmake | 57 ++++++++++++++ 5 files changed, 197 insertions(+), 127 deletions(-) delete mode 100644 cmake/FindCUDACompiler.cmake create mode 100644 cmake/FindCUDACompilerClang.cmake create mode 100644 cmake/FindCUDACompilerHIP.cmake create mode 100644 cmake/FindCUDACompilerNVCC.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 31b8dceddcb..fdbb0a2e9dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,7 +129,20 @@ endforeach(func_name __PRETTY_FUNCTION__ __FUNCTION__) # CUDA compiler if(WITH_CUDA) - find_package(CUDACompiler REQUIRED) + set(WITH_CUDA_COMPILER "nvcc" CACHE STRING "Select the CUDA compiler, can be 'nvcc' (default), 'hip', or 'clang'") + if (WITH_CUDA_COMPILER STREQUAL "nvcc") + find_package(CUDA 9.0 REQUIRED) + find_package(CUDACompilerNVCC 9.0 REQUIRED) + elseif (WITH_CUDA_COMPILER STREQUAL "hip") + set(ROCM_HOME "/opt/rocm" CACHE FILEPATH "Path to AMD ROCm") + list(APPEND CMAKE_MODULE_PATH "${ROCM_HOME}/hip/cmake") + find_package(HIP 1.5.18494 MODULE REQUIRED) + find_package(CUDACompilerHIP REQUIRED) + elseif (WITH_CUDA_COMPILER STREQUAL "clang") + find_package(CUDACompilerClang REQUIRED) + else() + message(FATAL_ERROR "Cannot process option -DWITH_CUDA_COMPILER='${WITH_CUDA_COMPILER}'") + endif() endif(WITH_CUDA) find_package(PythonInterp 3.5 REQUIRED) diff --git a/cmake/FindCUDACompiler.cmake b/cmake/FindCUDACompiler.cmake deleted file mode 100644 index a8a6f25a346..00000000000 --- a/cmake/FindCUDACompiler.cmake +++ /dev/null @@ -1,126 +0,0 @@ -# Find a CUDA-capable compiler, include its libraries and declare a custom -# `add_library()` wrapper function named `add_gpu_library()`. - -if(EXISTS "$ENV{NVCC}" AND NOT CUDA_NVCC_EXECUTABLE) - set(CUDA_NVCC_EXECUTABLE $ENV{NVCC} CACHE FILEPATH "Path to CUDA compiler.") -endif() - -# Option 1: the cuda compiler is the same as the C++ compiler (e.g. Clang) -if(CUDA_NVCC_EXECUTABLE STREQUAL CMAKE_CXX_COMPILER) - message(STATUS "Found CUDA-capable host compiler: ${CUDA_NVCC_EXECUTABLE}") - set(CUDA 1) - set(CUDA_COMPILER_EXE ${CUDA_NVCC_EXECUTABLE}) - if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" - OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") - execute_process(COMMAND ${CUDA_NVCC_EXECUTABLE} ${CMAKE_CXX_FLAGS} - --verbose - ERROR_VARIABLE CUDA_DIR_STRING) - string(REGEX - REPLACE "^.*Found CUDA installation: ([^,]+).*\$" - "\\1" - CUDA_DIR - "${CUDA_DIR_STRING}") - string(REGEX - REPLACE "^.*Found CUDA installation: .* version ([0-9]+).*\$" - "\\1" - CUDA_VERSION - "${CUDA_DIR_STRING}") - message(STATUS "Found CUDA version: ${CUDA_VERSION}") - message(STATUS "Found CUDA installation: ${CUDA_DIR}") - if(CUDA_VERSION VERSION_LESS 7.0) - message(FATAL_ERROR "CUDA version does not match requirements.") - endif() - else() - set(CUDA_DIR "/usr/local/cuda") - endif() - find_library(CUDART_LIBRARY NAMES cudart PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib /usr/local/nvidia/lib NO_DEFAULT_PATH) - find_library(CUFFT_LIBRARY NAMES cufft PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib /usr/local/nvidia/lib NO_DEFAULT_PATH) - - function(add_gpu_library) - set(options STATIC SHARED MODULE EXCLUDE_FROM_ALL) - set(oneValueArgs) - set(multiValueArgs) - cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) - list(REMOVE_AT ARG_UNPARSED_ARGUMENTS 0) - set_source_files_properties(${ARG_UNPARSED_ARGUMENTS} PROPERTIES LANGUAGE "CXX" COMPILE_FLAGS "${CUDA_NVCC_FLAGS}") - add_library(${ARGV}) - set_target_properties(${ARGV0} PROPERTIES LINKER_LANGUAGE "CXX") - target_link_libraries(${ARGV0} PRIVATE ${CUDA_LIBRARY} ${CUDART_LIBRARY}) - target_link_libraries(${ARGV0} PRIVATE ${CUFFT_LIBRARY}) - - foreach(file ${ARG_UNPARSED_ARGUMENTS}) - if(${file} MATCHES "\\.cu$") - if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.8.9) - set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "--cuda-gpu-arch=sm_30 --cuda-gpu-arch=sm_52") - else() - set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "--cuda-gpu-arch=sm_30") - endif() - endif() - endforeach() - endfunction() -else() - # Option 2: the cuda compiler is HIP - set(ROCM_HOME "/opt/rocm" CACHE STRING "Path to AMD ROCm") - list(APPEND CMAKE_MODULE_PATH "${ROCM_HOME}/hip/cmake") - find_package(HIP 1.5.18494 QUIET MODULE) - if(HIP_FOUND) - set(HCC_PATH "${HIP_ROOT_DIR}") - find_package(HIP MODULE) - message(STATUS "Found HIP compiler: ${HIP_HIPCC_EXECUTABLE}") - set(CUDA 1) - set(HIP 1) - set(CUDA_COMPILER_EXE ${HIP_HIPCC_EXECUTABLE}) - list(APPEND HIP_HCC_FLAGS "-I${HIP_ROOT_DIR}/include -I${ROCM_HOME}/include -Wno-c99-designator -Wno-macro-redefined -Wno-duplicate-decl-specifier -std=c++${CMAKE_CXX_STANDARD}") - list(APPEND HIP_HCC_FLAGS "-pedantic -Wall -Wextra -Wno-sign-compare -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-missing-braces -Wno-gnu-anonymous-struct -Wno-nested-anon-types -Wno-gnu-zero-variadic-macro-arguments") - if(WARNINGS_ARE_ERRORS) - list(APPEND HIP_HCC_FLAGS "-Werror") - endif() - - find_library(ROCFFT_LIB name "rocfft" PATHS "${ROCM_HOME}/lib") - - function(add_gpu_library) - hip_add_library(${ARGV}) - set_target_properties(${ARGV0} PROPERTIES LINKER_LANGUAGE HIP) - target_link_libraries(${ARGV0} PRIVATE "${ROCFFT_LIB}") - endfunction() - else() - # Option 3: the cuda compiler is NVCC - find_package(CUDA 9.0) - if(CUDA_FOUND) - if(NOT CUDA_NVCC_EXECUTABLE STREQUAL "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc") - get_filename_component(NVCC_EXECUTABLE_DIRNAME "${CUDA_NVCC_EXECUTABLE}" DIRECTORY) - get_filename_component(NVCC_EXECUTABLE_DIRNAME "${NVCC_EXECUTABLE_DIRNAME}" DIRECTORY) - message(WARNING "Your nvcc (${CUDA_NVCC_EXECUTABLE}) 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.") - endif() - set(CUDA 1) - set(CUDA_COMPILER_EXE ${CUDA_NVCC_EXECUTABLE}) - - set(CUDA_LINK_LIBRARIES_KEYWORD PUBLIC) - - set(CUDA_NVCC_FLAGS_DEBUG "${CUDA_NVCC_FLAGS_DEBUG} -g") - set(CUDA_NVCC_FLAGS_RELEASE "${CUDA_NVCC_FLAGS_RELEASE} -O3 -DNDEBUG") - set(CUDA_NVCC_FLAGS_MINSIZEREL "${CUDA_NVCC_FLAGS_MINSIZEREL} -Os -DNDEBUG") - set(CUDA_NVCC_FLAGS_RELWITHDEBINFO "${CUDA_NVCC_FLAGS_RELWITHDEBINFO} -g -O2") - set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_52,code=compute_52 -std=c++${CMAKE_CXX_STANDARD}") - SET(CUDA_PROPAGATE_HOST_FLAGS OFF) - - if(WARNINGS_ARE_ERRORS) - set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler -Werror") - endif() - - if (CMAKE_OSX_SYSROOT) - set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler -isysroot -Xcompiler ${CMAKE_OSX_SYSROOT}") - endif() - - function(add_gpu_library) - cuda_add_library(${ARGV}) - set_property(TARGET ${ARGV0} PROPERTY CUDA_SEPARABLE_COMPILATION ON) - target_link_libraries(${ARGV0} PRIVATE ${CUDA_CUFFT_LIBRARIES}) - endfunction() - - endif(CUDA_FOUND) - endif() -endif() - -include( FindPackageHandleStandardArgs ) -FIND_PACKAGE_HANDLE_STANDARD_ARGS( CudaCompiler REQUIRED_VARS CUDA_COMPILER_EXE ) diff --git a/cmake/FindCUDACompilerClang.cmake b/cmake/FindCUDACompilerClang.cmake new file mode 100644 index 00000000000..0dcfa2afff2 --- /dev/null +++ b/cmake/FindCUDACompilerClang.cmake @@ -0,0 +1,81 @@ +# Copyright (C) 2009-2020 The ESPResSo project +# Copyright (C) 2009,2010 +# Max-Planck-Institute for Polymer Research, Theory Group +# +# This file is part of ESPResSo. +# +# ESPResSo is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ESPResSo is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# 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()`. + +if (NOT (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" + OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")) + message(FATAL_ERROR "To compile CUDA code with Clang, the C++ compiler must be Clang, not ${CMAKE_CXX_COMPILER_ID}.") +endif() + +set(CMAKE_CUDA_COMPILER ${CMAKE_CXX_COMPILER}) +set(CUDA 1) + +execute_process(COMMAND ${CMAKE_CUDA_COMPILER} ${CMAKE_CXX_FLAGS} + --verbose + ERROR_VARIABLE CUDA_DIR_STRING) +string(REGEX + REPLACE "^.*Found CUDA installation: ([^,]+).*\$" + "\\1" + CUDA_DIR + "${CUDA_DIR_STRING}") +string(REGEX + REPLACE "^.*Found CUDA installation: .* version ([0-9]+).*\$" + "\\1" + CUDA_VERSION + "${CUDA_DIR_STRING}") + +message(STATUS "Found CUDA-capable host compiler: ${CMAKE_CUDA_COMPILER}") +message(STATUS "Found CUDA version: ${CUDA_VERSION}") +message(STATUS "Found CUDA installation: ${CUDA_DIR}") + +if(CUDA_VERSION VERSION_LESS 7.0) + message(FATAL_ERROR "CUDA version does not match requirements.") +endif() + +find_library(CUDART_LIBRARY NAMES cudart PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib /usr/local/nvidia/lib NO_DEFAULT_PATH) +find_library(CUFFT_LIBRARY NAMES cufft PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib /usr/local/nvidia/lib NO_DEFAULT_PATH) + +function(add_gpu_library) + set(options STATIC SHARED MODULE EXCLUDE_FROM_ALL) + set(oneValueArgs) + set(multiValueArgs) + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) + list(REMOVE_AT ARG_UNPARSED_ARGUMENTS 0) + set_source_files_properties(${ARG_UNPARSED_ARGUMENTS} PROPERTIES LANGUAGE "CXX" COMPILE_FLAGS "${CUDA_NVCC_FLAGS}") + add_library(${ARGV}) + set_target_properties(${ARGV0} PROPERTIES LINKER_LANGUAGE "CXX") + target_link_libraries(${ARGV0} PRIVATE ${CUDA_LIBRARY} ${CUDART_LIBRARY}) + target_link_libraries(${ARGV0} PRIVATE ${CUFFT_LIBRARY}) + + foreach(file ${ARG_UNPARSED_ARGUMENTS}) + if(${file} MATCHES "\\.cu$") + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.8.9) + set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "--cuda-gpu-arch=sm_30 --cuda-gpu-arch=sm_52") + else() + set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "--cuda-gpu-arch=sm_30") + endif() + endif() + endforeach() +endfunction() + +include( FindPackageHandleStandardArgs ) +FIND_PACKAGE_HANDLE_STANDARD_ARGS( CudaCompilerClang REQUIRED_VARS CMAKE_CUDA_COMPILER ) diff --git a/cmake/FindCUDACompilerHIP.cmake b/cmake/FindCUDACompilerHIP.cmake new file mode 100644 index 00000000000..d19213d0bb1 --- /dev/null +++ b/cmake/FindCUDACompilerHIP.cmake @@ -0,0 +1,45 @@ +# Copyright (C) 2009-2020 The ESPResSo project +# Copyright (C) 2009,2010 +# Max-Planck-Institute for Polymer Research, Theory Group +# +# This file is part of ESPResSo. +# +# ESPResSo is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ESPResSo is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# Find the HIP compiler, include its libraries and declare a custom +# `add_library()` wrapper function named `add_gpu_library()`. + +set(CMAKE_CUDA_COMPILER ${HIP_HIPCC_EXECUTABLE}) +set(CUDA 1) +set(HIP 1) + +set(HCC_PATH "${HIP_ROOT_DIR}") + +list(APPEND HIP_HCC_FLAGS "-I${HIP_ROOT_DIR}/include -I${ROCM_HOME}/include -Wno-c99-designator -Wno-macro-redefined -Wno-duplicate-decl-specifier -std=c++${CMAKE_CXX_STANDARD}") +list(APPEND HIP_HCC_FLAGS "-pedantic -Wall -Wextra -Wno-sign-compare -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-missing-braces -Wno-gnu-anonymous-struct -Wno-nested-anon-types -Wno-gnu-zero-variadic-macro-arguments") +if(WARNINGS_ARE_ERRORS) + list(APPEND HIP_HCC_FLAGS "-Werror") +endif() + +find_library(ROCFFT_LIB name "rocfft" PATHS "${ROCM_HOME}/lib") + +function(add_gpu_library) + hip_add_library(${ARGV}) + set_target_properties(${ARGV0} PROPERTIES LINKER_LANGUAGE HIP) + target_link_libraries(${ARGV0} PRIVATE "${ROCFFT_LIB}") +endfunction() + +include( FindPackageHandleStandardArgs ) +FIND_PACKAGE_HANDLE_STANDARD_ARGS( CudaCompilerHIP REQUIRED_VARS CMAKE_CUDA_COMPILER ) diff --git a/cmake/FindCUDACompilerNVCC.cmake b/cmake/FindCUDACompilerNVCC.cmake new file mode 100644 index 00000000000..d9fd2fae162 --- /dev/null +++ b/cmake/FindCUDACompilerNVCC.cmake @@ -0,0 +1,57 @@ +# Copyright (C) 2009-2020 The ESPResSo project +# Copyright (C) 2009,2010 +# Max-Planck-Institute for Polymer Research, Theory Group +# +# This file is part of ESPResSo. +# +# ESPResSo is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ESPResSo is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# 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()`. + +set(CMAKE_CUDA_COMPILER ${CUDA_NVCC_EXECUTABLE}) +set(CUDA 1) + +if(NOT CUDA_NVCC_EXECUTABLE STREQUAL "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc") + get_filename_component(NVCC_EXECUTABLE_DIRNAME "${CUDA_NVCC_EXECUTABLE}" DIRECTORY) + get_filename_component(NVCC_EXECUTABLE_DIRNAME "${NVCC_EXECUTABLE_DIRNAME}" DIRECTORY) + message(WARNING "Your nvcc (${CUDA_NVCC_EXECUTABLE}) 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.") +endif() + +set(CUDA_LINK_LIBRARIES_KEYWORD PUBLIC) + +SET(CUDA_PROPAGATE_HOST_FLAGS OFF) + +set(CUDA_NVCC_FLAGS_DEBUG "${CUDA_NVCC_FLAGS_DEBUG} -g") +set(CUDA_NVCC_FLAGS_RELEASE "${CUDA_NVCC_FLAGS_RELEASE} -O3 -DNDEBUG") +set(CUDA_NVCC_FLAGS_MINSIZEREL "${CUDA_NVCC_FLAGS_MINSIZEREL} -Os -DNDEBUG") +set(CUDA_NVCC_FLAGS_RELWITHDEBINFO "${CUDA_NVCC_FLAGS_RELWITHDEBINFO} -g -O2") + +set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_52,code=compute_52 -std=c++${CMAKE_CXX_STANDARD}") +if(WARNINGS_ARE_ERRORS) + set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler -Werror") +endif() +if (CMAKE_OSX_SYSROOT) + set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler -isysroot -Xcompiler ${CMAKE_OSX_SYSROOT}") +endif() + +function(add_gpu_library) + cuda_add_library(${ARGV}) + set_property(TARGET ${ARGV0} PROPERTY CUDA_SEPARABLE_COMPILATION ON) + target_link_libraries(${ARGV0} PRIVATE ${CUDA_CUFFT_LIBRARIES}) +endfunction() + +include( FindPackageHandleStandardArgs ) +FIND_PACKAGE_HANDLE_STANDARD_ARGS( CudaCompilerNVCC REQUIRED_VARS CMAKE_CUDA_COMPILER ) From f148cca059a16f02d4f596ea7e43b4d76472d9b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 11 Mar 2020 21:30:33 +0100 Subject: [PATCH 03/35] Check the CUDA version for all compilers The minimum CUDA version is 9.0 for NVCC and 8.0 for Clang. For the Clang compiler and the Clang-based HIP compiler, the minimum version that is tested in CI is 6.0.0. --- CMakeLists.txt | 10 ++++++---- cmake/FindCUDACompilerClang.cmake | 9 ++++++--- cmake/FindCUDACompilerHIP.cmake | 13 ++++++++++++- cmake/FindCUDACompilerNVCC.cmake | 13 ++++++++++++- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fdbb0a2e9dd..2cf03d788fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,17 +129,19 @@ endforeach(func_name __PRETTY_FUNCTION__ __FUNCTION__) # CUDA compiler if(WITH_CUDA) + set(CMAKE_CUDA_STANDARD 9.0) set(WITH_CUDA_COMPILER "nvcc" CACHE STRING "Select the CUDA compiler, can be 'nvcc' (default), 'hip', or 'clang'") if (WITH_CUDA_COMPILER STREQUAL "nvcc") - find_package(CUDA 9.0 REQUIRED) - find_package(CUDACompilerNVCC 9.0 REQUIRED) + find_package(CUDA ${CMAKE_CUDA_STANDARD} REQUIRED) + find_package(CUDACompilerNVCC ${CMAKE_CUDA_STANDARD} REQUIRED) elseif (WITH_CUDA_COMPILER STREQUAL "hip") set(ROCM_HOME "/opt/rocm" CACHE FILEPATH "Path to AMD ROCm") list(APPEND CMAKE_MODULE_PATH "${ROCM_HOME}/hip/cmake") find_package(HIP 1.5.18494 MODULE REQUIRED) - find_package(CUDACompilerHIP REQUIRED) + find_package(CUDACompilerHIP 6.0 REQUIRED) elseif (WITH_CUDA_COMPILER STREQUAL "clang") - find_package(CUDACompilerClang REQUIRED) + set(CMAKE_CUDA_STANDARD 8.0) + find_package(CUDACompilerClang 6.0 REQUIRED) else() message(FATAL_ERROR "Cannot process option -DWITH_CUDA_COMPILER='${WITH_CUDA_COMPILER}'") endif() diff --git a/cmake/FindCUDACompilerClang.cmake b/cmake/FindCUDACompilerClang.cmake index 0dcfa2afff2..b6e8b8af656 100644 --- a/cmake/FindCUDACompilerClang.cmake +++ b/cmake/FindCUDACompilerClang.cmake @@ -27,6 +27,7 @@ if (NOT (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" endif() set(CMAKE_CUDA_COMPILER ${CMAKE_CXX_COMPILER}) +set(CMAKE_CUDA_COMPILER_VERSION ${CMAKE_CXX_COMPILER_VERSION}) set(CUDA 1) execute_process(COMMAND ${CMAKE_CUDA_COMPILER} ${CMAKE_CXX_FLAGS} @@ -47,8 +48,8 @@ message(STATUS "Found CUDA-capable host compiler: ${CMAKE_CUDA_COMPILER}") message(STATUS "Found CUDA version: ${CUDA_VERSION}") message(STATUS "Found CUDA installation: ${CUDA_DIR}") -if(CUDA_VERSION VERSION_LESS 7.0) - message(FATAL_ERROR "CUDA version does not match requirements.") +if(CUDA_VERSION VERSION_LESS ${CMAKE_CUDA_STANDARD}) + message(FATAL_ERROR "${CMAKE_CUDA_COMPILER} was built for CUDA ${CUDA_VERSION}: version does not match requirements (CUDA ${CMAKE_CUDA_STANDARD}).") endif() find_library(CUDART_LIBRARY NAMES cudart PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib /usr/local/nvidia/lib NO_DEFAULT_PATH) @@ -78,4 +79,6 @@ function(add_gpu_library) endfunction() include( FindPackageHandleStandardArgs ) -FIND_PACKAGE_HANDLE_STANDARD_ARGS( CudaCompilerClang REQUIRED_VARS CMAKE_CUDA_COMPILER ) +FIND_PACKAGE_HANDLE_STANDARD_ARGS( CudaCompilerClang + REQUIRED_VARS CMAKE_CUDA_COMPILER + VERSION_VAR CMAKE_CUDA_COMPILER_VERSION ) diff --git a/cmake/FindCUDACompilerHIP.cmake b/cmake/FindCUDACompilerHIP.cmake index d19213d0bb1..5f3d0d10755 100644 --- a/cmake/FindCUDACompilerHIP.cmake +++ b/cmake/FindCUDACompilerHIP.cmake @@ -25,6 +25,15 @@ set(CMAKE_CUDA_COMPILER ${HIP_HIPCC_EXECUTABLE}) set(CUDA 1) set(HIP 1) +execute_process(COMMAND ${CMAKE_CUDA_COMPILER} --version + OUTPUT_VARIABLE HIPCC_VERSION_STRING) + +string(REGEX + REPLACE "^.*HCC [Cc]lang version ([0-9\.]+).*\$" + "\\1" + CMAKE_CUDA_COMPILER_VERSION + "${HIPCC_VERSION_STRING}") + set(HCC_PATH "${HIP_ROOT_DIR}") list(APPEND HIP_HCC_FLAGS "-I${HIP_ROOT_DIR}/include -I${ROCM_HOME}/include -Wno-c99-designator -Wno-macro-redefined -Wno-duplicate-decl-specifier -std=c++${CMAKE_CXX_STANDARD}") @@ -42,4 +51,6 @@ function(add_gpu_library) endfunction() include( FindPackageHandleStandardArgs ) -FIND_PACKAGE_HANDLE_STANDARD_ARGS( CudaCompilerHIP REQUIRED_VARS CMAKE_CUDA_COMPILER ) +FIND_PACKAGE_HANDLE_STANDARD_ARGS( CudaCompilerHIP + REQUIRED_VARS CMAKE_CUDA_COMPILER + VERSION_VAR CMAKE_CUDA_COMPILER_VERSION ) diff --git a/cmake/FindCUDACompilerNVCC.cmake b/cmake/FindCUDACompilerNVCC.cmake index d9fd2fae162..d3c3fb29da3 100644 --- a/cmake/FindCUDACompilerNVCC.cmake +++ b/cmake/FindCUDACompilerNVCC.cmake @@ -24,6 +24,15 @@ set(CMAKE_CUDA_COMPILER ${CUDA_NVCC_EXECUTABLE}) set(CUDA 1) +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}") + if(NOT CUDA_NVCC_EXECUTABLE STREQUAL "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc") get_filename_component(NVCC_EXECUTABLE_DIRNAME "${CUDA_NVCC_EXECUTABLE}" DIRECTORY) get_filename_component(NVCC_EXECUTABLE_DIRNAME "${NVCC_EXECUTABLE_DIRNAME}" DIRECTORY) @@ -54,4 +63,6 @@ function(add_gpu_library) endfunction() include( FindPackageHandleStandardArgs ) -FIND_PACKAGE_HANDLE_STANDARD_ARGS( CudaCompilerNVCC REQUIRED_VARS CMAKE_CUDA_COMPILER ) +FIND_PACKAGE_HANDLE_STANDARD_ARGS( CudaCompilerNVCC + REQUIRED_VARS CMAKE_CUDA_COMPILER + VERSION_VAR CMAKE_CUDA_COMPILER_VERSION ) From 8008f8d330563fca151b85bafe2ac037bf549d77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 11 Mar 2020 21:56:42 +0100 Subject: [PATCH 04/35] Document CUDA compiler selection mechanism --- doc/sphinx/installation.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/sphinx/installation.rst b/doc/sphinx/installation.rst index 6cd01a1d9a9..44db74751d5 100644 --- a/doc/sphinx/installation.rst +++ b/doc/sphinx/installation.rst @@ -669,8 +669,8 @@ options are available: * ``WITH_VALGRIND_INSTRUMENTATION``: Build with valgrind instrumentation markers -When the value in the :file:`CMakeLists.txt` file is set to ON the corresponding -option is created if the value of the option is set to OFF the +When the value in the :file:`CMakeLists.txt` file is set to ON, the corresponding +option is created; if the value of the option is set to OFF, the corresponding option is not created. These options can also be modified by calling ``cmake`` with the command line argument ``-D``: @@ -678,6 +678,13 @@ by calling ``cmake`` with the command line argument ``-D``: cmake -D WITH_HDF5=OFF srcdir +When an option is activated, additional options may become available. +For example with ``-D WITH_CUDA=ON``, one can choose the CUDA compiler with +``-D WITH_CUDA_COMPILER=``, where ```` can be +``nvcc`` (default), ``clang`` or ``hip``. For ``hip``, an additional +``-D ROCM_HOME=`` variable becomes available, with default value +``ROCM_HOME=/opt/rocm``. + In the rare event when working with cmake and you want to have a totally clean build (for example because you switched the compiler), remove the build directory and create a new one. From 57e1e99e0a70bb7bbcfe0165c54c452cc59b5d9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 11 Mar 2020 21:57:26 +0100 Subject: [PATCH 05/35] Document how to access CMake variables --- doc/sphinx/installation.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/sphinx/installation.rst b/doc/sphinx/installation.rst index 44db74751d5..35b35ef6c69 100644 --- a/doc/sphinx/installation.rst +++ b/doc/sphinx/installation.rst @@ -601,6 +601,10 @@ having multiple build directories you can build several variants of |es|, each variant having different activated features, and for as many platforms as you want. +Once you've run ``ccmake``, you can list the configured variables with +``cmake -LAH -N | less`` (uses a pager) or with ``ccmake ..`` and pressing +key ``t`` to toggle the advanced mode on (uses the curses interface). + **Example:** When the source directory is :file:`srcdir` (the files where unpacked to this From 64a13a5ee09008b17deee29a42d15ca741fb94db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 11 Mar 2020 21:58:23 +0100 Subject: [PATCH 06/35] Remove outdated CMake advice The ESPResSo CMake project now has proper dependencies for every target in the source code, documentation and tests. It is no longer necessary to delete the build directory to start a fresh build. --- doc/sphinx/installation.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doc/sphinx/installation.rst b/doc/sphinx/installation.rst index 35b35ef6c69..33a950d6a48 100644 --- a/doc/sphinx/installation.rst +++ b/doc/sphinx/installation.rst @@ -689,11 +689,6 @@ For example with ``-D WITH_CUDA=ON``, one can choose the CUDA compiler with ``-D ROCM_HOME=`` variable becomes available, with default value ``ROCM_HOME=/opt/rocm``. -In the rare event when working with cmake and you want to have a totally -clean build (for example because you switched the compiler), remove the -build directory and create a new one. - - Compiling, testing and installing --------------------------------- From 6bac9e9ea1ee9fc670ca4a9b4de165f3868f5249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Thu, 12 Mar 2020 20:45:20 +0100 Subject: [PATCH 07/35] New CUDA compiler selection mechanism in CI Explicitly toggle GPU code on/off with WITH_CUDA and select the compiler with WITH_CUDA_COMPILER. --- .gitlab-ci.yml | 30 +++++++++++++++--------------- maintainer/CI/build_cmake.sh | 2 +- maintainer/CI/build_docker.sh | 1 + 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6feec27bbe6..6c90aeabb56 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -75,7 +75,7 @@ style_doxygen: - mkdir build - cd build - cp ../maintainer/configs/maxset.hpp myconfig.hpp - - cmake .. + - cmake .. -DWITH_CUDA=OFF - bash ../maintainer/CI/dox_warnings.sh tags: - docker @@ -97,7 +97,7 @@ maxset: <<: *global_job_definition stage: build script: - - export myconfig=maxset with_coverage=true + - export with_cuda=false myconfig=maxset with_coverage=true - bash maintainer/CI/build_cmake.sh tags: - docker @@ -107,7 +107,7 @@ no_rotation: <<: *global_job_definition stage: build script: - - export myconfig=no_rotation with_coverage=true + - export with_cuda=false myconfig=no_rotation with_coverage=true - bash maintainer/CI/build_cmake.sh tags: - docker @@ -171,7 +171,7 @@ cuda10-maxset: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-python3:cuda-10.1 script: - - export myconfig=maxset with_coverage=false test_timeout=900 srcdir=${CI_PROJECT_DIR} + - export myconfig=maxset with_cuda=true with_coverage=false test_timeout=900 srcdir=${CI_PROJECT_DIR} - export cmake_params="-DIPYTHON_EXECUTABLE=$(which jupyter)" - bash maintainer/CI/build_cmake.sh artifacts: @@ -188,7 +188,7 @@ cuda9-maxset: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-python3:cuda-9.0 script: - - export myconfig=maxset with_coverage=true test_timeout=900 srcdir=${CI_PROJECT_DIR} + - export myconfig=maxset with_cuda=true with_coverage=true test_timeout=900 srcdir=${CI_PROJECT_DIR} - sed -i 's/ or "DISPLAY" in os.environ/ or True/' src/python/espressomd/visualization.pyx - bash maintainer/CI/build_cmake.sh artifacts: @@ -206,7 +206,7 @@ tutorials-samples-maxset: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-python3:cuda-10.1 script: - - export myconfig=maxset with_coverage=false make_check_unit_tests=false make_check_python=false + - export myconfig=maxset with_cuda=true with_coverage=false make_check_unit_tests=false make_check_python=false - export make_check_tutorials=true make_check_samples=true make_check_benchmarks=false test_timeout=1200 - bash maintainer/CI/build_cmake.sh tags: @@ -219,7 +219,7 @@ tutorials-samples-default: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-python3:cuda-10.1 script: - - export myconfig=default with_coverage=false make_check_unit_tests=false make_check_python=false + - export myconfig=default with_cuda=true with_coverage=false make_check_unit_tests=false make_check_python=false - export make_check_tutorials=true make_check_samples=true make_check_benchmarks=false test_timeout=1200 - bash maintainer/CI/build_cmake.sh tags: @@ -234,7 +234,7 @@ tutorials-samples-empty: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-python3:cuda-10.1 script: - - export myconfig=empty with_coverage=false make_check_unit_tests=false make_check_python=false + - export myconfig=empty with_cuda=true with_coverage=false make_check_unit_tests=false make_check_python=false - export make_check_tutorials=true make_check_samples=true make_check_benchmarks=false test_timeout=1200 with_scafacos=false - bash maintainer/CI/build_cmake.sh tags: @@ -249,7 +249,7 @@ tutorials-samples-no-gpu: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-python3:cuda-10.1 script: - - export myconfig=maxset with_coverage=false make_check_unit_tests=false make_check_python=false + - export myconfig=maxset with_cuda=true with_coverage=false make_check_unit_tests=false make_check_python=false - export make_check_tutorials=true make_check_samples=true make_check_benchmarks=false test_timeout=1200 hide_gpu=true - bash maintainer/CI/build_cmake.sh tags: @@ -263,7 +263,7 @@ installation: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-python3:cuda-10.1 script: - - export myconfig=maxset with_coverage=false make_check_unit_tests=false make_check_python=false + - export myconfig=maxset with_cuda=true with_coverage=false make_check_unit_tests=false make_check_python=false - export srcdir=${CI_PROJECT_DIR} test_timeout=1800 - bash maintainer/CI/build_cmake.sh - cd build @@ -294,7 +294,7 @@ empty: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/clang-python3:6.0 script: - - export myconfig=empty with_static_analysis=true + - export myconfig=empty with_cuda=true cmake_params="-DWITH_CUDA_COMPILER=clang" with_static_analysis=true - bash maintainer/CI/build_cmake.sh tags: - docker @@ -306,7 +306,7 @@ ubuntu:wo-dependencies: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-python3:wo-dependencies script: - - export myconfig=maxset make_check_unit_tests=false make_check_python=false + - export myconfig=maxset with_cuda=false make_check_unit_tests=false make_check_python=false - bash maintainer/CI/build_cmake.sh tags: - docker @@ -319,7 +319,7 @@ rocm-maxset: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/rocm-python3:latest script: - - export myconfig=maxset + - export myconfig=maxset with_cuda=true cmake_params="-DWITH_CUDA_COMPILER=hip" - bash maintainer/CI/build_cmake.sh tags: - amdgpu @@ -389,7 +389,7 @@ clang:6.0: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/clang-python3:6.0 script: - - export myconfig=maxset with_coverage=false with_static_analysis=true with_asan=true with_ubsan=true test_timeout=900 + - export myconfig=maxset with_cuda=true cmake_params="-DWITH_CUDA_COMPILER=clang" with_coverage=false with_static_analysis=true with_asan=true with_ubsan=true test_timeout=900 - bash maintainer/CI/build_cmake.sh timeout: 2h tags: @@ -403,7 +403,7 @@ intel:18: stage: build image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/intel-python3:18 script: - - export myconfig=maxset with_coverage=false I_MPI_SHM_LMT=shm + - export myconfig=maxset with_cuda=true with_coverage=false I_MPI_SHM_LMT=shm - export cxx_flags=-O2 - bash maintainer/CI/build_cmake.sh tags: diff --git a/maintainer/CI/build_cmake.sh b/maintainer/CI/build_cmake.sh index a2bca03f1bc..4cf60e6a00b 100755 --- a/maintainer/CI/build_cmake.sh +++ b/maintainer/CI/build_cmake.sh @@ -214,7 +214,7 @@ if [ "${with_static_analysis}" = true ]; then fi if [ "${with_cuda}" = true ]; then - : + cmake_params="-DWITH_CUDA=ON ${cmake_params}" else cmake_params="-DWITH_CUDA=OFF ${cmake_params}" fi diff --git a/maintainer/CI/build_docker.sh b/maintainer/CI/build_docker.sh index 37e0274820c..f49ebb5d0c5 100755 --- a/maintainer/CI/build_docker.sh +++ b/maintainer/CI/build_docker.sh @@ -24,6 +24,7 @@ cmake_params=${cmake_params} with_fftw=${with_fftw} with_python_interface=true with_coverage=${with_coverage} +with_cuda=false myconfig=${myconfig} check_procs=${check_procs} make_check=${make_check} From b1277d8b48941a8477d20a670c17b7f91a85b7a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Thu, 12 Mar 2020 20:46:11 +0100 Subject: [PATCH 08/35] Make the default value of WITH_CUDA option OFF With the CUDA compiler guessing mechanism removed, the user must explicitly states if CUDA is available and which compiler to use. --- CMakeLists.txt | 2 +- maintainer/CI/build_cmake.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2cf03d788fa..e55d091bb4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,7 @@ set(CMAKE_FIND_FRAMEWORK LAST) option(WITH_PYTHON "Build with Python bindings" ON) option(WITH_GSL "Build with GSL support" ON) -option(WITH_CUDA "Build with GPU support" ON) +option(WITH_CUDA "Build with GPU support" OFF) option(WITH_HDF5 "Build with HDF5 support" ON) option(WITH_TESTS "Enable tests" ON) option(WITH_SCAFACOS "Build with Scafacos support" OFF) diff --git a/maintainer/CI/build_cmake.sh b/maintainer/CI/build_cmake.sh index 4cf60e6a00b..d296caf3b5d 100755 --- a/maintainer/CI/build_cmake.sh +++ b/maintainer/CI/build_cmake.sh @@ -94,7 +94,7 @@ set_default_value make_check_python true set_default_value make_check_tutorials false set_default_value make_check_samples false set_default_value make_check_benchmarks false -set_default_value with_cuda true +set_default_value with_cuda false set_default_value build_type "Debug" set_default_value with_ccache false set_default_value with_scafacos true From 932a3e92ea0a5d9b86e203110a28b5407cf92429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Fri, 13 Mar 2020 13:41:54 +0100 Subject: [PATCH 09/35] Patch hipcc environment variables in ROCm 3.X In ROCm 3.0 and 3.1, environment variables for hipcc and hcc are overriden by incorrect paths (espressomd/docker#156). This causes CMake to generate an incorrect linking command for EspressoCore.so: in `/opt/rocm/bin/hipcc_cmake_linker_helper /opt/rocm -fPIC ...`, either path `/opt/rocm` is an empty string, or both the linker path and path `/opt/rocm` are empty strings. Calling `find_package()` twice with an overriden `HCC_PATH` fixes the linking command. --- CMakeLists.txt | 3 +++ cmake/FindCUDACompilerHIP.cmake | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e55d091bb4e..76da1dbe978 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,6 +138,9 @@ if(WITH_CUDA) set(ROCM_HOME "/opt/rocm" CACHE FILEPATH "Path to AMD ROCm") list(APPEND CMAKE_MODULE_PATH "${ROCM_HOME}/hip/cmake") find_package(HIP 1.5.18494 MODULE REQUIRED) + # patch HCC_PATH environment variable and reload HIP (for ROCm 3.0/3.1) + set(HCC_PATH "${HIP_ROOT_DIR}") + find_package(HIP 1.5.18494 MODULE REQUIRED) find_package(CUDACompilerHIP 6.0 REQUIRED) elseif (WITH_CUDA_COMPILER STREQUAL "clang") set(CMAKE_CUDA_STANDARD 8.0) diff --git a/cmake/FindCUDACompilerHIP.cmake b/cmake/FindCUDACompilerHIP.cmake index 5f3d0d10755..4e9d54d30f2 100644 --- a/cmake/FindCUDACompilerHIP.cmake +++ b/cmake/FindCUDACompilerHIP.cmake @@ -34,8 +34,6 @@ string(REGEX CMAKE_CUDA_COMPILER_VERSION "${HIPCC_VERSION_STRING}") -set(HCC_PATH "${HIP_ROOT_DIR}") - list(APPEND HIP_HCC_FLAGS "-I${HIP_ROOT_DIR}/include -I${ROCM_HOME}/include -Wno-c99-designator -Wno-macro-redefined -Wno-duplicate-decl-specifier -std=c++${CMAKE_CXX_STANDARD}") list(APPEND HIP_HCC_FLAGS "-pedantic -Wall -Wextra -Wno-sign-compare -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-missing-braces -Wno-gnu-anonymous-struct -Wno-nested-anon-types -Wno-gnu-zero-variadic-macro-arguments") if(WARNINGS_ARE_ERRORS) From 662d03fba58374d9fd9c1b694fa3796ae4297038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Fri, 13 Mar 2020 14:05:45 +0100 Subject: [PATCH 10/35] Print CMake version during configuration Knowing the CMake version is extremely useful when reviewing CMake logs attached in bug reports. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 76da1dbe978..5b8f2d7aee2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ # cmake_minimum_required(VERSION 3.10) +message(STATUS "CMake version: ${CMAKE_VERSION}") if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.13) cmake_policy(SET CMP0076 NEW) endif() From f8457a36fa0abbd78c24d6d8973c219ec810bce9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Fri, 13 Mar 2020 16:57:08 +0100 Subject: [PATCH 11/35] Modern CMake: naming convention for CUDA variables The C++ standard used for CUDA code is set in `CMAKE_CUDA_STANDARD`. Variable `CMAKE_CUDA_VERSION` was renamed to `MINIMAL_CUDA_VERSION` for clarity. --- CMakeLists.txt | 9 +++++---- cmake/FindCUDACompilerClang.cmake | 4 ++-- cmake/FindCUDACompilerHIP.cmake | 2 +- cmake/FindCUDACompilerNVCC.cmake | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b8f2d7aee2..305f1f58871 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,11 +130,12 @@ endforeach(func_name __PRETTY_FUNCTION__ __FUNCTION__) # CUDA compiler if(WITH_CUDA) - set(CMAKE_CUDA_STANDARD 9.0) + set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD}) + set(MINIMAL_CUDA_VERSION 9.0) set(WITH_CUDA_COMPILER "nvcc" CACHE STRING "Select the CUDA compiler, can be 'nvcc' (default), 'hip', or 'clang'") if (WITH_CUDA_COMPILER STREQUAL "nvcc") - find_package(CUDA ${CMAKE_CUDA_STANDARD} REQUIRED) - find_package(CUDACompilerNVCC ${CMAKE_CUDA_STANDARD} REQUIRED) + find_package(CUDA ${MINIMAL_CUDA_VERSION} REQUIRED) + find_package(CUDACompilerNVCC ${MINIMAL_CUDA_VERSION} REQUIRED) elseif (WITH_CUDA_COMPILER STREQUAL "hip") set(ROCM_HOME "/opt/rocm" CACHE FILEPATH "Path to AMD ROCm") list(APPEND CMAKE_MODULE_PATH "${ROCM_HOME}/hip/cmake") @@ -144,7 +145,7 @@ if(WITH_CUDA) find_package(HIP 1.5.18494 MODULE REQUIRED) find_package(CUDACompilerHIP 6.0 REQUIRED) elseif (WITH_CUDA_COMPILER STREQUAL "clang") - set(CMAKE_CUDA_STANDARD 8.0) + set(MINIMAL_CUDA_VERSION 8.0) find_package(CUDACompilerClang 6.0 REQUIRED) else() message(FATAL_ERROR "Cannot process option -DWITH_CUDA_COMPILER='${WITH_CUDA_COMPILER}'") diff --git a/cmake/FindCUDACompilerClang.cmake b/cmake/FindCUDACompilerClang.cmake index b6e8b8af656..dd08e4cec85 100644 --- a/cmake/FindCUDACompilerClang.cmake +++ b/cmake/FindCUDACompilerClang.cmake @@ -48,8 +48,8 @@ message(STATUS "Found CUDA-capable host compiler: ${CMAKE_CUDA_COMPILER}") message(STATUS "Found CUDA version: ${CUDA_VERSION}") message(STATUS "Found CUDA installation: ${CUDA_DIR}") -if(CUDA_VERSION VERSION_LESS ${CMAKE_CUDA_STANDARD}) - message(FATAL_ERROR "${CMAKE_CUDA_COMPILER} was built for CUDA ${CUDA_VERSION}: version does not match requirements (CUDA ${CMAKE_CUDA_STANDARD}).") +if(CUDA_VERSION VERSION_LESS ${MINIMAL_CUDA_VERSION}) + message(FATAL_ERROR "${CMAKE_CUDA_COMPILER} was built for CUDA ${CUDA_VERSION}: version does not match requirements (CUDA ${MINIMAL_CUDA_VERSION}).") endif() find_library(CUDART_LIBRARY NAMES cudart PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib /usr/local/nvidia/lib NO_DEFAULT_PATH) diff --git a/cmake/FindCUDACompilerHIP.cmake b/cmake/FindCUDACompilerHIP.cmake index 4e9d54d30f2..7b7ebca8f12 100644 --- a/cmake/FindCUDACompilerHIP.cmake +++ b/cmake/FindCUDACompilerHIP.cmake @@ -34,7 +34,7 @@ string(REGEX CMAKE_CUDA_COMPILER_VERSION "${HIPCC_VERSION_STRING}") -list(APPEND HIP_HCC_FLAGS "-I${HIP_ROOT_DIR}/include -I${ROCM_HOME}/include -Wno-c99-designator -Wno-macro-redefined -Wno-duplicate-decl-specifier -std=c++${CMAKE_CXX_STANDARD}") +list(APPEND HIP_HCC_FLAGS "-I${HIP_ROOT_DIR}/include -I${ROCM_HOME}/include -Wno-c99-designator -Wno-macro-redefined -Wno-duplicate-decl-specifier -std=c++${CMAKE_CUDA_STANDARD}") list(APPEND HIP_HCC_FLAGS "-pedantic -Wall -Wextra -Wno-sign-compare -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-missing-braces -Wno-gnu-anonymous-struct -Wno-nested-anon-types -Wno-gnu-zero-variadic-macro-arguments") if(WARNINGS_ARE_ERRORS) list(APPEND HIP_HCC_FLAGS "-Werror") diff --git a/cmake/FindCUDACompilerNVCC.cmake b/cmake/FindCUDACompilerNVCC.cmake index d3c3fb29da3..8a0b57dfb7c 100644 --- a/cmake/FindCUDACompilerNVCC.cmake +++ b/cmake/FindCUDACompilerNVCC.cmake @@ -48,7 +48,7 @@ set(CUDA_NVCC_FLAGS_RELEASE "${CUDA_NVCC_FLAGS_RELEASE} -O3 -DNDEBUG") set(CUDA_NVCC_FLAGS_MINSIZEREL "${CUDA_NVCC_FLAGS_MINSIZEREL} -Os -DNDEBUG") set(CUDA_NVCC_FLAGS_RELWITHDEBINFO "${CUDA_NVCC_FLAGS_RELWITHDEBINFO} -g -O2") -set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_52,code=compute_52 -std=c++${CMAKE_CXX_STANDARD}") +set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_52,code=compute_52 -std=c++${CMAKE_CUDA_STANDARD}") if(WARNINGS_ARE_ERRORS) set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler -Werror") endif() From 929e16c3c2ad791b981e2e6cc24721d8255c8e90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Fri, 13 Mar 2020 17:20:20 +0100 Subject: [PATCH 12/35] Fix nvcc compiler error The nvcc `-O` optimization flag can only take a number. --- cmake/FindCUDACompilerNVCC.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/FindCUDACompilerNVCC.cmake b/cmake/FindCUDACompilerNVCC.cmake index 8a0b57dfb7c..cc045d71dc7 100644 --- a/cmake/FindCUDACompilerNVCC.cmake +++ b/cmake/FindCUDACompilerNVCC.cmake @@ -45,7 +45,7 @@ SET(CUDA_PROPAGATE_HOST_FLAGS OFF) set(CUDA_NVCC_FLAGS_DEBUG "${CUDA_NVCC_FLAGS_DEBUG} -g") set(CUDA_NVCC_FLAGS_RELEASE "${CUDA_NVCC_FLAGS_RELEASE} -O3 -DNDEBUG") -set(CUDA_NVCC_FLAGS_MINSIZEREL "${CUDA_NVCC_FLAGS_MINSIZEREL} -Os -DNDEBUG") +set(CUDA_NVCC_FLAGS_MINSIZEREL "${CUDA_NVCC_FLAGS_MINSIZEREL} -O2 -DNDEBUG") set(CUDA_NVCC_FLAGS_RELWITHDEBINFO "${CUDA_NVCC_FLAGS_RELWITHDEBINFO} -g -O2") set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_52,code=compute_52 -std=c++${CMAKE_CUDA_STANDARD}") From 444757024db6b6de5437dd2d34b3a3dd6738cc9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Sat, 14 Mar 2020 18:08:54 +0100 Subject: [PATCH 13/35] Fix clang compiler error Cannot compile CUDA code with coverage enabled using Clang. --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 305f1f58871..1c7f9c0d428 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,6 +145,9 @@ if(WITH_CUDA) find_package(HIP 1.5.18494 MODULE REQUIRED) find_package(CUDACompilerHIP 6.0 REQUIRED) elseif (WITH_CUDA_COMPILER STREQUAL "clang") + if(WITH_COVERAGE) + message(FATAL_ERROR "The combination of options '-DWITH_CUDA_COMPILER=${WITH_CUDA_COMPILER} -DWITH_COVERAGE=${WITH_COVERAGE}' is not supported.") + endif() set(MINIMAL_CUDA_VERSION 8.0) find_package(CUDACompilerClang 6.0 REQUIRED) else() From 8061ba8fa0fc9d44ed8d7baab5003d11855cd3ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Sat, 14 Mar 2020 20:38:15 +0100 Subject: [PATCH 14/35] Refactor optimization flags, simplify CI script Rewrite CUDA flags based on the CXX flags: CMAKE_CXX_FLAGS_DEBUG = -O0 -g CMAKE_CXX_FLAGS_RELEASE = -O3 -DNDEBUG CMAKE_CXX_FLAGS_MINSIZEREL = -Os -DNDEBUG CMAKE_CXX_FLAGS_RELWITHDEBINFO = -O2 -g -DNDEBUG Add a COVERAGE build type that uses -O0 for host and -O3 for device. This replaces the logic in the CI script that had to touch `CMAKE_CXX_FLAGS` and `CUDA_NVCC_FLAGS`. The -O0 optimization flag for host avoids ending up with source code lines in the gcov output with neither hit or miss. According to `man gcov`: > compile your code without optimization if you plan to use gcov > because the optimization, by combining some lines of code into > one function, may not give you as much information as you need --- .gitlab-ci.yml | 2 +- CMakeLists.txt | 8 ++++++-- cmake/FindCUDACompilerClang.cmake | 10 +++++++++- cmake/FindCUDACompilerHIP.cmake | 10 ++++++++++ cmake/FindCUDACompilerNVCC.cmake | 11 ++++++----- cmake/unit_test.cmake | 4 ++-- maintainer/CI/build_cmake.sh | 23 +---------------------- maintainer/CI/build_docker.sh | 3 ++- src/core/CMakeLists.txt | 4 ++-- 9 files changed, 39 insertions(+), 36 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6c90aeabb56..1ff0ce53e6f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -404,7 +404,7 @@ intel:18: image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/intel-python3:18 script: - export myconfig=maxset with_cuda=true with_coverage=false I_MPI_SHM_LMT=shm - - export cxx_flags=-O2 + - export cmake_params="-DCMAKE_CXX_FLAGS=-O2" - bash maintainer/CI/build_cmake.sh tags: - docker diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c7f9c0d428..bf32a5d310d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ set(PROJECT_VERSION "4.2-dev") set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE) + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Coverage." FORCE) endif(NOT CMAKE_BUILD_TYPE) # On Mac OS X, first look for other packages, then frameworks @@ -70,7 +70,11 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - option(WITH_COVERAGE "Generate code coverage report" OFF) + if(CMAKE_BUILD_TYPE STREQUAL Coverage) + option(WITH_COVERAGE "Generate code coverage report" ON) + else() + option(WITH_COVERAGE "Generate code coverage report" OFF) + endif() option(WITH_ASAN "Build with address sanitizer" OFF) option(WITH_UBSAN "Build with undefined behavior sanitizer" OFF) endif() diff --git a/cmake/FindCUDACompilerClang.cmake b/cmake/FindCUDACompilerClang.cmake index dd08e4cec85..1c5de920647 100644 --- a/cmake/FindCUDACompilerClang.cmake +++ b/cmake/FindCUDACompilerClang.cmake @@ -52,6 +52,13 @@ if(CUDA_VERSION VERSION_LESS ${MINIMAL_CUDA_VERSION}) message(FATAL_ERROR "${CMAKE_CUDA_COMPILER} was built for CUDA ${CUDA_VERSION}: version does not match requirements (CUDA ${MINIMAL_CUDA_VERSION}).") endif() +set(CUDA_NVCC_FLAGS_DEBUG "${CUDA_NVCC_FLAGS_DEBUG} -g") +set(CUDA_NVCC_FLAGS_RELEASE "${CUDA_NVCC_FLAGS_RELEASE} -O3 -DNDEBUG") +set(CUDA_NVCC_FLAGS_MINSIZEREL "${CUDA_NVCC_FLAGS_MINSIZEREL} -O2 -DNDEBUG") +set(CUDA_NVCC_FLAGS_RELWITHDEBINFO "${CUDA_NVCC_FLAGS_RELWITHDEBINFO} -O2 -g -DNDEBUG") +set(CUDA_NVCC_FLAGS_COVERAGE "${CUDA_NVCC_FLAGS_COVERAGE} -O3 -g") +string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER) + find_library(CUDART_LIBRARY NAMES cudart PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib /usr/local/nvidia/lib NO_DEFAULT_PATH) find_library(CUFFT_LIBRARY NAMES cufft PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib /usr/local/nvidia/lib NO_DEFAULT_PATH) @@ -61,7 +68,7 @@ function(add_gpu_library) set(multiValueArgs) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) list(REMOVE_AT ARG_UNPARSED_ARGUMENTS 0) - set_source_files_properties(${ARG_UNPARSED_ARGUMENTS} PROPERTIES LANGUAGE "CXX" COMPILE_FLAGS "${CUDA_NVCC_FLAGS}") + set_source_files_properties(${ARG_UNPARSED_ARGUMENTS} PROPERTIES LANGUAGE "CXX") add_library(${ARGV}) set_target_properties(${ARGV0} PROPERTIES LINKER_LANGUAGE "CXX") target_link_libraries(${ARGV0} PRIVATE ${CUDA_LIBRARY} ${CUDART_LIBRARY}) @@ -69,6 +76,7 @@ function(add_gpu_library) foreach(file ${ARG_UNPARSED_ARGUMENTS}) if(${file} MATCHES "\\.cu$") + set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "${CUDA_NVCC_FLAGS} ${CUDA_NVCC_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}") if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.8.9) set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "--cuda-gpu-arch=sm_30 --cuda-gpu-arch=sm_52") else() diff --git a/cmake/FindCUDACompilerHIP.cmake b/cmake/FindCUDACompilerHIP.cmake index 7b7ebca8f12..e77fdd8f1bd 100644 --- a/cmake/FindCUDACompilerHIP.cmake +++ b/cmake/FindCUDACompilerHIP.cmake @@ -40,6 +40,16 @@ if(WARNINGS_ARE_ERRORS) list(APPEND HIP_HCC_FLAGS "-Werror") endif() +set(HIP_HIPCC_FLAGS_DEBUG "${HIP_HIPCC_FLAGS_DEBUG} -g") +set(HIP_HIPCC_FLAGS_RELEASE "${HIP_HIPCC_FLAGS_RELEASE} -O3 -DNDEBUG") +set(HIP_HIPCC_FLAGS_MINSIZEREL "${HIP_HIPCC_FLAGS_MINSIZEREL} -O2 -DNDEBUG") +set(HIP_HIPCC_FLAGS_RELWITHDEBINFO "${HIP_HIPCC_FLAGS_RELWITHDEBINFO} -O2 -g -DNDEBUG") +set(HIP_HIPCC_FLAGS_COVERAGE "${HIP_HIPCC_FLAGS_COVERAGE} -O3 -g") + +if(WARNINGS_ARE_ERRORS) + set(HIP_HCC_FLAGS "${HIP_HCC_FLAGS} -Werror") +endif() + find_library(ROCFFT_LIB name "rocfft" PATHS "${ROCM_HOME}/lib") function(add_gpu_library) diff --git a/cmake/FindCUDACompilerNVCC.cmake b/cmake/FindCUDACompilerNVCC.cmake index cc045d71dc7..2d4cb461d41 100644 --- a/cmake/FindCUDACompilerNVCC.cmake +++ b/cmake/FindCUDACompilerNVCC.cmake @@ -44,16 +44,17 @@ set(CUDA_LINK_LIBRARIES_KEYWORD PUBLIC) SET(CUDA_PROPAGATE_HOST_FLAGS OFF) set(CUDA_NVCC_FLAGS_DEBUG "${CUDA_NVCC_FLAGS_DEBUG} -g") -set(CUDA_NVCC_FLAGS_RELEASE "${CUDA_NVCC_FLAGS_RELEASE} -O3 -DNDEBUG") -set(CUDA_NVCC_FLAGS_MINSIZEREL "${CUDA_NVCC_FLAGS_MINSIZEREL} -O2 -DNDEBUG") -set(CUDA_NVCC_FLAGS_RELWITHDEBINFO "${CUDA_NVCC_FLAGS_RELWITHDEBINFO} -g -O2") +set(CUDA_NVCC_FLAGS_RELEASE "${CUDA_NVCC_FLAGS_RELEASE} -O3 -Xptxas=-O3 -Xcompiler=-O3 -DNDEBUG") +set(CUDA_NVCC_FLAGS_MINSIZEREL "${CUDA_NVCC_FLAGS_MINSIZEREL} -O2 -Xptxas=-O2 -Xcompiler=-Os -DNDEBUG") +set(CUDA_NVCC_FLAGS_RELWITHDEBINFO "${CUDA_NVCC_FLAGS_RELWITHDEBINFO} -O2 -g -Xptxas=-O2 -Xcompiler=-O2,-g -DNDEBUG") +set(CUDA_NVCC_FLAGS_COVERAGE "${CUDA_NVCC_FLAGS_COVERAGE} -O3 -g -Xptxas=-O3 -Xcompiler=-O0,-g") set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_52,code=compute_52 -std=c++${CMAKE_CUDA_STANDARD}") if(WARNINGS_ARE_ERRORS) - set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler -Werror") + set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler=-Werror -Xptxas=-Werror") endif() if (CMAKE_OSX_SYSROOT) - set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler -isysroot -Xcompiler ${CMAKE_OSX_SYSROOT}") + set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler=-isysroot -Xcompiler=${CMAKE_OSX_SYSROOT}") endif() function(add_gpu_library) diff --git a/cmake/unit_test.cmake b/cmake/unit_test.cmake index 86fbb477606..c372151473b 100644 --- a/cmake/unit_test.cmake +++ b/cmake/unit_test.cmake @@ -28,8 +28,8 @@ function(UNIT_TEST) target_link_libraries(${TEST_NAME} PRIVATE ${TEST_DEPENDS}) endif() if(WITH_COVERAGE) - target_compile_options(${TEST_NAME} PUBLIC "$<$:-g>") - target_compile_options(${TEST_NAME} PUBLIC "$<$:-O0>") + target_compile_options(${TEST_NAME} PUBLIC "-g") + target_compile_options(${TEST_NAME} PUBLIC "$,-O0,-Og>") target_compile_options(${TEST_NAME} PUBLIC "$<$:-fprofile-instr-generate>") target_compile_options(${TEST_NAME} PUBLIC "$<$:-fcoverage-mapping>") target_compile_options(${TEST_NAME} PUBLIC "$<$>:--coverage>") diff --git a/maintainer/CI/build_cmake.sh b/maintainer/CI/build_cmake.sh index d296caf3b5d..ecb5af79793 100755 --- a/maintainer/CI/build_cmake.sh +++ b/maintainer/CI/build_cmake.sh @@ -107,33 +107,12 @@ else run_checks=false fi -# If there are no user-provided flags, default -# ones are added according to ${with_coverage} -nvcc_flags="${cxx_flags}" -if [ -z "${cxx_flags}" ]; then - if [ "${with_coverage}" = true ]; then - cxx_flags="-Og" - nvcc_flags="-O3" - else - if [ "${run_checks}" = true ]; then - cxx_flags="-O3" - nvcc_flags="-O3" - else - cxx_flags="-O0" - nvcc_flags="-O0" - fi - fi -fi - if [ "${with_coverage}" = true ]; then + build_type="Coverage" bash <(curl -s https://codecov.io/env) 1>/dev/null 2>&1 fi cmake_params="-DCMAKE_BUILD_TYPE=${build_type} -DWARNINGS_ARE_ERRORS=ON -DTEST_NP:INT=${check_procs} ${cmake_params}" -cmake_params="${cmake_params} -DCMAKE_CXX_FLAGS=${cxx_flags}" -if [ "${with_cuda}" = true ]; then - cmake_params="${cmake_params} -DCUDA_NVCC_FLAGS=${nvcc_flags}" -fi cmake_params="${cmake_params} -DCMAKE_INSTALL_PREFIX=/tmp/espresso-unit-tests" cmake_params="${cmake_params} -DTEST_TIMEOUT=${test_timeout}" if [ "${with_ccache}" = true ]; then diff --git a/maintainer/CI/build_docker.sh b/maintainer/CI/build_docker.sh index f49ebb5d0c5..08d68cc34d7 100755 --- a/maintainer/CI/build_docker.sh +++ b/maintainer/CI/build_docker.sh @@ -23,11 +23,12 @@ insource=${insource} cmake_params=${cmake_params} with_fftw=${with_fftw} with_python_interface=true -with_coverage=${with_coverage} +with_coverage=false with_cuda=false myconfig=${myconfig} check_procs=${check_procs} make_check=${make_check} +build_type="Debug" EOF if [ -z "${image}" ]; then diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index d88809d1acf..9ee637ca0ad 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -74,8 +74,8 @@ install(TARGETS EspressoCore LIBRARY DESTINATION ${PYTHON_INSTDIR}/espressomd) target_compile_options( EspressoCore PUBLIC - "$<$,$>:-g>" - "$<$,$>:-O0>" + "$<$:-g>" + "$,$>,-O0,-Og>" "$<$,$>:-fprofile-instr-generate>" "$<$,$>:-fcoverage-mapping>" "$<$,$>>:--coverage>" From df04e0838c8bce30ce8994d07f2cd6f5689172a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Sat, 14 Mar 2020 20:40:03 +0100 Subject: [PATCH 15/35] Remove obsolete CI options --- maintainer/CI/build_cmake.sh | 31 ++++++------------------------- maintainer/CI/build_docker.sh | 7 ++----- 2 files changed, 8 insertions(+), 30 deletions(-) diff --git a/maintainer/CI/build_cmake.sh b/maintainer/CI/build_cmake.sh index ecb5af79793..8d30e65301c 100755 --- a/maintainer/CI/build_cmake.sh +++ b/maintainer/CI/build_cmake.sh @@ -74,11 +74,9 @@ set_default_value() { # handle environment variables -set_default_value insource false set_default_value srcdir "$(pwd)" set_default_value cmake_params "" set_default_value with_fftw true -set_default_value with_python_interface true set_default_value with_coverage false set_default_value with_ubsan false set_default_value with_asan false @@ -128,32 +126,21 @@ if [ "${hide_gpu}" = true ]; then export CUDA_VISIBLE_DEVICES="" fi -if [ "${insource}" = true ]; then - builddir="${srcdir}" -elif [ -z "${builddir}" ]; then - builddir="${srcdir}/build" -fi +builddir="${srcdir}/build" -outp insource srcdir builddir \ +outp srcdir builddir \ make_check_unit_tests make_check_python make_check_tutorials make_check_samples make_check_benchmarks \ cmake_params with_fftw \ - with_python_interface with_coverage \ + with_coverage \ with_ubsan with_asan \ check_odd_only \ with_static_analysis myconfig \ build_procs check_procs \ with_cuda with_ccache -if [ "${insource}" = false ]; then - if [ ! -d "${builddir}" ]; then - echo "Creating ${builddir}..." - mkdir -p "${builddir}" - fi -fi - -if [ "${insource}" = false ]; then - cd "${builddir}" -fi +echo "Creating ${builddir}..." +mkdir -p "${builddir}" +cd "${builddir}" # load MPI module if necessary if [ -f "/etc/os-release" ]; then @@ -170,12 +157,6 @@ else cmake_params="-DCMAKE_DISABLE_FIND_PACKAGE_FFTW3=ON ${cmake_params}" fi -if [ "${with_python_interface}" = true ]; then - cmake_params="-DWITH_PYTHON=ON ${cmake_params}" -else - cmake_params="-DWITH_PYTHON=OFF ${cmake_params}" -fi - if [ "${with_coverage}" = true ]; then cmake_params="-DWITH_COVERAGE=ON ${cmake_params}" fi diff --git a/maintainer/CI/build_docker.sh b/maintainer/CI/build_docker.sh index 08d68cc34d7..6fa1e0b3310 100755 --- a/maintainer/CI/build_docker.sh +++ b/maintainer/CI/build_docker.sh @@ -19,10 +19,8 @@ ENV_FILE=$(mktemp esXXXXXXX.env) cat > "${ENV_FILE}" < Date: Sat, 14 Mar 2020 21:30:48 +0100 Subject: [PATCH 16/35] Refactor build type and CUDA compiler selection Generate a warning for incorrect build types and override them with 'Release'. Move the `set(CMAKE_BUILD_TYPE CACHE)` declaration out of the conditional such that its help message always gets displayed in cmake/ccmake. List the possible values as properties to allow cycling in ccmake and cmake-gui (instead of manually typing them). Same thing for WITH_CUDA_COMPILER. This is achieved by creating a wrapper around the `option()` function that accepts an enum value (stored as a string) instead of a boolean value. --- CMakeLists.txt | 7 +++---- cmake/option_enum.cmake | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 cmake/option_enum.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index bf32a5d310d..b1f07144119 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ include(FeatureSummary) include(GNUInstallDirs) project(ESPResSo) include(cmake/FindPythonModule.cmake) +include(cmake/option_enum.cmake) if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.12") cmake_policy(SET CMP0074 NEW) endif() @@ -46,9 +47,7 @@ set(PROJECT_VERSION "4.2-dev") # Cmake modules/macros are in a subdirectory to keep this file cleaner set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel Coverage." FORCE) -endif(NOT CMAKE_BUILD_TYPE) +option_enum(varname "CMAKE_BUILD_TYPE" help_text "build type" default_value "Release" possible_values "Debug;Release;RelWithDebInfo;MinSizeRel;Coverage") # On Mac OS X, first look for other packages, then frameworks set(CMAKE_FIND_FRAMEWORK LAST) @@ -136,7 +135,7 @@ endforeach(func_name __PRETTY_FUNCTION__ __FUNCTION__) if(WITH_CUDA) set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD}) set(MINIMAL_CUDA_VERSION 9.0) - set(WITH_CUDA_COMPILER "nvcc" CACHE STRING "Select the CUDA compiler, can be 'nvcc' (default), 'hip', or 'clang'") + option_enum(varname "WITH_CUDA_COMPILER" help_text "CUDA compiler" default_value "nvcc" possible_values "nvcc;hip;clang") if (WITH_CUDA_COMPILER STREQUAL "nvcc") find_package(CUDA ${MINIMAL_CUDA_VERSION} REQUIRED) find_package(CUDACompilerNVCC ${MINIMAL_CUDA_VERSION} REQUIRED) diff --git a/cmake/option_enum.cmake b/cmake/option_enum.cmake new file mode 100644 index 00000000000..ed2a7d51ee2 --- /dev/null +++ b/cmake/option_enum.cmake @@ -0,0 +1,38 @@ +# Copyright (C) 2020 The ESPResSo project +# +# This file is part of ESPResSo. +# +# ESPResSo is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ESPResSo is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# Like `option()`, but takes an additional list of valid values that is used +# to check the user input, generate a help string with all options, and set +# the list of possible values in ccmake/cmake-gui (e.g. in ccmake, one can +# cycle through the list of values with [enter] instead of typing them). +macro(option_enum) + cmake_parse_arguments(option_enum "" "varname;help_text;default_value" "possible_values" ${ARGN}) + # Process user input + set(option_enum_input_value "${${option_enum_varname}}") + if(NOT option_enum_input_value IN_LIST option_enum_possible_values) + if(option_enum_input_value) + message(WARNING "Unknown ${option_enum_help_text} '${option_enum_input_value}', defaulting to '${option_enum_default_value}'") + endif() + set(option_enum_input_value ${option_enum_default_value}) + endif() + # Declare variable with a help string + string(REPLACE ";" " " option_enum_possible_values_concat "${option_enum_possible_values}") + set(${option_enum_varname} ${option_enum_input_value} CACHE STRING "Choose the ${option_enum_help_text}, options are: ${option_enum_possible_values_concat}" FORCE) + # Set the possible values for ccmake and cmake-gui + set_property(CACHE ${option_enum_varname} PROPERTY STRINGS ${option_enum_possible_values}) +endmacro() From 6865fe99f0e7bbf771e70968eed18ae5c7e887cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Sat, 14 Mar 2020 21:36:00 +0100 Subject: [PATCH 17/35] Update CMake documentation and license headers --- CMakeLists.txt | 5 +++-- cmake/FindPythonHeaders.cmake | 20 ++++++++++++++++++++ cmake/MyConfig.cmake | 12 ++++++------ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b1f07144119..097d8e2a6f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # Copyright (C) 2009-2019 The ESPResSo project -# Copyright (C) 2009,2010 +# Copyright (C) 2009,2010 # Max-Planck-Institute for Polymer Research, Theory Group # # This file is part of ESPResSo. @@ -44,9 +44,10 @@ set(PROJECT_VERSION "4.2-dev") # CMake internal vars # -# Cmake modules/macros are in a subdirectory to keep this file cleaner +# CMake modules/macros are in a subdirectory to keep this file cleaner set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +# Select the build type option_enum(varname "CMAKE_BUILD_TYPE" help_text "build type" default_value "Release" possible_values "Debug;Release;RelWithDebInfo;MinSizeRel;Coverage") # On Mac OS X, first look for other packages, then frameworks diff --git a/cmake/FindPythonHeaders.cmake b/cmake/FindPythonHeaders.cmake index 7097b7aaf4f..7bae289d397 100644 --- a/cmake/FindPythonHeaders.cmake +++ b/cmake/FindPythonHeaders.cmake @@ -1,9 +1,28 @@ +# Copyright (C) 2020 The ESPResSo project +# +# This file is part of ESPResSo. +# +# ESPResSo is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# ESPResSo is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + # find the Python C++ headers execute_process( COMMAND ${PYTHON_EXECUTABLE} -c "import distutils.sysconfig as cg; print(cg.get_python_inc())" OUTPUT_VARIABLE PYTHON_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE) + # find Python installation directory if(NOT PYTHON_INSTDIR) execute_process( @@ -13,5 +32,6 @@ if(NOT PYTHON_INSTDIR) OUTPUT_VARIABLE PYTHON_INSTDIR OUTPUT_STRIP_TRAILING_WHITESPACE) endif(NOT PYTHON_INSTDIR) + include( FindPackageHandleStandardArgs ) FIND_PACKAGE_HANDLE_STANDARD_ARGS( PythonHeaders REQUIRED_VARS PYTHON_INCLUDE_DIRS PYTHON_INSTDIR ) diff --git a/cmake/MyConfig.cmake b/cmake/MyConfig.cmake index 577ed655adc..404ca884f58 100644 --- a/cmake/MyConfig.cmake +++ b/cmake/MyConfig.cmake @@ -1,5 +1,5 @@ # Copyright (C) 2011 Olaf Lenz -# Copyright (C) 2015 The ESPResSo Project +# Copyright (C) 2015,2020 The ESPResSo Project # # This file is part of ESPResSo. # @@ -16,8 +16,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -# This cmake script is used to find out what myconfig header to use. -# It needs the variables + +# This CMake script is used to find out which myconfig header to use. # heed the environment variable "ESPRESSO_MYCONFIG" if(NOT MYCONFIG_FILE) @@ -29,7 +29,7 @@ else() NAMES ${MYCONFIG_NAME} PATHS ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR} NO_DEFAULT_PATH) - # use the default if it is not + # otherwise, use the default one if(NOT MYCONFIG_FILE) set(MYCONFIG_FILE ${CMAKE_SOURCE_DIR}/src/config/myconfig-default.hpp) endif() @@ -39,6 +39,6 @@ endif() configure_file(${MYCONFIG_FILE} ${CMAKE_BINARY_DIR}/src/config/myconfig-final.hpp COPYONLY) add_custom_target(myconfig DEPENDS ${CMAKE_BINARY_DIR}/src/config/myconfig-final.hpp) message(STATUS "Config file: ${MYCONFIG_FILE}") -# Clear variable, otherwise cmake must be run by hand to detect myconfig -# Also prevents find_file from skipping when variable is already set +# Clear variable, otherwise cmake must be run by hand to detect myconfig. +# Also prevents find_file from skipping when variable is already set. unset(MYCONFIG_FILE CACHE) From ff2f98ff9fb222002808bb2e6e7d17133955ad00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 16 Mar 2020 16:54:30 +0100 Subject: [PATCH 18/35] Add oversubscription guard The same guard is used in the CMake logic for Python tests. --- maintainer/CI/build_cmake.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/maintainer/CI/build_cmake.sh b/maintainer/CI/build_cmake.sh index 8d30e65301c..a15fc5b2e8f 100755 --- a/maintainer/CI/build_cmake.sh +++ b/maintainer/CI/build_cmake.sh @@ -262,7 +262,11 @@ else start "TEST" if [ "${HIP_PLATFORM}" != "hcc" ]; then - mpiexec -n ${check_procs} ./pypresso "${srcdir}/testsuite/python/particle.py" || exit 1 + check_proc_particle_test=${check_procs} + if [ "${check_proc_particle_test}" -gt 4 ]; then + check_proc_particle_test=4 + fi + mpiexec -n ${check_proc_particle_test} ./pypresso "${srcdir}/testsuite/python/particle.py" || exit 1 fi end "TEST" From b8e22a93b681be49367c3f0ddf3a7773dcc1537d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 16 Mar 2020 19:12:17 +0100 Subject: [PATCH 19/35] Fix GPU optimization flag for Coverage builds --- cmake/FindCUDACompilerNVCC.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/FindCUDACompilerNVCC.cmake b/cmake/FindCUDACompilerNVCC.cmake index 2d4cb461d41..ca98e487dcb 100644 --- a/cmake/FindCUDACompilerNVCC.cmake +++ b/cmake/FindCUDACompilerNVCC.cmake @@ -47,7 +47,7 @@ set(CUDA_NVCC_FLAGS_DEBUG "${CUDA_NVCC_FLAGS_DEBUG} -g") set(CUDA_NVCC_FLAGS_RELEASE "${CUDA_NVCC_FLAGS_RELEASE} -O3 -Xptxas=-O3 -Xcompiler=-O3 -DNDEBUG") set(CUDA_NVCC_FLAGS_MINSIZEREL "${CUDA_NVCC_FLAGS_MINSIZEREL} -O2 -Xptxas=-O2 -Xcompiler=-Os -DNDEBUG") set(CUDA_NVCC_FLAGS_RELWITHDEBINFO "${CUDA_NVCC_FLAGS_RELWITHDEBINFO} -O2 -g -Xptxas=-O2 -Xcompiler=-O2,-g -DNDEBUG") -set(CUDA_NVCC_FLAGS_COVERAGE "${CUDA_NVCC_FLAGS_COVERAGE} -O3 -g -Xptxas=-O3 -Xcompiler=-O0,-g") +set(CUDA_NVCC_FLAGS_COVERAGE "${CUDA_NVCC_FLAGS_COVERAGE} -O3 -g -Xptxas=-O3 -Xcompiler=-Og,-g") set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_52,code=compute_52 -std=c++${CMAKE_CUDA_STANDARD}") if(WARNINGS_ARE_ERRORS) From 74c4c4c7f66f9d45bb4e0eb904a935053b84e0ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Thu, 2 Apr 2020 20:16:56 +0200 Subject: [PATCH 20/35] Add a RelWithAssert build type The "release with assertions" build type restores the original behavior of the CI pipeline for non-coverage CI jobs: -O3 for faster tests and -g to get a minimal backtrace in GDB. --- CMakeLists.txt | 4 +++- cmake/FindCUDACompilerClang.cmake | 1 + cmake/FindCUDACompilerHIP.cmake | 1 + cmake/FindCUDACompilerNVCC.cmake | 1 + cmake/unit_test.cmake | 1 - maintainer/CI/build_cmake.sh | 2 +- maintainer/CI/build_docker.sh | 2 +- src/core/CMakeLists.txt | 1 - 8 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 097d8e2a6f3..91010574231 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,9 @@ set(PROJECT_VERSION "4.2-dev") set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # Select the build type -option_enum(varname "CMAKE_BUILD_TYPE" help_text "build type" default_value "Release" possible_values "Debug;Release;RelWithDebInfo;MinSizeRel;Coverage") +option_enum(varname "CMAKE_BUILD_TYPE" help_text "build type" default_value "Release" possible_values "Debug;Release;RelWithDebInfo;MinSizeRel;Coverage;RelWithAssert") +set(CMAKE_CXX_FLAGS_COVERAGE "-Og -g") +set(CMAKE_CXX_FLAGS_RELWITHASSERT "-O3 -g") # On Mac OS X, first look for other packages, then frameworks set(CMAKE_FIND_FRAMEWORK LAST) diff --git a/cmake/FindCUDACompilerClang.cmake b/cmake/FindCUDACompilerClang.cmake index 1c5de920647..71acd335ac9 100644 --- a/cmake/FindCUDACompilerClang.cmake +++ b/cmake/FindCUDACompilerClang.cmake @@ -57,6 +57,7 @@ set(CUDA_NVCC_FLAGS_RELEASE "${CUDA_NVCC_FLAGS_RELEASE} -O3 -DNDEBUG") set(CUDA_NVCC_FLAGS_MINSIZEREL "${CUDA_NVCC_FLAGS_MINSIZEREL} -O2 -DNDEBUG") set(CUDA_NVCC_FLAGS_RELWITHDEBINFO "${CUDA_NVCC_FLAGS_RELWITHDEBINFO} -O2 -g -DNDEBUG") set(CUDA_NVCC_FLAGS_COVERAGE "${CUDA_NVCC_FLAGS_COVERAGE} -O3 -g") +set(CUDA_NVCC_FLAGS_RELWITHASSERT "${CUDA_NVCC_FLAGS_RELWITHASSERT} -O3 -g") string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER) find_library(CUDART_LIBRARY NAMES cudart PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib /usr/local/nvidia/lib NO_DEFAULT_PATH) diff --git a/cmake/FindCUDACompilerHIP.cmake b/cmake/FindCUDACompilerHIP.cmake index e77fdd8f1bd..a99265936d2 100644 --- a/cmake/FindCUDACompilerHIP.cmake +++ b/cmake/FindCUDACompilerHIP.cmake @@ -45,6 +45,7 @@ set(HIP_HIPCC_FLAGS_RELEASE "${HIP_HIPCC_FLAGS_RELEASE} -O3 -DNDEBUG") set(HIP_HIPCC_FLAGS_MINSIZEREL "${HIP_HIPCC_FLAGS_MINSIZEREL} -O2 -DNDEBUG") set(HIP_HIPCC_FLAGS_RELWITHDEBINFO "${HIP_HIPCC_FLAGS_RELWITHDEBINFO} -O2 -g -DNDEBUG") set(HIP_HIPCC_FLAGS_COVERAGE "${HIP_HIPCC_FLAGS_COVERAGE} -O3 -g") +set(HIP_HIPCC_FLAGS_RELWITHASSERT "${HIP_HIPCC_FLAGS_RELWITHASSERT} -O3 -g") if(WARNINGS_ARE_ERRORS) set(HIP_HCC_FLAGS "${HIP_HCC_FLAGS} -Werror") diff --git a/cmake/FindCUDACompilerNVCC.cmake b/cmake/FindCUDACompilerNVCC.cmake index ca98e487dcb..b8c4093223f 100644 --- a/cmake/FindCUDACompilerNVCC.cmake +++ b/cmake/FindCUDACompilerNVCC.cmake @@ -48,6 +48,7 @@ set(CUDA_NVCC_FLAGS_RELEASE "${CUDA_NVCC_FLAGS_RELEASE} -O3 -Xptxas=-O3 -Xcompil set(CUDA_NVCC_FLAGS_MINSIZEREL "${CUDA_NVCC_FLAGS_MINSIZEREL} -O2 -Xptxas=-O2 -Xcompiler=-Os -DNDEBUG") set(CUDA_NVCC_FLAGS_RELWITHDEBINFO "${CUDA_NVCC_FLAGS_RELWITHDEBINFO} -O2 -g -Xptxas=-O2 -Xcompiler=-O2,-g -DNDEBUG") set(CUDA_NVCC_FLAGS_COVERAGE "${CUDA_NVCC_FLAGS_COVERAGE} -O3 -g -Xptxas=-O3 -Xcompiler=-Og,-g") +set(CUDA_NVCC_FLAGS_RELWITHASSERT "${CUDA_NVCC_FLAGS_RELWITHASSERT} -O3 -g -Xptxas=-O3 -Xcompiler=-O3,-g") set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_52,code=compute_52 -std=c++${CMAKE_CUDA_STANDARD}") if(WARNINGS_ARE_ERRORS) diff --git a/cmake/unit_test.cmake b/cmake/unit_test.cmake index c372151473b..b9c5acd4417 100644 --- a/cmake/unit_test.cmake +++ b/cmake/unit_test.cmake @@ -29,7 +29,6 @@ function(UNIT_TEST) endif() if(WITH_COVERAGE) target_compile_options(${TEST_NAME} PUBLIC "-g") - target_compile_options(${TEST_NAME} PUBLIC "$,-O0,-Og>") target_compile_options(${TEST_NAME} PUBLIC "$<$:-fprofile-instr-generate>") target_compile_options(${TEST_NAME} PUBLIC "$<$:-fcoverage-mapping>") target_compile_options(${TEST_NAME} PUBLIC "$<$>:--coverage>") diff --git a/maintainer/CI/build_cmake.sh b/maintainer/CI/build_cmake.sh index a15fc5b2e8f..cff9f9c5e05 100755 --- a/maintainer/CI/build_cmake.sh +++ b/maintainer/CI/build_cmake.sh @@ -93,7 +93,7 @@ set_default_value make_check_tutorials false set_default_value make_check_samples false set_default_value make_check_benchmarks false set_default_value with_cuda false -set_default_value build_type "Debug" +set_default_value build_type "RelWithAssert" set_default_value with_ccache false set_default_value with_scafacos true set_default_value test_timeout 300 diff --git a/maintainer/CI/build_docker.sh b/maintainer/CI/build_docker.sh index 6fa1e0b3310..38af9cc5164 100755 --- a/maintainer/CI/build_docker.sh +++ b/maintainer/CI/build_docker.sh @@ -26,7 +26,7 @@ with_cuda=false myconfig=${myconfig} check_procs=${check_procs} make_check=${make_check} -build_type="Debug" +build_type="RelWithAssert" EOF if [ -z "${image}" ]; then diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 9ee637ca0ad..1e72ef0b770 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -75,7 +75,6 @@ target_compile_options( EspressoCore PUBLIC "$<$:-g>" - "$,$>,-O0,-Og>" "$<$,$>:-fprofile-instr-generate>" "$<$,$>:-fcoverage-mapping>" "$<$,$>>:--coverage>" From 5e67a3a449aa4f1563ac872b6386a9391b27bbdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Thu, 2 Apr 2020 20:10:39 +0200 Subject: [PATCH 21/35] Test the Release build type in CI The original `build_cmake.sh` logic was accidentally compiling ESPResSo with optimization flag -O0 in job "installation", leading to a significant slowdown in CI. --- .gitlab-ci.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1ff0ce53e6f..58b46da1869 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -264,11 +264,9 @@ installation: image: gitlab.icp.uni-stuttgart.de:4567/espressomd/docker/ubuntu-python3:cuda-10.1 script: - export myconfig=maxset with_cuda=true with_coverage=false make_check_unit_tests=false make_check_python=false - - export srcdir=${CI_PROJECT_DIR} test_timeout=1800 + - export srcdir=${CI_PROJECT_DIR} test_timeout=1800 build_type=Release - bash maintainer/CI/build_cmake.sh - cd build - # install ESPResSo (in CI, pypresso will run up to 5 times slower when - # located outside the build directory, hence the larger timeout value) - make install # get path of installed files - CI_INSTALL_DIR="/tmp/espresso-unit-tests" @@ -277,16 +275,14 @@ installation: - cp -r "src/python/object_in_fluid" "${CI_INSTALL_PYTHON_PATH}/object_in_fluid" # run all tests with the installed files - sed -i "s|$(pwd)/pypresso|${CI_INSTALL_DIR}/bin/pypresso|" testsuite/{python,scripts/samples,scripts/tutorials}/CTestTestfile.cmake - # skip long tests - - sed -i "/tutorial_11-ferrofluid_3/d" testsuite/scripts/tutorials/CTestTestfile.cmake - - make -j2 check_python_skip_long + - make -j2 check_python - make -j2 check_samples - make -j2 check_tutorials tags: - docker - linux - cuda - timeout: 3h + timeout: 2h when: manual empty: From dcbc98f0fb1e27fd4cb8b295e689fcf8ec64ede8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Thu, 2 Apr 2020 20:25:26 +0200 Subject: [PATCH 22/35] Print the complete list of CMake options Move all the if/else logic for CMake options above the function call that prints shell variables to display the full CMake command in CI. --- maintainer/CI/build_cmake.sh | 57 ++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/maintainer/CI/build_cmake.sh b/maintainer/CI/build_cmake.sh index cff9f9c5e05..891380ebb73 100755 --- a/maintainer/CI/build_cmake.sh +++ b/maintainer/CI/build_cmake.sh @@ -113,6 +113,7 @@ fi cmake_params="-DCMAKE_BUILD_TYPE=${build_type} -DWARNINGS_ARE_ERRORS=ON -DTEST_NP:INT=${check_procs} ${cmake_params}" cmake_params="${cmake_params} -DCMAKE_INSTALL_PREFIX=/tmp/espresso-unit-tests" cmake_params="${cmake_params} -DTEST_TIMEOUT=${test_timeout}" + if [ "${with_ccache}" = true ]; then cmake_params="${cmake_params} -DWITH_CCACHE=ON" fi @@ -120,6 +121,34 @@ if [ "${with_scafacos}" = true ]; then cmake_params="${cmake_params} -DWITH_SCAFACOS=ON" fi +if [ "${with_fftw}" = true ]; then + : +else + cmake_params="-DCMAKE_DISABLE_FIND_PACKAGE_FFTW3=ON ${cmake_params}" +fi + +if [ "${with_coverage}" = true ]; then + cmake_params="-DWITH_COVERAGE=ON ${cmake_params}" +fi + +if [ "${with_asan}" = true ]; then + cmake_params="-DWITH_ASAN=ON ${cmake_params}" +fi + +if [ "${with_ubsan}" = true ]; then + cmake_params="-DWITH_UBSAN=ON ${cmake_params}" +fi + +if [ "${with_static_analysis}" = true ]; then + cmake_params="-DWITH_CLANG_TIDY=ON ${cmake_params}" +fi + +if [ "${with_cuda}" = true ]; then + cmake_params="-DWITH_CUDA=ON ${cmake_params}" +else + cmake_params="-DWITH_CUDA=OFF ${cmake_params}" +fi + command -v nvidia-smi && nvidia-smi || true if [ "${hide_gpu}" = true ]; then echo "Hiding gpu from Cuda via CUDA_VISIBLE_DEVICES" @@ -151,34 +180,6 @@ fi # CONFIGURE start "CONFIGURE" -if [ "${with_fftw}" = true ]; then - : -else - cmake_params="-DCMAKE_DISABLE_FIND_PACKAGE_FFTW3=ON ${cmake_params}" -fi - -if [ "${with_coverage}" = true ]; then - cmake_params="-DWITH_COVERAGE=ON ${cmake_params}" -fi - -if [ "${with_asan}" = true ]; then - cmake_params="-DWITH_ASAN=ON ${cmake_params}" -fi - -if [ "${with_ubsan}" = true ]; then - cmake_params="-DWITH_UBSAN=ON ${cmake_params}" -fi - -if [ "${with_static_analysis}" = true ]; then - cmake_params="-DWITH_CLANG_TIDY=ON ${cmake_params}" -fi - -if [ "${with_cuda}" = true ]; then - cmake_params="-DWITH_CUDA=ON ${cmake_params}" -else - cmake_params="-DWITH_CUDA=OFF ${cmake_params}" -fi - MYCONFIG_DIR="${srcdir}/maintainer/configs" if [ "${myconfig}" = "default" ]; then echo "Using default myconfig." From 6b87f2a6845e0f35213ede88b77287ae6ce2028e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Fri, 3 Apr 2020 22:16:34 +0200 Subject: [PATCH 23/35] Apply clang-format --- CMakeLists.txt | 23 ++++++++++----- cmake/FindCUDACompilerClang.cmake | 49 ++++++++++++++++--------------- cmake/FindCUDACompilerHIP.cmake | 15 ++++------ cmake/FindCUDACompilerNVCC.cmake | 19 ++++++------ 4 files changed, 58 insertions(+), 48 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c481eb6c50..f2db2cf38a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,10 @@ set(PROJECT_VERSION "4.2-dev") set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # Select the build type -option_enum(varname "CMAKE_BUILD_TYPE" help_text "build type" default_value "Release" possible_values "Debug;Release;RelWithDebInfo;MinSizeRel;Coverage;RelWithAssert") +option_enum( + varname "CMAKE_BUILD_TYPE" help_text "build type" default_value "Release" + possible_values + "Debug;Release;RelWithDebInfo;MinSizeRel;Coverage;RelWithAssert") set(CMAKE_CXX_FLAGS_COVERAGE "-Og -g") set(CMAKE_CXX_FLAGS_RELWITHASSERT "-O3 -g") @@ -136,11 +139,12 @@ endforeach(func_name __PRETTY_FUNCTION__ __FUNCTION__) if(WITH_CUDA) set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD}) set(MINIMAL_CUDA_VERSION 9.0) - option_enum(varname "WITH_CUDA_COMPILER" help_text "CUDA compiler" default_value "nvcc" possible_values "nvcc;hip;clang") - if (WITH_CUDA_COMPILER STREQUAL "nvcc") + option_enum(varname "WITH_CUDA_COMPILER" help_text "CUDA compiler" + default_value "nvcc" possible_values "nvcc;hip;clang") + if(WITH_CUDA_COMPILER STREQUAL "nvcc") find_package(CUDA ${MINIMAL_CUDA_VERSION} REQUIRED) find_package(CUDACompilerNVCC ${MINIMAL_CUDA_VERSION} REQUIRED) - elseif (WITH_CUDA_COMPILER STREQUAL "hip") + elseif(WITH_CUDA_COMPILER STREQUAL "hip") set(ROCM_HOME "/opt/rocm" CACHE FILEPATH "Path to AMD ROCm") list(APPEND CMAKE_MODULE_PATH "${ROCM_HOME}/hip/cmake") find_package(HIP 1.5.18494 MODULE REQUIRED) @@ -152,14 +156,19 @@ if(WITH_CUDA) endif() find_package(HIP 1.5.18494 MODULE REQUIRED) find_package(CUDACompilerHIP 6.0 REQUIRED) - elseif (WITH_CUDA_COMPILER STREQUAL "clang") + elseif(WITH_CUDA_COMPILER STREQUAL "clang") if(WITH_COVERAGE) - message(FATAL_ERROR "The combination of options '-DWITH_CUDA_COMPILER=${WITH_CUDA_COMPILER} -DWITH_COVERAGE=${WITH_COVERAGE}' is not supported.") + message( + FATAL_ERROR + "The combination of options '-DWITH_CUDA_COMPILER=${WITH_CUDA_COMPILER} -DWITH_COVERAGE=${WITH_COVERAGE}' is not supported." + ) endif() set(MINIMAL_CUDA_VERSION 8.0) find_package(CUDACompilerClang 6.0 REQUIRED) else() - message(FATAL_ERROR "Cannot process option -DWITH_CUDA_COMPILER='${WITH_CUDA_COMPILER}'") + message( + FATAL_ERROR + "Cannot process option -DWITH_CUDA_COMPILER='${WITH_CUDA_COMPILER}'") endif() endif(WITH_CUDA) diff --git a/cmake/FindCUDACompilerClang.cmake b/cmake/FindCUDACompilerClang.cmake index 71acd335ac9..329aff8bb8f 100644 --- a/cmake/FindCUDACompilerClang.cmake +++ b/cmake/FindCUDACompilerClang.cmake @@ -21,35 +21,34 @@ # Find the Clang compiler, include its libraries and declare a custom # `add_library()` wrapper function named `add_gpu_library()`. -if (NOT (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" - OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")) - message(FATAL_ERROR "To compile CUDA code with Clang, the C++ compiler must be Clang, not ${CMAKE_CXX_COMPILER_ID}.") +if(NOT (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL + "AppleClang")) + message( + FATAL_ERROR + "To compile CUDA code with Clang, the C++ compiler must be Clang, not ${CMAKE_CXX_COMPILER_ID}." + ) endif() set(CMAKE_CUDA_COMPILER ${CMAKE_CXX_COMPILER}) set(CMAKE_CUDA_COMPILER_VERSION ${CMAKE_CXX_COMPILER_VERSION}) set(CUDA 1) -execute_process(COMMAND ${CMAKE_CUDA_COMPILER} ${CMAKE_CXX_FLAGS} - --verbose +execute_process(COMMAND ${CMAKE_CUDA_COMPILER} ${CMAKE_CXX_FLAGS} --verbose ERROR_VARIABLE CUDA_DIR_STRING) -string(REGEX - REPLACE "^.*Found CUDA installation: ([^,]+).*\$" - "\\1" - CUDA_DIR - "${CUDA_DIR_STRING}") -string(REGEX - REPLACE "^.*Found CUDA installation: .* version ([0-9]+).*\$" - "\\1" - CUDA_VERSION - "${CUDA_DIR_STRING}") +string(REGEX REPLACE "^.*Found CUDA installation: ([^,]+).*\$" "\\1" CUDA_DIR + "${CUDA_DIR_STRING}") +string(REGEX REPLACE "^.*Found CUDA installation: .* version ([0-9]+).*\$" + "\\1" CUDA_VERSION "${CUDA_DIR_STRING}") message(STATUS "Found CUDA-capable host compiler: ${CMAKE_CUDA_COMPILER}") message(STATUS "Found CUDA version: ${CUDA_VERSION}") message(STATUS "Found CUDA installation: ${CUDA_DIR}") if(CUDA_VERSION VERSION_LESS ${MINIMAL_CUDA_VERSION}) - message(FATAL_ERROR "${CMAKE_CUDA_COMPILER} was built for CUDA ${CUDA_VERSION}: version does not match requirements (CUDA ${MINIMAL_CUDA_VERSION}).") + message( + FATAL_ERROR + "${CMAKE_CUDA_COMPILER} was built for CUDA ${CUDA_VERSION}: version does not match requirements (CUDA ${MINIMAL_CUDA_VERSION})." + ) endif() set(CUDA_NVCC_FLAGS_DEBUG "${CUDA_NVCC_FLAGS_DEBUG} -g") @@ -60,14 +59,18 @@ set(CUDA_NVCC_FLAGS_COVERAGE "${CUDA_NVCC_FLAGS_COVERAGE} -O3 -g") set(CUDA_NVCC_FLAGS_RELWITHASSERT "${CUDA_NVCC_FLAGS_RELWITHASSERT} -O3 -g") string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER) -find_library(CUDART_LIBRARY NAMES cudart PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib /usr/local/nvidia/lib NO_DEFAULT_PATH) -find_library(CUFFT_LIBRARY NAMES cufft PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib /usr/local/nvidia/lib NO_DEFAULT_PATH) +find_library( + CUDART_LIBRARY NAMES cudart PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib + /usr/local/nvidia/lib NO_DEFAULT_PATH) +find_library( + CUFFT_LIBRARY NAMES cufft PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib + /usr/local/nvidia/lib NO_DEFAULT_PATH) function(add_gpu_library) set(options STATIC SHARED MODULE EXCLUDE_FROM_ALL) set(oneValueArgs) set(multiValueArgs) - cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) + cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) list(REMOVE_AT ARG_UNPARSED_ARGUMENTS 0) set_source_files_properties(${ARG_UNPARSED_ARGUMENTS} PROPERTIES LANGUAGE "CXX") add_library(${ARGV}) @@ -87,7 +90,7 @@ function(add_gpu_library) endforeach() endfunction() -include( FindPackageHandleStandardArgs ) -FIND_PACKAGE_HANDLE_STANDARD_ARGS( CudaCompilerClang - REQUIRED_VARS CMAKE_CUDA_COMPILER - VERSION_VAR CMAKE_CUDA_COMPILER_VERSION ) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + CudaCompilerClang REQUIRED_VARS CMAKE_CUDA_COMPILER VERSION_VAR + CMAKE_CUDA_COMPILER_VERSION) diff --git a/cmake/FindCUDACompilerHIP.cmake b/cmake/FindCUDACompilerHIP.cmake index 543aaa82cfc..e18fc4ce0ce 100644 --- a/cmake/FindCUDACompilerHIP.cmake +++ b/cmake/FindCUDACompilerHIP.cmake @@ -28,11 +28,8 @@ set(HIP 1) execute_process(COMMAND ${CMAKE_CUDA_COMPILER} --version OUTPUT_VARIABLE HIPCC_VERSION_STRING) -string(REGEX - REPLACE "^.*HCC [Cc]lang version ([0-9\.]+).*\$" - "\\1" - CMAKE_CUDA_COMPILER_VERSION - "${HIPCC_VERSION_STRING}") +string(REGEX REPLACE "^.*HCC [Cc]lang version ([0-9\.]+).*\$" "\\1" + CMAKE_CUDA_COMPILER_VERSION "${HIPCC_VERSION_STRING}") list(APPEND HIP_HCC_FLAGS "-I${HIP_ROOT_DIR}/include -I${ROCM_HOME}/include -Wno-c99-designator -Wno-macro-redefined -Wno-duplicate-decl-specifier -std=c++${CMAKE_CUDA_STANDARD}") list(APPEND HIP_HCC_FLAGS "-pedantic -Wall -Wextra -Wno-sign-compare -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-missing-braces -Wno-gnu-anonymous-struct -Wno-nested-anon-types -Wno-gnu-zero-variadic-macro-arguments") @@ -62,7 +59,7 @@ function(add_gpu_library) target_link_libraries(${ARGV0} PRIVATE "${ROCFFT_LIB}") endfunction() -include( FindPackageHandleStandardArgs ) -FIND_PACKAGE_HANDLE_STANDARD_ARGS( CudaCompilerHIP - REQUIRED_VARS CMAKE_CUDA_COMPILER - VERSION_VAR CMAKE_CUDA_COMPILER_VERSION ) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + CudaCompilerHIP REQUIRED_VARS CMAKE_CUDA_COMPILER VERSION_VAR + CMAKE_CUDA_COMPILER_VERSION) diff --git a/cmake/FindCUDACompilerNVCC.cmake b/cmake/FindCUDACompilerNVCC.cmake index b8c4093223f..f579df96907 100644 --- a/cmake/FindCUDACompilerNVCC.cmake +++ b/cmake/FindCUDACompilerNVCC.cmake @@ -29,19 +29,20 @@ execute_process(COMMAND ${CMAKE_CUDA_COMPILER} --version string(REGEX REPLACE "^.*Cuda compilation tools, release [0-9\.]+, V([0-9\.]+).*\$" - "\\1" - CMAKE_CUDA_COMPILER_VERSION - "${NVCC_VERSION_STRING}") + "\\1" CMAKE_CUDA_COMPILER_VERSION "${NVCC_VERSION_STRING}") if(NOT CUDA_NVCC_EXECUTABLE STREQUAL "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc") get_filename_component(NVCC_EXECUTABLE_DIRNAME "${CUDA_NVCC_EXECUTABLE}" DIRECTORY) get_filename_component(NVCC_EXECUTABLE_DIRNAME "${NVCC_EXECUTABLE_DIRNAME}" DIRECTORY) - message(WARNING "Your nvcc (${CUDA_NVCC_EXECUTABLE}) 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.") + message( + WARNING + "Your nvcc (${CUDA_NVCC_EXECUTABLE}) 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." + ) endif() set(CUDA_LINK_LIBRARIES_KEYWORD PUBLIC) -SET(CUDA_PROPAGATE_HOST_FLAGS OFF) +set(CUDA_PROPAGATE_HOST_FLAGS OFF) set(CUDA_NVCC_FLAGS_DEBUG "${CUDA_NVCC_FLAGS_DEBUG} -g") set(CUDA_NVCC_FLAGS_RELEASE "${CUDA_NVCC_FLAGS_RELEASE} -O3 -Xptxas=-O3 -Xcompiler=-O3 -DNDEBUG") @@ -64,7 +65,7 @@ function(add_gpu_library) target_link_libraries(${ARGV0} PRIVATE ${CUDA_CUFFT_LIBRARIES}) endfunction() -include( FindPackageHandleStandardArgs ) -FIND_PACKAGE_HANDLE_STANDARD_ARGS( CudaCompilerNVCC - REQUIRED_VARS CMAKE_CUDA_COMPILER - VERSION_VAR CMAKE_CUDA_COMPILER_VERSION ) +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args( + CudaCompilerNVCC REQUIRED_VARS CMAKE_CUDA_COMPILER VERSION_VAR + CMAKE_CUDA_COMPILER_VERSION) From de9f0b3101449f1ba9c32c42a169904878702d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Fri, 3 Apr 2020 23:53:16 +0200 Subject: [PATCH 24/35] Factor out coverage flags --- CMakeLists.txt | 13 +++++++++++++ cmake/unit_test.cmake | 13 +------------ src/core/CMakeLists.txt | 15 ++------------- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f2db2cf38a0..f615a35ed78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -331,6 +331,19 @@ set(CMAKE_SHARED_LIBRARY_PREFIX "") if(WARNINGS_ARE_ERRORS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") endif(WARNINGS_ARE_ERRORS) + +add_library(coverage_interface INTERFACE) +target_compile_options( + coverage_interface + INTERFACE + "$<$:-g>" + "$<$,$>:-fprofile-instr-generate>" + "$<$,$>:-fcoverage-mapping>" + "$<$,$>>:--coverage>" + "$<$,$>>:-fprofile-arcs>" + "$<$,$>>:-ftest-coverage>" +) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-sign-compare -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-missing-braces" ) diff --git a/cmake/unit_test.cmake b/cmake/unit_test.cmake index 35873221ac5..1e75c4dfcb6 100644 --- a/cmake/unit_test.cmake +++ b/cmake/unit_test.cmake @@ -28,22 +28,11 @@ function(UNIT_TEST) # Build tests only when testing set_target_properties(${TEST_NAME} PROPERTIES EXCLUDE_FROM_ALL ON) target_link_libraries(${TEST_NAME} PRIVATE Boost::unit_test_framework) + target_link_libraries(${TEST_NAME} PUBLIC coverage_interface) if(TEST_DEPENDS) target_link_libraries(${TEST_NAME} PRIVATE ${TEST_DEPENDS}) endif() if(WITH_COVERAGE) - target_compile_options(${TEST_NAME} PUBLIC "-g") - target_compile_options( - ${TEST_NAME} - PUBLIC "$<$:-fprofile-instr-generate>") - target_compile_options( - ${TEST_NAME} PUBLIC "$<$:-fcoverage-mapping>") - target_compile_options( - ${TEST_NAME} PUBLIC "$<$>:--coverage>") - target_compile_options( - ${TEST_NAME} PUBLIC "$<$>:-fprofile-arcs>") - target_compile_options( - ${TEST_NAME} PUBLIC "$<$>:-ftest-coverage>") if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") target_link_libraries(${TEST_NAME} PUBLIC gcov) endif() diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index d897dcff243..c6284d8ea3e 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -72,25 +72,14 @@ endif(CUDA) install(TARGETS EspressoCore LIBRARY DESTINATION ${PYTHON_INSTDIR}/espressomd) -target_compile_options( - EspressoCore - PUBLIC - "$<$:-g>" - "$<$,$>:-fprofile-instr-generate>" - "$<$,$>:-fcoverage-mapping>" - "$<$,$>>:--coverage>" - "$<$,$>>:-fprofile-arcs>" - "$<$,$>>:-ftest-coverage>" -) - target_link_libraries( EspressoCore PRIVATE EspressoConfig shapes Profiler "$<$:${FFTW3_LIBRARIES}>" "$<$:Scafacos>" PUBLIC - utils MPI::MPI_CXX Random123 Boost::serialization Boost::mpi - "$<$:${HDF5_LIBRARIES}>" + coverage_interface utils MPI::MPI_CXX Random123 Boost::serialization + Boost::mpi "$<$:${HDF5_LIBRARIES}>" "$<$:Boost::filesystem>" "$<$:h5xx>" "$<$,$>>:gcov>") From 7336b0b24d0c319cc97a752d78ad61d8287bf2c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Thu, 9 Apr 2020 21:41:40 +0200 Subject: [PATCH 25/35] Detect CUDA libraries installed via nvidia-cuda-toolkit --- cmake/FindCUDACompilerClang.cmake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmake/FindCUDACompilerClang.cmake b/cmake/FindCUDACompilerClang.cmake index 329aff8bb8f..c51b74fb366 100644 --- a/cmake/FindCUDACompilerClang.cmake +++ b/cmake/FindCUDACompilerClang.cmake @@ -61,10 +61,12 @@ string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER) find_library( CUDART_LIBRARY NAMES cudart PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib - /usr/local/nvidia/lib NO_DEFAULT_PATH) + /usr/local/nvidia/lib + /usr/lib/x86_64-linux-gnu NO_DEFAULT_PATH) find_library( CUFFT_LIBRARY NAMES cufft PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib - /usr/local/nvidia/lib NO_DEFAULT_PATH) + /usr/local/nvidia/lib + /usr/lib/x86_64-linux-gnu NO_DEFAULT_PATH) function(add_gpu_library) set(options STATIC SHARED MODULE EXCLUDE_FROM_ALL) From 50342b64755e4d9458c58be0aac76147e175fa00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Thu, 16 Apr 2020 22:04:44 +0200 Subject: [PATCH 26/35] Modern CMake Use interface libraries for compiler flags instead of populating variable with global scope that are injected in the compilation and linking commands of all libraries (e.g. CMAKE_CXX_FLAGS). Remove duplicated compile flags. Give meaningful names to variables in FindCUDA* CMake files. Document CMake policies and add CMP0025 to distinguish between Clang and AppleClang. Replace simple if/else blocks by generator expressions. --- CMakeLists.txt | 124 ++++++++++++----------- cmake/FindCUDACompilerClang.cmake | 26 +++-- cmake/FindCUDACompilerHIP.cmake | 44 ++++---- cmake/FindCUDACompilerNVCC.cmake | 30 +++--- cmake/unit_test.cmake | 8 +- src/core/CMakeLists.txt | 13 +-- src/core/cluster_analysis/CMakeLists.txt | 2 +- src/core/io/mpiio/CMakeLists.txt | 3 +- src/python/espressomd/CMakeLists.txt | 47 ++++----- src/scafacos/CMakeLists.txt | 2 +- src/script_interface/CMakeLists.txt | 3 +- src/shapes/CMakeLists.txt | 2 +- src/utils/CMakeLists.txt | 2 +- 13 files changed, 146 insertions(+), 160 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f615a35ed78..f8de5e2631e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,15 +20,24 @@ cmake_minimum_required(VERSION 3.10) message(STATUS "CMake version: ${CMAKE_VERSION}") -if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.13) +if(POLICY CMP0076) + # make target_sources() convert relative paths to absolute cmake_policy(SET CMP0076 NEW) endif() +if(POLICY CMP0025) + # make CXX_COMPILER_ID return "AppleClang" instead of "Clang" for Apple Clang + cmake_policy(SET CMP0025 NEW) +endif() +# CMake modules/macros are in a subdirectory to keep this file cleaner +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + include(FeatureSummary) include(GNUInstallDirs) project(ESPResSo) -include(cmake/FindPythonModule.cmake) -include(cmake/option_enum.cmake) -if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.12") +include(FindPythonModule) +include(option_enum) +if(POLICY CMP0074) + # make find_package() use _ROOT variables cmake_policy(SET CMP0074 NEW) endif() @@ -44,16 +53,13 @@ set(PROJECT_VERSION "4.2-dev") # CMake internal vars # -# CMake modules/macros are in a subdirectory to keep this file cleaner -set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) - # Select the build type option_enum( varname "CMAKE_BUILD_TYPE" help_text "build type" default_value "Release" possible_values "Debug;Release;RelWithDebInfo;MinSizeRel;Coverage;RelWithAssert") -set(CMAKE_CXX_FLAGS_COVERAGE "-Og -g") -set(CMAKE_CXX_FLAGS_RELWITHASSERT "-O3 -g") +set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE} -Og -g") +set(CMAKE_CXX_FLAGS_RELWITHASSERT "${CMAKE_CXX_FLAGS_RELWITHASSERT} -O3 -g") # On Mac OS X, first look for other packages, then frameworks set(CMAKE_FIND_FRAMEWORK LAST) @@ -71,16 +77,16 @@ option(WITH_SCAFACOS "Build with Scafacos support" OFF) option(WITH_BENCHMARKS "Enable benchmarks" OFF) option(WITH_VALGRIND_INSTRUMENTATION "Build with valgrind instrumentation markers" OFF) -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") option(WITH_CLANG_TIDY "Run Clang-Tidy during compilation" OFF) endif() -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL - "GNU") +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL + "GNU") option(WITH_COVERAGE "Generate code coverage report" OFF) option(WITH_ASAN "Build with address sanitizer" OFF) option(WITH_UBSAN "Build with undefined behavior sanitizer" OFF) endif() -if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT APPLE) +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT APPLE) option( WITH_MSAN "Build with memory sanitizer (experimental; requires a memory-sanitized Python interpreter)" @@ -160,15 +166,12 @@ if(WITH_CUDA) if(WITH_COVERAGE) message( FATAL_ERROR - "The combination of options '-DWITH_CUDA_COMPILER=${WITH_CUDA_COMPILER} -DWITH_COVERAGE=${WITH_COVERAGE}' is not supported." - ) + "Cannot enable code coverage with Clang as the CUDA compiler") endif() set(MINIMAL_CUDA_VERSION 8.0) find_package(CUDACompilerClang 6.0 REQUIRED) else() - message( - FATAL_ERROR - "Cannot process option -DWITH_CUDA_COMPILER='${WITH_CUDA_COMPILER}'") + message(FATAL_ERROR "Unknown CUDA compiler '${WITH_CUDA_COMPILER}'") endif() endif(WITH_CUDA) @@ -328,69 +331,65 @@ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTDIR}/espressomd") # drop 'lib' prefix from all libraries set(CMAKE_SHARED_LIBRARY_PREFIX "") -if(WARNINGS_ARE_ERRORS) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") -endif(WARNINGS_ARE_ERRORS) - add_library(coverage_interface INTERFACE) +if(WITH_COVERAGE) + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + target_compile_options( + coverage_interface INTERFACE -g -fprofile-instr-generate + -fcoverage-mapping) + else() + target_compile_options( + coverage_interface INTERFACE -g --coverage -fprofile-arcs -ftest-coverage) + target_link_libraries(coverage_interface INTERFACE gcov) + endif() +endif() + +add_library(cxx_interface INTERFACE) target_compile_options( - coverage_interface - INTERFACE - "$<$:-g>" - "$<$,$>:-fprofile-instr-generate>" - "$<$,$>:-fcoverage-mapping>" - "$<$,$>>:--coverage>" - "$<$,$>>:-fprofile-arcs>" - "$<$,$>>:-ftest-coverage>" -) - -set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-sign-compare -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-missing-braces" -) + cxx_interface + INTERFACE -Wall -Wextra $<$:-Werror> + # disable warnings from -Wextra + -Wno-sign-compare -Wno-unused-function -Wno-unused-variable + -Wno-unused-parameter -Wno-missing-braces + $<$:-Wno-clobbered;-Wno-cast-function-type> + $<$:-wd592>) + +# disable more warnings from -Wextra if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi") + target_compile_options(cxx_interface INTERFACE -Wno-psabi) endif() if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "7.0.0")) - # disable warnings from -Wextra - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-implicit-fallthrough") -endif() -if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - # disable warnings from -Wextra - set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -Wno-clobbered -Wno-cast-function-type") -endif() -if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") - # disable warnings from -Wextra - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd592") + target_compile_options(cxx_interface INTERFACE -Wno-implicit-fallthrough) endif() if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel") - # G++ and Intel don't know this flag - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-private-field") + target_compile_options(cxx_interface INTERFACE -Wno-unused-private-field) endif() if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -Wno-gnu-zero-variadic-macro-arguments") + target_compile_options(cxx_interface + INTERFACE -Wno-gnu-zero-variadic-macro-arguments) endif() + if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.8.5") - # older versions don't support -Wno-pedantic which we need in src/python - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") + # older GCC versions don't support -Wno-pedantic which we need in src/python + target_compile_options(cxx_interface INTERFACE -pedantic) endif() if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "16.0") # workaround for compiler crash related to decltype() and variadic template # usage inside Boost - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_NO_CXX11_VARIADIC_TEMPLATES") + target_compile_options(cxx_interface + INTERFACE -DBOOST_NO_CXX11_VARIADIC_TEMPLATES) endif() # prevent 80-bit arithmetic on old Intel processors if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_SIZEOF_VOID_P EQUAL 4 AND CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffloat-store") + target_compile_options(cxx_interface INTERFACE -ffloat-store) endif() set(CMAKE_MACOSX_RPATH TRUE) @@ -402,18 +401,23 @@ if(WITH_ASAN AND WITH_MSAN) endif() if(WITH_ASAN) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -O1") - set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer") + target_compile_options(cxx_interface INTERFACE -fsanitize=address + -fno-omit-frame-pointer) + target_link_libraries(cxx_interface INTERFACE -fsanitize=address) endif() if(WITH_MSAN) set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -O1") - set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -fsanitize=memory -fno-omit-frame-pointer") + target_compile_options(cxx_interface INTERFACE -fsanitize=memory + -fno-omit-frame-pointer) + target_link_libraries(cxx_interface INTERFACE -fsanitize=memory) endif() if(WITH_UBSAN) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined") + target_compile_options(cxx_interface INTERFACE -fsanitize=undefined) + target_link_libraries(cxx_interface INTERFACE -fsanitize=undefined) endif() +target_link_libraries(cxx_interface INTERFACE coverage_interface) + # # Testing # ############################################################################## diff --git a/cmake/FindCUDACompilerClang.cmake b/cmake/FindCUDACompilerClang.cmake index c51b74fb366..7556b9f13e8 100644 --- a/cmake/FindCUDACompilerClang.cmake +++ b/cmake/FindCUDACompilerClang.cmake @@ -21,8 +21,7 @@ # Find the Clang compiler, include its libraries and declare a custom # `add_library()` wrapper function named `add_gpu_library()`. -if(NOT (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL - "AppleClang")) +if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang") message( FATAL_ERROR "To compile CUDA code with Clang, the C++ compiler must be Clang, not ${CMAKE_CXX_COMPILER_ID}." @@ -58,6 +57,10 @@ set(CUDA_NVCC_FLAGS_RELWITHDEBINFO "${CUDA_NVCC_FLAGS_RELWITHDEBINFO} -O2 -g -DN set(CUDA_NVCC_FLAGS_COVERAGE "${CUDA_NVCC_FLAGS_COVERAGE} -O3 -g") set(CUDA_NVCC_FLAGS_RELWITHASSERT "${CUDA_NVCC_FLAGS_RELWITHASSERT} -O3 -g") string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER) +set(gpu_interface_flags "${CUDA_NVCC_FLAGS} ${CUDA_NVCC_FLAGS_${CMAKE_BUILD_TYPE_UPPER}} --cuda-gpu-arch=sm_30") +if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.8.9) + set(gpu_interface_flags "${gpu_interface_flags} --cuda-gpu-arch=sm_52") +endif() find_library( CUDART_LIBRARY NAMES cudart PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib @@ -73,21 +76,16 @@ function(add_gpu_library) set(oneValueArgs) set(multiValueArgs) cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + list(GET ARG_UNPARSED_ARGUMENTS 0 TARGET_NAME) list(REMOVE_AT ARG_UNPARSED_ARGUMENTS 0) - set_source_files_properties(${ARG_UNPARSED_ARGUMENTS} PROPERTIES LANGUAGE "CXX") + set(TARGET_SOURCES ${ARG_UNPARSED_ARGUMENTS}) + set_source_files_properties(${TARGET_SOURCES} PROPERTIES LANGUAGE "CXX") add_library(${ARGV}) - set_target_properties(${ARGV0} PROPERTIES LINKER_LANGUAGE "CXX") - target_link_libraries(${ARGV0} PRIVATE ${CUDA_LIBRARY} ${CUDART_LIBRARY}) - target_link_libraries(${ARGV0} PRIVATE ${CUFFT_LIBRARY}) - - foreach(file ${ARG_UNPARSED_ARGUMENTS}) + set_target_properties(${TARGET_NAME} PROPERTIES LINKER_LANGUAGE "CXX") + target_link_libraries(${TARGET_NAME} PRIVATE ${CUDA_LIBRARY} ${CUDART_LIBRARY} ${CUFFT_LIBRARY}) + foreach(file ${TARGET_SOURCES}) if(${file} MATCHES "\\.cu$") - set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "${CUDA_NVCC_FLAGS} ${CUDA_NVCC_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}") - if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.8.9) - set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "--cuda-gpu-arch=sm_30 --cuda-gpu-arch=sm_52") - else() - set_source_files_properties(${file} PROPERTIES COMPILE_FLAGS "--cuda-gpu-arch=sm_30") - endif() + set_source_files_properties (${file} PROPERTY COMPILE_FLAGS ${gpu_interface_flags}) endif() endforeach() endfunction() diff --git a/cmake/FindCUDACompilerHIP.cmake b/cmake/FindCUDACompilerHIP.cmake index e18fc4ce0ce..02955dcf990 100644 --- a/cmake/FindCUDACompilerHIP.cmake +++ b/cmake/FindCUDACompilerHIP.cmake @@ -31,32 +31,30 @@ execute_process(COMMAND ${CMAKE_CUDA_COMPILER} --version string(REGEX REPLACE "^.*HCC [Cc]lang version ([0-9\.]+).*\$" "\\1" CMAKE_CUDA_COMPILER_VERSION "${HIPCC_VERSION_STRING}") -list(APPEND HIP_HCC_FLAGS "-I${HIP_ROOT_DIR}/include -I${ROCM_HOME}/include -Wno-c99-designator -Wno-macro-redefined -Wno-duplicate-decl-specifier -std=c++${CMAKE_CUDA_STANDARD}") -list(APPEND HIP_HCC_FLAGS "-pedantic -Wall -Wextra -Wno-sign-compare -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter -Wno-missing-braces -Wno-gnu-anonymous-struct -Wno-nested-anon-types -Wno-gnu-zero-variadic-macro-arguments") -if(NOT HIP_VERSION VERSION_LESS "3.3") - list(APPEND HIP_HCC_FLAGS "-Wno-deprecated-copy") -endif() -if(WARNINGS_ARE_ERRORS) - list(APPEND HIP_HCC_FLAGS "-Werror") -endif() - -set(HIP_HIPCC_FLAGS_DEBUG "${HIP_HIPCC_FLAGS_DEBUG} -g") -set(HIP_HIPCC_FLAGS_RELEASE "${HIP_HIPCC_FLAGS_RELEASE} -O3 -DNDEBUG") -set(HIP_HIPCC_FLAGS_MINSIZEREL "${HIP_HIPCC_FLAGS_MINSIZEREL} -O2 -DNDEBUG") -set(HIP_HIPCC_FLAGS_RELWITHDEBINFO "${HIP_HIPCC_FLAGS_RELWITHDEBINFO} -O2 -g -DNDEBUG") -set(HIP_HIPCC_FLAGS_COVERAGE "${HIP_HIPCC_FLAGS_COVERAGE} -O3 -g") -set(HIP_HIPCC_FLAGS_RELWITHASSERT "${HIP_HIPCC_FLAGS_RELWITHASSERT} -O3 -g") - -if(WARNINGS_ARE_ERRORS) - set(HIP_HCC_FLAGS "${HIP_HCC_FLAGS} -Werror") -endif() - -find_library(ROCFFT_LIB name "rocfft" PATHS "${ROCM_HOME}/lib") +list(APPEND HIP_HCC_FLAGS + -std=c++${CMAKE_CUDA_STANDARD} -pedantic -Wall -Wextra + -Wno-sign-compare -Wno-unused-function -Wno-unused-variable + -Wno-unused-parameter -Wno-missing-braces -Wno-gnu-anonymous-struct + -Wno-nested-anon-types -Wno-gnu-zero-variadic-macro-arguments + -Wno-c99-designator -Wno-macro-redefined -Wno-duplicate-decl-specifier + $<$:-Wno-deprecated-copy> + $<$:-Werror>) + +list(APPEND HIP_HIPCC_FLAGS_DEBUG -g) +list(APPEND HIP_HIPCC_FLAGS_RELEASE -O3 -DNDEBUG) +list(APPEND HIP_HIPCC_FLAGS_MINSIZEREL -O2 -DNDEBUG) +list(APPEND HIP_HIPCC_FLAGS_RELWITHDEBINFO -O2 -g -DNDEBUG) +list(APPEND HIP_HIPCC_FLAGS_COVERAGE -O3 -g) +list(APPEND HIP_HIPCC_FLAGS_RELWITHASSERT -O3 -g) + +find_library(ROCFFT_LIB name "rocfft" PATHS ${ROCM_HOME}/lib) function(add_gpu_library) hip_add_library(${ARGV}) - set_target_properties(${ARGV0} PROPERTIES LINKER_LANGUAGE HIP) - target_link_libraries(${ARGV0} PRIVATE "${ROCFFT_LIB}") + set(GPU_TARGET_NAME ${ARGV0}) + set_target_properties(${GPU_TARGET_NAME} PROPERTIES LINKER_LANGUAGE HIP) + target_link_libraries(${GPU_TARGET_NAME} PRIVATE ${ROCFFT_LIB}) + target_include_directories(${GPU_TARGET_NAME} PRIVATE ${HIP_ROOT_DIR}/include ${ROCM_HOME}/include) endfunction() include(FindPackageHandleStandardArgs) diff --git a/cmake/FindCUDACompilerNVCC.cmake b/cmake/FindCUDACompilerNVCC.cmake index f579df96907..5bfea7a250a 100644 --- a/cmake/FindCUDACompilerNVCC.cmake +++ b/cmake/FindCUDACompilerNVCC.cmake @@ -44,25 +44,23 @@ set(CUDA_LINK_LIBRARIES_KEYWORD PUBLIC) set(CUDA_PROPAGATE_HOST_FLAGS OFF) -set(CUDA_NVCC_FLAGS_DEBUG "${CUDA_NVCC_FLAGS_DEBUG} -g") -set(CUDA_NVCC_FLAGS_RELEASE "${CUDA_NVCC_FLAGS_RELEASE} -O3 -Xptxas=-O3 -Xcompiler=-O3 -DNDEBUG") -set(CUDA_NVCC_FLAGS_MINSIZEREL "${CUDA_NVCC_FLAGS_MINSIZEREL} -O2 -Xptxas=-O2 -Xcompiler=-Os -DNDEBUG") -set(CUDA_NVCC_FLAGS_RELWITHDEBINFO "${CUDA_NVCC_FLAGS_RELWITHDEBINFO} -O2 -g -Xptxas=-O2 -Xcompiler=-O2,-g -DNDEBUG") -set(CUDA_NVCC_FLAGS_COVERAGE "${CUDA_NVCC_FLAGS_COVERAGE} -O3 -g -Xptxas=-O3 -Xcompiler=-Og,-g") -set(CUDA_NVCC_FLAGS_RELWITHASSERT "${CUDA_NVCC_FLAGS_RELWITHASSERT} -O3 -g -Xptxas=-O3 -Xcompiler=-O3,-g") - -set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_52,code=compute_52 -std=c++${CMAKE_CUDA_STANDARD}") -if(WARNINGS_ARE_ERRORS) - set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler=-Werror -Xptxas=-Werror") -endif() -if (CMAKE_OSX_SYSROOT) - set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler=-isysroot -Xcompiler=${CMAKE_OSX_SYSROOT}") -endif() +list(APPEND CUDA_NVCC_FLAGS_DEBUG -g) +list(APPEND CUDA_NVCC_FLAGS_RELEASE -O3 -Xptxas=-O3 -Xcompiler=-O3 -DNDEBUG) +list(APPEND CUDA_NVCC_FLAGS_MINSIZEREL -O2 -Xptxas=-O2 -Xcompiler=-Os -DNDEBUG) +list(APPEND CUDA_NVCC_FLAGS_RELWITHDEBINFO -O2 -g -Xptxas=-O2 -Xcompiler=-O2,-g -DNDEBUG) +list(APPEND CUDA_NVCC_FLAGS_COVERAGE -O3 -g -Xptxas=-O3 -Xcompiler=-Og,-g) +list(APPEND CUDA_NVCC_FLAGS_RELWITHASSERT -O3 -g -Xptxas=-O3 -Xcompiler=-O3,-g) +list(APPEND CUDA_NVCC_FLAGS + -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_52,code=sm_52 + -gencode=arch=compute_52,code=compute_52 -std=c++${CMAKE_CUDA_STANDARD} + $<$:-Xcompiler=-Werror;-Xptxas=-Werror> + $<$:-Xcompiler=-isysroot;-Xcompiler=${CMAKE_OSX_SYSROOT}>) function(add_gpu_library) cuda_add_library(${ARGV}) - set_property(TARGET ${ARGV0} PROPERTY CUDA_SEPARABLE_COMPILATION ON) - target_link_libraries(${ARGV0} PRIVATE ${CUDA_CUFFT_LIBRARIES}) + set(GPU_TARGET_NAME ${ARGV0}) + set_property(TARGET ${GPU_TARGET_NAME} PROPERTY CUDA_SEPARABLE_COMPILATION ON) + target_link_libraries(${GPU_TARGET_NAME} PRIVATE ${CUDA_CUFFT_LIBRARIES} utils Boost::serialization Boost::mpi) endfunction() include(FindPackageHandleStandardArgs) diff --git a/cmake/unit_test.cmake b/cmake/unit_test.cmake index 1e75c4dfcb6..628b9d330f3 100644 --- a/cmake/unit_test.cmake +++ b/cmake/unit_test.cmake @@ -28,17 +28,11 @@ function(UNIT_TEST) # Build tests only when testing set_target_properties(${TEST_NAME} PROPERTIES EXCLUDE_FROM_ALL ON) target_link_libraries(${TEST_NAME} PRIVATE Boost::unit_test_framework) - target_link_libraries(${TEST_NAME} PUBLIC coverage_interface) if(TEST_DEPENDS) target_link_libraries(${TEST_NAME} PRIVATE ${TEST_DEPENDS}) endif() - if(WITH_COVERAGE) - if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_link_libraries(${TEST_NAME} PUBLIC gcov) - endif() - endif() target_include_directories(${TEST_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src/core) - target_link_libraries(${TEST_NAME} PRIVATE EspressoConfig) + target_link_libraries(${TEST_NAME} PRIVATE EspressoConfig cxx_interface) # If NUM_PROC is given, set up MPI parallel test case if(TEST_NUM_PROC) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index c6284d8ea3e..b8950e7ff33 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -76,12 +76,10 @@ target_link_libraries( EspressoCore PRIVATE EspressoConfig shapes Profiler "$<$:${FFTW3_LIBRARIES}>" - "$<$:Scafacos>" - PUBLIC - coverage_interface utils MPI::MPI_CXX Random123 Boost::serialization - Boost::mpi "$<$:${HDF5_LIBRARIES}>" - "$<$:Boost::filesystem>" "$<$:h5xx>" - "$<$,$>>:gcov>") + $<$:Scafacos> cxx_interface + PUBLIC utils MPI::MPI_CXX Random123 Boost::serialization Boost::mpi + "$<$:${HDF5_LIBRARIES}>" + $<$:Boost::filesystem> $<$:h5xx>) target_include_directories( EspressoCore @@ -90,8 +88,7 @@ target_include_directories( PUBLIC "$<$:${HDF5_INCLUDE_DIRS}>" SYSTEM PRIVATE "$<$:${FFTW3_INCLUDE_DIR}>") -target_compile_definitions(EspressoCore - PUBLIC "$<$:H5XX_USE_MPI>") +target_compile_definitions(EspressoCore PUBLIC $<$:H5XX_USE_MPI>) add_subdirectory(accumulators) add_subdirectory(actor) diff --git a/src/core/cluster_analysis/CMakeLists.txt b/src/core/cluster_analysis/CMakeLists.txt index 025967ffd2f..73fbd203f99 100644 --- a/src/core/cluster_analysis/CMakeLists.txt +++ b/src/core/cluster_analysis/CMakeLists.txt @@ -4,7 +4,7 @@ install(TARGETS core_cluster_analysis LIBRARY DESTINATION ${PYTHON_INSTDIR}/espressomd) set_target_properties(core_cluster_analysis PROPERTIES MACOSX_RPATH TRUE) target_link_libraries(core_cluster_analysis PUBLIC EspressoCore - PRIVATE EspressoConfig) + PRIVATE EspressoConfig cxx_interface) if(GSL) target_link_libraries(core_cluster_analysis PRIVATE GSL::gsl GSL::gslcblas) diff --git a/src/core/io/mpiio/CMakeLists.txt b/src/core/io/mpiio/CMakeLists.txt index 7c4b0dc4228..b0a17b6caee 100644 --- a/src/core/io/mpiio/CMakeLists.txt +++ b/src/core/io/mpiio/CMakeLists.txt @@ -1,4 +1,5 @@ add_library(mpiio SHARED mpiio.cpp) target_include_directories(mpiio PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -target_link_libraries(mpiio PRIVATE EspressoConfig EspressoCore MPI::MPI_CXX) +target_link_libraries(mpiio PRIVATE EspressoConfig EspressoCore MPI::MPI_CXX + cxx_interface) install(TARGETS mpiio LIBRARY DESTINATION ${PYTHON_INSTDIR}/espressomd) diff --git a/src/python/espressomd/CMakeLists.txt b/src/python/espressomd/CMakeLists.txt index 5eda89913bc..8c03c524796 100644 --- a/src/python/espressomd/CMakeLists.txt +++ b/src/python/espressomd/CMakeLists.txt @@ -59,6 +59,24 @@ add_subdirectory(io) list(APPEND cython_SRC ${CMAKE_CURRENT_BINARY_DIR}/code_info.pyx) list(REMOVE_DUPLICATES cython_SRC) +add_library(pyx_interface INTERFACE) +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_compile_options( + pyx_interface INTERFACE -Wno-pedantic -Wno-cpp -Wno-strict-aliasing + -Wno-maybe-uninitialized -Wno-unused-variable) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL + "AppleClang") + target_compile_options( + pyx_interface INTERFACE -Wno-pedantic -Wno-\#warnings + -Wno-sometimes-uninitialized -Wno-unused-variable) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") + target_compile_options(pyx_interface INTERFACE -wd1224) +else() + target_compile_options(pyx_interface INTERFACE -Wno-pedantic + -Wno-unused-variable) +endif() +target_link_libraries(pyx_interface INTERFACE cxx_interface) + # Configure, compile and install Cython files foreach(cython_file ${cython_SRC}) get_filename_component(basename ${cython_file} NAME_WE) @@ -79,9 +97,8 @@ foreach(cython_file ${cython_SRC}) add_custom_command( OUTPUT ${outputpath} COMMAND - ${CYTHON_EXECUTABLE} - "$<$:--warning-errors>" -3 --cplus - --directive embedsignature=True --directive binding=True -I + ${CYTHON_EXECUTABLE} $<$:--warning-errors> + -3 --cplus --directive embedsignature=True --directive binding=True -I ${CMAKE_CURRENT_SOURCE_DIR} -I ${CMAKE_CURRENT_BINARY_DIR} ${cython_file} -o ${outputpath} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/.. @@ -100,32 +117,10 @@ foreach(cython_file ${cython_SRC}) ${target} PROPERTIES SUFFIX ".so" LINK_FLAGS "-undefined dynamic_lookup") endif() - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set_source_files_properties( - ${outputpath} - PROPERTIES - COMPILE_FLAGS - "-Wno-pedantic -Wno-cpp -Wno-strict-aliasing -Wno-maybe-uninitialized -Wno-unused-variable" - ) - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID - STREQUAL "AppleClang") - set_source_files_properties( - ${outputpath} - PROPERTIES - COMPILE_FLAGS - "-Wno-pedantic -Wno-#warnings -Wno-sometimes-uninitialized -Wno-unused-variable" - ) - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel") - set_source_files_properties(${outputpath} PROPERTIES COMPILE_FLAGS - "-wd1224") - else() - set_source_files_properties( - ${outputpath} PROPERTIES COMPILE_FLAGS - "-Wno-pedantic -Wno-unused-variable") - endif() set_target_properties(${target} PROPERTIES CXX_CLANG_TIDY "") target_link_libraries(${target} PRIVATE EspressoConfig EspressoCore ScriptInterface) + target_link_libraries(${target} PRIVATE pyx_interface) target_include_directories(${target} SYSTEM PRIVATE ${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR}) add_dependencies(espressomd ${target}) diff --git a/src/scafacos/CMakeLists.txt b/src/scafacos/CMakeLists.txt index 9a06e5314e8..0201a21a593 100644 --- a/src/scafacos/CMakeLists.txt +++ b/src/scafacos/CMakeLists.txt @@ -3,6 +3,6 @@ add_library(Scafacos SHARED ${Scafacos_SRC}) target_include_directories(Scafacos PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${SCAFACOS_INCLUDE_DIRS}) target_link_libraries(Scafacos PRIVATE ${SCAFACOS_LDFLAGS}) -target_link_libraries(Scafacos PUBLIC MPI::MPI_CXX) +target_link_libraries(Scafacos PUBLIC MPI::MPI_CXX PRIVATE cxx_interface) install(TARGETS Scafacos DESTINATION ${PYTHON_INSTDIR}/espressomd) diff --git a/src/script_interface/CMakeLists.txt b/src/script_interface/CMakeLists.txt index 342e1d57707..c9c96de035f 100644 --- a/src/script_interface/CMakeLists.txt +++ b/src/script_interface/CMakeLists.txt @@ -18,6 +18,7 @@ install(TARGETS ScriptInterface target_link_libraries( ScriptInterface PRIVATE EspressoConfig EspressoCore - PUBLIC mpiio utils MPI::MPI_CXX shapes core_cluster_analysis) + PUBLIC mpiio utils MPI::MPI_CXX shapes core_cluster_analysis + PRIVATE cxx_interface) target_include_directories(ScriptInterface PUBLIC ${CMAKE_SOURCE_DIR}/src) diff --git a/src/shapes/CMakeLists.txt b/src/shapes/CMakeLists.txt index a5c20f71eca..9bb12aa5f11 100644 --- a/src/shapes/CMakeLists.txt +++ b/src/shapes/CMakeLists.txt @@ -4,7 +4,7 @@ set(SOURCE_FILES src/SpheroCylinder.cpp src/Stomatocyte.cpp src/Torus.cpp src/Wall.cpp) add_library(shapes SHARED ${SOURCE_FILES}) -target_link_libraries(shapes PUBLIC utils PRIVATE Boost::boost) +target_link_libraries(shapes PUBLIC utils PRIVATE Boost::boost cxx_interface) target_include_directories( shapes PUBLIC $ $) diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 66e557ee6c6..9c365b615cb 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -1,7 +1,7 @@ add_library(utils INTERFACE) target_include_directories( utils INTERFACE $ - $) + $ Boost::serialization Boost::mpi) install(TARGETS utils LIBRARY DESTINATION ${PYTHON_INSTDIR}/espressomd) From be61c3a1e56f8b2b7f9b4a0a6d0693a48ecf9d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Fri, 17 Apr 2020 18:02:02 +0200 Subject: [PATCH 27/35] Simplify HIP detection Move ROCm path patching logic in FindCUDACompilerHIP.cmake and check only the HIP version. --- CMakeLists.txt | 12 +----------- cmake/FindCUDACompilerHIP.cmake | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f8de5e2631e..3b35a3c2834 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,17 +151,7 @@ if(WITH_CUDA) find_package(CUDA ${MINIMAL_CUDA_VERSION} REQUIRED) find_package(CUDACompilerNVCC ${MINIMAL_CUDA_VERSION} REQUIRED) elseif(WITH_CUDA_COMPILER STREQUAL "hip") - set(ROCM_HOME "/opt/rocm" CACHE FILEPATH "Path to AMD ROCm") - list(APPEND CMAKE_MODULE_PATH "${ROCM_HOME}/hip/cmake") - find_package(HIP 1.5.18494 MODULE REQUIRED) - # patch HCC_PATH environment variable and reload HIP (for ROCm 3.0/3.1) - if(HIP_VERSION VERSION_LESS "3.1") - set(HCC_PATH "${HIP_ROOT_DIR}") - else() - set(HCC_PATH "${ROCM_HOME}/hcc") - endif() - find_package(HIP 1.5.18494 MODULE REQUIRED) - find_package(CUDACompilerHIP 6.0 REQUIRED) + find_package(CUDACompilerHIP 1.5.18494 REQUIRED) elseif(WITH_CUDA_COMPILER STREQUAL "clang") if(WITH_COVERAGE) message( diff --git a/cmake/FindCUDACompilerHIP.cmake b/cmake/FindCUDACompilerHIP.cmake index 02955dcf990..3c34c3114c3 100644 --- a/cmake/FindCUDACompilerHIP.cmake +++ b/cmake/FindCUDACompilerHIP.cmake @@ -21,16 +21,20 @@ # Find the HIP compiler, include its libraries and declare a custom # `add_library()` wrapper function named `add_gpu_library()`. -set(CMAKE_CUDA_COMPILER ${HIP_HIPCC_EXECUTABLE}) +set(ROCM_HOME "/opt/rocm" CACHE FILEPATH "Path to AMD ROCm") +list(APPEND CMAKE_MODULE_PATH "${ROCM_HOME}/hip/cmake") +find_package(HIP ${CUDACompilerHIP_FIND_VERSION} MODULE REQUIRED) +# patch HCC_PATH environment variable and reload HIP +if(HIP_VERSION VERSION_LESS 3.1) + set(HCC_PATH "${HIP_ROOT_DIR}") +else() + set(HCC_PATH "${ROCM_HOME}/hcc") +endif() +find_package(HIP ${CUDACompilerHIP_FIND_VERSION} MODULE REQUIRED) + set(CUDA 1) set(HIP 1) -execute_process(COMMAND ${CMAKE_CUDA_COMPILER} --version - OUTPUT_VARIABLE HIPCC_VERSION_STRING) - -string(REGEX REPLACE "^.*HCC [Cc]lang version ([0-9\.]+).*\$" "\\1" - CMAKE_CUDA_COMPILER_VERSION "${HIPCC_VERSION_STRING}") - list(APPEND HIP_HCC_FLAGS -std=c++${CMAKE_CUDA_STANDARD} -pedantic -Wall -Wextra -Wno-sign-compare -Wno-unused-function -Wno-unused-variable @@ -59,5 +63,4 @@ endfunction() include(FindPackageHandleStandardArgs) find_package_handle_standard_args( - CudaCompilerHIP REQUIRED_VARS CMAKE_CUDA_COMPILER VERSION_VAR - CMAKE_CUDA_COMPILER_VERSION) + CudaCompilerHIP REQUIRED_VARS HIP_HIPCC_EXECUTABLE VERSION_VAR HIP_VERSION) From b798fabece831fff753f8c847ff4781679d7ae3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Fri, 17 Apr 2020 18:35:33 +0200 Subject: [PATCH 28/35] Fix Travis shell error The double quotes were not removed by the shell interpreter. --- maintainer/CI/build_docker.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maintainer/CI/build_docker.sh b/maintainer/CI/build_docker.sh index 38af9cc5164..af6a593d4dc 100755 --- a/maintainer/CI/build_docker.sh +++ b/maintainer/CI/build_docker.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # Copyright (C) 2016-2019 The ESPResSo project # # This file is part of ESPResSo. @@ -26,7 +26,7 @@ with_cuda=false myconfig=${myconfig} check_procs=${check_procs} make_check=${make_check} -build_type="RelWithAssert" +build_type=RelWithAssert EOF if [ -z "${image}" ]; then From 58978df93663b04fb9c1425d2f348a3408c52612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Sat, 18 Apr 2020 00:15:19 +0200 Subject: [PATCH 29/35] Correctly detect CUDA versions with Clang Clang returns "version unknown" for unsupported CUDA libraries, or doesn't return a version string (depending on CMAKE_CXX_FLAGS), causing the CMake regex to store the complete Clang stdout in the CUDA_VERSION variable instead of a valid version number. This is now fixed, and the CUDA version is now shown as .. --- cmake/FindCUDACompilerClang.cmake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmake/FindCUDACompilerClang.cmake b/cmake/FindCUDACompilerClang.cmake index 7556b9f13e8..46adafa0bc3 100644 --- a/cmake/FindCUDACompilerClang.cmake +++ b/cmake/FindCUDACompilerClang.cmake @@ -36,10 +36,13 @@ execute_process(COMMAND ${CMAKE_CUDA_COMPILER} ${CMAKE_CXX_FLAGS} --verbose ERROR_VARIABLE CUDA_DIR_STRING) string(REGEX REPLACE "^.*Found CUDA installation: ([^,]+).*\$" "\\1" CUDA_DIR "${CUDA_DIR_STRING}") -string(REGEX REPLACE "^.*Found CUDA installation: .* version ([0-9]+).*\$" +string(REGEX REPLACE "^.*Found CUDA installation: .* version ([0-9\.]+|unknown).*\$" "\\1" CUDA_VERSION "${CUDA_DIR_STRING}") message(STATUS "Found CUDA-capable host compiler: ${CMAKE_CUDA_COMPILER}") +if(NOT CUDA_DIR_STRING MATCHES "Found CUDA installation" OR CUDA_VERSION STREQUAL "unknown") + message(FATAL_ERROR "Clang found no compatible CUDA library.") +endif() message(STATUS "Found CUDA version: ${CUDA_VERSION}") message(STATUS "Found CUDA installation: ${CUDA_DIR}") From 82e4d9dba764afae571845862201f852bd15d1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 20 Apr 2020 17:57:36 +0200 Subject: [PATCH 30/35] Remove NVIDIA installation instructions on OSX --- doc/sphinx/installation.rst | 9 --------- 1 file changed, 9 deletions(-) diff --git a/doc/sphinx/installation.rst b/doc/sphinx/installation.rst index 33a950d6a48..baeb77649e9 100644 --- a/doc/sphinx/installation.rst +++ b/doc/sphinx/installation.rst @@ -217,12 +217,6 @@ Installing packages using Homebrew brew link --force cython pip install PyOpenGL matplotlib -Installing CUDA -""""""""""""""" - -If your Mac has an Nvidia graphics card, you should also download and install the -CUDA SDK [6]_ to make use of GPU computation. - .. _Quick installation: Quick installation @@ -874,6 +868,3 @@ use one tool at a time. .. [5] http://www.fftw.org/ - -.. [6] - https://developer.nvidia.com/cuda-downloads From ad8044e68a696f49d4168b312e6dd6cd9f2d6a2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 20 Apr 2020 18:02:09 +0200 Subject: [PATCH 31/35] Update links to dockerfiles --- doc/sphinx/installation.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/sphinx/installation.rst b/doc/sphinx/installation.rst index baeb77649e9..de4b14e4354 100644 --- a/doc/sphinx/installation.rst +++ b/doc/sphinx/installation.rst @@ -126,10 +126,10 @@ Installing requirements on other Linux distributions Please refer to the following Dockerfiles to find the minimum set of packages required to compile |es| on other Linux distributions: -* `CentOS 7 `_ -* `Fedora 30 `_ -* `Debian 10 `_ -* `OpenSUSE Leap 15.1 `_ +* `CentOS `_ +* `Fedora `_ +* `Debian `_ +* `OpenSUSE `_ .. _Installing requirements on Mac OS X: From 5b91c0e75c958ec182d79e562ef5f81b7311ed7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 20 Apr 2020 20:03:12 +0200 Subject: [PATCH 32/35] Fix incorrect formula --- doc/sphinx/electrostatics.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/sphinx/electrostatics.rst b/doc/sphinx/electrostatics.rst index 304ec307041..d5f1ae1bac3 100644 --- a/doc/sphinx/electrostatics.rst +++ b/doc/sphinx/electrostatics.rst @@ -7,7 +7,7 @@ The Coulomb (or electrostatic) interaction is defined as follows. For a pair of particles at distance :math:`r` with charges :math:`q_1` and :math:`q_2`, the interaction is given by -.. math:: U_C(r)=C \cdot \frac{q_1 q_2}{r}. +.. math:: U_C(r)=C \cdot \frac{q_1 q_2}{r} where @@ -16,10 +16,10 @@ where :label: coulomb_prefactor is a prefactor which can be set by the user. The commonly used Bjerrum length -:math:`l_B = e_o^2 / (4 \pi \varepsilon_0 \varepsilon_r k_B T)` is the length at +:math:`l_B = e^2 / (4 \pi \varepsilon_0 \varepsilon_r k_B T)` is the length at which the Coulomb energy between two unit charges is equal to the thermal energy :math:`k_B T`. -Based on the this length, the prefactor is given by :math:`C=l_B k_B T`. +Based on this length, the prefactor is given by :math:`C=l_B k_B T / e^2`. Computing electrostatic interactions is computationally very expensive. |es| features some state-of-the-art algorithms to deal with these From fb5686adad858cd71d569e3b1da0165b0924f7bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 20 Apr 2020 20:06:47 +0200 Subject: [PATCH 33/35] Replace magic values by their full expressions --- .../02-charged_system/02-charged_system-2.ipynb | 7 +++++-- .../02-charged_system/scripts/nacl_units.py | 7 +++++-- .../02-charged_system/scripts/nacl_units_vis.py | 7 +++++-- samples/visualization_charged.py | 17 +++++++++++------ 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/doc/tutorials/02-charged_system/02-charged_system-2.ipynb b/doc/tutorials/02-charged_system/02-charged_system-2.ipynb index ef2d7958224..ea135ce6faa 100644 --- a/doc/tutorials/02-charged_system/02-charged_system-2.ipynb +++ b/doc/tutorials/02-charged_system/02-charged_system-2.ipynb @@ -101,8 +101,11 @@ "time_step = 0.001823\n", "temp = 1198.3\n", "gamma = 50\n", - "#l_bjerrum = 0.885^2 * e^2/(4*pi*epsilon_0*k_B*T)\n", - "l_bjerrum = 130878.0 / temp\n", + "k_B = 1.380649e-23 # units of [J/K]\n", + "q_e = 1.602176634e-19 # units of [C]\n", + "epsilon_0 = 8.8541878128e-12 # units of [C^2/J/m]\n", + "coulomb_prefactor = q_e**2 / (4 * numpy.pi * epsilon_0) * 1e10\n", + "l_bjerrum = 0.885**2 * coulomb_prefactor / (k_B * temp)\n", "wall_margin = 0.5\n", "Ez = 0\n", "\n", diff --git a/doc/tutorials/02-charged_system/scripts/nacl_units.py b/doc/tutorials/02-charged_system/scripts/nacl_units.py index e3fff54167f..97eb780080e 100644 --- a/doc/tutorials/02-charged_system/scripts/nacl_units.py +++ b/doc/tutorials/02-charged_system/scripts/nacl_units.py @@ -37,8 +37,11 @@ time_step = 0.001823 temp = 298.0 gamma = 4.55917 -#l_bjerrum = 0.885^2 * e^2/(4*pi*epsilon_0*k_B*T) -l_bjerrum = 130878.0 / temp +k_B = 1.380649e-23 # units of [J/K] +q_e = 1.602176634e-19 # units of [C] +epsilon_0 = 8.8541878128e-12 # units of [C^2/J/m] +coulomb_prefactor = q_e**2 / (4 * numpy.pi * epsilon_0) * 1e10 +l_bjerrum = 0.885**2 * coulomb_prefactor / (k_B * temp) num_steps_equilibration = 9000 num_configs = 50 diff --git a/doc/tutorials/02-charged_system/scripts/nacl_units_vis.py b/doc/tutorials/02-charged_system/scripts/nacl_units_vis.py index d21adbea97d..d81062d7e28 100644 --- a/doc/tutorials/02-charged_system/scripts/nacl_units_vis.py +++ b/doc/tutorials/02-charged_system/scripts/nacl_units_vis.py @@ -75,8 +75,11 @@ def decreaseTemp(): time_step = 0.001823 temp = 298.0 gamma = 20.0 -#l_bjerrum = 0.885^2 * e^2/(4*pi*epsilon_0*k_B*T) -l_bjerrum = 130878.0 / temp +k_B = 1.380649e-23 # units of [J/K] +q_e = 1.602176634e-19 # units of [C] +epsilon_0 = 8.8541878128e-12 # units of [C^2/J/m] +coulomb_prefactor = q_e**2 / (4 * numpy.pi * epsilon_0) * 1e10 +l_bjerrum = 0.885**2 * coulomb_prefactor / (k_B * temp) num_steps_equilibration = 30 diff --git a/samples/visualization_charged.py b/samples/visualization_charged.py index 7bad987b0e4..b5b7c228ac2 100644 --- a/samples/visualization_charged.py +++ b/samples/visualization_charged.py @@ -45,12 +45,17 @@ kb_kjmol = 0.0083145 temperature = SI_temperature * kb_kjmol -# COULOMB PREFACTOR (elementary charge)^2 / (4*pi*epsilon_0) in Angstrom * -# kJ/mol -epsilon_r = 4.0 -coulomb_prefactor = 1.67101e5 * kb_kjmol / epsilon_r +# COULOMB PREFACTOR (elementary charge)^2 / (4*pi*epsilon) in Angstrom*kJ/mol +epsilon_r = 4.0 # dimensionless +epsilon_0 = 8.8541878128e-12 # units of [C^2/J/m] +q_e = 1.602176634e-19 # units of [C] +avogadro = 6.022e23 # units of [mol] +prefactor = q_e**2 / (4 * np.pi * epsilon_r * epsilon_0) # units of [J.m] +# convert energies to kJ/mol, with distances in Angstroms +coulomb_prefactor = prefactor * avogadro / 1000 * 1e10 # FORCE FIELDS +# distances in Angstroms, epsilons in kBT, masses in g/mol species = ["Cl", "Na", "Colloid", "Solvent"] types = {"Cl": 0, "Na": 1, "Colloid": 2, "Solvent": 3} charges = {"Cl": -1.0, "Na": 1.0, "Colloid": -3.0, "Solvent": 0.0} @@ -114,11 +119,11 @@ def combination_rule_sigma(rule, sig1, sig2): epsilon=lj_eps, sigma=lj_sig, cutoff=lj_cut, shift="auto") energy = system.analysis.energy() -print("Before Minimization: E_total = {}".format(energy['total'])) +print("Before Minimization: E_total = {:.2e}".format(energy['total'])) steepest_descent(system, f_max=1000, gamma=30.0, max_steps=1000, max_displacement=0.01) energy = system.analysis.energy() -print("After Minimization: E_total = {}".format(energy['total'])) +print("After Minimization: E_total = {:.2e}".format(energy['total'])) print("Tune p3m") p3m = electrostatics.P3M(prefactor=coulomb_prefactor, accuracy=1e-1) From 801bca406d30060fb4dcf5c60b759542ec3735b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 20 Apr 2020 20:44:14 +0200 Subject: [PATCH 34/35] Explain how to visualize domain decomposition --- doc/sphinx/system_setup.rst | 3 ++- samples/visualization_cellsystem.py | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/sphinx/system_setup.rst b/doc/sphinx/system_setup.rst index 0358dd18307..26f9ab9fe49 100644 --- a/doc/sphinx/system_setup.rst +++ b/doc/sphinx/system_setup.rst @@ -118,7 +118,8 @@ The properties of the cell system can be accessed by * :py:attr:`~espressomd.cellsystem.CellSystem.node_grid` (int[3]) 3D node grid for real space domain decomposition (optional, if - unset an optimal set is chosen automatically). + unset an optimal set is chosen automatically). The domain decomposition + can be visualized with :file:`samples/visualization_cellsystem.py`. * :py:attr:`~espressomd.cellsystem.CellSystem.skin` diff --git a/samples/visualization_cellsystem.py b/samples/visualization_cellsystem.py index ac43049db46..250f43a8989 100644 --- a/samples/visualization_cellsystem.py +++ b/samples/visualization_cellsystem.py @@ -16,7 +16,11 @@ # along with this program. If not, see . """ Visualize the system cells and MPI domains. Run ESPResSo in parallel -to color particles by node. +to color particles by node. With OpenMPI, this can be achieved using +``mpiexec -n 4 ./pypresso ../samples/visualization_cellsystem.py``. +Set property ``system.cell_system.node_grid = [i, j, k]`` (with ``i * j * k`` +equal to the number of MPI ranks) to change the way the cellsystem is +partitioned. Only the domain of MPI rank 0 will be shown in wireframe. """ import espressomd @@ -41,6 +45,7 @@ system.time_step = 0.0005 system.cell_system.set_domain_decomposition(use_verlet_lists=True) system.cell_system.skin = 0.4 +#system.cell_system.node_grid = [i, j, k] for i in range(100): system.part.add(pos=box * np.random.random(3)) From 135a717d512d6685ead8d30327ec1d3456800a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 20 Apr 2020 20:55:45 +0200 Subject: [PATCH 35/35] Document which HDF5 package to install Repositories offer serial and parallel versions of the libhdf5 package. Only the parallel version can be used by ESPResSo. --- doc/sphinx/io.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/sphinx/io.rst b/doc/sphinx/io.rst index d6e9aaced9c..b6fe13b79a7 100644 --- a/doc/sphinx/io.rst +++ b/doc/sphinx/io.rst @@ -121,7 +121,10 @@ Writing H5MD-files .. note:: - Requires ``H5MD`` external feature, enabled with ``-DWITH_HDF5=ON``. + Requires ``H5MD`` external feature, enabled with ``-DWITH_HDF5=ON``. Also + requires a parallel version of HDF5. On Ubuntu, this can be installed via + either ``libhdf5-openmpi-dev`` for OpenMPI or ``libhdf5-mpich-dev`` for + MPICH, but not ``libhdf5-dev`` which is the serial version. For large amounts of data it's a good idea to store it in the hdf5 (H5MD is based on hdf5) file format (see https://www.hdfgroup.org/ for