My Project
FPGABILU0.hpp
1 /*
2  Copyright 2020 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 FPGA_BILU0_HEADER_INCLUDED
21 #define FPGA_BILU0_HEADER_INCLUDED
22 
23 #include <vector>
24 
25 #include <opm/simulators/linalg/bda/ILUReorder.hpp>
26 #include <opm/simulators/linalg/bda/BlockedMatrix.hpp>
27 
28 namespace bda
29 {
30 
31 /*
32  * This class implements a Blocked ILU0 preconditioner, with output data
33  * specifically formatted for the FPGA.
34  * The decomposition and reorders of the rows of the matrix are done on CPU.
35  */
36 
37 template <unsigned int block_size>
38 class FPGABILU0
39 {
40 
41 private:
42  int N; // number of rows of the matrix
43  int Nb; // number of blockrows of the matrix
44  int nnz; // number of nonzeroes of the matrix (scalar)
45  int nnzbs; // number of blocks of the matrix
46  std::unique_ptr<BlockedMatrix<block_size> > LMat = nullptr, UMat = nullptr, LUMat = nullptr;
47  std::shared_ptr<BlockedMatrix<block_size> > rMat = nullptr; // reordered mat
48  double *invDiagVals = nullptr;
49  std::vector<int> diagIndex;
50  std::vector<int> toOrder, fromOrder;
51  std::vector<int> rowsPerColor;
52  int numColors;
53  int verbosity;
54 
55  // sizes and arrays used during RDF generation
56  std::vector<std::vector<double> > nnzValues, LnnzValues, UnnzValues;
57  std::vector<short int> colIndices, LColIndices, UColIndices;
58  std::vector<unsigned char> NROffsets, LNROffsets, UNROffsets;
59  std::vector<int> PIndicesAddr, LPIndicesAddr, UPIndicesAddr;
60  std::vector<int> colorSizes, LColorSizes, UColorSizes;
61  std::vector<int> nnzValsSizes, LnnzValsSizes, UnnzValsSizes;
62  std::vector<std::vector<int> > colIndicesInColor, LColIndicesInColor, UColIndicesInColor;
63 
64  int rowSize, valSize;
65  int LRowSize, LValSize, LNumColors;
66  int URowSize, UValSize, UNumColors;
67  std::vector<double> blockDiag;
68  ILUReorder opencl_ilu_reorder;
69  bool level_scheduling = false, graph_coloring = false;
70  int numResultPointers = 21;
71  std::vector<void *> resultPointers;
72  int numResultSizes = 18;
73  std::vector<int> resultSizes;
74  int maxRowsPerColor, maxColsPerColor, maxNNZsPerRow, maxNumColors; // are set via the constructor
75 
76 public:
77 
78  FPGABILU0(ILUReorder opencl_ilu_reorder, int verbosity, int maxRowsPerColor, int maxColsPerColor, int maxNNZsPerRow, int maxNumColors);
79 
80  ~FPGABILU0();
81 
82  // analysis (optional)
83  bool init(BlockedMatrix<block_size> *mat);
84 
85  // ilu_decomposition
86  bool create_preconditioner(BlockedMatrix<block_size> *mat);
87 
88  int* getToOrder()
89  {
90  return toOrder.data();
91  }
92 
93  int* getFromOrder()
94  {
95  return fromOrder.data();
96  }
97 
98  BlockedMatrix<block_size>* getRMat()
99  {
100  return rMat.get();
101  }
102 
103  void **getResultPointers()
104  {
105  return resultPointers.data();
106  }
107 
108  int *getResultSizes()
109  {
110  return resultSizes.data();
111  }
112 
113 };
114 
115 } //namespace bda
116 
117 #endif // FPGA_BILU0_HEADER_INCLUDED
This struct resembles a blocked csr matrix, like Dune::BCRSMatrix.
Definition: BlockedMatrix.hpp:36
Definition: FPGABILU0.hpp:39