diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 80a4682e24..057f01fc6f 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -396,7 +396,6 @@ if(CUDA_FOUND OR hip_FOUND) ADD_CUDA_OR_HIP_FILE(PUBLIC_HEADER_FILES opm/simulators/linalg AmgxInterface.hpp) ADD_CUDA_OR_HIP_FILE(PUBLIC_HEADER_FILES opm/simulators/linalg HypreInterface.hpp) ADD_CUDA_OR_HIP_FILE(PUBLIC_HEADER_FILES opm/simulators/linalg hypreinterface/HypreCpuTransfers.hpp) - ADD_CUDA_OR_HIP_FILE(PUBLIC_HEADER_FILES opm/simulators/linalg hypreinterface/HypreDataStructures.hpp) ADD_CUDA_OR_HIP_FILE(PUBLIC_HEADER_FILES opm/simulators/linalg hypreinterface/HypreErrorHandling.hpp) ADD_CUDA_OR_HIP_FILE(PUBLIC_HEADER_FILES opm/simulators/linalg hypreinterface/HypreGpuTransfers.hpp) ADD_CUDA_OR_HIP_FILE(PUBLIC_HEADER_FILES opm/simulators/linalg hypreinterface/HypreSetup.hpp) @@ -1421,6 +1420,7 @@ endif() if(HYPRE_FOUND) list(APPEND PUBLIC_HEADER_FILES opm/simulators/linalg/HyprePreconditioner.hpp + opm/simulators/linalg/hypreinterface/HypreDataStructures.hpp opm/simulators/linalg/hypreinterface/HypreUtils.hpp ) endif() diff --git a/opm/simulators/linalg/gpuistl/HypreInterface.hpp b/opm/simulators/linalg/gpuistl/HypreInterface.hpp index f1d7dd81fa..15a646a8ee 100644 --- a/opm/simulators/linalg/gpuistl/HypreInterface.hpp +++ b/opm/simulators/linalg/gpuistl/HypreInterface.hpp @@ -21,7 +21,7 @@ #define OPM_HYPRE_INTERFACE_HPP #include -#include +#include #include #include #include @@ -59,10 +59,10 @@ namespace Opm::gpuistl */ namespace HypreInterface { - using HostArrays = ::Opm::gpuistl::HypreHostDataArrays; - using DeviceArrays = ::Opm::gpuistl::HypreDeviceDataArrays; - using ParallelInfo = ::Opm::gpuistl::ParallelInfo; - using SparsityPattern = ::Opm::gpuistl::SparsityPattern; + using HostArrays = ::Opm::linalg::HypreInterface::HypreHostDataArrays; + using DeviceArrays = ::Opm::linalg::HypreInterface::HypreDeviceDataArrays; + using ParallelInfo = ::Opm::linalg::HypreInterface::ParallelInfo; + using SparsityPattern = ::Opm::linalg::HypreInterface::SparsityPattern; /** * @brief Initialize the Hypre library and set memory/execution policy @@ -110,13 +110,17 @@ namespace HypreInterface * @brief Setup parallel information for Hypre (automatically detects serial/parallel) */ template - ParallelInfo setupHypreParallelInfo(const CommType& comm, const MatrixType& matrix); + linalg::HypreInterface::ParallelInfo + setupHypreParallelInfo(const CommType& comm, const MatrixType& matrix); /** * @brief Setup sparsity pattern from matrix (automatically detects CPU/GPU type) */ template - SparsityPattern setupSparsityPattern(const MatrixType& matrix, const ParallelInfo& par_info, bool owner_first); + linalg::HypreInterface::SparsityPattern + setupSparsityPattern(const MatrixType& matrix, + const linalg::HypreInterface::ParallelInfo& par_info, + bool owner_first); /** * @brief Compute row indexes for HYPRE_IJMatrixSetValues2 diff --git a/opm/simulators/linalg/gpuistl/hypreinterface/HypreCpuTransfers.hpp b/opm/simulators/linalg/gpuistl/hypreinterface/HypreCpuTransfers.hpp index 104affbdce..145069a68e 100644 --- a/opm/simulators/linalg/gpuistl/hypreinterface/HypreCpuTransfers.hpp +++ b/opm/simulators/linalg/gpuistl/hypreinterface/HypreCpuTransfers.hpp @@ -20,7 +20,7 @@ #ifndef OPM_HYPRE_CPU_TRANSFERS_HPP #define OPM_HYPRE_CPU_TRANSFERS_HPP -#include +#include #include #include @@ -66,9 +66,9 @@ template void transferCpuVectorToHypre(const VectorType& cpu_vec, HYPRE_IJVector hypre_vec, - HypreHostDataArrays& host_arrays, - [[maybe_unused]] const HypreDeviceDataArrays& device_arrays, - const ParallelInfo& par_info, + linalg::HypreInterface::HypreHostDataArrays& host_arrays, + [[maybe_unused]] const linalg::HypreInterface::HypreDeviceDataArrays& device_arrays, + const linalg::HypreInterface::ParallelInfo& par_info, bool use_gpu_backend) { const int N = static_cast(host_arrays.indices.size()); @@ -126,9 +126,9 @@ template void transferHypreToCpuVector(HYPRE_IJVector hypre_vec, VectorType& cpu_vec, - HypreHostDataArrays& host_arrays, - [[maybe_unused]] const HypreDeviceDataArrays& device_arrays, - const ParallelInfo& par_info, + linalg::HypreInterface::HypreHostDataArrays& host_arrays, + [[maybe_unused]] const linalg::HypreInterface::HypreDeviceDataArrays& device_arrays, + const linalg::HypreInterface::ParallelInfo& par_info, bool use_gpu_backend) { const int N = static_cast(host_arrays.indices.size()); @@ -186,9 +186,9 @@ template void updateMatrixFromCpuMatrix(const MatrixType& cpu_matrix, HYPRE_IJMatrix hypre_matrix, - const SparsityPattern& sparsity_pattern, - const HypreHostDataArrays& host_arrays, - [[maybe_unused]] const HypreDeviceDataArrays& device_arrays, + const linalg::HypreInterface::SparsityPattern& sparsity_pattern, + const linalg::HypreInterface::HypreHostDataArrays& host_arrays, + [[maybe_unused]] const linalg::HypreInterface::HypreDeviceDataArrays& device_arrays, bool use_gpu_backend) { const auto N = sparsity_pattern.rows.size(); diff --git a/opm/simulators/linalg/gpuistl/hypreinterface/HypreGpuTransfers.hpp b/opm/simulators/linalg/gpuistl/hypreinterface/HypreGpuTransfers.hpp index 818a707f4e..53fea583fd 100644 --- a/opm/simulators/linalg/gpuistl/hypreinterface/HypreGpuTransfers.hpp +++ b/opm/simulators/linalg/gpuistl/hypreinterface/HypreGpuTransfers.hpp @@ -20,7 +20,7 @@ #ifndef OPM_HYPRE_GPU_TRANSFERS_HPP #define OPM_HYPRE_GPU_TRANSFERS_HPP -#include +#include #include #if HAVE_CUDA @@ -57,9 +57,9 @@ template void transferGpuVectorToHypre(const VectorType& gpu_vec, HYPRE_IJVector hypre_vec, - HypreHostDataArrays& host_arrays, - const HypreDeviceDataArrays& device_arrays, - const ParallelInfo& par_info, + linalg::HypreInterface::HypreHostDataArrays& host_arrays, + const linalg::HypreInterface::HypreDeviceDataArrays& device_arrays, + const linalg::HypreInterface::ParallelInfo& par_info, bool use_gpu_backend) { const int N = static_cast(host_arrays.indices.size()); @@ -114,9 +114,9 @@ template void transferHypreToGpuVector(HYPRE_IJVector hypre_vec, VectorType& gpu_vec, - HypreHostDataArrays& host_arrays, - const HypreDeviceDataArrays& device_arrays, - const ParallelInfo& par_info, + linalg::HypreInterface::HypreHostDataArrays& host_arrays, + const linalg::HypreInterface::HypreDeviceDataArrays& device_arrays, + const linalg::HypreInterface::ParallelInfo& par_info, bool use_gpu_backend) { const int N = static_cast(host_arrays.indices.size()); @@ -172,9 +172,9 @@ template void updateMatrixFromGpuSparseMatrix(const MatrixType& gpu_matrix, HYPRE_IJMatrix hypre_matrix, - const SparsityPattern& sparsity_pattern, - const HypreHostDataArrays& host_arrays, - const HypreDeviceDataArrays& device_arrays, + const linalg::HypreInterface::SparsityPattern& sparsity_pattern, + const linalg::HypreInterface::HypreHostDataArrays& host_arrays, + const linalg::HypreInterface::HypreDeviceDataArrays& device_arrays, bool use_gpu_backend) { const auto N = sparsity_pattern.rows.size(); diff --git a/opm/simulators/linalg/gpuistl/hypreinterface/HypreSetup.hpp b/opm/simulators/linalg/gpuistl/hypreinterface/HypreSetup.hpp index c318fa758d..55818d33b0 100644 --- a/opm/simulators/linalg/gpuistl/hypreinterface/HypreSetup.hpp +++ b/opm/simulators/linalg/gpuistl/hypreinterface/HypreSetup.hpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include @@ -51,24 +51,28 @@ namespace Opm::gpuistl::HypreInterface // GPU-specific helper functions template -SparsityPattern setupSparsityPatternFromGpuMatrix(const GpuSparseMatrixWrapper& gpu_matrix, - const ParallelInfo& par_info, - bool owner_first); +linalg::HypreInterface::SparsityPattern +setupSparsityPatternFromGpuMatrix(const GpuSparseMatrixWrapper& gpu_matrix, + const linalg::HypreInterface::ParallelInfo& par_info, + bool owner_first); template std::vector computeRowIndexesWithMappingGpu(const GpuSparseMatrixWrapper& gpu_matrix, const std::vector& local_dune_to_local_hypre); // Serial helper functions -ParallelInfo setupHypreParallelInfoSerial(HYPRE_Int N); + linalg::HypreInterface::ParallelInfo setupHypreParallelInfoSerial(HYPRE_Int N); // Parallel helper functions template -ParallelInfo setupHypreParallelInfoParallel(const CommType& comm, const MatrixType& matrix); +linalg::HypreInterface::ParallelInfo +setupHypreParallelInfoParallel(const CommType& comm, const MatrixType& matrix); template -SparsityPattern -setupSparsityPatternFromCpuMatrix(const MatrixType& matrix, const ParallelInfo& par_info, bool owner_first); +linalg::HypreInterface::SparsityPattern +setupSparsityPatternFromCpuMatrix(const MatrixType& matrix, + const linalg::HypreInterface::ParallelInfo& par_info, + bool owner_first); template std::vector computeRowIndexesWithMappingCpu(const MatrixType& matrix, @@ -259,7 +263,7 @@ destroyVector(HYPRE_IJVector vector) * @return ParallelInfo structure containing mappings and offsets */ template -ParallelInfo +linalg::HypreInterface::ParallelInfo setupHypreParallelInfo(const CommType& comm, const MatrixType& matrix) { if constexpr (std::is_same_v) { @@ -275,10 +279,10 @@ setupHypreParallelInfo(const CommType& comm, const MatrixType& matrix) * @param N Number of rows * @return ParallelInfo structure containing mappings and offsets */ -inline ParallelInfo +inline linalg::HypreInterface::ParallelInfo setupHypreParallelInfoSerial(HYPRE_Int N) { - ParallelInfo info; + linalg::HypreInterface::ParallelInfo info; info.N_owned = N; info.local_dune_to_local_hypre.resize(N); @@ -359,10 +363,10 @@ setupHypreParallelInfoSerial(HYPRE_Int N) * @note May modify comm if index set holes are detected (rare in OPM) */ template -inline ParallelInfo +linalg::HypreInterface::ParallelInfo setupHypreParallelInfoParallel(const CommType& comm, const MatrixType& matrix) { - ParallelInfo info; + linalg::HypreInterface::ParallelInfo info; const auto& collective_comm = comm.communicator(); // Initialize mapping arrays to not owned (-1) state @@ -463,8 +467,10 @@ setupHypreParallelInfoParallel(const CommType& comm, const MatrixType& matrix) * @return Sparsity pattern information */ template -SparsityPattern -setupSparsityPattern(const MatrixType& matrix, const ParallelInfo& par_info, bool owner_first) + linalg::HypreInterface::SparsityPattern +setupSparsityPattern(const MatrixType& matrix, + const linalg::HypreInterface::ParallelInfo& par_info, + bool owner_first) { #if HYPRE_USING_CUDA || HYPRE_USING_HIP if constexpr (is_gpu_type::value) { @@ -485,10 +491,12 @@ setupSparsityPattern(const MatrixType& matrix, const ParallelInfo& par_info, boo * @return Sparsity pattern information */ template -SparsityPattern -setupSparsityPatternFromCpuMatrix(const MatrixType& matrix, const ParallelInfo& par_info, bool owner_first) +linalg::HypreInterface::SparsityPattern +setupSparsityPatternFromCpuMatrix(const MatrixType& matrix, + const linalg::HypreInterface::ParallelInfo& par_info, + bool owner_first) { - SparsityPattern pattern; + linalg::HypreInterface::SparsityPattern pattern; // Determine the size for cols array based on owner_first if (owner_first) { @@ -550,12 +558,12 @@ setupSparsityPatternFromCpuMatrix(const MatrixType& matrix, const ParallelInfo& * @return Sparsity pattern information */ template -SparsityPattern +linalg::HypreInterface::SparsityPattern setupSparsityPatternFromGpuMatrix(const GpuSparseMatrixWrapper& gpu_matrix, - const ParallelInfo& par_info, + const linalg::HypreInterface::ParallelInfo& par_info, bool owner_first) { - SparsityPattern pattern; + linalg::HypreInterface::SparsityPattern pattern; // Determine the size for cols array based on owner_first if (owner_first) { diff --git a/opm/simulators/linalg/gpuistl/hypreinterface/HypreDataStructures.hpp b/opm/simulators/linalg/hypreinterface/HypreDataStructures.hpp similarity index 98% rename from opm/simulators/linalg/gpuistl/hypreinterface/HypreDataStructures.hpp rename to opm/simulators/linalg/hypreinterface/HypreDataStructures.hpp index 969325c5ef..9074b07d3b 100644 --- a/opm/simulators/linalg/gpuistl/hypreinterface/HypreDataStructures.hpp +++ b/opm/simulators/linalg/hypreinterface/HypreDataStructures.hpp @@ -25,7 +25,7 @@ #include <_hypre_utilities.h> #include -namespace Opm::gpuistl +namespace Opm::linalg::HypreInterface { /** @@ -154,6 +154,7 @@ struct HypreDeviceDataArrays { */ HYPRE_Real* matrix_buffer_device = nullptr; }; -} // namespace Opm::gpuistl + +} // namespace Opm::linalg::HypreInterface #endif // OPM_HYPRE_DATA_STRUCTURES_HPP