imate
C++/CUDA Reference
cu_csr_matrix.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright 2021, Siavash Ameli <sameli@berkeley.edu>
3  * SPDX-License-Identifier: BSD-3-Clause
4  * SPDX-FileType: SOURCE
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the license found in the LICENSE.txt file in the root
8  * directory of this source tree.
9  */
10 
11 
12 #ifndef _CU_LINEAR_OPERATOR_CU_CSR_MATRIX_H_
13 #define _CU_LINEAR_OPERATOR_CU_CSR_MATRIX_H_
14 
15 
16 // =======
17 // Headers
18 // =======
19 
20 #include "../_definitions/types.h" // FlagType, LongIndexType
21 #include "../_c_linear_operator/c_csr_matrix.h" // cCSRMatrix
22 #include "./cu_matrix.h" // cuMatrix
23 
24 
25 // =============
26 // cu CSR Matrix
27 // =============
28 
29 template <typename DataType>
30 class cuCSRMatrix :
31  public cuMatrix<DataType>,
32  public cCSRMatrix<DataType>
33 {
34  public:
35 
36  // Member methods
37  cuCSRMatrix();
38 
40  const DataType* A_data_,
41  const LongIndexType* A_indices_,
42  const LongIndexType* A_index_pointer_,
43  const LongIndexType num_rows_,
44  const LongIndexType num_columns_,
45  const int num_gpu_devices_);
46 
47  virtual ~cuCSRMatrix();
48 
49  virtual void dot(
50  const DataType* device_vector,
51  DataType* device_product);
52 
53  virtual void dot_plus(
54  const DataType* device_vector,
55  const DataType alpha,
56  DataType* device_product);
57 
58  virtual void transpose_dot(
59  const DataType* device_vector,
60  DataType* device_product);
61 
62  virtual void transpose_dot_plus(
63  const DataType* device_vector,
64  const DataType alpha,
65  DataType* device_product);
66 
67  protected:
68 
69  // Member methods
70  virtual void copy_host_to_device();
71 
72  void allocate_buffer(
73  const int device_id,
74  cusparseOperation_t cusparse_operation,
75  const DataType alpha,
76  const DataType beta,
77  cusparseDnVecDescr_t& cusparse_input_vector,
78  cusparseDnVecDescr_t& cusparse_output_vector,
79  cusparseSpMVAlg_t algorithm);
80 
81  // Member data
82  DataType** device_A_data;
85  void** device_buffer;
87  cusparseSpMatDescr_t* cusparse_matrix_A;
88 };
89 
90 #endif // _CU_LINEAR_OPERATOR_CU_CSR_MATRIX_H_
size_t * device_buffer_num_bytes
Definition: cu_csr_matrix.h:86
cuCSRMatrix()
Default constructor.
virtual ~cuCSRMatrix()
Virtual desructor.
virtual void transpose_dot(const DataType *device_vector, DataType *device_product)
cusparseSpMatDescr_t * cusparse_matrix_A
Definition: cu_csr_matrix.h:87
virtual void dot_plus(const DataType *device_vector, const DataType alpha, DataType *device_product)
LongIndexType ** device_A_index_pointer
Definition: cu_csr_matrix.h:84
DataType ** device_A_data
Definition: cu_csr_matrix.h:82
virtual void dot(const DataType *device_vector, DataType *device_product)
virtual void transpose_dot_plus(const DataType *device_vector, const DataType alpha, DataType *device_product)
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.
virtual void copy_host_to_device()
Copies the member data from the host memory to the device memory.
LongIndexType ** device_A_indices
Definition: cu_csr_matrix.h:83
void ** device_buffer
Definition: cu_csr_matrix.h:85
Base class for constant matrices.
Definition: cu_matrix.h:41
int LongIndexType
Definition: types.h:60