From 0915dc462baedadbaae0a3309d54e35742b949de Mon Sep 17 00:00:00 2001 From: Gregor Olenik Date: Fri, 21 Jun 2024 10:05:35 +0200 Subject: [PATCH 01/20] set ginkgo verson to develop --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 895020167..d76b8e93a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ if((NOT OGL_ALLOW_REFERENCE_ONLY) AND (NOT OGL_USE_EXTERNAL_GINKGO)) endif() set(GINKGO_CHECKOUT_VERSION - "fc86d48b78cebd2b2c5833a2dcf0fe40f615cf19" + "develop" CACHE STRING "Use specific version of ginkgo") include(CheckIncludeFileCXX) From 7fb6956456e9b0edc114b65b9f0715160e8d58d2 Mon Sep 17 00:00:00 2001 From: Gregor Olenik Date: Fri, 21 Jun 2024 10:19:41 +0200 Subject: [PATCH 02/20] copy cmake files over --- CMakeLists.txt | 112 ++++++++++++++++++++++++++-------------------- CMakePresets.json | 73 +++++++++++++++++++++++++----- 2 files changed, 125 insertions(+), 60 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d76b8e93a..ba63f7f16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,9 +14,13 @@ if(NOT DEFINED ENV{FOAM_SRC}) message(FATAL_ERROR "You must source OpenFOAM before building OGL") endif() -# Configuration options +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) +# Configuration options include(cmake/build_type_helpers.cmake) +include(cmake/OpenFOAM.cmake) list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/") include(CheckIncludeFileCXX) @@ -26,16 +30,37 @@ option(OGL_USE_FOAM_FOUNDATION_VERSION "Build OGL for the OpenFOAM Foundation version" FALSE) option(OGL_BUILD_UNITTEST "Build OGL unittests" FALSE) option(OGL_CUDA_ARCHITECTURES "Which cuda architecture to build for" "native") -option(GINKGO_BUILD_CUDA "Build Ginkgo with cuda backend" FALSE) -option(GINKGO_BUILD_HIP "Build Ginkgo with hip backend" FALSE) -option(GINKGO_BUILD_SYCL "Build Ginkgo with sycl backend" FALSE) -option(GINKGO_BUILD_OMP "Build Ginkgo with omp backend" FALSE) option(GINKGO_BUILD_REFERENCE "Build Ginkgo with reference backend" TRUE) option(OGL_ALLOW_REFERENCE_ONLY "Enable builds of Ginkgo with reference backend only" FALSE) -option(GINKGO_FORCE_GPU_AWARE_MPI "Build Ginkgo using device aware MPI" TRUE) +option(OGL_ENABLE_SANITIZE_ADDRESS "Enable address sanitizer" FALSE) +option(OGL_ENABLE_SANITIZE_LEAK "Enable leak sanitizer" FALSE) +option(OGL_ENABLE_SANITIZE_UB "Enable undefined behaviour sanitizer" FALSE) +option(OGL_ENABLE_SANITIZE_THREAD "Enable thread sanitizer" FALSE) +option(OGL_ENABLE_SANITIZE_MEMORY "Enable memory sanitizer" FALSE) + option(GINKGO_WITH_OGL_EXTENSIONS "Whether ginkgo was build with OGL extension" FALSE) +option(GINKGO_BUILD_REFERENCE "Build Ginkgo with reference backend" TRUE) + +option(GINKGO_FORCE_GPU_AWARE_MPI "Build Ginkgo using device aware MPI" TRUE) +option(GINKGO_BUILD_CUDA "Build Ginkgo with cuda backend" FALSE) +option(GINKGO_BUILD_HIP "Build Ginkgo with hip backend" FALSE) +option(GINKGO_BUILD_SYCL "Build Ginkgo with sycl backend" FALSE) +option(GINKGO_BUILD_OMP "Build Ginkgo with omp backend" FALSE) + +set(GINKGO_BUILD_MPI + ON + CACHE INTERNAL "") +set(GINKGO_BUILD_TESTS + OFF + CACHE INTERNAL "") +set(GINKGO_BUILD_EXAMPLES + OFF + CACHE INTERNAL "") +set(GINKGO_BUILD_BENCHMARKS + OFF + CACHE INTERNAL "") if((NOT OGL_ALLOW_REFERENCE_ONLY) AND (NOT OGL_USE_EXTERNAL_GINKGO)) if((NOT GINKGO_BUILD_CUDA) @@ -49,7 +74,7 @@ if((NOT OGL_ALLOW_REFERENCE_ONLY) AND (NOT OGL_USE_EXTERNAL_GINKGO)) endif() set(GINKGO_CHECKOUT_VERSION - "develop" + "ogl_rebase_1.8.0" CACHE STRING "Use specific version of ginkgo") include(CheckIncludeFileCXX) @@ -58,44 +83,24 @@ check_include_file_cxx(cxxabi.h GKO_HAVE_CXXABI_H) include(cmake/package_helpers.cmake) include(cmake/build_helpers.cmake) include(cmake/install_helpers.cmake) +include(cmake/Sanitizer.cmake) ginkgo_find_package(Ginkgo "Ginkgo::ginkgo" FALSE 1.7.0) add_subdirectory(third_party) -# If ginkgo is not found at this point, look for the third_party installation -if(NOT ${OGL_USE_EXTERNAL_GINKGO}) - find_package( - Ginkgo - CONFIG - 1.7.0 - REQUIRED - PATHS - $ENV{FOAM_USER_LIBBIN}/cmake/Ginkgo - ${CMAKE_CURRENT_BINARY_DIR}/third_party/ginkgo/build/install/lib/cmake) -endif() - -# C++ 14 standard or later is required to interface with Ginkgo OGL itself uses -# some c++ 17 features - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_POSITION_INDEPENDENT_CODE ON) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -O0 -ggdb") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} \ - -Wall -Wpedantic -Wextra -march=native -fopenmp -fPIC -Wno-undefined-var-template" + -Wall -Wpedantic -Wextra -Wextra -march=native -fopenmp -fPIC -Wno-undefined-var-template" ) if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") message("Compiling with clang") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) - set(CMAKE_CXX_FLAGS_DEBUG - "${CMAKE_CXX_FLAGS_DEBUG} \ - -fno-omit-frame-pointer \ - -fsanitize=address") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} \ + -fno-omit-frame-pointer") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} \ @@ -113,8 +118,8 @@ elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") "${CMAKE_CXX_FLAGS_DEBUG} \ --coverage\ -fprofile-arcs \ - -ggdb3") - # * fsanitize = address \ - ftest - coverage \ + -ggdb3 \ + ") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} \ @@ -138,6 +143,7 @@ if(APPLE) target_compile_definitions(OGL PRIVATE APPLE arm64) else() target_compile_definitions(OGL PRIVATE linux64) + target_link_libraries(OGL PRIVATE stdc++fs) endif() # Add a custom command that produces version.cpp, plus a dummy output that's not @@ -161,12 +167,13 @@ target_sources( DevicePersistent/Vector/Vector.C DevicePersistent/DeviceIdGuard/DeviceIdGuard.C DevicePersistent/ExecutorHandler/ExecutorHandler.C - DevicePersistent/CsrMatrixWrapper/CsrMatrixWrapper.C + DevicePersistent/HostMatrixAdapter/HostMatrixAdapter.C Preconditioner/Preconditioner.C BaseWrapper/lduBase/GKOlduBase.C BaseWrapper/CoupledLduBase/GKOCoupledLduBase.C - HostMatrix/HostMatrix.C - HostMatrix/HostMatrixFreeFunctions.C + MatrixWrapper/LDUMatrix/HostMatrix.C + MatrixWrapper/LDUMatrix/HostMatrixFreeFunctions.C + MatrixWrapper/CommunicationPattern/CommunicationPattern.C Solver/CG/GKOCG.C Solver/BiCGStab/GKOBiCGStab.C # Solver / IR / GKOIR.C Solver / Multigrid / GKOMultigrid.C @@ -175,14 +182,15 @@ target_sources( PUBLIC common/common.H StoppingCriterion/StoppingCriterion.H lduLduBase/lduLduBase.H - HostMatrix/HostMatrix.H + MatrixWrapper/LDUMatrix/HostMatrix.H + MatrixWrapper/Combination/Combination.H DevicePersistent/Base/Base.H DevicePersistent/Partition/Partition.H DevicePersistent/Array/Array.H DevicePersistent/Vector/Vector.H DevicePersistent/ExecutorHandler/ExecutorHandler.H DevicePersistent/DeviceIdGuard/DeviceIdGuard.H - DevicePersistent/CsrMatrixWrapper/CsrMatrixWrapper.H + DevicePersistent/HostMatrixAdapter/HostMatrixAdapter.H Preconditioner/Preconditioner.H BaseWrapper/lduBase/GKOlduBase.H BaseWrapper/CoupledLduBase/GKOCoupledLduBase.H @@ -194,17 +202,14 @@ target_sources( # LduMatrix / GKOACG / GKOACG.H ) -target_include_directories( - OGL SYSTEM - PUBLIC $ENV{FOAM_SRC}/finiteVolume/lnInclude - $ENV{FOAM_SRC}/meshTools/lnInclude $ENV{FOAM_SRC}/OpenFOAM/lnInclude - $ENV{FOAM_SRC}/OSspecific/POSIX/lnInclude ${CMAKE_CURRENT_SOURCE_DIR}) +enable_sanitizers( + OGL ${OGL_ENABLE_SANITIZE_ADDRESS} ${OGL_ENABLE_SANITIZE_LEAK} + ${OGL_ENABLE_SANITIZE_UB} ${OGL_ENABLE_SANITIZE_THREAD} + ${OGL_ENABLE_SANITIZE_MEMORY}) -target_link_libraries( - OGL - PRIVATE $ENV{FOAM_LIBBIN}/libOpenFOAM.so $ENV{FOAM_LIBBIN}/libfiniteVolume.so - $ENV{FOAM_LIBBIN}/$ENV{FOAM_MPI}/libPstream.so - PUBLIC Ginkgo::ginkgo stdc++fs) +target_include_directories(OGL SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +target_link_libraries(OGL PRIVATE OpenFOAM Ginkgo::ginkgo) if(${GINKGO_WITH_OGL_EXTENSIONS}) target_compile_definitions(OGL PRIVATE GINKGO_WITH_OGL_EXTENSIONS=1) @@ -236,4 +241,13 @@ add_custom_target( COMMAND find . -name CMakeLists.txt -exec cmake-format -i {} + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) -install(TARGETS OGL DESTINATION $ENV{FOAM_USER_LIBBIN}) +install( + TARGETS OGL + ginkgo + ginkgo_device + ginkgo_hip + ginkgo_cuda + ginkgo_omp + ginkgo_dpcpp + ginkgo_reference + DESTINATION $ENV{FOAM_USER_LIBBIN}) diff --git a/CMakePresets.json b/CMakePresets.json index 890dd7613..6f9dfc3e4 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -1,28 +1,46 @@ { - "version": 2, + "version": 6, "cmakeMinimumRequired": { "major": 3, - "minor": 20, + "minor": 25, "patch": 0 }, "configurePresets": [ { "name": "default", + "hidden": true, "displayName": "Default Config", "description": "Default build using Ninja generator", "generator": "Ninja", - "binaryDir": "${sourceDir}/build/Release", "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release" + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "CMAKE_INSTALL_PREFIX": "$env{FOAM_USER_LIBBIN}/.." } }, { - "name": "ninja-cpuonly-release", - "inherits": "default", - "displayName": "No GPU, Ninja", - "description": "Release build without GPU support using Ninja Multi-Config generator", - "generator": "Ninja Multi-Config", - "binaryDir": "${sourceDir}/build/ReleaseCPUOnly", + "name": "debug", + "hidden": true, + "displayName": "Default Config", + "description": "Default build using Ninja generator", + "generator": "Ninja", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_INSTALL_PREFIX": "$env{FOAM_USER_LIBBIN}/.." + } + }, + { + "name": "ninja", + "hidden": true, + "displayName": "Default Config", + "description": "Default build using Ninja generator", + "generator": "Ninja" + }, + { + "name": "cpuonly", + "hidden": true, + "displayName": "Default Config", + "description": "Default build using Ninja generator", + "generator": "Ninja", "cacheVariables": { "OGL_ALLOW_REFERENCE_ONLY": { "type": "BOOL", @@ -30,6 +48,20 @@ } } }, + { + "name": "ninja-cpuonly-debug", + "displayName": "No GPU, Ninja", + "inherits": ["debug", "ninja", "cpuonly"], + "description": "Debug build without GPU support using Ninja Multi-Config generator", + "binaryDir": "${sourceDir}/build/DebugCPUOnly" + }, + { + "name": "ninja-cpuonly-release", + "inherits": ["default", "ninja", "cpuonly"], + "displayName": "No GPU, Ninja", + "description": "Debug build without GPU support using Ninja Multi-Config generator", + "binaryDir": "${sourceDir}/build/ReleaseCPUOnly" + }, { "name": "ninja-cuda-release", "inherits": "default", @@ -83,6 +115,11 @@ "configurePreset": "ninja-cpuonly-release", "configuration": "Release" }, + { + "name": "ninja-cpuonly-debug", + "configurePreset": "ninja-cpuonly-debug", + "configuration": "Release" + }, { "name": "ninja-cuda-release", "configurePreset": "ninja-cuda-release", @@ -98,6 +135,20 @@ "configurePreset": "ninja-sycl-release", "configuration": "Release" } + ], + "workflowPresets": [ + { + "name": "ninja-cpuonly-release", + "steps": [ + { + "type": "configure", + "name": "ninja-cpuonly-release" + }, + { + "type": "build", + "name": "ninja-cpuonly-release" + } + ] + } ] - } From d49249f14e46ca11d7a269be5d60c8fb194145bd Mon Sep 17 00:00:00 2001 From: Gregor Olenik Date: Fri, 21 Jun 2024 10:22:51 +0200 Subject: [PATCH 03/20] require ginkgo 1.8.0 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba63f7f16..fc6c473b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,7 +85,7 @@ include(cmake/build_helpers.cmake) include(cmake/install_helpers.cmake) include(cmake/Sanitizer.cmake) -ginkgo_find_package(Ginkgo "Ginkgo::ginkgo" FALSE 1.7.0) +ginkgo_find_package(Ginkgo "Ginkgo::ginkgo" FALSE 1.8.0) add_subdirectory(third_party) From aec85e5d0ac6fd487f7d4cca4bfe41e028c17b85 Mon Sep 17 00:00:00 2001 From: Gregor Olenik Date: Fri, 21 Jun 2024 10:25:42 +0200 Subject: [PATCH 04/20] add Sanitizer --- cmake/Sanitizer.cmake | 103 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 cmake/Sanitizer.cmake diff --git a/cmake/Sanitizer.cmake b/cmake/Sanitizer.cmake new file mode 100644 index 000000000..c79772ffa --- /dev/null +++ b/cmake/Sanitizer.cmake @@ -0,0 +1,103 @@ +# SPDX-License-Identifier: Unlicense +# SPDX-FileCopyrightText: 2023 Jason Turner +# SPDX-FileCopyrightText: 2023 NeoFOAM authors +############################################################################## +# This function will enable sanitizers # +# from here # +# https://github.com/cpp-best-practices/cmake_template # +############################################################################## + +function( + enable_sanitizers + project_name + ENABLE_SANITIZE_ADDRESS + ENABLE_SANITIZE_LEAK + ENABLE_SANITIZE_UNDEFINED_BEHAVIOR + ENABLE_SANITIZE_THREAD + ENABLE_SANITIZE_MEMORY) + +# message(FATAL_ERROR "add addr ${ENABLE_NEOFOAM_SANITIZE_ADDRESS}") + + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") + set(SANITIZERS "") + + if(${ENABLE_SANITIZE_ADDRESS}) + list(APPEND SANITIZERS "address") + endif() + + if(${ENABLE_SANITIZE_LEAK}) + message(FATAL_ERROR "add leak") + list(APPEND SANITIZERS "leak") + endif() + + if(${ENABLE_SANITIZE_UNDEFINED_BEHAVIOR}) + list(APPEND SANITIZERS "undefined") + endif() + + if(${ENABLE_SANITIZE_THREAD}) + if("address" IN_LIST SANITIZERS OR "leak" IN_LIST SANITIZERS) + message(WARNING "Thread sanitizer does not work with Address and Leak sanitizer enabled") + else() + list(APPEND SANITIZERS "thread") + endif() + endif() + + if(${ENABLE_SANITIZE_MEMORY} AND CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") + message( + WARNING + "Memory sanitizer requires all the code (including libc++) to be MSan-instrumented otherwise it reports false positives" + ) + if("address" IN_LIST SANITIZERS + OR "thread" IN_LIST SANITIZERS + OR "leak" IN_LIST SANITIZERS) + # message(FATAL_ERROR "Memory sanitizer does not work with Address, Thread or Leak sanitizer enabled") + else() + list(APPEND SANITIZERS "memory") + endif() + endif() + elseif(MSVC) + if(${ENABLE_SANITIZE_ADDRESS}) + list(APPEND SANITIZERS "address") + endif() + if(${ENABLE_SANITIZE_LEAK} + OR ${ENABLE_SANITIZE_UNDEFINED_BEHAVIOR} + OR ${ENABLE_SANITIZE_THREAD} + OR ${ENABLE_SANITIZE_MEMORY}) + message(WARNING "MSVC only supports address sanitizer") + endif() + endif() + + list( + JOIN + SANITIZERS + "," + LIST_OF_SANITIZERS) + + if(LIST_OF_SANITIZERS) + if(NOT + "${LIST_OF_SANITIZERS}" + STREQUAL + "") + if(NOT MSVC) + # message(FATAL_ERROR "${project_name} ${LIST_OF_SANITIZERS}") + target_compile_options(${project_name} PRIVATE -fsanitize=${LIST_OF_SANITIZERS}) + target_link_options(${project_name} PRIVATE -fsanitize=${LIST_OF_SANITIZERS}) + else() + string(FIND "$ENV{PATH}" "$ENV{VSINSTALLDIR}" index_of_vs_install_dir) + if("${index_of_vs_install_dir}" STREQUAL "-1") + message( + SEND_ERROR + "Using MSVC sanitizers requires setting the MSVC environment before building the project. Please manually open the MSVC command prompt and rebuild the project." + ) + endif() + target_compile_options(${project_name} INTERFACE /fsanitize=${LIST_OF_SANITIZERS} /Zi /INCREMENTAL:NO) + target_compile_definitions(${project_name} INTERFACE _DISABLE_VECTOR_ANNOTATION _DISABLE_STRING_ANNOTATION) + target_link_options(${project_name} INTERFACE /INCREMENTAL:NO) + endif() + endif() + endif() + +endfunction() + + + From 5cad3c9377bab45dce42892e1bc043804134a1e9 Mon Sep 17 00:00:00 2001 From: Gregor Olenik Date: Fri, 21 Jun 2024 10:33:51 +0200 Subject: [PATCH 05/20] add OpenFOAM config --- CMakeLists.txt | 7 +++---- cmake/OpenFOAM.cmake | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 cmake/OpenFOAM.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index fc6c473b9..650113017 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,11 +16,10 @@ endif() set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_POSITION_INDEPENDENT_CODE ON) +set(BUILD_SHARED_LIBS ON) # Configuration options include(cmake/build_type_helpers.cmake) -include(cmake/OpenFOAM.cmake) list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/") include(CheckIncludeFileCXX) @@ -84,6 +83,7 @@ include(cmake/package_helpers.cmake) include(cmake/build_helpers.cmake) include(cmake/install_helpers.cmake) include(cmake/Sanitizer.cmake) +include(cmake/OpenFOAM.cmake) ginkgo_find_package(Ginkgo "Ginkgo::ginkgo" FALSE 1.8.0) @@ -92,7 +92,7 @@ add_subdirectory(third_party) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -O0 -ggdb") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} \ - -Wall -Wpedantic -Wextra -Wextra -march=native -fopenmp -fPIC -Wno-undefined-var-template" + -Wall -Wpedantic -Wextra -march=native -fopenmp -Wno-undefined-var-template" ) if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") @@ -130,7 +130,6 @@ elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") ") endif() -option(BUILD_SHARED_LIBS "Build shared library" ON) add_library(OGL "") target_compile_definitions(OGL PUBLIC NoRepository) diff --git a/cmake/OpenFOAM.cmake b/cmake/OpenFOAM.cmake new file mode 100644 index 000000000..11fda5bf8 --- /dev/null +++ b/cmake/OpenFOAM.cmake @@ -0,0 +1,25 @@ +# SPDX-FileCopyrightText: 2024 OGL authors +# +# SPDX-License-Identifier: GPL-3.0-or-later + +add_library(OpenFOAM SHARED IMPORTED) + +target_include_directories( + OpenFOAM + INTERFACE $ENV{FOAM_SRC}/finiteVolume/lnInclude + $ENV{FOAM_SRC}/meshTools/lnInclude + $ENV{FOAM_SRC}/OpenFOAM/lnInclude + $ENV{FOAM_SRC}/OSspecific/POSIX/lnInclude) +if(APPLE) + set_target_properties( + OpenFOAM + PROPERTIES IMPORTED_LOCATION $ENV{FOAM_LIBBIN}/libOpenFOAM.dylib + $ENV{FOAM_LIBBIN}/libfiniteVolume.dylib + $ENV{FOAM_LIBBIN}/$ENV{FOAM_MPI}/libPstream.dylib) +else() + set_target_properties( + OpenFOAM + PROPERTIES IMPORTED_LOCATION $ENV{FOAM_LIBBIN}/libOpenFOAM.so + $ENV{FOAM_LIBBIN}/libfiniteVolume.so + $ENV{FOAM_LIBBIN}/$ENV{FOAM_MPI}/libPstream.so) +endif() From 48408080614a79ece3b5edd9d37542ecc23cd8b7 Mon Sep 17 00:00:00 2001 From: Gregor Olenik Date: Fri, 21 Jun 2024 10:54:14 +0200 Subject: [PATCH 06/20] clean up --- CMakeLists.txt | 14 +------------- CMakePresets.json | 27 ++++++--------------------- cmake/ginkgo.cmake | 17 +++++++++++++++++ third_party/CMakeLists.txt | 8 -------- third_party/ginkgo/CMakeLists.txt | 24 ------------------------ 5 files changed, 24 insertions(+), 66 deletions(-) create mode 100644 cmake/ginkgo.cmake delete mode 100644 third_party/CMakeLists.txt delete mode 100644 third_party/ginkgo/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 650113017..95d9626fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,8 +86,7 @@ include(cmake/Sanitizer.cmake) include(cmake/OpenFOAM.cmake) ginkgo_find_package(Ginkgo "Ginkgo::ginkgo" FALSE 1.8.0) - -add_subdirectory(third_party) +include(cmake/ginkgo.cmake) set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -O0 -ggdb") set(CMAKE_CXX_FLAGS_RELEASE @@ -166,39 +165,28 @@ target_sources( DevicePersistent/Vector/Vector.C DevicePersistent/DeviceIdGuard/DeviceIdGuard.C DevicePersistent/ExecutorHandler/ExecutorHandler.C - DevicePersistent/HostMatrixAdapter/HostMatrixAdapter.C Preconditioner/Preconditioner.C BaseWrapper/lduBase/GKOlduBase.C BaseWrapper/CoupledLduBase/GKOCoupledLduBase.C - MatrixWrapper/LDUMatrix/HostMatrix.C - MatrixWrapper/LDUMatrix/HostMatrixFreeFunctions.C - MatrixWrapper/CommunicationPattern/CommunicationPattern.C Solver/CG/GKOCG.C Solver/BiCGStab/GKOBiCGStab.C - # Solver / IR / GKOIR.C Solver / Multigrid / GKOMultigrid.C Solver/GMRES/GKOGMRES.C - # LduMatrix / GKOACG / GKOACG.C PUBLIC common/common.H StoppingCriterion/StoppingCriterion.H lduLduBase/lduLduBase.H - MatrixWrapper/LDUMatrix/HostMatrix.H - MatrixWrapper/Combination/Combination.H DevicePersistent/Base/Base.H DevicePersistent/Partition/Partition.H DevicePersistent/Array/Array.H DevicePersistent/Vector/Vector.H DevicePersistent/ExecutorHandler/ExecutorHandler.H DevicePersistent/DeviceIdGuard/DeviceIdGuard.H - DevicePersistent/HostMatrixAdapter/HostMatrixAdapter.H Preconditioner/Preconditioner.H BaseWrapper/lduBase/GKOlduBase.H BaseWrapper/CoupledLduBase/GKOCoupledLduBase.H Solver/CG/GKOCG.H Solver/IR/GKOIR.H - # Solver / Multigrid / GKOMultigrid.H Solver/BiCGStab/GKOBiCGStab.H Solver/GMRES/GKOGMRES.H - # LduMatrix / GKOACG / GKOACG.H ) enable_sanitizers( diff --git a/CMakePresets.json b/CMakePresets.json index 6f9dfc3e4..a177e8aa6 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -7,22 +7,18 @@ }, "configurePresets": [ { - "name": "default", + "name": "release", "hidden": true, - "displayName": "Default Config", "description": "Default build using Ninja generator", - "generator": "Ninja", "cacheVariables": { - "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "CMAKE_BUILD_TYPE": "Release", "CMAKE_INSTALL_PREFIX": "$env{FOAM_USER_LIBBIN}/.." } }, { "name": "debug", "hidden": true, - "displayName": "Default Config", "description": "Default build using Ninja generator", - "generator": "Ninja", "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", "CMAKE_INSTALL_PREFIX": "$env{FOAM_USER_LIBBIN}/.." @@ -31,16 +27,13 @@ { "name": "ninja", "hidden": true, - "displayName": "Default Config", "description": "Default build using Ninja generator", "generator": "Ninja" }, { "name": "cpuonly", "hidden": true, - "displayName": "Default Config", "description": "Default build using Ninja generator", - "generator": "Ninja", "cacheVariables": { "OGL_ALLOW_REFERENCE_ONLY": { "type": "BOOL", @@ -57,17 +50,16 @@ }, { "name": "ninja-cpuonly-release", - "inherits": ["default", "ninja", "cpuonly"], + "inherits": ["release", "ninja", "cpuonly"], "displayName": "No GPU, Ninja", "description": "Debug build without GPU support using Ninja Multi-Config generator", "binaryDir": "${sourceDir}/build/ReleaseCPUOnly" }, { "name": "ninja-cuda-release", - "inherits": "default", + "inherits": ["release", "ninja", "cpuonly"], "displayName": "CUDA, Ninja", "description": "Release build for cuda using Ninja Multi-Config generator", - "generator": "Ninja Multi-Config", "binaryDir": "${sourceDir}/build/ReleaseCuda", "cacheVariables": { "GINKGO_BUILD_CUDA": { @@ -78,10 +70,9 @@ }, { "name": "ninja-hip-release", - "inherits": "default", + "inherits": ["release", "ninja", "cpuonly"], "displayName": "HIP, Ninja", "description": "Release build for hip using Ninja Multi-Config generator", - "generator": "Ninja Multi-Config", "binaryDir": "${sourceDir}/build/ReleaseHip", "cacheVariables": { "GINKGO_BUILD_HIP": { @@ -92,11 +83,9 @@ }, { "name": "ninja-sycl-release", - "inherits": "default", + "inherits": ["release", "ninja", "cpuonly"], "displayName": "SYCL, Ninja", "description": "Release build for sycl using Ninja Multi-Config generator", - "generator": "Ninja Multi-Config", - "binaryDir": "${sourceDir}/build/ReleaseSycl", "cacheVariables": { "GINKGO_BUILD_SYCL": { "type": "BOOL", @@ -106,10 +95,6 @@ } ], "buildPresets": [ - { - "name": "default", - "configurePreset": "default" - }, { "name": "ninja-cpuonly-release", "configurePreset": "ninja-cpuonly-release", diff --git a/cmake/ginkgo.cmake b/cmake/ginkgo.cmake new file mode 100644 index 000000000..b78d36a33 --- /dev/null +++ b/cmake/ginkgo.cmake @@ -0,0 +1,17 @@ +# SPDX-FileCopyrightText: 2024 OGL authors +# +# SPDX-License-Identifier: GPL-3.0-or-later + +include(FetchContent) + +if(NOT ${OGL_USE_EXTERNAL_GINKGO}) + FetchContent_Declare( + Ginkgo + QUITE + GIT_SHALLOW ON + GIT_REPOSITORY "https://github.com/ginkgo-project/ginkgo.git" + GIT_TAG ${GINKGO_CHECKOUT_VERSION} + ) + + FetchContent_MakeAvailable(Ginkgo) +endif() diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt deleted file mode 100644 index cae820569..000000000 --- a/third_party/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# SPDX-FileCopyrightText: 2024 OGL authors -# -# SPDX-License-Identifier: GPL-3.0-or-later - -ginkgo_add_subdirectory(Ginkgo ginkgo) -set(CMAKE_MODULE_PATH - "${CMAKE_MODULE_PATH}" - PARENT_SCOPE) diff --git a/third_party/ginkgo/CMakeLists.txt b/third_party/ginkgo/CMakeLists.txt deleted file mode 100644 index 758716bd3..000000000 --- a/third_party/ginkgo/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# SPDX-FileCopyrightText: 2024 OGL authors -# -# SPDX-License-Identifier: GPL-3.0-or-later - -# TODO pass flags from main CMAKE file -ginkgo_load_git_package( - ginkgo_external - "https://github.com/ginkgo-project/ginkgo.git" - ${GINKGO_CHECKOUT_VERSION} - "-DGINKGO_BUILD_CUDA=${GINKGO_BUILD_CUDA}" - "-DGINKGO_BUILD_HIP=${GINKGO_BUILD_HIP}" - "-DGINKGO_BUILD_OMP=${GINKGO_BUILD_OMP}" - "-DGINKGO_BUILD_MPI=ON" - "-DGINKGO_BUILD_TESTS=OFF" - "-DGINKGO_BUILD_EXAMPLES=OFF" - "-DGINKGO_BUILD_BENCHMARKS=OFF" - "-DGINKGO_BUILD_REFERENCE=${GINKGO_BUILD_REFERENCE}" - "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" - "-DCMAKE_CUDA_ARCHITECTURES=${OGL_CUDA_ARCHITECTURES}" - "-DGINKGO_BUILD_HWLOC=OFF" - "-DGINKGO_FORCE_GPU_AWARE_MPI=${GINKGO_FORCE_GPU_AWARE_MPI}" - "-DCMAKE_INSTALL_PREFIX=$ENV{FOAM_USER_LIBBIN}/.." - "-DBUILD_SHARED_LIBS=ON" - "-DCMAKE_CXX_STANDARD=17") From b10aba0bfdd67e9beffc36344a8fc39d0e836bcc Mon Sep 17 00:00:00 2001 From: Gregor Olenik Date: Fri, 21 Jun 2024 11:12:43 +0200 Subject: [PATCH 07/20] add Unlicense --- LICENSES/Unlicense.txt | 10 ++++++++++ cmake/Sanitizer.cmake | 1 + 2 files changed, 11 insertions(+) create mode 100644 LICENSES/Unlicense.txt diff --git a/LICENSES/Unlicense.txt b/LICENSES/Unlicense.txt new file mode 100644 index 000000000..cde4ac698 --- /dev/null +++ b/LICENSES/Unlicense.txt @@ -0,0 +1,10 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means. + +In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/cmake/Sanitizer.cmake b/cmake/Sanitizer.cmake index c79772ffa..da09c84f8 100644 --- a/cmake/Sanitizer.cmake +++ b/cmake/Sanitizer.cmake @@ -1,6 +1,7 @@ # SPDX-License-Identifier: Unlicense # SPDX-FileCopyrightText: 2023 Jason Turner # SPDX-FileCopyrightText: 2023 NeoFOAM authors + ############################################################################## # This function will enable sanitizers # # from here # From 14afac6feb7bd08414e933767ae528f527fb9e60 Mon Sep 17 00:00:00 2001 From: Gregor Olenik Date: Fri, 21 Jun 2024 11:16:00 +0200 Subject: [PATCH 08/20] add changelog entry --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d146b417b..1ab685043 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ SPDX-FileCopyrightText: 2024 OGL authors SPDX-License-Identifier: GPL-3.0-or-later --> - +# 0.6.0 (unreleased) +- Build Ginkgo as subdirectory build [PR #135](https://github.com/hpsim/OGL/pull/135) # 0.5.4 (unreleased) - Add a warning message to users who use dpcpp as the executor name [PR #129](https://github.com/hpsim/OGL/pull/129) - Add support for SP scalars and determine label and scalar size from env variable [PR #120](https://github.com/hpsim/OGL/pull/120) From 164fc9447cd98703161f43039d3461a32f94501c Mon Sep 17 00:00:00 2001 From: Gregor Olenik Date: Wed, 26 Jun 2024 11:46:42 +0200 Subject: [PATCH 09/20] remove non compiling code --- DevicePersistent/Base/Base.C | 4 ---- DevicePersistent/CsrMatrixWrapper/CsrMatrixWrapper.H | 11 ----------- DevicePersistent/Partition/Partition.H | 11 ++++------- Preconditioner/Preconditioner.H | 12 ++++++------ 4 files changed, 10 insertions(+), 28 deletions(-) diff --git a/DevicePersistent/Base/Base.C b/DevicePersistent/Base/Base.C index 66660a4d4..abf416eef 100644 --- a/DevicePersistent/Base/Base.C +++ b/DevicePersistent/Base/Base.C @@ -26,10 +26,6 @@ defineTemplateTypeNameWithName(DevicePersistentBase, // typedef needed to avoid confusion with the comma separated template // arguments as macro arguments -typedef gko::experimental::distributed::localized_partition