openclPreconditioner.hpp
Go to the documentation of this file.
1/*
2 Copyright 2021 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_OPENCLPRECONDITIONER_HEADER_INCLUDED
21#define OPM_OPENCLPRECONDITIONER_HEADER_INCLUDED
22
25
26namespace Opm::Accelerator {
27
28template<class Scalar> class BlockedMatrix;
29
30template <class Scalar, unsigned int block_size>
31class openclPreconditioner : public Preconditioner<Scalar, block_size>
32{
33
34protected:
35 std::shared_ptr<cl::Context> context;
36 std::shared_ptr<cl::CommandQueue> queue;
37 std::vector<cl::Event> events;
38 cl_int err;
39
40 openclPreconditioner(int verbosity_) :
41 Preconditioner<Scalar, block_size>(verbosity_)
42 {};
43
44public:
45 virtual ~openclPreconditioner() = default;
46
47 static std::unique_ptr<openclPreconditioner<Scalar, block_size>> create(PreconditionerType type, int verbosity, bool opencl_ilu_parallel);
48
49 // nested Preconditioners might need to override this
50 virtual void setOpencl(std::shared_ptr<cl::Context>& context, std::shared_ptr<cl::CommandQueue>& queue);
51
52 // apply preconditioner, x = prec(y)
53 virtual void apply(const cl::Buffer& y, cl::Buffer& x) = 0;
54
55 // create/update preconditioner, probably used every linear solve
56 // the version with two params can be overloaded, if not, it will default to using the one param version
59};
60} //namespace Opm
61
62#endif
Definition: BlockedMatrix.hpp:29
Definition: Preconditioner.hpp:41
int verbosity
Definition: Preconditioner.hpp:47
Definition: openclPreconditioner.hpp:32
cl_int err
Definition: openclPreconditioner.hpp:38
virtual void apply(const cl::Buffer &y, cl::Buffer &x)=0
std::shared_ptr< cl::Context > context
Definition: openclPreconditioner.hpp:35
static std::unique_ptr< openclPreconditioner< Scalar, block_size > > create(PreconditionerType type, int verbosity, bool opencl_ilu_parallel)
virtual bool create_preconditioner(BlockedMatrix< Scalar > *mat)=0
openclPreconditioner(int verbosity_)
Definition: openclPreconditioner.hpp:40
virtual bool create_preconditioner(BlockedMatrix< Scalar > *mat, BlockedMatrix< Scalar > *jacMat)=0
std::vector< cl::Event > events
Definition: openclPreconditioner.hpp:37
virtual void setOpencl(std::shared_ptr< cl::Context > &context, std::shared_ptr< cl::CommandQueue > &queue)
std::shared_ptr< cl::CommandQueue > queue
Definition: openclPreconditioner.hpp:36
Definition: amgclSolverBackend.hpp:44
PreconditionerType
Definition: Preconditioner.hpp:31