My Project
Loading...
Searching...
No Matches
rocsparsePreconditioner.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_ROCSPARSEPRECONDITIONER_HEADER_INCLUDED
21#define OPM_ROCSPARSEPRECONDITIONER_HEADER_INCLUDED
22
23#include <opm/simulators/linalg/gpubridge/Preconditioner.hpp>
24
25#include <rocsparse/rocsparse.h>
26
27namespace Opm::Accelerator {
28
29template<class Scalar> class BlockedMatrix;
30
31template <class Scalar, unsigned int block_size>
32class rocsparsePreconditioner : public Preconditioner<Scalar, block_size>
33{
34
35protected:
36 rocsparse_handle handle;
39 rocsparse_mat_descr descr_L, descr_U;
40
41 hipStream_t stream;
42
43 rocsparsePreconditioner(int verbosity_) :
45 {};
46
47public:
48 int nnzbs_prec = 0; // number of nnz blocks in preconditioner matrix M
49 bool useJacMatrix = false;
50 std::shared_ptr<BlockedMatrix<Scalar>> jacMat{}; // matrix for preconditioner
51
52 static std::unique_ptr<rocsparsePreconditioner<Scalar, block_size>> create(PreconditionerType type,
53 int verbosity);
54
55 virtual bool initialize(std::shared_ptr<BlockedMatrix<Scalar>> matrix,
56 std::shared_ptr<BlockedMatrix<Scalar>> jacMatrix,
57 rocsparse_int* d_Arows,
58 rocsparse_int* d_Acols) = 0;
59
60 virtual void copy_system_to_gpu(Scalar* b) = 0;
61
64 virtual void update_system_on_gpu(Scalar* b) = 0;
65
66 void set_matrix_analysis(rocsparse_mat_descr descr_L,
67 rocsparse_mat_descr descr_U);
68
69 void set_context(rocsparse_handle handle,
71 rocsparse_operation operation,
72 hipStream_t stream);
73
74 void setJacMat(const BlockedMatrix<Scalar>& jacMat);
75};
76} //namespace Opm
77
78#endif
This struct resembles a blocked csr matrix, like Dune::BCRSMatrix.
Definition BlockedMatrix.hpp:29
Definition Preconditioner.hpp:41
Definition rocsparsePreconditioner.hpp:33
virtual void update_system_on_gpu(Scalar *b)=0
Update linear system to GPU.
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:242