HypreDataStructures: move out of gpuistl

put in new folder/namespace linalg/hypreinterface
This commit is contained in:
Arne Morten Kvarving committed 2026-05-18 09:22:14 +02:00
1 parent 9be8d7e55e
commit 7b2ad981bb
6 files changed
+64 -51

No files matched your search

+1 -1
View File
@@ -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()
@@ -21,7 +21,7 @@
#define OPM_HYPRE_INTERFACE_HPP
#include <opm/simulators/linalg/gpuistl/hypreinterface/HypreCpuTransfers.hpp>
#include <opm/simulators/linalg/gpuistl/hypreinterface/HypreDataStructures.hpp>
#include <opm/simulators/linalg/hypreinterface/HypreDataStructures.hpp>
#include <opm/simulators/linalg/gpuistl/hypreinterface/HypreErrorHandling.hpp>
#include <opm/simulators/linalg/gpuistl/hypreinterface/HypreGpuTransfers.hpp>
#include <opm/simulators/linalg/gpuistl/hypreinterface/HypreSetup.hpp>
@@ -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 <typename CommType, typename MatrixType>
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 <typename MatrixType>
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
@@ -20,7 +20,7 @@
#ifndef OPM_HYPRE_CPU_TRANSFERS_HPP
#define OPM_HYPRE_CPU_TRANSFERS_HPP
#include <opm/simulators/linalg/gpuistl/hypreinterface/HypreDataStructures.hpp>
#include <opm/simulators/linalg/hypreinterface/HypreDataStructures.hpp>
#include <opm/simulators/linalg/gpuistl/hypreinterface/HypreErrorHandling.hpp>
#include <HYPRE.h>
@@ -66,9 +66,9 @@ template <typename VectorType>
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<int>(host_arrays.indices.size());
@@ -126,9 +126,9 @@ template <typename VectorType>
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<int>(host_arrays.indices.size());
@@ -186,9 +186,9 @@ template <typename MatrixType>
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();
@@ -20,7 +20,7 @@
#ifndef OPM_HYPRE_GPU_TRANSFERS_HPP
#define OPM_HYPRE_GPU_TRANSFERS_HPP
#include <opm/simulators/linalg/gpuistl/hypreinterface/HypreDataStructures.hpp>
#include <opm/simulators/linalg/hypreinterface/HypreDataStructures.hpp>
#include <opm/simulators/linalg/gpuistl/hypreinterface/HypreErrorHandling.hpp>
#if HAVE_CUDA
@@ -57,9 +57,9 @@ template <typename VectorType>
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<int>(host_arrays.indices.size());
@@ -114,9 +114,9 @@ template <typename VectorType>
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<int>(host_arrays.indices.size());
@@ -172,9 +172,9 @@ template <typename MatrixType>
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();
@@ -22,7 +22,7 @@
#include <opm/simulators/linalg/PropertyTree.hpp>
#include <opm/simulators/linalg/gpuistl/detail/gpu_type_detection.hpp>
#include <opm/simulators/linalg/gpuistl/hypreinterface/HypreDataStructures.hpp>
#include <opm/simulators/linalg/hypreinterface/HypreDataStructures.hpp>
#include <opm/simulators/linalg/gpuistl/hypreinterface/HypreErrorHandling.hpp>
#include <dune/istl/owneroverlapcopy.hh>
@@ -51,24 +51,28 @@ namespace Opm::gpuistl::HypreInterface
// GPU-specific helper functions
template <typename T, bool ForceLegacy>
SparsityPattern setupSparsityPatternFromGpuMatrix(const GpuSparseMatrixWrapper<T, ForceLegacy>& gpu_matrix,
const ParallelInfo& par_info,
bool owner_first);
linalg::HypreInterface::SparsityPattern
setupSparsityPatternFromGpuMatrix(const GpuSparseMatrixWrapper<T, ForceLegacy>& gpu_matrix,
const linalg::HypreInterface::ParallelInfo& par_info,
bool owner_first);
template <typename T, bool ForceLegacy>
std::vector<HYPRE_Int> computeRowIndexesWithMappingGpu(const GpuSparseMatrixWrapper<T, ForceLegacy>& gpu_matrix,
const std::vector<int>& local_dune_to_local_hypre);
// Serial helper functions
ParallelInfo setupHypreParallelInfoSerial(HYPRE_Int N);
linalg::HypreInterface::ParallelInfo setupHypreParallelInfoSerial(HYPRE_Int N);
// Parallel helper functions
template <typename CommType, typename MatrixType>
ParallelInfo setupHypreParallelInfoParallel(const CommType& comm, const MatrixType& matrix);
linalg::HypreInterface::ParallelInfo
setupHypreParallelInfoParallel(const CommType& comm, const MatrixType& matrix);
template <typename MatrixType>
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 <typename MatrixType>
std::vector<HYPRE_Int> computeRowIndexesWithMappingCpu(const MatrixType& matrix,
@@ -259,7 +263,7 @@ destroyVector(HYPRE_IJVector vector)
* @return ParallelInfo structure containing mappings and offsets
*/
template <typename CommType, typename MatrixType>
ParallelInfo
linalg::HypreInterface::ParallelInfo
setupHypreParallelInfo(const CommType& comm, const MatrixType& matrix)
{
if constexpr (std::is_same_v<CommType, Dune::Amg::SequentialInformation>) {
@@ -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 <typename CommType, typename MatrixType>
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 <typename MatrixType>
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<MatrixType>::value) {
@@ -485,10 +491,12 @@ setupSparsityPattern(const MatrixType& matrix, const ParallelInfo& par_info, boo
* @return Sparsity pattern information
*/
template <typename MatrixType>
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 <typename T, bool ForceLegacy>
SparsityPattern
linalg::HypreInterface::SparsityPattern
setupSparsityPatternFromGpuMatrix(const GpuSparseMatrixWrapper<T, ForceLegacy>& 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) {
@@ -25,7 +25,7 @@
#include <_hypre_utilities.h>
#include <vector>
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