![]() |
imate
C++/CUDA Reference
|
Container for CSR matrices. More...
#include <cu_csr_matrix.h>


Public Member Functions | |
| cuCSRMatrix () | |
| Default constructor. | |
| cuCSRMatrix (const DataType *A_data_, const LongIndexType *A_indices_, const LongIndexType *A_index_pointer_, const LongIndexType num_rows_, const LongIndexType num_columns_, const FlagType A_is_symmetric_, const int num_gpu_devices_) | |
| Constructor. | |
| virtual | ~cuCSRMatrix () |
| Destructor. | |
| virtual FlagType | is_identity_matrix () const |
| Checks whether the matrix is identity. | |
| LongIndexType | get_nnz () const |
| Returns the number of non-zero elements of the sparse matrix. | |
| virtual void | dot (const DataType *device_vector, DataType *device_product) |
| Matrix vector product. | |
| virtual void | dot_plus (const DataType *device_vector, const DataType alpha, DataType *device_product) |
| Matrix vector product written in place. | |
| virtual void | transpose_dot (const DataType *device_vector, DataType *device_product) |
| Transposed-matrix vector product. | |
| virtual void | transpose_dot_plus (const DataType *device_vector, const DataType alpha, DataType *device_product) |
| Transposed-matrix vector product written in place. | |
Public Member Functions inherited from cuMatrix< DataType > | |
| cuMatrix () | |
| Default constructor. | |
| cuMatrix (const FlagType A_is_symmetric_) | |
| Constructor. | |
| virtual | ~cuMatrix () |
| Destructor. | |
| DataType | get_eigenvalue (const DataType *known_parameters, const DataType known_eigenvalue, const DataType *inquiry_parameters) const |
| This virtual function is implemented from its pure virtual function of the base class. In this class, this functio has no use and was only implemented so that this class be able to be instantiated (due to the pure virtual function). | |
| virtual void | set_symmetry (const FlagType symmetric) |
| Specify whether the matrix is symmetic or non-symmetric. | |
Public Member Functions inherited from cuLinearOperator< DataType > | |
| cuLinearOperator () | |
| Default constructor. | |
| cuLinearOperator (const int num_gpu_devices_) | |
Constructor with setting num_rows and num_columns. | |
| virtual | ~cuLinearOperator () |
| Destructor. | |
| cublasHandle_t | get_cublas_handle () const |
This function returns a reference to the cublasHandle_t object. The object will be created, if it is not created already. | |
| void | set_parameters (DataType *parameters_) |
Sets the scalar parameter this->parameters. Parameter is initialized to NULL. However, before calling dot or transpose_dot functions, the parameters must be set. | |
Public Member Functions inherited from cLinearOperatorBase | |
| cLinearOperatorBase () | |
| Default constructor. | |
| cLinearOperatorBase (const LongIndexType num_rows_, const LongIndexType num_columns_) | |
Constructor with setting num_rows and num_columns. | |
| virtual | ~cLinearOperatorBase () |
| Destructor. | |
| LongIndexType | get_num_rows () const |
| Returns the number of rows of the matrix. | |
| LongIndexType | get_num_columns () const |
| Returns the number of columns of the matrix. | |
| IndexType | get_num_parameters () const |
| Returns the number of parameters of the linear operator. | |
| FlagType | is_eigenvalue_relation_known () const |
| Returns a flag that determines whether a relation between the parameters of the operator and its eigenvalue(s) is known. | |
Protected Member Functions | |
| virtual void | copy_host_to_device () |
| Copies the member data from the host memory to the device memory. | |
| void | allocate_buffer (const int device_id, cusparseOperation_t cusparse_operation, const DataType alpha, const DataType beta, cusparseDnVecDescr_t &cusparse_input_vector, cusparseDnVecDescr_t &cusparse_output_vector, cusparseSpMVAlg_t algorithm) |
Allocates an external buffer for matrix-vector multiplication using cusparseSpMV function. | |
Protected Member Functions inherited from cuLinearOperator< DataType > | |
| int | query_gpu_devices () const |
| Before any numerical computation, this method chechs if any gpu device is available on the machine, or notifies the user if nothing was found. | |
| void | initialize_cublas_handle () |
Creates a cublasHandle_t object, if not created already. | |
| void | initialize_cusparse_handle () |
Creates a cusparseHandle_t object, if not created already. | |
Protected Attributes | |
| const DataType * | A_data |
| const LongIndexType * | A_indices |
| const LongIndexType * | A_index_pointer |
| DataType ** | device_A_data |
| LongIndexType ** | device_A_indices |
| LongIndexType ** | device_A_index_pointer |
| void ** | device_buffer |
| size_t * | device_buffer_num_bytes |
| cusparseSpMatDescr_t * | cusparse_matrix_A |
Protected Attributes inherited from cuMatrix< DataType > | |
| FlagType | A_is_symmetric |
Protected Attributes inherited from cuLinearOperator< DataType > | |
| int | num_gpu_devices |
| bool | copied_host_to_device |
| cublasHandle_t * | cublas_handle |
| cusparseHandle_t * | cusparse_handle |
| DataType * | parameters |
Protected Attributes inherited from cLinearOperatorBase | |
| const LongIndexType | num_rows |
| const LongIndexType | num_columns |
| FlagType | eigenvalue_relation_known |
| IndexType | num_parameters |
Container for CSR matrices.
The cCSRMatrix holds a two-dimensional compressed sparse row matrix, and can perofrom matrix-vector product and transposed matrix-vector product.
Definition at line 44 of file cu_csr_matrix.h.
| cuCSRMatrix< DataType >::cuCSRMatrix | ( | ) |
Default constructor.
Definition at line 41 of file cu_csr_matrix.cu.
| cuCSRMatrix< DataType >::cuCSRMatrix | ( | const DataType * | A_data_, |
| const LongIndexType * | A_indices_, | ||
| const LongIndexType * | A_index_pointer_, | ||
| const LongIndexType | num_rows_, | ||
| const LongIndexType | num_columns_, | ||
| const FlagType | A_is_symmetric_, | ||
| const int | num_gpu_devices_ | ||
| ) |
Constructor.
| [in] | A_data_ | 1D array of the data content of sparse matrix. The size of the array is the nnz of the matrix. |
| [in] | A_indices_ | 1D array indicating the column of each element in A_data_ . The size of this array is the nnz of the matrix. |
| [in] | A_index_pointer_ | 1D array pointing to the start of new rows in A_indices_ . The size of this array is num_rows+1 . The first element of this array is 0 and the last element of this array is the nnz of the matrix. |
| [in] | num_rows_ | Number of rows of A |
| [in] | num_columns_ | Number of columns of A |
| [in] | A_is_symmetric_ | Boolean. If A is symmetric, set this value to 1, otherwise 0. |
| [in] | num_gpu_devices_ | Number of GPU devices to be utilzied for parallel processing. |
Definition at line 83 of file cu_csr_matrix.cu.
References cuCSRMatrix< DataType >::copy_host_to_device(), cuCSRMatrix< DataType >::device_buffer, cuCSRMatrix< DataType >::device_buffer_num_bytes, cuLinearOperator< DataType >::initialize_cusparse_handle(), and cuLinearOperator< DataType >::num_gpu_devices.

