From 64f939773dc08f5234b463158d65dc5cc5d864bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Fri, 13 Dec 2024 19:28:01 +0100 Subject: [PATCH 1/2] CMake: Disable in-place builds --- CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d374aaa4d0..42411977f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,6 +60,13 @@ include(FetchContent) include(espresso_option_enum) include(espresso_enable_avx2_support) +if(EXISTS "${PROJECT_BINARY_DIR}/CMakeLists.txt") + message( + FATAL_ERROR + "${PROJECT_NAME} cannot be built in-place. Instead, create a build directory and run CMake from there. A new file 'CMakeCache.txt' and a new folder 'CMakeFiles' have just been created by CMake in the current folder and need to be removed." + ) +endif() + # # CMake internal vars # From a738812d26288a2f3433840c735c4c355b04cd4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Mon, 16 Dec 2024 16:14:37 +0100 Subject: [PATCH 2/2] CMake: Redesign targets --- CMakeLists.txt | 7 +- src/CMakeLists.txt | 2 +- src/core/CMakeLists.txt | 2 +- .../CMakeLists.txt | 19 ++--- src/script_interface/CMakeLists.txt | 2 +- src/walberla_bridge/CMakeLists.txt | 43 ++++++---- .../generated_kernels/CMakeLists.txt | 2 +- .../generated_kernels/CMakeLists.txt | 2 +- .../generated_kernels/CMakeLists.txt | 78 +++++++++---------- src/walberla_bridge/tests/CMakeLists.txt | 6 +- 10 files changed, 83 insertions(+), 80 deletions(-) rename src/{profiler => instrumentation}/CMakeLists.txt (55%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 42411977f0..613fd8ce82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -485,7 +485,7 @@ target_compile_options( $<$:-Wimplicit-float-conversion> $<$:-Wunused-exception-parameter> $<$:-Wmissing-variable-declarations> - $<$,$,11.0.0>>:-Wnon-c-typedef-for-linkage> + $<$:-Wnon-c-typedef-for-linkage> $<$>:-Wdelete-non-virtual-dtor> # disable warnings from -Wall and -Wextra -Wno-sign-compare @@ -494,9 +494,9 @@ target_compile_options( -Wno-array-bounds $<$:-Wno-restrict> $<$:-Wno-clobbered> + $<$:-Wno-cast-function-type> $<$:-diag-disable=592> $<$:-Wno-gnu-zero-variadic-macro-arguments> - $<$,$,8.1.0>>:-Wno-cast-function-type> $<$>:-Wno-implicit-fallthrough> $<$>:-Wno-unused-private-field> # warnings are errors @@ -694,7 +694,8 @@ if(ESPRESSO_BUILD_WITH_CALIPER) target_compile_options( caliper-runtime PRIVATE $<$:-Wno-maybe-uninitialized> - $<$:-Wno-volatile>) + $<$:-Wno-volatile> + $<$:-Wno-deprecated-volatile>) endif() # diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 40e23972f3..c93f52ab59 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -34,7 +34,7 @@ add_subdirectory(utils) add_subdirectory(shapes) add_subdirectory(core) add_subdirectory(config) -add_subdirectory(profiler) +add_subdirectory(instrumentation) if(ESPRESSO_BUILD_WITH_SCAFACOS) add_subdirectory(scafacos) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index d97b70a983..e32e9a689c 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -80,7 +80,7 @@ target_link_libraries( espresso_core PRIVATE espresso::config espresso::utils::mpi espresso::shapes espresso::cpp_flags PUBLIC espresso::utils MPI::MPI_CXX Random123 espresso::particle_observables - Boost::serialization Boost::mpi espresso::profiler) + Boost::serialization Boost::mpi espresso::instrumentation) target_include_directories(espresso_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/profiler/CMakeLists.txt b/src/instrumentation/CMakeLists.txt similarity index 55% rename from src/profiler/CMakeLists.txt rename to src/instrumentation/CMakeLists.txt index 62daa31a77..ecf8fda7f4 100644 --- a/src/profiler/CMakeLists.txt +++ b/src/instrumentation/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (C) 2019-2022 The ESPResSo project +# Copyright (C) 2019-2024 The ESPResSo project # # This file is part of ESPResSo. # @@ -17,22 +17,17 @@ # along with this program. If not, see . # -add_library(espresso_profiler INTERFACE) -add_library(espresso::profiler ALIAS espresso_profiler) +add_library(espresso_instrumentation INTERFACE) +add_library(espresso::instrumentation ALIAS espresso_instrumentation) if(ESPRESSO_BUILD_WITH_VALGRIND) - target_include_directories(espresso_profiler + target_include_directories(espresso_instrumentation INTERFACE "${VALGRIND_INCLUDE_DIRS}") endif() if(ESPRESSO_BUILD_WITH_CALIPER) - target_link_libraries(espresso_profiler INTERFACE caliper) - # workaround to handle the case where the build directory is outside `_deps` - cmake_path(GET CMAKE_BINARY_DIR FILENAME CMAKE_BINARY_DIR_BASENAME) - set(caliper_BINARY_DIR_ALTERNATIVE - "${CMAKE_BINARY_DIR}/${CMAKE_BINARY_DIR_BASENAME}/_deps/caliper-src") + target_link_libraries(espresso_instrumentation INTERFACE caliper) target_include_directories( - espresso_profiler - INTERFACE "${caliper_SOURCE_DIR}/include" "${caliper_BINARY_DIR}/include" - "${caliper_BINARY_DIR_ALTERNATIVE}/include") + espresso_instrumentation INTERFACE "${caliper_SOURCE_DIR}/include" + "${caliper_BINARY_DIR}/include") endif() diff --git a/src/script_interface/CMakeLists.txt b/src/script_interface/CMakeLists.txt index 3e795b2365..b8bcc4ff26 100644 --- a/src/script_interface/CMakeLists.txt +++ b/src/script_interface/CMakeLists.txt @@ -58,7 +58,7 @@ install(TARGETS espresso_script_interface target_link_libraries( espresso_script_interface PRIVATE espresso::config espresso::core - espresso::profiler + espresso::instrumentation PUBLIC espresso::utils MPI::MPI_CXX Boost::mpi espresso::shapes PRIVATE espresso::cpp_flags) diff --git a/src/walberla_bridge/CMakeLists.txt b/src/walberla_bridge/CMakeLists.txt index 6b2da504a0..e7b652c79d 100644 --- a/src/walberla_bridge/CMakeLists.txt +++ b/src/walberla_bridge/CMakeLists.txt @@ -17,6 +17,17 @@ # along with this program. If not, see . # +function(espresso_configure_walberla_target) + set(TARGET_NAME ${ARGV0}) + set_target_properties(${TARGET_NAME} PROPERTIES CXX_CLANG_TIDY "") + target_link_libraries(${TARGET_NAME} PRIVATE ${WALBERLA_LIBS}) + target_include_directories( + ${TARGET_NAME} PUBLIC include PRIVATE ${WALBERLA_INCLUDE_DIRS} + ${walberla_BINARY_DIR}/src) + install(TARGETS ${TARGET_NAME} + LIBRARY DESTINATION ${ESPRESSO_INSTALL_PYTHON}/espressomd) +endfunction() + add_library(espresso_walberla_cpp_flags INTERFACE) add_library(espresso::walberla::cpp_flags ALIAS espresso_walberla_cpp_flags) target_link_libraries( @@ -30,31 +41,33 @@ target_link_libraries( INTERFACE espresso::cuda_flags $<$:espresso::avx_flags>) -function(espresso_configure_walberla_target) - set(TARGET_NAME ${ARGV0}) - set_target_properties(${TARGET_NAME} PROPERTIES CXX_CLANG_TIDY "") - target_link_libraries(${TARGET_NAME} PRIVATE ${WALBERLA_LIBS}) - target_include_directories( - ${TARGET_NAME} PUBLIC include PRIVATE ${WALBERLA_INCLUDE_DIRS} - ${walberla_BINARY_DIR}/src) - install(TARGETS ${TARGET_NAME} - LIBRARY DESTINATION ${ESPRESSO_INSTALL_PYTHON}/espressomd) -endfunction() - add_library(espresso_walberla SHARED) +add_library(espresso_walberla_codegen SHARED) add_library(espresso::walberla ALIAS espresso_walberla) +add_library(espresso::walberla_codegen ALIAS espresso_walberla_codegen) espresso_configure_walberla_target(espresso_walberla) +espresso_configure_walberla_target(espresso_walberla_codegen) -target_link_libraries(espresso_walberla PUBLIC MPI::MPI_CXX espresso::utils +target_link_libraries( + espresso_walberla PUBLIC MPI::MPI_CXX espresso::utils + PRIVATE espresso::walberla::cpp_flags espresso::walberla_codegen) +target_link_libraries(espresso_walberla_codegen PRIVATE espresso::walberla::cpp_flags) -if(ESPRESSO_BUILD_WITH_CUDA AND WALBERLA_BUILD_WITH_CUDA) +if(WALBERLA_BUILD_WITH_CUDA) espresso_add_gpu_library(espresso_walberla_cuda SHARED) + espresso_add_gpu_library(espresso_walberla_codegen_cuda SHARED) add_library(espresso::walberla_cuda ALIAS espresso_walberla_cuda) + add_library(espresso::walberla_codegen_cuda ALIAS + espresso_walberla_codegen_cuda) espresso_configure_walberla_target(espresso_walberla_cuda) - target_link_libraries(espresso_walberla_cuda PUBLIC espresso::utils - PRIVATE CUDA::cuda_driver CUDA::cudart) + espresso_configure_walberla_target(espresso_walberla_codegen_cuda) + target_link_libraries( + espresso_walberla_cuda PUBLIC espresso::utils + PRIVATE CUDA::cuda_driver CUDA::cudart espresso::walberla_codegen_cuda) + target_link_libraries(espresso_walberla_codegen_cuda PRIVATE CUDA::cuda_driver + CUDA::cudart) endif() add_subdirectory(src) diff --git a/src/walberla_bridge/src/electrokinetics/generated_kernels/CMakeLists.txt b/src/walberla_bridge/src/electrokinetics/generated_kernels/CMakeLists.txt index b3236033ce..2858545b7f 100644 --- a/src/walberla_bridge/src/electrokinetics/generated_kernels/CMakeLists.txt +++ b/src/walberla_bridge/src/electrokinetics/generated_kernels/CMakeLists.txt @@ -19,7 +19,7 @@ foreach(precision double_precision single_precision) target_sources( - espresso_walberla + espresso_walberla_codegen PRIVATE DiffusiveFluxKernel_${precision}.cpp DiffusiveFluxKernelThermalized_${precision}.cpp DiffusiveFluxKernelWithElectrostatic_${precision}.cpp diff --git a/src/walberla_bridge/src/electrokinetics/reactions/generated_kernels/CMakeLists.txt b/src/walberla_bridge/src/electrokinetics/reactions/generated_kernels/CMakeLists.txt index d8e7950e9a..251aae94c4 100644 --- a/src/walberla_bridge/src/electrokinetics/reactions/generated_kernels/CMakeLists.txt +++ b/src/walberla_bridge/src/electrokinetics/reactions/generated_kernels/CMakeLists.txt @@ -20,7 +20,7 @@ foreach(n_species RANGE 1 5) foreach(precision double_precision single_precision) target_sources( - espresso_walberla + espresso_walberla_codegen PRIVATE ReactionKernelBulk_${n_species}_${precision}.cpp ReactionKernelIndexed_${n_species}_${precision}.cpp) endforeach() diff --git a/src/walberla_bridge/src/lattice_boltzmann/generated_kernels/CMakeLists.txt b/src/walberla_bridge/src/lattice_boltzmann/generated_kernels/CMakeLists.txt index eadeb04c2f..5258b73a18 100644 --- a/src/walberla_bridge/src/lattice_boltzmann/generated_kernels/CMakeLists.txt +++ b/src/walberla_bridge/src/lattice_boltzmann/generated_kernels/CMakeLists.txt @@ -17,47 +17,39 @@ # along with this program. If not, see . # -target_sources( - espresso_walberla - PRIVATE StreamSweepSinglePrecision.cpp StreamSweepDoublePrecision.cpp - PackInfoPdfSinglePrecision.cpp PackInfoPdfDoublePrecision.cpp - PackInfoVecSinglePrecision.cpp PackInfoVecDoublePrecision.cpp - InitialPDFsSetterSinglePrecision.cpp - InitialPDFsSetterDoublePrecision.cpp Dynamic_UBB_single_precision.cpp - Dynamic_UBB_double_precision.cpp) -if(ESPRESSO_BUILD_WITH_WALBERLA_AVX) - target_sources( - espresso_walberla - PRIVATE CollideSweepSinglePrecisionLeesEdwardsAVX.cpp - CollideSweepDoublePrecisionLeesEdwardsAVX.cpp - CollideSweepSinglePrecisionThermalizedAVX.cpp - CollideSweepDoublePrecisionThermalizedAVX.cpp - StreamSweepSinglePrecisionAVX.cpp StreamSweepDoublePrecisionAVX.cpp) -else() - target_sources( - espresso_walberla - PRIVATE CollideSweepSinglePrecisionLeesEdwards.cpp - CollideSweepDoublePrecisionLeesEdwards.cpp - CollideSweepSinglePrecisionThermalized.cpp - CollideSweepDoublePrecisionThermalized.cpp) -endif() -if(ESPRESSO_BUILD_WITH_CUDA AND WALBERLA_BUILD_WITH_CUDA) +foreach(precision single_precision double_precision) + target_sources(espresso_walberla_codegen PRIVATE Dynamic_UBB_${precision}.cpp) + if(WALBERLA_BUILD_WITH_CUDA) + target_sources(espresso_walberla_codegen_cuda + PRIVATE Dynamic_UBB_${precision}CUDA.cu) + endif() +endforeach() + +foreach(precision DoublePrecision SinglePrecision) target_sources( - espresso_walberla_cuda - PRIVATE CollideSweepDoublePrecisionLeesEdwardsCUDA.cu - CollideSweepDoublePrecisionThermalizedCUDA.cu - CollideSweepSinglePrecisionLeesEdwardsCUDA.cu - CollideSweepSinglePrecisionThermalizedCUDA.cu - FieldAccessorsDoublePrecisionCUDA.cu - FieldAccessorsSinglePrecisionCUDA.cu - StreamSweepDoublePrecisionCUDA.cu - StreamSweepSinglePrecisionCUDA.cu - InitialPDFsSetterDoublePrecisionCUDA.cu - InitialPDFsSetterSinglePrecisionCUDA.cu - PackInfoPdfSinglePrecisionCUDA.cu - PackInfoPdfDoublePrecisionCUDA.cu - PackInfoVecSinglePrecisionCUDA.cu - PackInfoVecDoublePrecisionCUDA.cu - Dynamic_UBB_double_precisionCUDA.cu - Dynamic_UBB_single_precisionCUDA.cu) -endif() + espresso_walberla_codegen + PRIVATE PackInfoPdf${precision}.cpp PackInfoVec${precision}.cpp + InitialPDFsSetter${precision}.cpp) + if(ESPRESSO_BUILD_WITH_WALBERLA_AVX) + target_sources( + espresso_walberla_codegen + PRIVATE CollideSweep${precision}LeesEdwardsAVX.cpp + CollideSweep${precision}ThermalizedAVX.cpp + StreamSweep${precision}AVX.cpp) + else() + target_sources( + espresso_walberla_codegen + PRIVATE CollideSweep${precision}LeesEdwards.cpp + CollideSweep${precision}Thermalized.cpp + StreamSweep${precision}.cpp) + endif() + if(WALBERLA_BUILD_WITH_CUDA) + target_sources( + espresso_walberla_codegen_cuda + PRIVATE CollideSweep${precision}LeesEdwardsCUDA.cu + CollideSweep${precision}ThermalizedCUDA.cu + FieldAccessors${precision}CUDA.cu StreamSweep${precision}CUDA.cu + InitialPDFsSetter${precision}CUDA.cu + PackInfoPdf${precision}CUDA.cu PackInfoVec${precision}CUDA.cu) + endif() +endforeach() diff --git a/src/walberla_bridge/tests/CMakeLists.txt b/src/walberla_bridge/tests/CMakeLists.txt index 06342ac225..7b3a85ab1b 100644 --- a/src/walberla_bridge/tests/CMakeLists.txt +++ b/src/walberla_bridge/tests/CMakeLists.txt @@ -23,9 +23,11 @@ function(ESPRESSO_ADD_TEST) cmake_parse_arguments(TEST "" "SRC;NAME;NUM_PROC" "DEPENDS" ${ARGN}) espresso_unit_test( SRC ${TEST_SRC} NAME ${TEST_NAME} NUM_PROC ${TEST_NUM_PROC} DEPENDS - ${TEST_DEPENDS} espresso::walberla espresso::utils) + ${TEST_DEPENDS} espresso::walberla espresso::walberla_codegen + espresso::utils) if(WALBERLA_BUILD_WITH_CUDA) - target_link_libraries(${TEST_NAME} PRIVATE espresso::walberla_cuda) + target_link_libraries(${TEST_NAME} PRIVATE espresso::walberla_cuda + espresso::walberla_codegen_cuda) endif() if(${TEST_SRC} MATCHES ".*\.cu$") target_link_libraries(${TEST_NAME} PRIVATE espresso::walberla::cuda_flags)