My Project
OpenclMatrix.hpp
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_OPENCLMATRIX_HEADER_INCLUDED
21 #define OPM_OPENCLMATRIX_HEADER_INCLUDED
22 
23 #include <vector>
24 
25 #include <opm/simulators/linalg/bda/opencl/opencl.hpp>
26 
27 namespace Opm
28 {
29 namespace Accelerator
30 {
31 
32 class Matrix;
33 class BlockedMatrix;
34 
37 class OpenclMatrix {
38 public:
39 
40  OpenclMatrix(cl::Context *context, int Nb_, int Mb_, int nnzbs_, unsigned int block_size_)
41  : Nb(Nb_),
42  Mb(Mb_),
43  nnzbs(nnzbs_),
44  block_size(block_size_)
45  {
46  nnzValues = cl::Buffer(*context, CL_MEM_READ_WRITE, sizeof(double) * block_size * block_size * nnzbs);
47  colIndices = cl::Buffer(*context, CL_MEM_READ_WRITE, sizeof(int) * nnzbs);
48  rowPointers = cl::Buffer(*context, CL_MEM_READ_WRITE, sizeof(int) * (Nb + 1));
49  }
50 
51  void upload(cl::CommandQueue *queue, double *vals, int *cols, int *rows);
52  void upload(cl::CommandQueue *queue, Matrix *matrix);
53  void upload(cl::CommandQueue *queue, BlockedMatrix *matrix);
54 
55  cl::Buffer nnzValues;
56  cl::Buffer colIndices;
57  cl::Buffer rowPointers;
58  int Nb, Mb;
59  int nnzbs;
60  unsigned int block_size;
61 };
62 
63 } // namespace Accelerator
64 } // namespace Opm
65 
66 #endif // OPM_OPENCLMATRIX_HEADER_INCLUDED
This struct resembles a blocked csr matrix, like Dune::BCRSMatrix.
Definition: BlockedMatrix.hpp:37
This struct resembles a csr matrix, only doubles are supported The data is stored in contiguous memor...
Definition: Matrix.hpp:32
This struct resembles a csr matrix, only doubles are supported The matrix data is stored in OpenCL Bu...
Definition: OpenclMatrix.hpp:37
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: BlackoilPhases.hpp:27