|
virtual |
Destructor.
Definition at line 129 of file cu_csr_matrix.cu.
References CudaAPI< ArrayType >::del(), cusparse_api::destroy_cusparse_matrix(), and CudaAPI< ArrayType >::set_device().

|
protected |
Allocates an external buffer for matrix-vector multiplication using cusparseSpMV function.
If buffer size if not the same as required buffer size, allocate (or reallocate) memory. The allocation is always performed in the first call of this function since buffer size is initialized to zero in constructor. But for the next calls it might not be reallocated if the buffer size is the same.
| [in] | device_id | The ID of the GPU device, from 0 to num_gpu_devices-1. |
| [in] | cusparse_operation | The CuSparfse operation, which can be CUSPARSE_OPERATION_NON_TRANSPOSE or CUSPARSE_OPERATION_TRANSPOSE. |
| [in] | alpha | Scalar. The parameter \( \alpha \) in matrix-vector multiplication. |
| [in] | beta | Scalar. The parameter \( \beta \) in matrix-vector multiplication. |
| [in] | cusparse_input_vector | Input vector in the matrix-vector multiplication. |
| [in] | cusparse_output_vector | Output vector in the matrix-vector multiplication. |
| [in] | algorithm | CuSparse algorithm for sparse matrix-vector product. Possible values can be CUSPARSE_SPMV_ALG_DEFAULT, CUSPARSE_SPMV_CSR_ALG1, CUSPARSE_SPMV_CSR_ALG2, etc. |
Definition at line 306 of file cu_csr_matrix.cu.
References CudaAPI< ArrayType >::alloc_bytes(), cusparse_api::cusparse_matrix_buffer_size(), and CudaAPI< ArrayType >::del().

|
protectedvirtual |
Copies the member data from the host memory to the device memory.
Implements cuMatrix< DataType >.
Definition at line 199 of file cu_csr_matrix.cu.
References CudaAPI< ArrayType >::alloc(), CudaAPI< ArrayType >::copy_to_device(), cusparse_api::create_cusparse_csr_matrix(), omp_get_thread_num(), omp_set_num_threads(), and CudaAPI< ArrayType >::set_device().
Referenced by cuCSRMatrix< DataType >::cuCSRMatrix().


