PARALUTION  1.0.0
PARALUTION
gpu_matrix_csr.hpp
Go to the documentation of this file.
1 
2 #ifndef PARALUTION_GPU_MATRIX_CSR_HPP_
3 #define PARALUTION_GPU_MATRIX_CSR_HPP_
4 
5 #include "../base_matrix.hpp"
6 #include "../base_vector.hpp"
7 #include "../matrix_formats.hpp"
8 
9 #include <cuda.h>
10 #include <cusparse_v2.h>
11 
12 namespace paralution {
13 
14 template <typename ValueType>
15 class GPUAcceleratorMatrixCSR : public GPUAcceleratorMatrix<ValueType> {
16 
17 public:
18 
20  GPUAcceleratorMatrixCSR(const Paralution_Backend_Descriptor local_backend);
21  virtual ~GPUAcceleratorMatrixCSR();
22 
23  virtual void info(void) const;
24  virtual unsigned int get_mat_format(void) const { return CSR; }
25 
26  virtual void Clear(void);
27  virtual bool Zeros(void);
28 
29  virtual void AllocateCSR(const int nnz, const int nrow, const int ncol);
30  virtual void SetDataPtrCSR(int **row_offset, int **col, ValueType **val,
31  const int nnz, const int nrow, const int ncol);
32  virtual void LeaveDataPtrCSR(int **row_offset, int **col, ValueType **val);
33 
34  virtual bool ConvertFrom(const BaseMatrix<ValueType> &mat);
35 
36  virtual void CopyFrom(const BaseMatrix<ValueType> &mat);
37  virtual void CopyFromAsync(const BaseMatrix<ValueType> &mat);
38  virtual void CopyTo(BaseMatrix<ValueType> *mat) const;
39  virtual void CopyToAsync(BaseMatrix<ValueType> *mat) const;
40 
41  virtual void CopyFromHost(const HostMatrix<ValueType> &src);
42  virtual void CopyFromHostAsync(const HostMatrix<ValueType> &src);
43  virtual void CopyToHost(HostMatrix<ValueType> *dst) const;
44  virtual void CopyToHostAsync(HostMatrix<ValueType> *dst) const;
45 
46  virtual void CopyFromCSR(const int *row_offsets, const int *col, const ValueType *val);
47  virtual void CopyToCSR(int *row_offsets, int *col, ValueType *val) const;
48 
49  virtual bool Permute(const BaseVector<int> &permutation);
50 
51  virtual bool Scale(const ValueType alpha);
52  virtual bool ScaleDiagonal(const ValueType alpha);
53  virtual bool ScaleOffDiagonal(const ValueType alpha);
54  virtual bool AddScalar(const ValueType alpha);
55  virtual bool AddScalarDiagonal(const ValueType alpha);
56  virtual bool AddScalarOffDiagonal(const ValueType alpha);
57 
58  virtual bool ExtractSubMatrix(const int row_offset,
59  const int col_offset,
60  const int row_size,
61  const int col_size,
62  BaseMatrix<ValueType> *mat) const;
63 
64  virtual bool ExtractDiagonal(BaseVector<ValueType> *vec_diag) const;
65  virtual bool ExtractInverseDiagonal(BaseVector<ValueType> *vec_inv_diag) const;
66  virtual bool ExtractL(BaseMatrix<ValueType> *L) const;
67  virtual bool ExtractLDiagonal(BaseMatrix<ValueType> *L) const;
68 
69  virtual bool ExtractU(BaseMatrix<ValueType> *U) const;
70  virtual bool ExtractUDiagonal(BaseMatrix<ValueType> *U) const;
71 
72  virtual bool MaximalIndependentSet(int &size,
73  BaseVector<int> *permutation) const;
74  virtual bool MultiColoring(int &num_colors,
75  int **size_colors,
76  BaseVector<int> *permutation) const;
77 
78  virtual bool DiagonalMatrixMultR(const BaseVector<ValueType> &diag);
79  virtual bool DiagonalMatrixMultL(const BaseVector<ValueType> &diag);
80 
81  virtual bool MatMatMult(const BaseMatrix<ValueType> &A, const BaseMatrix<ValueType> &B);
82 
83  virtual bool MatrixAdd(const BaseMatrix<ValueType> &mat, const ValueType alpha,
84  const ValueType beta, const bool structure);
85 
86  virtual bool ILU0Factorize(void);
87 
88  virtual bool ICFactorize(BaseVector<ValueType> *inv_diag = NULL);
89 
90 
91  virtual void LUAnalyse(void);
92  virtual void LUAnalyseClear(void);
93  virtual bool LUSolve(const BaseVector<ValueType> &in, BaseVector<ValueType> *out) const;
94 
95  virtual void LLAnalyse(void);
96  virtual void LLAnalyseClear(void);
97  virtual bool LLSolve(const BaseVector<ValueType> &in, BaseVector<ValueType> *out) const;
98  virtual bool LLSolve(const BaseVector<ValueType> &in, const BaseVector<ValueType> &inv_diag,
99  BaseVector<ValueType> *out) const;
100 
101  virtual void LAnalyse(const bool diag_unit=false);
102  virtual void LAnalyseClear(void);
103  virtual bool LSolve(const BaseVector<ValueType> &in, BaseVector<ValueType> *out) const;
104 
105  virtual void UAnalyse(const bool diag_unit=false);
106  virtual void UAnalyseClear(void);
107  virtual bool USolve(const BaseVector<ValueType> &in, BaseVector<ValueType> *out) const;
108 
109 
110  virtual bool Gershgorin(ValueType &lambda_min,
111  ValueType &lambda_max) const;
112 
113  virtual void Apply(const BaseVector<ValueType> &in, BaseVector<ValueType> *out) const;
114  virtual void ApplyAdd(const BaseVector<ValueType> &in, const ValueType scalar,
115  BaseVector<ValueType> *out) const;
116 
117  virtual bool Compress(const double drop_off);
118 
119  virtual bool ReplaceColumnVector(const int idx, const BaseVector<ValueType> &vec);
120  virtual bool ExtractColumnVector(const int idx, BaseVector<ValueType> *vec) const;
121  virtual bool ExtractRowVector(const int idx, BaseVector<ValueType> *vec) const;
122 
123  virtual bool Transpose(void);
124 
125 private:
126 
128 
129  friend class GPUAcceleratorMatrixDIA<ValueType>;
130  friend class GPUAcceleratorMatrixELL<ValueType>;
131  friend class GPUAcceleratorMatrixHYB<ValueType>;
132 
133  friend class BaseVector<ValueType>;
134  friend class AcceleratorVector<ValueType>;
135  friend class GPUAcceleratorVector<ValueType>;
136 
137  cusparseSolveAnalysisInfo_t L_mat_info_;
138  cusparseSolveAnalysisInfo_t U_mat_info_;
139  cusparseMatDescr_t L_mat_descr_;
140  cusparseMatDescr_t U_mat_descr_;
141  cusparseMatDescr_t mat_descr_;
142 
144 
145 };
146 
147 
148 }
149 
150 #endif // PARALUTION_GPU_MATRIX_CSR_HPP_
A
Definition: pcg_example.m:10
virtual void CopyFromHostAsync(const HostMatrix< ValueType > &src)
Async copy (accelerator matrix) from host matrix.
virtual void info(void) const
Shows simple info about the object.
virtual bool LUSolve(const BaseVector< ValueType > &in, BaseVector< ValueType > *out) const
Solve LU out = in; if level-scheduling algorithm is provided then the graph traversing is performed i...
virtual bool MultiColoring(int &num_colors, int **size_colors, BaseVector< int > *permutation) const
Perform multi-coloring decomposition of the matrix; Returns number of colors, the corresponding sizes...
virtual void CopyToHost(HostMatrix< ValueType > *dst) const
Copy (accelerator matrix) to host matrix.
virtual bool Transpose(void)
Transpose the matrix.
Definition: base_matrix.hpp:44
virtual void ApplyAdd(const BaseVector< ValueType > &in, const ValueType scalar, BaseVector< ValueType > *out) const
Apply and add the matrix to vector, out = out + scalar*this*in;.
virtual bool Zeros(void)
Set all the values to zero.
const IndexType idx
Definition: cuda_kernels_coo.hpp:115
virtual void LLAnalyseClear(void)
Delete the analysed data (see LLAnalyse)
virtual bool DiagonalMatrixMultR(const BaseVector< ValueType > &diag)
Multiply the matrix with diagonal matrix (stored in LocalVector), this=this*diag (right multiplicatio...
virtual void SetDataPtrCSR(int **row_offset, int **col, ValueType **val, const int nnz, const int nrow, const int ncol)
Initialize a CSR matrix on the Host with externally allocated data.
virtual void LeaveDataPtrCSR(int **row_offset, int **col, ValueType **val)
Leave a CSR matrix to Host pointers.
virtual bool AddScalarOffDiagonal(const ValueType alpha)
Add alpha to the off-diagonal entries of the matrix.
virtual bool MatrixAdd(const BaseMatrix< ValueType > &mat, const ValueType alpha, const ValueType beta, const bool structure)
Perform matrix addition, this = alpha*this + beta*mat; if structure==false the structure of the matri...
Definition: backend_manager.hpp:10
cusparseMatDescr_t L_mat_descr_
Definition: gpu_matrix_csr.hpp:139
virtual bool MatMatMult(const BaseMatrix< ValueType > &A, const BaseMatrix< ValueType > &B)
Multiply two matrices, this = A * B.
Definition: base_vector.hpp:16
nnz
Definition: pcg_example.m:8
cusparseMatDescr_t U_mat_descr_
Definition: gpu_matrix_csr.hpp:140
MatrixCSR< ValueType, int > mat_
Definition: gpu_matrix_csr.hpp:127
const IndexType const IndexType const IndexType const ValueType const ValueType scalar
Definition: cuda_kernels_coo.hpp:91
virtual bool ScaleOffDiagonal(const ValueType alpha)
Scale the off-diagonal entries of the matrix with alpha.
virtual void Apply(const BaseVector< ValueType > &in, BaseVector< ValueType > *out) const
Apply the matrix to vector, out = this*in;.
virtual bool DiagonalMatrixMultL(const BaseVector< ValueType > &diag)
Multiply the matrix with diagonal matrix (stored in LocalVector), this=diag*this (left multiplication...
virtual void LUAnalyse(void)
Analyse the structure (level-scheduling)
virtual bool ExtractL(BaseMatrix< ValueType > *L) const
Extract the lower triangular matrix.
virtual bool ScaleDiagonal(const ValueType alpha)
Scale the diagonal entries of the matrix with alpha.
virtual bool Gershgorin(ValueType &lambda_min, ValueType &lambda_max) const
Compute the spectrum approximation with Gershgorin circles theorem.
virtual bool ICFactorize(BaseVector< ValueType > *inv_diag=NULL)
Perform IC(0) factorization.
virtual void LLAnalyse(void)
Analyse the structure (level-scheduling)
virtual bool ExtractUDiagonal(BaseMatrix< ValueType > *U) const
Extract the upper triangular matrix including diagonal.
virtual void CopyFrom(const BaseMatrix< ValueType > &mat)
Copy from another matrix.
virtual void UAnalyseClear(void)
Delete the analysed data (see UAnalyse) U-party.
virtual void UAnalyse(const bool diag_unit=false)
Analyse the structure (level-scheduling) U-part; diag_unit == true the diag is 1; diag_unit == false ...
virtual void Clear(void)
Clear (free) the matrix.
virtual void CopyToHostAsync(HostMatrix< ValueType > *dst) const
Async opy (accelerator matrix) to host matrix.
virtual void CopyFromCSR(const int *row_offsets, const int *col, const ValueType *val)
Copy from CSR array (the matrix has to be allocated)
virtual bool Compress(const double drop_off)
Delete all entries abs(a_ij) <= drop_off; the diagonal elements are never deleted.
virtual unsigned int get_mat_format(void) const
Return the matrix format id (see matrix_formats.hpp)
Definition: gpu_matrix_csr.hpp:24
virtual bool ExtractLDiagonal(BaseMatrix< ValueType > *L) const
Extract the lower triangular matrix including diagonal.
virtual bool Permute(const BaseVector< int > &permutation)
Perform (forward) permutation of the matrix.
virtual bool ConvertFrom(const BaseMatrix< ValueType > &mat)
Convert the matrix from another matrix (with different structure)
virtual bool MaximalIndependentSet(int &size, BaseVector< int > *permutation) const
Perform maximal independent set decomposition of the matrix; Returns the size of the maximal independ...
Base class for all host/accelerator matrices.
Definition: base_matrix.hpp:92
cusparseSolveAnalysisInfo_t L_mat_info_
Definition: gpu_matrix_csr.hpp:137
virtual void CopyToCSR(int *row_offsets, int *col, ValueType *val) const
Copy to CSR array (the arrays have to be allocated)
virtual bool Scale(const ValueType alpha)
Scale all values.
cusparseMatDescr_t mat_descr_
Definition: gpu_matrix_csr.hpp:141
virtual bool LLSolve(const BaseVector< ValueType > &in, BaseVector< ValueType > *out) const
Solve LL^T out = in; if level-scheduling algorithm is provided then the graph.
Definition: backend_manager.cpp:43
GPUAcceleratorVector< ValueType > * tmp_vec_
Definition: gpu_matrix_csr.hpp:143
virtual void CopyTo(BaseMatrix< ValueType > *mat) const
Copy to another matrix.
virtual bool USolve(const BaseVector< ValueType > &in, BaseVector< ValueType > *out) const
Solve U out = in; if level-scheduling algorithm is provided then the graph traversing is performed in...
virtual bool AddScalarDiagonal(const ValueType alpha)
Add alpha to the diagonal entries of the matrix.
Definition: backend_manager.hpp:14
Definition: matrix_formats.hpp:21
virtual bool ILU0Factorize(void)
Perform ILU(0) factorization.
virtual void CopyFromAsync(const BaseMatrix< ValueType > &mat)
Async copy from another matrix.
virtual void AllocateCSR(const int nnz, const int nrow, const int ncol)
Allocate CSR Matrix.
virtual void LAnalyse(const bool diag_unit=false)
Analyse the structure (level-scheduling) L-part diag_unit == true the diag is 1; diag_unit == false t...
Definition: base_matrix.hpp:46
virtual bool ExtractColumnVector(const int idx, BaseVector< ValueType > *vec) const
Extract values from a column of a matrix to a vector.
virtual bool ExtractInverseDiagonal(BaseVector< ValueType > *vec_inv_diag) const
Extract the inverse (reciprocal) diagonal values of the matrix into a LocalVector.
virtual bool ReplaceColumnVector(const int idx, const BaseVector< ValueType > &vec)
Replace a column vector of a matrix.
virtual bool ExtractDiagonal(BaseVector< ValueType > *vec_diag) const
Extract the diagonal values of the matrix into a LocalVector.
virtual bool LSolve(const BaseVector< ValueType > &in, BaseVector< ValueType > *out) const
Solve L out = in; if level-scheduling algorithm is provided then the graph traversing is performed in...
virtual void LUAnalyseClear(void)
Delete the analysed data (see LUAnalyse)
virtual void LAnalyseClear(void)
Delete the analysed data (see LAnalyse) L-party.
virtual void CopyFromHost(const HostMatrix< ValueType > &src)
Copy (accelerator matrix) from host matrix.
Definition: base_matrix.hpp:48
virtual void CopyToAsync(BaseMatrix< ValueType > *mat) const
Copy to another matrix.
virtual bool ExtractSubMatrix(const int row_offset, const int col_offset, const int row_size, const int col_size, BaseMatrix< ValueType > *mat) const
Extrat a sub-matrix with row/col_offset and row/col_size.
virtual bool AddScalar(const ValueType alpha)
Add alpha to all values.
virtual bool ExtractRowVector(const int idx, BaseVector< ValueType > *vec) const
Extract values from a row of a matrix to a vector.
cusparseSolveAnalysisInfo_t U_mat_info_
Definition: gpu_matrix_csr.hpp:138
virtual bool ExtractU(BaseMatrix< ValueType > *U) const
Extract the upper triangular matrix.