openclBILU0.hpp
Go to the documentation of this file.
1/*
2 Copyright 2019 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_OPENCLBILU0_HPP
21#define OPM_OPENCLBILU0_HPP
22
24
28
29#include <memory>
30#include <mutex>
31
32namespace Opm::Accelerator {
33
37template<class Scalar, unsigned int block_size>
38class openclBILU0 : public openclPreconditioner<Scalar,block_size>
39{
41
42 using Base::N;
43 using Base::Nb;
44 using Base::nnz;
45 using Base::nnzb;
46 using Base::verbosity;
47 using Base::context;
48 using Base::queue;
49 using Base::events;
50 using Base::err;
51
52private:
53 std::unique_ptr<BlockedMatrix<Scalar>> LUmat{};
54#if CHOW_PATEL
55 std::unique_ptr<BlockedMatrix<Scalar>> Lmat{}, Umat{};
56#endif
57 std::vector<Scalar> invDiagVals;
58 std::vector<int> diagIndex;
59 std::vector<int> rowsPerColor; // color i contains rowsPerColor[i] rows, which are processed in parallel
60 std::vector<int> rowsPerColorPrefix; // the prefix sum of rowsPerColor
61 std::vector<int> toOrder, fromOrder;
62 int numColors;
63 std::once_flag pattern_uploaded;
64
65 bool opencl_ilu_parallel;
66
67 struct GPU_storage {
68 cl::Buffer invDiagVals; // nnz values of diagonal blocks of the matrix, inverted
69 cl::Buffer diagIndex; // index of diagonal block of each row, used to differentiate between lower and upper triangular part
70 cl::Buffer rowsPerColor; // number of rows for every color
71 cl::Buffer rowIndices; // mapping every row to another index
72 // after mapping, all rows that are processed in parallel are contiguous
73 // equal to the contents of fromOrder
74#if CHOW_PATEL
75 cl::Buffer Lvals, Lcols, Lrows;
76 cl::Buffer Uvals, Ucols, Urows;
77#else
78 cl::Buffer LUvals, LUcols, LUrows;
79#endif
80 };
81
82 GPU_storage s;
83
84#if CHOW_PATEL
85 ChowPatelIlu<block_size> chowPatelIlu;
86#endif
87
88public:
89
90 openclBILU0(bool opencl_ilu_parallel, int verbosity);
91
92 // analysis, extract parallelism if specified
95 BlockedMatrix<Scalar>* jacMat) override;
96
97 // ilu_decomposition
100 BlockedMatrix<Scalar>* jacMat) override;
101
102 // apply preconditioner, x = prec(y)
103 // via Lz = y
104 // and Ux = z
105 void apply(const cl::Buffer& y, cl::Buffer& x) override;
106 void apply(Scalar&, Scalar&) override {}
107
108 std::tuple<std::vector<int>, std::vector<int>, std::vector<int>>
110 {
111 return {{LUmat->rowPointers, LUmat->rowPointers + (Nb + 1)},
112 {LUmat->colIndices, LUmat->colIndices + nnzb}, diagIndex};
113 }
114
115 std::pair<cl::Buffer, cl::Buffer> get_preconditioner_data()
116 {
117#if CHOW_PATEL
118 return std::make_pair(s.Lvals, s.invDiagVals); // send dummy, BISAI is disabled when ChowPatel is selected
119#else
120 return std::make_pair(s.LUvals, s.invDiagVals);
121#endif
122 }
123};
124
125} // namespace Opm::Accelerator
126
127#endif
Definition: BlockedMatrix.hpp:29
int nnz
Definition: Preconditioner.hpp:45
int Nb
Definition: Preconditioner.hpp:44
int verbosity
Definition: Preconditioner.hpp:47
int nnzb
Definition: Preconditioner.hpp:46
int N
Definition: Preconditioner.hpp:43
Definition: openclBILU0.hpp:39
void apply(Scalar &, Scalar &) override
Definition: openclBILU0.hpp:106
void apply(const cl::Buffer &y, cl::Buffer &x) override
bool analyze_matrix(BlockedMatrix< Scalar > *mat, BlockedMatrix< Scalar > *jacMat) override
bool create_preconditioner(BlockedMatrix< Scalar > *mat, BlockedMatrix< Scalar > *jacMat) override
std::tuple< std::vector< int >, std::vector< int >, std::vector< int > > get_preconditioner_structure()
Definition: openclBILU0.hpp:109
bool analyze_matrix(BlockedMatrix< Scalar > *mat) override
bool create_preconditioner(BlockedMatrix< Scalar > *mat) override
std::pair< cl::Buffer, cl::Buffer > get_preconditioner_data()
Definition: openclBILU0.hpp:115
openclBILU0(bool opencl_ilu_parallel, int verbosity)
Definition: openclPreconditioner.hpp:32
cl_int err
Definition: openclPreconditioner.hpp:38
std::shared_ptr< cl::Context > context
Definition: openclPreconditioner.hpp:35
std::vector< cl::Event > events
Definition: openclPreconditioner.hpp:37
std::shared_ptr< cl::CommandQueue > queue
Definition: openclPreconditioner.hpp:36
Definition: amgclSolverBackend.hpp:44