|
virtual |
Matrix vector product.
Performs the matrix vector product \( \boldsymbol{y} = \mathbf{A} \boldsymbol{x} \).
| [in] | device_vector | A one-dimensional input vector \( \boldsymbol{x} \) with size the of the number of columns of the matrix \( \mathbf{A} \). This array should be on GPU device. |
| [out] | device_product | A one-dimensional output vector \( \boldsymbol{y} \) with the size of the number of rows of \( \mathbf{A} \). This vector will be overwritten. This array should be on GPU device. |
Implements cuLinearOperator< DataType >.
Definition at line 449 of file cu_csr_matrix.cu.
References cu_arithmetics::abs(), cusparse_api::create_cusparse_vector(), cusparse_api::cusparse_matvec(), CUSPARSE_SPMV_ALG_DEFAULT, cusparse_api::destroy_cusparse_vector(), and CudaAPI< ArrayType >::get_device().

|
virtual |
Matrix vector product written in place.
Performs the matrix vector product \( \boldsymbol{y} = \boldsymbol{y} + \alpha \mathbf{A} \boldsymbol{x} \).
| [in] | device_vector | A one-dimensional input vector \( \boldsymbol{x} \) with size the of the number of columns of the matrix \( \mathbf{A} \). This array should be on GPU device. |
| [in] | alpha | A scalar. |
| [out] | device_product | A one-dimensional output vector \( \boldsymbol{y} \) with the size of the number of rows of \( \mathbf{A} \). This array should be on GPU device. |
Implements cuMatrix< DataType >.
Definition at line 517 of file cu_csr_matrix.cu.
References cu_arithmetics::abs(), cusparse_api::create_cusparse_vector(), cusparse_api::cusparse_matvec(), CUSPARSE_SPMV_ALG_DEFAULT, cusparse_api::destroy_cusparse_vector(), and CudaAPI< ArrayType >::get_device().

| LongIndexType cuCSRMatrix< DataType >::get_nnz | ( | ) | const |
Returns the number of non-zero elements of the sparse matrix.
The nnz of a CSR matrix can be obtained from the last element of A_index_pointer. The size of array A_index_pointer is one plus the number of rows of the matrix.
Definition at line 420 of file cu_csr_matrix.cu.
|
virtual |
Checks whether the matrix is identity.
The identity check is primarily performed in the cAffineMatrixFunction class.
1 if the input matrix is identity, and 0 otherwise.Implements cuMatrix< DataType >.
Definition at line 352 of file cu_csr_matrix.cu.
References cu_arithmetics::is_equal().

|
virtual |
Transposed-matrix vector product.
Performs the matrix vector product \( \boldsymbol{y} = \mathbf{A}^{\intercal} \boldsymbol{x} \).
| [in] | device_vector | A one-dimensional input vector \( \boldsymbol{x} \) with size the of the number of columns of the matrix \( \mathbf{A} \). This array should be on GPU device. |
| [out] | device_product | A one-dimensional output vector \( \boldsymbol{y} \) with the size of the number of rows of \( \mathbf{A} \). This vector will be overwritten. This array should be on GPU device. |
Implements cuLinearOperator< DataType >.
Definition at line 583 of file cu_csr_matrix.cu.
References cu_arithmetics::abs(), cusparse_api::create_cusparse_vector(), cusparse_api::cusparse_matvec(), CUSPARSE_SPMV_ALG_DEFAULT, cusparse_api::destroy_cusparse_vector(), and CudaAPI< ArrayType >::get_device().

|
virtual |
Transposed-matrix vector product written in place.
Performs the matrix vector product \( \boldsymbol{y} = \boldsymbol{y} + \alpha \mathbf{A}^{\intercal} \boldsymbol{x} \).
| [in] | device_vector | A one-dimensional input vector \( \boldsymbol{x} \) with size the of the number of columns of the matrix \( \mathbf{A} \). This array should be on GPU device. |
| [in] | alpha | A scalar. |
| [out] | device_product | A one-dimensional output vector \( \boldsymbol{y} \) with the size of the number of rows of \( \mathbf{A} \). This array should be on GPU device. |
Implements cuMatrix< DataType >.
Definition at line 652 of file cu_csr_matrix.cu.
References cu_arithmetics::abs(), cusparse_api::create_cusparse_vector(), cusparse_api::cusparse_matvec(), CUSPARSE_SPMV_ALG_DEFAULT, cusparse_api::destroy_cusparse_vector(), and CudaAPI< ArrayType >::get_device().

|
protected |
Definition at line 99 of file cu_csr_matrix.h.
|
protected |
Definition at line 101 of file cu_csr_matrix.h.
|
protected |
Definition at line 100 of file cu_csr_matrix.h.
|
protected |
Definition at line 107 of file cu_csr_matrix.h.
|
protected |
Definition at line 102 of file cu_csr_matrix.h.
|
protected |
Definition at line 104 of file cu_csr_matrix.h.
|
protected |
Definition at line 103 of file cu_csr_matrix.h.
|
protected |
Definition at line 105 of file cu_csr_matrix.h.
Referenced by cuCSRMatrix< DataType >::cuCSRMatrix().
|
protected |
Definition at line 106 of file cu_csr_matrix.h.
Referenced by cuCSRMatrix< DataType >::cuCSRMatrix().