20 #ifndef OPM_HYPRE_SETUP_GPU_HPP 21 #define OPM_HYPRE_SETUP_GPU_HPP 23 #include <opm/simulators/linalg/gpuistl/detail/gpu_type_detection.hpp> 24 #include <opm/simulators/linalg/hypreinterface/HypreDataStructures.hpp> 25 #include <opm/simulators/linalg/hypreinterface/HypreErrorHandling.hpp> 27 #include <dune/istl/owneroverlapcopy.hh> 28 #include <dune/istl/paamg/graph.hh> 29 #include <dune/istl/paamg/pinfo.hh> 30 #include <dune/istl/repartition.hh> 34 #include <opm/simulators/linalg/gpuistl_hip/GpuSparseMatrixWrapper.hpp> 36 #include <opm/simulators/linalg/gpuistl/GpuSparseMatrixWrapper.hpp> 41 #include <HYPRE_parcsr_ls.h> 42 #include <_hypre_utilities.h> 51 template <
typename T,
bool ForceLegacy>
52 linalg::HypreInterface::SparsityPattern
53 setupSparsityPatternFromGpuMatrix(
const GpuSparseMatrixWrapper<T, ForceLegacy>& gpu_matrix,
54 const linalg::HypreInterface::ParallelInfo& par_info,
57 template <
typename T,
bool ForceLegacy>
58 std::vector<HYPRE_Int> computeRowIndexesWithMappingGpu(
const GpuSparseMatrixWrapper<T, ForceLegacy>& gpu_matrix,
59 const std::vector<int>& local_dune_to_local_hypre);
69 template <
typename T,
bool ForceLegacy>
70 linalg::HypreInterface::SparsityPattern
71 setupSparsityPatternFromGpuMatrix(
const GpuSparseMatrixWrapper<T, ForceLegacy>& gpu_matrix,
72 const linalg::HypreInterface::ParallelInfo& par_info,
75 linalg::HypreInterface::SparsityPattern pattern;
79 std::size_t cols_size = 0;
81 auto host_row_ptrs = gpu_matrix.getRowIndices().asStdVector();
82 for (
int rind = 0; rind < static_cast<int>(gpu_matrix.N()); ++rind) {
83 if (par_info.local_dune_to_local_hypre[rind] >= 0) {
84 const int row_start = host_row_ptrs[rind];
85 const int row_end = host_row_ptrs[rind + 1];
86 cols_size += (row_end - row_start);
89 pattern.
nnz = cols_size;
92 pattern.nnz = gpu_matrix.nonzeroes();
96 pattern.ncols.resize(par_info.N_owned);
97 pattern.rows.resize(par_info.N_owned);
98 pattern.cols.resize(pattern.nnz);
101 auto host_row_ptrs = gpu_matrix.getRowIndices().asStdVector();
102 auto host_col_indices = gpu_matrix.getColumnIndices().asStdVector();
105 for (
int rind = 0; rind < static_cast<int>(gpu_matrix.N()); ++rind) {
106 const int local_rowIdx = par_info.local_dune_to_local_hypre[rind];
110 if (owner_first && local_rowIdx < 0) {
114 const int row_start = host_row_ptrs[rind];
115 const int row_end = host_row_ptrs[rind + 1];
116 const int num_cols = row_end - row_start;
118 if (local_rowIdx >= 0) {
120 const int global_rowIdx = par_info.local_dune_to_global_hypre[rind];
121 pattern.rows[local_rowIdx] = global_rowIdx;
122 pattern.ncols[local_rowIdx] = num_cols;
126 for (
int col_idx = row_start; col_idx < row_end; ++col_idx) {
127 const int colIdx = host_col_indices[col_idx];
128 const int global_colIdx = par_info.local_dune_to_global_hypre[colIdx];
129 assert(global_colIdx >= 0);
130 pattern.cols[pos++] = global_colIdx;
148 template <
typename T,
bool ForceLegacy>
149 std::vector<HYPRE_Int>
150 computeRowIndexesWithMappingGpu(
const GpuSparseMatrixWrapper<T, ForceLegacy>& gpu_matrix,
151 const std::vector<int>& local_dune_to_local_hypre)
153 const int N = std::count_if(
154 local_dune_to_local_hypre.begin(), local_dune_to_local_hypre.end(), [](
int val) {
return val >= 0; });
155 std::vector<HYPRE_Int> row_indexes(N);
158 auto host_row_ptrs = gpu_matrix.getRowIndices().asStdVector();
161 for (
int dune_row_idx = 0; dune_row_idx < static_cast<int>(gpu_matrix.N()); ++dune_row_idx) {
162 const int hypre_row_idx = local_dune_to_local_hypre[dune_row_idx];
164 if (hypre_row_idx >= 0) {
167 row_indexes[hypre_row_idx] = host_row_ptrs[dune_row_idx];
176 #endif // OPM_HYPRE_SETUP_GPU_HPP HYPRE_Int nnz
Number of non-zero entries in matrix.
Definition: HypreDataStructures.hpp:97
Definition: HypreCpuTransfers.hpp:29