Skip to content

Commit

Permalink
Improve code portability (#5020)
Browse files Browse the repository at this point in the history
Description of changes:
- upgrade to latest waLBerla version and most recent pystencils/lbmpy/sympy releases
   - rewrite codegen pipeline to support multiple pystencils versions
- bugfixes:
   - remove sources of NaN, float overflow, and most float underflow
   - copy all waLBerla shared objects to the installation directory
   - add prefix to waLBerla and Caliper shared objects to avoid name clashes
- new feature: floating point exceptions instrumentation for x86 and Armv8
- run CI on Apple M1 (virtual machine, ARM 64bit architecture)
- give fine control over Clang-Tidy diagnostics for each CMake target
  • Loading branch information
kodiakhq[bot] authored Jan 17, 2025
2 parents ba9d026 + 5d58598 commit 74490c0
Show file tree
Hide file tree
Showing 176 changed files with 5,173 additions and 3,393 deletions.
6 changes: 4 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ CheckOptions:
- key: modernize-use-noexcept.ReplacementString
value: ''
- key: modernize-use-noexcept.UseNoexceptFalse
value: '1'
value: 'true'
- key: modernize-use-nullptr.NullMacros
value: 'NULL'
- key: modernize-use-transparent-functors.SafeMode
value: '1'
value: 'true'
- key: modernize-use-using.IgnoreExternC
value: 'true'
- key: readability-simplify-boolean-expr.ChainedConditionalAssignment
value: '0'
- key: readability-simplify-boolean-expr.ChainedConditionalReturn
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/push_pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ permissions:

jobs:
macos:
runs-on: macos-13
runs-on: macos-14
if: ${{ github.repository == 'espressomd/espresso' }}
steps:
- name: Checkout
Expand All @@ -28,8 +28,8 @@ jobs:
- name: Build and check
uses: ./.github/actions/build_and_check
env:
build_procs: 4
check_procs: 4
build_procs: 3
check_procs: 3
with_ccache: 'true'

debian:
Expand Down
10 changes: 8 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ stages:
image: ghcr.io/espressomd/docker/fedora:f7f8ef2c0ca93c67aa16b9f91785492fb04ecc1b
variables:
GIT_SUBMODULE_STRATEGY: none
GET_SOURCES_ATTEMPTS: 3
before_script:
- git config --global --add safe.directory ${CI_PROJECT_DIR}
dependencies: []
Expand All @@ -32,6 +33,7 @@ stages:

variables:
GIT_SUBMODULE_STRATEGY: recursive
GET_SOURCES_ATTEMPTS: 3
CCACHE_DIR: /cache
CCACHE_MAXSIZE: 100G
with_ccache: 'true'
Expand Down Expand Up @@ -69,7 +71,7 @@ style_doxygen:
- mkdir build
- cd build
- cp ../maintainer/configs/maxset.hpp myconfig.hpp
- cmake .. -D ESPRESSO_BUILD_WITH_CUDA=ON -D ESPRESSO_BUILD_WITH_GSL=ON -D ESPRESSO_BUILD_WITH_HDF5=ON -D ESPRESSO_BUILD_WITH_SCAFACOS=ON -D ESPRESSO_BUILD_WITH_WALBERLA=ON -D ESPRESSO_BUILD_WITH_WALBERLA_FFT=ON -D ESPRESSO_BUILD_WITH_STOKESIAN_DYNAMICS=ON -D ESPRESSO_BUILD_WITH_CALIPER=ON
- cmake .. -D ESPRESSO_BUILD_WITH_CUDA=ON -D ESPRESSO_BUILD_WITH_GSL=ON -D ESPRESSO_BUILD_WITH_HDF5=ON -D ESPRESSO_BUILD_WITH_SCAFACOS=ON -D ESPRESSO_BUILD_WITH_WALBERLA=ON -D ESPRESSO_BUILD_WITH_WALBERLA_FFT=ON -D ESPRESSO_BUILD_WITH_STOKESIAN_DYNAMICS=ON -D ESPRESSO_BUILD_WITH_CALIPER=ON -D ESPRESSO_BUILD_WITH_FPE=ON
- sh ../maintainer/CI/dox_warnings.sh
tags:
- espresso
Expand Down Expand Up @@ -132,7 +134,8 @@ no_rotation:
with_cuda: 'false'
myconfig: 'no_rotation'
with_coverage: 'true'
with_scafacos: 'true'
with_scafacos: 'false'
with_fpe: 'true'
check_skip_long: 'true'
script:
- bash maintainer/CI/build_cmake.sh
Expand All @@ -148,6 +151,8 @@ fedora:40:
variables:
with_cuda: 'false'
with_gsl: 'false'
with_scafacos: 'false'
with_fpe: 'true'
myconfig: 'maxset'
make_check_python: 'true'
with_stokesian_dynamics: 'true'
Expand Down Expand Up @@ -422,6 +427,7 @@ empty:
with_scafacos: 'false'
with_walberla: 'false'
with_stokesian_dynamics: 'false'
with_fpe: 'true'
with_coverage: 'false'
with_coverage_python: 'true'
script:
Expand Down
93 changes: 85 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ include(GNUInstallDirs)
include(FetchContent)
include(espresso_option_enum)
include(espresso_enable_avx2_support)
include(espresso_override_clang_tidy_checks)

if(EXISTS "${PROJECT_BINARY_DIR}/CMakeLists.txt")
message(
Expand All @@ -79,6 +80,10 @@ espresso_option_enum(
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE} -Og -g")
set(CMAKE_CXX_FLAGS_RELWITHASSERT "${CMAKE_CXX_FLAGS_RELWITHASSERT} -O3 -g")

# build targets as static libraries unless otherwise specified
set(ESPRESSO_BUILD_SHARED_LIBS_DEFAULT OFF)
set(BUILD_SHARED_LIBS ${ESPRESSO_BUILD_SHARED_LIBS_DEFAULT})

# On Mac OS X, first look for other packages, then frameworks
set(CMAKE_FIND_FRAMEWORK LAST)

Expand All @@ -93,7 +98,7 @@ set(FETCHCONTENT_UPDATES_DISCONNECTED ON)
FetchContent_Declare(
walberla
GIT_REPOSITORY https://i10git.cs.fau.de/walberla/walberla.git
GIT_TAG b0842e1a493ce19ef1bbb8d2cf382fc343970a7f
GIT_TAG f36fa0a68bae59f0b516f6587ea8fa7c24a41141
)
FetchContent_Declare(
stokesian_dynamics
Expand All @@ -103,7 +108,7 @@ FetchContent_Declare(
FetchContent_Declare(
caliper
GIT_REPOSITORY https://github.com/LLNL/Caliper.git
GIT_TAG v2.10.0
GIT_TAG v2.12.0
)
# cmake-format: on

Expand All @@ -129,6 +134,8 @@ option(ESPRESSO_BUILD_BENCHMARKS "Enable benchmarks" OFF)
option(ESPRESSO_BUILD_WITH_VALGRIND "Build with Valgrind instrumentation" OFF)
option(ESPRESSO_BUILD_WITH_CALIPER "Build with Caliper instrumentation" OFF)
option(ESPRESSO_BUILD_WITH_CPPCHECK "Run Cppcheck during compilation" OFF)
option(ESPRESSO_BUILD_WITH_FPE
"Build with floating-point exceptions instrumentation" OFF)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
option(ESPRESSO_BUILD_WITH_CLANG_TIDY "Run Clang-Tidy during compilation" OFF)
endif()
Expand Down Expand Up @@ -258,7 +265,7 @@ endif()
# Python interpreter and Cython interface library
if(ESPRESSO_BUILD_WITH_PYTHON)
find_package(Python 3.10 REQUIRED COMPONENTS Interpreter Development NumPy)
find_package(Cython 0.29.28...<3.0.10 REQUIRED)
find_package(Cython 0.29.28...<3.0.12 REQUIRED)
find_program(IPYTHON_EXECUTABLE NAMES jupyter ipython3 ipython)
endif()

Expand All @@ -274,6 +281,8 @@ set(ESPRESSO_INSTALL_BINDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}")
# folder for C++ and CUDA shared objects
set(ESPRESSO_INSTALL_LIBDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")

set(ESPRESSO_OLD_CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}")

# python site-packages, can be overriden with CMake options
if(ESPRESSO_BUILD_WITH_PYTHON)
if(NOT ESPRESSO_INSTALL_PYTHON)
Expand Down Expand Up @@ -342,11 +351,12 @@ if(ESPRESSO_BUILD_WITH_GSL)
endif()

if(ESPRESSO_BUILD_WITH_STOKESIAN_DYNAMICS)
set(CMAKE_INSTALL_LIBDIR "${ESPRESSO_INSTALL_LIBDIR}")
FetchContent_GetProperties(stokesian_dynamics)
set(STOKESIAN_DYNAMICS 1)
if(NOT stokesian_dynamics_POPULATED)
set(CMAKE_INSTALL_LIBDIR "${ESPRESSO_INSTALL_LIBDIR}")
FetchContent_MakeAvailable(stokesian_dynamics)
set(CMAKE_INSTALL_LIBDIR "${ESPRESSO_OLD_CMAKE_INSTALL_LIBDIR}")
endif()
endif()

Expand Down Expand Up @@ -454,7 +464,8 @@ set(CMAKE_INSTALL_RPATH "${ESPRESSO_INSTALL_LIBDIR}")
#

# drop 'lib' prefix from all libraries
set(CMAKE_SHARED_LIBRARY_PREFIX "")
set(ESPRESSO_SHARED_LIBRARY_PREFIX "")
set(CMAKE_SHARED_LIBRARY_PREFIX "${ESPRESSO_SHARED_LIBRARY_PREFIX}")

add_library(espresso_coverage_flags INTERFACE)
add_library(espresso::coverage_flags ALIAS espresso_coverage_flags)
Expand Down Expand Up @@ -581,6 +592,33 @@ if(ESPRESSO_BUILD_WITH_CLANG_TIDY)
find_package(ClangTidy "${CMAKE_CXX_COMPILER_VERSION}" EXACT REQUIRED)
set(ESPRESSO_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}")
set(ESPRESSO_CUDA_CLANG_TIDY "${CLANG_TIDY_EXE};--extra-arg=--cuda-host-only")
set(SKIP_CLANG_TIDY_CHECKS "")
set(SKIP_CLANG_TIDY_CHECKS_CXX "")
set(SKIP_CLANG_TIDY_CHECKS_CUDA "")
if(ESPRESSO_BUILD_WITH_CALIPER)
# Clang-Tidy sometimes emits diagnostics in code enclosed in `extern "C"`
# that are not always actionable, since they may rely on keywords only
# available in the C++ language. While some checks have an extra flag
# 'IgnoreExternC' to disable them inside C code, not all affected checks
# have been fixed yet. For an in-depth discussion on this topic, see
# https://github.com/llvm/llvm-project/issues/35272
list(APPEND SKIP_CLANG_TIDY_CHECKS "-modernize-use-auto")
list(APPEND SKIP_CLANG_TIDY_CHECKS "-modernize-use-nullptr")
list(APPEND SKIP_CLANG_TIDY_CHECKS "-modernize-deprecated-headers")
endif()
if(ESPRESSO_BUILD_WITH_CUDA)
# silence casts in cuda_runtime.h (for both C++ and CUDA source files)
list(APPEND SKIP_CLANG_TIDY_CHECKS "-bugprone-casting-through-void")
# silence nullptr dereference in cuda::thrust
list(APPEND SKIP_CLANG_TIDY_CHECKS_CUDA
"-clang-analyzer-core.NonNullParamChecker")
endif()
espresso_override_clang_tidy_checks(
ESPRESSO_CXX_CLANG_TIDY "${SKIP_CLANG_TIDY_CHECKS}"
"${SKIP_CLANG_TIDY_CHECKS_CXX}")
espresso_override_clang_tidy_checks(
ESPRESSO_CUDA_CLANG_TIDY "${SKIP_CLANG_TIDY_CHECKS}"
"${SKIP_CLANG_TIDY_CHECKS_CUDA}")
endif()

if(ESPRESSO_BUILD_WITH_CPPCHECK)
Expand Down Expand Up @@ -650,23 +688,52 @@ if(ESPRESSO_BUILD_WITH_WALBERLA)
endif()
set(WALBERLA_BUILD_WITH_FASTMATH off CACHE BOOL "")
if(NOT walberla_POPULATED)
set(BUILD_SHARED_LIBS ON)
set(CMAKE_SHARED_LIBRARY_PREFIX "libwalberla_")
FetchContent_MakeAvailable(walberla)
set(BUILD_SHARED_LIBS ${ESPRESSO_BUILD_SHARED_LIBS_DEFAULT})
set(CMAKE_SHARED_LIBRARY_PREFIX "${ESPRESSO_SHARED_LIBRARY_PREFIX}")
endif()
set(WALBERLA_LIBS
walberla::core walberla::domain_decomposition walberla::blockforest
walberla::boundary walberla::field walberla::lbm walberla::timeloop
walberla::vtk)
if(ESPRESSO_BUILD_WITH_WALBERLA_FFT)
if(WALBERLA_BUILD_WITH_FFTW)
set(WALBERLA_LIBS ${WALBERLA_LIBS} walberla::fft)
endif()
if(ESPRESSO_BUILD_WITH_CUDA AND WALBERLA_BUILD_WITH_CUDA)
if(WALBERLA_BUILD_WITH_CUDA)
set(WALBERLA_LIBS ${WALBERLA_LIBS} walberla::gpu)
endif()
set(WALBERLA_LIBS_EXPORT
${WALBERLA_LIBS}
walberla::lodepng
walberla::sqlite3
walberla::lbm_generated
walberla::pe
walberla::pe_coupling
walberla::pde
walberla::mesa_pd
walberla::lbm_mesapd_coupling
walberla::sqlite
walberla::executiontree
walberla::geometry
walberla::postprocessing
walberla::gather
walberla::gui)
# workaround for https://gitlab.kitware.com/cmake/cmake/-/issues/21283
foreach(target_w_namespace IN LISTS WALBERLA_LIBS)
string(REPLACE "walberla::" "" target_wo_namespace ${target_w_namespace})
add_library(${target_w_namespace} ALIAS ${target_wo_namespace})
endforeach()
# install all waLBerla shared objects
foreach(target_w_namespace IN LISTS WALBERLA_LIBS_EXPORT)
string(REPLACE "walberla::" "" target_wo_namespace ${target_w_namespace})
get_target_property(target_type ${target_wo_namespace} TYPE)
if(${target_type} STREQUAL "SHARED_LIBRARY")
install(TARGETS ${target_wo_namespace}
LIBRARY DESTINATION "${ESPRESSO_INSTALL_LIBDIR}")
endif()
endforeach()
if(ESPRESSO_BUILD_WITH_WALBERLA_AVX)
function(espresso_avx_flags_callback COMPILER_AVX2_FLAG)
target_compile_options(
Expand All @@ -683,10 +750,19 @@ if(ESPRESSO_BUILD_WITH_CALIPER)
set(CALIPER_WITH_MPI on CACHE BOOL "")
set(CALIPER_WITH_NVTX off CACHE BOOL "")
set(CALIPER_WITH_CUPTI off CACHE BOOL "")
set(CALIPER_BUILD_SHARED_LIBS on CACHE BOOL "")
set(CALIPER_INSTALL_CONFIG off CACHE BOOL "")
set(CALIPER_INSTALL_HEADERS off CACHE BOOL "")
if(NOT caliper_POPULATED)
set(BUILD_SHARED_LIBS ON)
set(CMAKE_INSTALL_LIBDIR "${ESPRESSO_INSTALL_LIBDIR}")
set(CMAKE_SHARED_LIBRARY_PREFIX "lib")
FetchContent_MakeAvailable(caliper)
set(BUILD_SHARED_LIBS ${ESPRESSO_BUILD_SHARED_LIBS_DEFAULT})
set(CMAKE_INSTALL_LIBDIR "${ESPRESSO_OLD_CMAKE_INSTALL_LIBDIR}")
set(CMAKE_SHARED_LIBRARY_PREFIX "${ESPRESSO_SHARED_LIBRARY_PREFIX}")
endif()
target_compile_options(caliper-common
PRIVATE $<$<CXX_COMPILER_ID:GNU>:-Wno-restrict>)
target_compile_options(
caliper-services
PRIVATE
Expand All @@ -696,6 +772,7 @@ if(ESPRESSO_BUILD_WITH_CALIPER)
PRIVATE $<$<CXX_COMPILER_ID:GNU>:-Wno-maybe-uninitialized>
$<$<CXX_COMPILER_ID:GNU>:-Wno-volatile>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-deprecated-volatile>)
set_target_properties(caliper-runtime PROPERTIES CXX_CLANG_TIDY "")
endif()

#
Expand Down
2 changes: 2 additions & 0 deletions cmake/espresso_cmake_config.cmakein
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#cmakedefine ESPRESSO_BUILD_WITH_CALIPER

#cmakedefine ESPRESSO_BUILD_WITH_FPE

#define PACKAGE_NAME "${PROJECT_NAME}"

/**
Expand Down
64 changes: 64 additions & 0 deletions cmake/espresso_override_clang_tidy_checks.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#
# Copyright (C) 2024 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 <http://www.gnu.org/licenses/>.
#

# Override Clang-Tidy checks.
#
# This function appends an extra flag "--checks=..." in the parent scope
# variable whose name is passed as first argument. The second and third
# arguments are the general and the language-specific overrides, respectively.
# This way you can append a common set of overrides plus language-specific
# overrides in two variables named MYPROJECT_CXX_CLANG_TIDY and
# MYPROJECT_CUDA_CLANG_TIDY, which are used to set the CXX_CLANG_TIDY and
# CUDA_CLANG_TIDY properties of CMake targets.
#
# Example:
# ```cmake
# include(espresso_override_clang_tidy_checks)
# if(MYPROJECT_BUILD_WITH_CLANG_TIDY)
# find_package(ClangTidy "${CMAKE_CXX_COMPILER_VERSION}" EXACT REQUIRED)
# set(MYPROJECT_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}")
# set(MYPROJECT_CUDA_CLANG_TIDY "${CLANG_TIDY_EXE};--extra-arg=--cuda-host-only")
# set(SKIP_CLANG_TIDY_CHECKS "")
# set(SKIP_CLANG_TIDY_CHECKS_CXX "")
# set(SKIP_CLANG_TIDY_CHECKS_CUDA "")
# # silence false positives in code enclosed in `extern "C" { /* ... */ }`
# list(APPEND SKIP_CLANG_TIDY_CHECKS "-modernize-use-auto")
# if (MYPROJECT_BUILD_WITH_CUDA)
# # silence casts in cuda_runtime.h (for both C++ and CUDA source files)
# list(APPEND SKIP_CLANG_TIDY_CHECKS "-bugprone-casting-through-void")
# # silence nullptr dereference in cuda::thrust (only for CUDA files)
# list(APPEND SKIP_CLANG_TIDY_CHECKS_CUDA "-clang-analyzer-core.NonNullParamChecker")
# endif()
# espresso_override_clang_tidy_checks(MYPROJECT_CXX_CLANG_TIDY "${SKIP_CLANG_TIDY_CHECKS}" "${SKIP_CLANG_TIDY_CHECKS_CXX}")
# espresso_override_clang_tidy_checks(MYPROJECT_CUDA_CLANG_TIDY "${SKIP_CLANG_TIDY_CHECKS}" "${SKIP_CLANG_TIDY_CHECKS_CUDA}")
# set_target_properties(myproject_core PROPERTIES CXX_CLANG_TIDY "${MYPROJECT_CXX_CLANG_TIDY}")
# set_target_properties(myproject_cuda PROPERTIES CUDA_CLANG_TIDY "${MYPROJECT_CUDA_CLANG_TIDY}")
# endif()
# ```

function(espresso_override_clang_tidy_checks)
set(VARNAME "${ARGV0}")
set(CHECKS "${ARGV1}")
set(CHECKS_LANG "${ARGV2}")
list(APPEND CHECKS ${CHECKS_LANG})
if(CHECKS)
list(JOIN CHECKS "," CHECKS_STRING)
set(${VARNAME} "${${VARNAME}};--checks=${CHECKS_STRING}" PARENT_SCOPE)
endif()
endfunction()
Loading

0 comments on commit 74490c0

Please sign in to comment.