opm-simulators
Loading...
Searching...
No Matches
rocsparseBILU0.hpp
1/*
2 Copyright 2024 Equinor ASA
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef OPM_ROCSPARSEBILU0_HPP
21#define OPM_ROCSPARSEBILU0_HPP
22
23#include <opm/simulators/linalg/gpubridge/BlockedMatrix.hpp>
24#include <opm/simulators/linalg/gpubridge/WellContributions.hpp>
25
26#include <opm/simulators/linalg/gpubridge/rocm/rocsparsePreconditioner.hpp>
27
28#include <rocblas/rocblas.h>
29#include <rocsparse/rocsparse.h>
30
31#include <hip/hip_version.h>
32
33namespace Opm::Accelerator {
34
38template <class Scalar, unsigned int block_size>
39class rocsparseBILU0 : public rocsparsePreconditioner<Scalar, block_size>
40{
41 typedef rocsparsePreconditioner<Scalar, block_size> Base;
42
43 using Base::N;
44 using Base::Nb;
45 using Base::nnz;
46 using Base::nnzb;
47 using Base::verbosity;
48
49private:
50
51 rocsparse_mat_descr descr_M, descr_L, descr_U;
52 rocsparse_mat_info ilu_info;
53#if HIP_VERSION >= 50400000
54 rocsparse_mat_info spmv_info;
55#endif
56
57 rocsparse_int *d_Mrows, *d_Mcols;
58 Scalar *d_Mvals, *d_t;
59 void *d_buffer; // buffer space, used by rocsparse ilu0 analysis
60
61 std::size_t d_bufferSize_M=0, d_bufferSize_L=0, d_bufferSize_U=0, d_bufferSize=0;
62
63public:
64
65 rocsparseBILU0(int verbosity_);
66 ~rocsparseBILU0();
67
73 bool initialize(std::shared_ptr<BlockedMatrix<Scalar>> matrix,
74 std::shared_ptr<BlockedMatrix<Scalar>> jacMatrix,
75 rocsparse_int *d_Arows,
76 rocsparse_int *d_Acols) override;
77
79 bool analyze_matrix();
80
83 bool analyze_matrix(BlockedMatrix<Scalar> *mat) override;
84
89 BlockedMatrix<Scalar> *jacMat) override;
90
94
99 BlockedMatrix<Scalar> *jacMat) override;
100
107 void apply(const Scalar& y,
108 Scalar& x,
109 WellContributions<Scalar>& wellContribs) override;
110
113 void copy_system_to_gpu(Scalar *mVals) override;
114
120 void copy_values_to_gpu(Scalar *mVals, int *mRows, int *mCols, bool reuse);
121
124 void update_system_on_gpu(Scalar*, Scalar* b) override;
125
126};
127} // namespace Opm
128
129#endif
This struct resembles a blocked csr matrix, like Dune::BCRSMatrix.
Definition BlockedMatrix.hpp:29
bool create_preconditioner(BlockedMatrix< Scalar > *mat) override
ILU decomposition.
Definition rocsparseBILU0.cpp:328
void apply(const Scalar &y, Scalar &x, WellContributions< Scalar > &wellContribs) override
Apply preconditioner, x = prec(y) via Lz = y and Ux = z.
Definition rocsparseBILU0.cpp:428
void copy_values_to_gpu(Scalar *mVals, int *mRows, int *mCols, bool reuse)
Copy matrix A values to GPU.
Definition rocsparseBILU0.cpp:393
bool initialize(std::shared_ptr< BlockedMatrix< Scalar > > matrix, std::shared_ptr< BlockedMatrix< Scalar > > jacMatrix, rocsparse_int *d_Arows, rocsparse_int *d_Acols) override
Initialize GPU and allocate memory.
Definition rocsparseBILU0.cpp:75
bool analyze_matrix()
Analysis, extract parallelism if specified.
Definition rocsparseBILU0.cpp:124
void copy_system_to_gpu(Scalar *mVals) override
Copy matrix A values to GPU.
Definition rocsparseBILU0.cpp:369
void update_system_on_gpu(Scalar *, Scalar *b) override
Update GPU values after a new assembly is done.
Definition rocsparseBILU0.cpp:406
This class serves to eliminate the need to include the WellContributions into the matrix (with –matri...
Definition WellContributions.hpp:51