From 7b2639583dfe81c4f023a0879ba95510e0fa04f5 Mon Sep 17 00:00:00 2001 From: Thomas Padioleau Date: Wed, 30 Oct 2024 15:51:01 +0100 Subject: [PATCH] Add a cmake formatting tool in the CI (#670) * Add a cmake formatting tool in the CI * Fix cmake files format * Review of cedricchevalier19, adding a contributing note about formatting with a formatting configuration file --- .gersemirc | 9 + .github/workflows/tests.yml | 19 ++ CMakeLists.txt | 319 ++++++++++++++-------------- README.md | 25 +++ benchmarks/CMakeLists.txt | 14 +- cmake/DDCVendorConfiguration.cmake | 24 ++- examples/CMakeLists.txt | 16 +- tests/CMakeLists.txt | 14 +- tests/discrete_space/CMakeLists.txt | 13 +- tests/fft/CMakeLists.txt | 6 +- tests/splines/CMakeLists.txt | 252 ++++++++++------------ 11 files changed, 364 insertions(+), 347 deletions(-) create mode 100644 .gersemirc diff --git a/.gersemirc b/.gersemirc new file mode 100644 index 000000000..6a9130cf0 --- /dev/null +++ b/.gersemirc @@ -0,0 +1,9 @@ +# Copyright (C) The DDC development team, see COPYRIGHT.md file +# +# SPDX-License-Identifier: MIT + +# yaml-language-server: $schema=https://raw.githubusercontent.com/BlankSpruce/gersemi/0.17.0/gersemi/configuration.schema.json + +definitions: ["cmake"] +indent: 4 +line_length: 100 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 143d41fdc..61cf741c6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -26,6 +26,25 @@ jobs: if: always() uses: fsfe/reuse-action@v4 + cmake-format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install python3 virtual environments + run: | + sudo apt-get update + sudo apt-get --yes install python3-pip python3-venv + - name: Install gersemi + run: | + python3 -m venv ./gersemi + . ./gersemi/bin/activate + python3 -m pip install gersemi==0.17 + - name: Run gersemi + run: | + . ./gersemi/bin/activate + gersemi --check cmake/DDCVendorConfiguration.cmake + find CMakeLists.txt tests/ examples/ benchmarks/ -name 'CMakeLists.txt' -exec gersemi --check '{}' '+' + id_repo: runs-on: ubuntu-latest steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index 79f1b5152..2838b234c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,20 +7,23 @@ project(DDC VERSION 0.1.0 LANGUAGES CXX) # List of options -option(DDC_BUILD_BENCHMARKS "Build DDC benchmarks." OFF) -option(DDC_BUILD_DOCUMENTATION "Build DDC documentation/website" OFF) -option(DDC_BUILD_DOUBLE_PRECISION "Build DDC with double precision support, float is used otherwise" ON) -option(DDC_BUILD_EXAMPLES "Build DDC examples" ON) -option(DDC_BUILD_KERNELS_FFT "Build DDC kernels for FFT" ON) -option(DDC_BUILD_KERNELS_SPLINES "Build DDC kernels for splines" ON) -option(DDC_BUILD_PDI_WRAPPER "Build DDC PDI wrapper" ON) -option(DDC_BUILD_TESTS "Build DDC tests if BUILD_TESTING is enabled" ON) +option(DDC_BUILD_BENCHMARKS "Build DDC benchmarks." OFF) +option(DDC_BUILD_DOCUMENTATION "Build DDC documentation/website" OFF) +option( + DDC_BUILD_DOUBLE_PRECISION + "Build DDC with double precision support, float is used otherwise" + ON +) +option(DDC_BUILD_EXAMPLES "Build DDC examples" ON) +option(DDC_BUILD_KERNELS_FFT "Build DDC kernels for FFT" ON) +option(DDC_BUILD_KERNELS_SPLINES "Build DDC kernels for splines" ON) +option(DDC_BUILD_PDI_WRAPPER "Build DDC PDI wrapper" ON) +option(DDC_BUILD_TESTS "Build DDC tests if BUILD_TESTING is enabled" ON) # Dependencies set(DDC_DEPENDENCY_POLICIES "AUTO" "EMBEDDED" "INSTALLED" "SUBPROJECT") - ## CMake modules include(CMakePackageConfigHelpers) @@ -30,235 +33,231 @@ include(CTest) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(DDCVendorConfiguration) - ## kokkos -set(DDC_Kokkos_DEPENDENCY_POLICY "AUTO" CACHE STRING "Policy to find the `Kokkos` package. Options: ${DDC_DEPENDENCY_POLICIES}") +set(DDC_Kokkos_DEPENDENCY_POLICY + "AUTO" + CACHE STRING + "Policy to find the `Kokkos` package. Options: ${DDC_DEPENDENCY_POLICIES}" +) set_property(CACHE DDC_Kokkos_DEPENDENCY_POLICY PROPERTY STRINGS "${DDC_DEPENDENCY_POLICIES}") if("${DDC_Kokkos_DEPENDENCY_POLICY}" STREQUAL "AUTO") - if(NOT TARGET Kokkos::kokkos) - find_package(Kokkos 4.4...4.5 CONFIG QUIET) - if(NOT Kokkos_FOUND) - ddc_configure_kokkos() - endif() - endif() + if(NOT TARGET Kokkos::kokkos) + find_package(Kokkos 4.4...4.5 CONFIG QUIET) + if(NOT Kokkos_FOUND) + ddc_configure_kokkos() + endif() + endif() elseif("${DDC_Kokkos_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED") - ddc_configure_kokkos() + ddc_configure_kokkos() elseif("${DDC_Kokkos_DEPENDENCY_POLICY}" STREQUAL "INSTALLED") - find_package(Kokkos 4.4...4.5 CONFIG REQUIRED) + find_package(Kokkos 4.4...4.5 CONFIG REQUIRED) endif() - ## PDI if("${DDC_BUILD_PDI_WRAPPER}") - if(NOT TARGET PDI::PDI_C) - find_package(PDI REQUIRED COMPONENTS C) - endif() + if(NOT TARGET PDI::PDI_C) + find_package(PDI REQUIRED COMPONENTS C) + endif() endif() - ## GoogleTest if("${BUILD_TESTING}" AND "${DDC_BUILD_TESTS}") - set(DDC_GTest_DEPENDENCY_POLICY "AUTO" CACHE STRING "Policy to find the `GTest` package. Options: ${DDC_DEPENDENCY_POLICIES}") - set_property(CACHE DDC_GTest_DEPENDENCY_POLICY PROPERTY STRINGS ${DDC_DEPENDENCY_POLICIES}) - - if("${DDC_GTest_DEPENDENCY_POLICY}" STREQUAL "AUTO") - if(NOT TARGET GTest::GTest AND NOT TARGET GTest::gtest) - find_package(GTest QUIET) - if(NOT GTest_FOUND) - ddc_configure_googletest() - endif() - endif() - elseif("${DDC_GTest_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED") - ddc_configure_googletest() - elseif("${DDC_GTest_DEPENDENCY_POLICY}" STREQUAL "INSTALLED") - find_package(GTest REQUIRED) - endif() - - include(GoogleTest) -endif() + set(DDC_GTest_DEPENDENCY_POLICY + "AUTO" + CACHE STRING + "Policy to find the `GTest` package. Options: ${DDC_DEPENDENCY_POLICIES}" + ) + set_property(CACHE DDC_GTest_DEPENDENCY_POLICY PROPERTY STRINGS ${DDC_DEPENDENCY_POLICIES}) + + if("${DDC_GTest_DEPENDENCY_POLICY}" STREQUAL "AUTO") + if(NOT TARGET GTest::GTest AND NOT TARGET GTest::gtest) + find_package(GTest QUIET) + if(NOT GTest_FOUND) + ddc_configure_googletest() + endif() + endif() + elseif("${DDC_GTest_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED") + ddc_configure_googletest() + elseif("${DDC_GTest_DEPENDENCY_POLICY}" STREQUAL "INSTALLED") + find_package(GTest REQUIRED) + endif() + include(GoogleTest) +endif() ## Google Benchmark if("${DDC_BUILD_BENCHMARKS}") - set(DDC_benchmark_DEPENDENCY_POLICY "AUTO" CACHE STRING "Policy to find the `benchmark` package. Options: ${DDC_DEPENDENCY_POLICIES}") - set_property(CACHE DDC_benchmark_DEPENDENCY_POLICY PROPERTY STRINGS ${DDC_DEPENDENCY_POLICIES}) - - if("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "AUTO") - if(NOT TARGET benchmark::benchmark) - find_package(benchmark QUIET) - if(NOT benchmark_FOUND) - ddc_configure_benchmark() - endif() - endif() - elseif("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED") - ddc_configure_benchmark() - elseif("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "INSTALLED") - find_package(benchmark REQUIRED) - endif() + set(DDC_benchmark_DEPENDENCY_POLICY + "AUTO" + CACHE STRING + "Policy to find the `benchmark` package. Options: ${DDC_DEPENDENCY_POLICIES}" + ) + set_property(CACHE DDC_benchmark_DEPENDENCY_POLICY PROPERTY STRINGS ${DDC_DEPENDENCY_POLICIES}) + + if("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "AUTO") + if(NOT TARGET benchmark::benchmark) + find_package(benchmark QUIET) + if(NOT benchmark_FOUND) + ddc_configure_benchmark() + endif() + endif() + elseif("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED") + ddc_configure_benchmark() + elseif("${DDC_benchmark_DEPENDENCY_POLICY}" STREQUAL "INSTALLED") + find_package(benchmark REQUIRED) + endif() endif() - ## Doxygen if("${DDC_BUILD_DOCUMENTATION}") - find_package(Doxygen 1.8.13 REQUIRED OPTIONAL_COMPONENTS dot) + find_package(Doxygen 1.8.13 REQUIRED OPTIONAL_COMPONENTS dot) endif() - # Our project ## The library itself - - add_library(DDC INTERFACE) target_compile_features(DDC INTERFACE cxx_std_17) -target_include_directories(DDC - INTERFACE - "$" - "$" -) -target_link_libraries(DDC - INTERFACE Kokkos::kokkos -) -target_compile_definitions(DDC - INTERFACE - MDSPAN_USE_PAREN_OPERATOR=1 +target_include_directories( + DDC + INTERFACE + "$" + "$" ) +target_link_libraries(DDC INTERFACE Kokkos::kokkos) +target_compile_definitions(DDC INTERFACE MDSPAN_USE_PAREN_OPERATOR=1) if("${DDC_BUILD_DOUBLE_PRECISION}") - target_compile_definitions(DDC INTERFACE DDC_BUILD_DOUBLE_PRECISION) + target_compile_definitions(DDC INTERFACE DDC_BUILD_DOUBLE_PRECISION) endif() add_library(DDC::DDC ALIAS DDC) -install( - TARGETS DDC - EXPORT DDCTargets -) +install(TARGETS DDC EXPORT DDCTargets) # Link library to DDC if("${DDC_BUILD_KERNELS_FFT}") - # Kokkos-fft - set(DDC_KokkosFFT_DEPENDENCY_POLICY "AUTO" CACHE STRING "Policy to find the `Kokkos-fft` package. Options: ${DDC_DEPENDENCY_POLICIES}") - set_property(CACHE DDC_KokkosFFT_DEPENDENCY_POLICY PROPERTY STRINGS "${DDC_DEPENDENCY_POLICIES}") - - if("${DDC_KokkosFFT_DEPENDENCY_POLICY}" STREQUAL "AUTO") - if(NOT TARGET KokkosFFT::fft) - find_package(KokkosFFT 0.2.1...<1 CONFIG QUIET) - if(NOT KokkosFFT_FOUND) + # Kokkos-fft + set(DDC_KokkosFFT_DEPENDENCY_POLICY + "AUTO" + CACHE STRING + "Policy to find the `Kokkos-fft` package. Options: ${DDC_DEPENDENCY_POLICIES}" + ) + set_property( + CACHE DDC_KokkosFFT_DEPENDENCY_POLICY + PROPERTY STRINGS "${DDC_DEPENDENCY_POLICIES}" + ) + + if("${DDC_KokkosFFT_DEPENDENCY_POLICY}" STREQUAL "AUTO") + if(NOT TARGET KokkosFFT::fft) + find_package(KokkosFFT 0.2.1...<1 CONFIG QUIET) + if(NOT KokkosFFT_FOUND) + ddc_configure_kokkos_fft() + endif() + endif() + elseif("${DDC_KokkosFFT_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED") ddc_configure_kokkos_fft() - endif() + elseif("${DDC_KokkosFFT_DEPENDENCY_POLICY}" STREQUAL "INSTALLED") + find_package(KokkosFFT 0.2.1...<1 CONFIG REQUIRED) endif() - elseif("${DDC_KokkosFFT_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED") - ddc_configure_kokkos_fft() - elseif("${DDC_KokkosFFT_DEPENDENCY_POLICY}" STREQUAL "INSTALLED") - find_package(KokkosFFT 0.2.1...<1 CONFIG REQUIRED) - endif() - - target_link_libraries(DDC INTERFACE KokkosFFT::fft) - target_compile_definitions(DDC INTERFACE "DDC_BUILD_KERNELS_FFT") + + target_link_libraries(DDC INTERFACE KokkosFFT::fft) + target_compile_definitions(DDC INTERFACE "DDC_BUILD_KERNELS_FFT") endif() if("${DDC_BUILD_KERNELS_SPLINES}") - # Ginkgo - find_package(Ginkgo 1.8.0 EXACT REQUIRED) - target_link_libraries(DDC INTERFACE Ginkgo::ginkgo) - - # Lapacke - find_package(LAPACKE REQUIRED) - target_link_libraries(DDC INTERFACE ${LAPACKE_LIBRARIES}) - target_include_directories(DDC SYSTEM INTERFACE ${LAPACKE_INCLUDE_DIRS}) - install( - FILES cmake/FindLAPACKE.cmake - DESTINATION lib/cmake/DDC) - - # Kokkos-kernels - set(DDC_KokkosKernels_DEPENDENCY_POLICY "AUTO" CACHE STRING "Policy to find the `KokkosKernels` package. Options: ${DDC_DEPENDENCY_POLICIES}") - set_property(CACHE DDC_KokkosKernels_DEPENDENCY_POLICY PROPERTY STRINGS "${DDC_DEPENDENCY_POLICIES}") - if("${DDC_KokkosKernels_DEPENDENCY_POLICY}" STREQUAL "AUTO") - if(NOT TARGET Kokkos::kokkoskernels) - find_package(KokkosKernels QUIET) - if(NOT KokkosKernels_FOUND) + # Ginkgo + find_package(Ginkgo 1.8.0 EXACT REQUIRED) + target_link_libraries(DDC INTERFACE Ginkgo::ginkgo) + + # Lapacke + find_package(LAPACKE REQUIRED) + target_link_libraries(DDC INTERFACE ${LAPACKE_LIBRARIES}) + target_include_directories(DDC SYSTEM INTERFACE ${LAPACKE_INCLUDE_DIRS}) + install(FILES cmake/FindLAPACKE.cmake DESTINATION lib/cmake/DDC) + + # Kokkos-kernels + set(DDC_KokkosKernels_DEPENDENCY_POLICY + "AUTO" + CACHE STRING + "Policy to find the `KokkosKernels` package. Options: ${DDC_DEPENDENCY_POLICIES}" + ) + set_property( + CACHE DDC_KokkosKernels_DEPENDENCY_POLICY + PROPERTY STRINGS "${DDC_DEPENDENCY_POLICIES}" + ) + if("${DDC_KokkosKernels_DEPENDENCY_POLICY}" STREQUAL "AUTO") + if(NOT TARGET Kokkos::kokkoskernels) + find_package(KokkosKernels QUIET) + if(NOT KokkosKernels_FOUND) + ddc_configure_kokkos_kernels() + endif() + endif() + elseif("${DDC_KokkosKernels_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED") ddc_configure_kokkos_kernels() - endif() + elseif("${DDC_KokkosKernels_DEPENDENCY_POLICY}" STREQUAL "INSTALLED") + find_package(KokkosKernels REQUIRED) endif() - elseif("${DDC_KokkosKernels_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED") - ddc_configure_kokkos_kernels() - elseif("${DDC_KokkosKernels_DEPENDENCY_POLICY}" STREQUAL "INSTALLED") - find_package(KokkosKernels REQUIRED) - endif() - - target_link_libraries(DDC INTERFACE Kokkos::kokkoskernels) - target_compile_definitions(DDC INTERFACE "DDC_BUILD_KERNELS_SPLINES") + + target_link_libraries(DDC INTERFACE Kokkos::kokkoskernels) + target_compile_definitions(DDC INTERFACE "DDC_BUILD_KERNELS_SPLINES") endif() ## The PDI wrapper if("${DDC_BUILD_PDI_WRAPPER}") - add_library(PDI_Wrapper INTERFACE) - target_compile_features(PDI_Wrapper INTERFACE cxx_std_17) - target_include_directories(PDI_Wrapper - INTERFACE - "$" - "$" - ) - target_link_libraries(PDI_Wrapper - INTERFACE - DDC::DDC - PDI::PDI_C) - target_compile_definitions(PDI_Wrapper INTERFACE "DDC_BUILD_PDI_WRAPPER") - add_library(DDC::PDI_Wrapper ALIAS PDI_Wrapper) - install( - TARGETS PDI_Wrapper - EXPORT DDCTargets) + add_library(PDI_Wrapper INTERFACE) + target_compile_features(PDI_Wrapper INTERFACE cxx_std_17) + target_include_directories( + PDI_Wrapper + INTERFACE + "$" + "$" + ) + target_link_libraries(PDI_Wrapper INTERFACE DDC::DDC PDI::PDI_C) + target_compile_definitions(PDI_Wrapper INTERFACE "DDC_BUILD_PDI_WRAPPER") + add_library(DDC::PDI_Wrapper ALIAS PDI_Wrapper) + install(TARGETS PDI_Wrapper EXPORT DDCTargets) endif() - ## if examples are enabled, build them if("${DDC_BUILD_EXAMPLES}") - add_subdirectory(examples/) + add_subdirectory(examples/) endif() - ## if tests are enabled, build them if("${BUILD_TESTING}" AND "${DDC_BUILD_TESTS}") - add_subdirectory(tests/) + add_subdirectory(tests/) endif() ## if benchmarks are enabled, build them if("${DDC_BUILD_BENCHMARKS}") - add_subdirectory(benchmarks/) + add_subdirectory(benchmarks/) endif() - ## if documentation is enabled, build it if("${DDC_BUILD_DOCUMENTATION}") - add_subdirectory(docs/) + add_subdirectory(docs/) endif() - ## installation -install( - EXPORT DDCTargets - NAMESPACE DDC:: - DESTINATION lib/cmake/DDC) +install(EXPORT DDCTargets NAMESPACE DDC:: DESTINATION lib/cmake/DDC) -install( - DIRECTORY include/ - TYPE INCLUDE) +install(DIRECTORY include/ TYPE INCLUDE) -configure_package_config_file(cmake/DDCConfig.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/DDCConfig.cmake - INSTALL_DESTINATION lib/cmake/DDC) +configure_package_config_file( + cmake/DDCConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/DDCConfig.cmake + INSTALL_DESTINATION lib/cmake/DDC +) -install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/DDCConfig.cmake - DESTINATION lib/cmake/DDC) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/DDCConfig.cmake DESTINATION lib/cmake/DDC) diff --git a/README.md b/README.md index cf6dfc96f..cd4ee170e 100644 --- a/README.md +++ b/README.md @@ -37,3 +37,28 @@ cd ddc cmake -B build -D DDC_BUILD_KERNELS_FFT=OFF -D DDC_BUILD_KERNELS_SPLINES=OFF -D DDC_BUILD_PDI_WRAPPER=OFF cmake --build build ``` + +## Contributing + +### Formatting + +The project makes use of formatting tools for the C++ ([clang-format](https://clang.llvm.org/docs/ClangFormat.html)) and cmake ([gersemi](https://github.com/BlankSpruce/gersemi)) files. The formatting must be applied for a PR to be accepted. + +To format a cmake file, please apply the command + +```bash +gersemi -i the-cmake-file +``` + +One can find the formatting style in the file `.gersemirc`. + +To format a C++ file, please apply the command + +```bash +clang-format -i the-cpp-file +``` + +One can find the formatting style in the file `.clang-format`. + +> [!WARNING] +> The formatting might not give the same result with different versions of a tool. diff --git a/benchmarks/CMakeLists.txt b/benchmarks/CMakeLists.txt index 2638a5693..c15911810 100644 --- a/benchmarks/CMakeLists.txt +++ b/benchmarks/CMakeLists.txt @@ -3,17 +3,9 @@ # SPDX-License-Identifier: MIT add_executable(ddc_benchmark_deepcopy deepcopy.cpp) -target_link_libraries(ddc_benchmark_deepcopy - PUBLIC - benchmark::benchmark - DDC::DDC -) +target_link_libraries(ddc_benchmark_deepcopy PUBLIC benchmark::benchmark DDC::DDC) if("${DDC_BUILD_KERNELS_SPLINES}") - add_executable(ddc_benchmark_splines splines.cpp) - target_link_libraries(ddc_benchmark_splines - PUBLIC - benchmark::benchmark - DDC::DDC - ) + add_executable(ddc_benchmark_splines splines.cpp) + target_link_libraries(ddc_benchmark_splines PUBLIC benchmark::benchmark DDC::DDC) endif() diff --git a/cmake/DDCVendorConfiguration.cmake b/cmake/DDCVendorConfiguration.cmake index d656e25cf..a4da702a0 100644 --- a/cmake/DDCVendorConfiguration.cmake +++ b/cmake/DDCVendorConfiguration.cmake @@ -7,7 +7,11 @@ macro(ddc_configure_benchmark) option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." OFF) - option(BENCHMARK_ENABLE_INSTALL "Enable installation of benchmark. (Projects embedding benchmark may want to turn this OFF.)" OFF) + option( + BENCHMARK_ENABLE_INSTALL + "Enable installation of benchmark. (Projects embedding benchmark may want to turn this OFF.)" + OFF + ) add_subdirectory(vendor/benchmark) endmacro() @@ -17,11 +21,23 @@ endmacro() macro(ddc_configure_kokkos) if("${Kokkos_ENABLE_CUDA}") - option(Kokkos_ENABLE_CUDA_CONSTEXPR "Whether to activate experimental relaxed constexpr functions" ON) - option(Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE "Whether to enable relocatable device code (RDC) for CUDA" ON) + option( + Kokkos_ENABLE_CUDA_CONSTEXPR + "Whether to activate experimental relaxed constexpr functions" + ON + ) + option( + Kokkos_ENABLE_CUDA_RELOCATABLE_DEVICE_CODE + "Whether to enable relocatable device code (RDC) for CUDA" + ON + ) endif() if("${Kokkos_ENABLE_HIP}") - option(Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE "Whether to enable relocatable device code (RDC) for HIP" ON) + option( + Kokkos_ENABLE_HIP_RELOCATABLE_DEVICE_CODE + "Whether to enable relocatable device code (RDC) for HIP" + ON + ) endif() add_subdirectory(vendor/kokkos) endmacro() diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c7b19a0d6..aa4df6592 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -12,20 +12,18 @@ target_link_libraries(uniform_heat_equation PUBLIC DDC::DDC) target_link_libraries(non_uniform_heat_equation PUBLIC DDC::DDC) target_link_libraries(uniform_heat_equation PUBLIC DDC::DDC) - if("${DDC_BUILD_PDI_WRAPPER}") - target_link_libraries(heat_equation PUBLIC DDC::PDI_Wrapper) - target_link_libraries(uniform_heat_equation PUBLIC DDC::PDI_Wrapper) - target_link_libraries(non_uniform_heat_equation PUBLIC DDC::PDI_Wrapper) - + target_link_libraries(heat_equation PUBLIC DDC::PDI_Wrapper) + target_link_libraries(uniform_heat_equation PUBLIC DDC::PDI_Wrapper) + target_link_libraries(non_uniform_heat_equation PUBLIC DDC::PDI_Wrapper) endif() if("${DDC_BUILD_KERNELS_FFT}") - add_executable(heat_equation_spectral heat_equation_spectral.cpp) - target_link_libraries(heat_equation_spectral PUBLIC DDC::DDC) + add_executable(heat_equation_spectral heat_equation_spectral.cpp) + target_link_libraries(heat_equation_spectral PUBLIC DDC::DDC) endif() add_executable(game_of_life game_of_life.cpp) target_link_libraries(game_of_life PUBLIC DDC::DDC) if("${DDC_BUILD_KERNELS_SPLINES}") - add_executable(characteristics_advection characteristics_advection.cpp) - target_link_libraries(characteristics_advection PUBLIC DDC::DDC) + add_executable(characteristics_advection characteristics_advection.cpp) + target_link_libraries(characteristics_advection PUBLIC DDC::DDC) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 68633585a..3b5885d86 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,7 +6,8 @@ cmake_minimum_required(VERSION 3.22) add_subdirectory(discrete_space) -add_executable(ddc_tests +add_executable( + ddc_tests main.cpp aligned_allocator.cpp chunk.cpp @@ -32,18 +33,13 @@ add_executable(ddc_tests multiple_discrete_dimensions.cpp ) target_compile_features(ddc_tests PUBLIC cxx_std_17) -target_link_libraries(ddc_tests - PUBLIC - GTest::gtest - DDC::DDC -) +target_link_libraries(ddc_tests PUBLIC GTest::gtest DDC::DDC) gtest_discover_tests(ddc_tests DISCOVERY_MODE PRE_TEST) if("${DDC_BUILD_KERNELS_FFT}") - add_subdirectory(fft) + add_subdirectory(fft) endif() if("${DDC_BUILD_KERNELS_SPLINES}") - add_subdirectory(splines) + add_subdirectory(splines) endif() - diff --git a/tests/discrete_space/CMakeLists.txt b/tests/discrete_space/CMakeLists.txt index ca6ca1175..775ab7e10 100644 --- a/tests/discrete_space/CMakeLists.txt +++ b/tests/discrete_space/CMakeLists.txt @@ -3,18 +3,9 @@ # SPDX-License-Identifier: MIT add_library(discrete_space_tests_lib STATIC discrete_space.cpp) -target_link_libraries(discrete_space_tests_lib - PUBLIC - GTest::gtest - DDC::DDC -) +target_link_libraries(discrete_space_tests_lib PUBLIC GTest::gtest DDC::DDC) add_executable(discrete_space_tests main.cpp) -target_link_libraries(discrete_space_tests - PUBLIC - discrete_space_tests_lib - GTest::gtest - DDC::DDC -) +target_link_libraries(discrete_space_tests PUBLIC discrete_space_tests_lib GTest::gtest DDC::DDC) gtest_discover_tests(discrete_space_tests DISCOVERY_MODE PRE_TEST) diff --git a/tests/fft/CMakeLists.txt b/tests/fft/CMakeLists.txt index d7389e2e2..7bf0c4f15 100644 --- a/tests/fft/CMakeLists.txt +++ b/tests/fft/CMakeLists.txt @@ -8,9 +8,5 @@ include(GoogleTest) add_executable(fft_tests ../main.cpp fft.cpp) target_compile_features(fft_tests PUBLIC cxx_std_17) -target_link_libraries(fft_tests - PUBLIC - GTest::gtest - DDC::DDC -) +target_link_libraries(fft_tests PUBLIC GTest::gtest DDC::DDC) gtest_discover_tests(fft_tests DISCOVERY_MODE PRE_TEST) diff --git a/tests/splines/CMakeLists.txt b/tests/splines/CMakeLists.txt index f99f66193..418ae2ac0 100644 --- a/tests/splines/CMakeLists.txt +++ b/tests/splines/CMakeLists.txt @@ -9,183 +9,159 @@ include(GoogleTest) set(SPLINES_TEST_DEGREE_MIN 3 CACHE STRING "Minimum degree to test splines.") set(SPLINES_TEST_DEGREE_MAX 3 CACHE STRING "Maximum degree to test splines.") -add_executable(splines_tests - ../main.cpp - knots_as_interpolation_points.cpp - view.cpp -) +add_executable(splines_tests ../main.cpp knots_as_interpolation_points.cpp view.cpp) target_compile_features(splines_tests PUBLIC cxx_std_17) -target_link_libraries(splines_tests - PUBLIC - GTest::gtest - DDC::DDC -) +target_link_libraries(splines_tests PUBLIC GTest::gtest DDC::DDC) gtest_discover_tests(splines_tests DISCOVERY_MODE PRE_TEST) -add_executable(bsplines_tests - ../main.cpp - bsplines.cpp -) +add_executable(bsplines_tests ../main.cpp bsplines.cpp) target_compile_features(bsplines_tests PUBLIC cxx_std_17) -target_link_libraries(bsplines_tests - PUBLIC - GTest::gtest - DDC::DDC -) +target_link_libraries(bsplines_tests PUBLIC GTest::gtest DDC::DDC) gtest_discover_tests(bsplines_tests DISCOVERY_MODE PRE_TEST) -add_executable(splines_linear_problem_tests - ../main.cpp - splines_linear_problem.cpp -) +add_executable(splines_linear_problem_tests ../main.cpp splines_linear_problem.cpp) target_compile_features(splines_linear_problem_tests PUBLIC cxx_std_17) -target_link_libraries(splines_linear_problem_tests - PUBLIC - GTest::gtest - DDC::DDC -) +target_link_libraries(splines_linear_problem_tests PUBLIC GTest::gtest DDC::DDC) gtest_discover_tests(splines_linear_problem_tests DISCOVERY_MODE PRE_TEST) foreach(DEGREE_X RANGE "${SPLINES_TEST_DEGREE_MIN}" "${SPLINES_TEST_DEGREE_MAX}") - foreach(BSPLINES_TYPE "BSPLINES_TYPE_UNIFORM" "BSPLINES_TYPE_NON_UNIFORM") - set(test_name "splines_tests_DEGREE_X_${DEGREE_X}_${BSPLINES_TYPE}") - add_executable("${test_name}" ../main.cpp periodic_spline_builder.cpp) - target_compile_features("${test_name}" PUBLIC cxx_std_17) - target_link_libraries("${test_name}" - PUBLIC - GTest::gtest - DDC::DDC - ) - target_compile_definitions("${test_name}" PUBLIC -DDEGREE_X=${DEGREE_X} -D${BSPLINES_TYPE}) - add_test("${test_name}" "${test_name}") - endforeach() + foreach(BSPLINES_TYPE "BSPLINES_TYPE_UNIFORM" "BSPLINES_TYPE_NON_UNIFORM") + set(test_name "splines_tests_DEGREE_X_${DEGREE_X}_${BSPLINES_TYPE}") + add_executable("${test_name}" ../main.cpp periodic_spline_builder.cpp) + target_compile_features("${test_name}" PUBLIC cxx_std_17) + target_link_libraries("${test_name}" PUBLIC GTest::gtest DDC::DDC) + target_compile_definitions("${test_name}" PUBLIC -DDEGREE_X=${DEGREE_X} -D${BSPLINES_TYPE}) + add_test("${test_name}" "${test_name}") + endforeach() endforeach() foreach(BCL "BCL_GREVILLE" "BCL_HERMITE") - foreach(BCR "BCR_GREVILLE" "BCR_HERMITE") - foreach(EVALUATOR "EVALUATOR_COSINE" "EVALUATOR_POLYNOMIAL") - foreach(DEGREE_X RANGE "${SPLINES_TEST_DEGREE_MIN}" "${SPLINES_TEST_DEGREE_MAX}") - foreach(BSPLINES_TYPE "BSPLINES_TYPE_UNIFORM" "BSPLINES_TYPE_NON_UNIFORM") - set(test_name "splines_tests_DEGREE_X_${DEGREE_X}_${BSPLINES_TYPE}_${EVALUATOR}_bcl_${BCL}_bcr_${BCR}") - add_executable("${test_name}" ../main.cpp non_periodic_spline_builder.cpp) - target_compile_features("${test_name}" PUBLIC cxx_std_17) - target_link_libraries("${test_name}" - PUBLIC - GTest::gtest - DDC::DDC - ) - target_compile_definitions("${test_name}" PUBLIC -DDEGREE_X=${DEGREE_X} -D${BSPLINES_TYPE} -D${EVALUATOR} -D${BCL} -D${BCR}) - add_test("${test_name}" "${test_name}") + foreach(BCR "BCR_GREVILLE" "BCR_HERMITE") + foreach(EVALUATOR "EVALUATOR_COSINE" "EVALUATOR_POLYNOMIAL") + foreach(DEGREE_X RANGE "${SPLINES_TEST_DEGREE_MIN}" "${SPLINES_TEST_DEGREE_MAX}") + foreach(BSPLINES_TYPE "BSPLINES_TYPE_UNIFORM" "BSPLINES_TYPE_NON_UNIFORM") + set(test_name + "splines_tests_DEGREE_X_${DEGREE_X}_${BSPLINES_TYPE}_${EVALUATOR}_bcl_${BCL}_bcr_${BCR}" + ) + add_executable("${test_name}" ../main.cpp non_periodic_spline_builder.cpp) + target_compile_features("${test_name}" PUBLIC cxx_std_17) + target_link_libraries("${test_name}" PUBLIC GTest::gtest DDC::DDC) + target_compile_definitions( + "${test_name}" + PUBLIC + -DDEGREE_X=${DEGREE_X} + -D${BSPLINES_TYPE} + -D${EVALUATOR} + -D${BCL} + -D${BCR} + ) + add_test("${test_name}" "${test_name}") + endforeach() + endforeach() endforeach() - endforeach() endforeach() - endforeach() endforeach() foreach(BC "BC_PERIODIC" "BC_GREVILLE") - foreach(DEGREE_X RANGE "${SPLINES_TEST_DEGREE_MIN}" "${SPLINES_TEST_DEGREE_MAX}") - foreach(BSPLINES_TYPE "BSPLINES_TYPE_UNIFORM" "BSPLINES_TYPE_NON_UNIFORM") - foreach(ER "ER_NULL" "ER_CONSTANT") - set(test_name "splines_tests_DEGREE_X_${DEGREE_X}_${BSPLINES_TYPE}_${EVALUATOR}_${BC}_${ER}") - add_executable("${test_name}" ../main.cpp extrapolation_rule.cpp) - target_compile_features("${test_name}" PUBLIC cxx_std_17) - target_link_libraries("${test_name}" - PUBLIC - GTest::gtest - DDC::DDC - ) - target_compile_definitions("${test_name}" PUBLIC -DDEGREE=${DEGREE_X} -D${BSPLINES_TYPE} -D${EVALUATOR} -D${BC} -D${ER}) - # add_test("${test_name}" "${test_name}") - gtest_discover_tests("${test_name}" DISCOVERY_MODE PRE_TEST) - endforeach() + foreach(DEGREE_X RANGE "${SPLINES_TEST_DEGREE_MIN}" "${SPLINES_TEST_DEGREE_MAX}") + foreach(BSPLINES_TYPE "BSPLINES_TYPE_UNIFORM" "BSPLINES_TYPE_NON_UNIFORM") + foreach(ER "ER_NULL" "ER_CONSTANT") + set(test_name + "splines_tests_DEGREE_X_${DEGREE_X}_${BSPLINES_TYPE}_${EVALUATOR}_${BC}_${ER}" + ) + add_executable("${test_name}" ../main.cpp extrapolation_rule.cpp) + target_compile_features("${test_name}" PUBLIC cxx_std_17) + target_link_libraries("${test_name}" PUBLIC GTest::gtest DDC::DDC) + target_compile_definitions( + "${test_name}" + PUBLIC -DDEGREE=${DEGREE_X} -D${BSPLINES_TYPE} -D${EVALUATOR} -D${BC} -D${ER} + ) + # add_test("${test_name}" "${test_name}") + gtest_discover_tests("${test_name}" DISCOVERY_MODE PRE_TEST) + endforeach() + endforeach() endforeach() - endforeach() endforeach() # LAPACK foreach(BC "BC_PERIODIC" "BC_GREVILLE" "BC_HERMITE") - foreach(DEGREE_X RANGE "${SPLINES_TEST_DEGREE_MIN}" "${SPLINES_TEST_DEGREE_MAX}") - foreach(BSPLINES_TYPE "BSPLINES_TYPE_UNIFORM" "BSPLINES_TYPE_NON_UNIFORM") - set(test_name "splines_tests_BATCHED_DEGREE_X_${DEGREE_X}_${BSPLINES_TYPE}_${BC}_LAPACK") - add_executable("${test_name}" ../main.cpp batched_spline_builder.cpp) - target_compile_features("${test_name}" PUBLIC cxx_std_17) - target_link_libraries("${test_name}" - PUBLIC - GTest::gtest - DDC::DDC - ) - target_compile_definitions("${test_name}" PUBLIC -DDEGREE_X=${DEGREE_X} -D${BSPLINES_TYPE} -D${BC} -DSOLVER_LAPACK) - # add_test("${test_name}" "${test_name}") - gtest_discover_tests("${test_name}" DISCOVERY_MODE PRE_TEST) + foreach(DEGREE_X RANGE "${SPLINES_TEST_DEGREE_MIN}" "${SPLINES_TEST_DEGREE_MAX}") + foreach(BSPLINES_TYPE "BSPLINES_TYPE_UNIFORM" "BSPLINES_TYPE_NON_UNIFORM") + set(test_name + "splines_tests_BATCHED_DEGREE_X_${DEGREE_X}_${BSPLINES_TYPE}_${BC}_LAPACK" + ) + add_executable("${test_name}" ../main.cpp batched_spline_builder.cpp) + target_compile_features("${test_name}" PUBLIC cxx_std_17) + target_link_libraries("${test_name}" PUBLIC GTest::gtest DDC::DDC) + target_compile_definitions( + "${test_name}" + PUBLIC -DDEGREE_X=${DEGREE_X} -D${BSPLINES_TYPE} -D${BC} -DSOLVER_LAPACK + ) + # add_test("${test_name}" "${test_name}") + gtest_discover_tests("${test_name}" DISCOVERY_MODE PRE_TEST) + endforeach() endforeach() - endforeach() endforeach() # GINKGO foreach(BC "BC_PERIODIC" "BC_GREVILLE" "BC_HERMITE") - foreach(DEGREE_X RANGE "${SPLINES_TEST_DEGREE_MIN}" "${SPLINES_TEST_DEGREE_MAX}") - foreach(BSPLINES_TYPE "BSPLINES_TYPE_UNIFORM" "BSPLINES_TYPE_NON_UNIFORM") - set(test_name "splines_tests_BATCHED_DEGREE_X_${DEGREE_X}_${BSPLINES_TYPE}_${BC}_GINKGO") - add_executable("${test_name}" ../main.cpp batched_spline_builder.cpp) - target_compile_features("${test_name}" PUBLIC cxx_std_17) - target_link_libraries("${test_name}" - PUBLIC - GTest::gtest - DDC::DDC - ) - target_compile_definitions("${test_name}" PUBLIC -DDEGREE_X=${DEGREE_X} -D${BSPLINES_TYPE} -D${BC} -DSOLVER_GINKGO) - # add_test("${test_name}" "${test_name}") - gtest_discover_tests("${test_name}" DISCOVERY_MODE PRE_TEST) + foreach(DEGREE_X RANGE "${SPLINES_TEST_DEGREE_MIN}" "${SPLINES_TEST_DEGREE_MAX}") + foreach(BSPLINES_TYPE "BSPLINES_TYPE_UNIFORM" "BSPLINES_TYPE_NON_UNIFORM") + set(test_name + "splines_tests_BATCHED_DEGREE_X_${DEGREE_X}_${BSPLINES_TYPE}_${BC}_GINKGO" + ) + add_executable("${test_name}" ../main.cpp batched_spline_builder.cpp) + target_compile_features("${test_name}" PUBLIC cxx_std_17) + target_link_libraries("${test_name}" PUBLIC GTest::gtest DDC::DDC) + target_compile_definitions( + "${test_name}" + PUBLIC -DDEGREE_X=${DEGREE_X} -D${BSPLINES_TYPE} -D${BC} -DSOLVER_GINKGO + ) + # add_test("${test_name}" "${test_name}") + gtest_discover_tests("${test_name}" DISCOVERY_MODE PRE_TEST) + endforeach() endforeach() - endforeach() endforeach() foreach(DEGREE_X RANGE "${SPLINES_TEST_DEGREE_MIN}" "${SPLINES_TEST_DEGREE_MAX}") - set(test_name "splines_ordered_points_DEGREE_X_${DEGREE_X}") - add_executable("${test_name}" ../main.cpp periodic_spline_builder_ordered_points.cpp) - target_compile_features("${test_name}" PUBLIC cxx_std_17) - target_link_libraries("${test_name}" - PUBLIC - GTest::gtest - DDC::DDC - ) - target_compile_definitions("${test_name}" PUBLIC -DDEGREE_X=${DEGREE_X}) - add_test("${test_name}" "${test_name}") + set(test_name "splines_ordered_points_DEGREE_X_${DEGREE_X}") + add_executable("${test_name}" ../main.cpp periodic_spline_builder_ordered_points.cpp) + target_compile_features("${test_name}" PUBLIC cxx_std_17) + target_link_libraries("${test_name}" PUBLIC GTest::gtest DDC::DDC) + target_compile_definitions("${test_name}" PUBLIC -DDEGREE_X=${DEGREE_X}) + add_test("${test_name}" "${test_name}") endforeach() foreach(DEGREE_X RANGE "${SPLINES_TEST_DEGREE_MIN}" "${SPLINES_TEST_DEGREE_MAX}") - foreach(BSPLINES_TYPE "BSPLINES_TYPE_UNIFORM" "BSPLINES_TYPE_NON_UNIFORM") - set(test_name "splines_tests_PERIODICITY_DEGREE_X_${DEGREE_X}_${BSPLINES_TYPE}") - add_executable("${test_name}" ../main.cpp periodicity_spline_builder.cpp) - target_compile_features("${test_name}" PUBLIC cxx_std_17) - target_link_libraries("${test_name}" - PUBLIC - GTest::gtest - DDC::DDC - ) - target_compile_definitions("${test_name}" PUBLIC -DDEGREE_X=${DEGREE_X} -D${BSPLINES_TYPE}) - # add_test("${test_name}" "${test_name}") - gtest_discover_tests("${test_name}" DISCOVERY_MODE PRE_TEST) - endforeach() + foreach(BSPLINES_TYPE "BSPLINES_TYPE_UNIFORM" "BSPLINES_TYPE_NON_UNIFORM") + set(test_name "splines_tests_PERIODICITY_DEGREE_X_${DEGREE_X}_${BSPLINES_TYPE}") + add_executable("${test_name}" ../main.cpp periodicity_spline_builder.cpp) + target_compile_features("${test_name}" PUBLIC cxx_std_17) + target_link_libraries("${test_name}" PUBLIC GTest::gtest DDC::DDC) + target_compile_definitions("${test_name}" PUBLIC -DDEGREE_X=${DEGREE_X} -D${BSPLINES_TYPE}) + # add_test("${test_name}" "${test_name}") + gtest_discover_tests("${test_name}" DISCOVERY_MODE PRE_TEST) + endforeach() endforeach() foreach(BC "BC_PERIODIC" "BC_GREVILLE" "BC_HERMITE") foreach(EVALUATOR "EVALUATOR_POLYNOMIAL") - foreach(DEGREE RANGE "${SPLINES_TEST_DEGREE_MIN}" "${SPLINES_TEST_DEGREE_MAX}") - foreach(BSPLINES_TYPE "BSPLINES_TYPE_UNIFORM" "BSPLINES_TYPE_NON_UNIFORM") - set(test_name "2d_splines_tests_BATCHED_DEGREE_${DEGREE}_${BSPLINES_TYPE}_${EVALUATOR}_${BC}") - add_executable("${test_name}" ../main.cpp batched_2d_spline_builder.cpp) - target_compile_features("${test_name}" PUBLIC cxx_std_17) - target_link_libraries("${test_name}" - PUBLIC - GTest::gtest - DDC::DDC - ) - target_compile_definitions("${test_name}" PUBLIC -DDEGREE=${DEGREE} -D${BSPLINES_TYPE} -D${EVALUATOR} -D${BC}) - # add_test("${test_name}" "${test_name}") - gtest_discover_tests("${test_name}" DISCOVERY_MODE PRE_TEST) - endforeach() + foreach(DEGREE RANGE "${SPLINES_TEST_DEGREE_MIN}" "${SPLINES_TEST_DEGREE_MAX}") + foreach(BSPLINES_TYPE "BSPLINES_TYPE_UNIFORM" "BSPLINES_TYPE_NON_UNIFORM") + set(test_name + "2d_splines_tests_BATCHED_DEGREE_${DEGREE}_${BSPLINES_TYPE}_${EVALUATOR}_${BC}" + ) + add_executable("${test_name}" ../main.cpp batched_2d_spline_builder.cpp) + target_compile_features("${test_name}" PUBLIC cxx_std_17) + target_link_libraries("${test_name}" PUBLIC GTest::gtest DDC::DDC) + target_compile_definitions( + "${test_name}" + PUBLIC -DDEGREE=${DEGREE} -D${BSPLINES_TYPE} -D${EVALUATOR} -D${BC} + ) + # add_test("${test_name}" "${test_name}") + gtest_discover_tests("${test_name}" DISCOVERY_MODE PRE_TEST) + endforeach() endforeach() - endforeach() + endforeach() endforeach()