imate
C++/CUDA Reference
cu_csc_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_CSC_MATRIX_H_
13 #define _CU_LINEAR_OPERATOR_CU_CSC_MATRIX_H_
14 
15 
16 // =======
17 // Headers
18 // =======
19 
20 #include "../_definitions/types.h" // FlagType, LongIndexType
21 #include "../_c_linear_operator/c_csc_matrix.h" // cCSCMatrix
22 #include "./cu_matrix.h" // cuMatrix
23 
24 
25 // =============
26 // cu CSC Matrix
27 // =============
28 
29 template <typename DataType>
30 class cuCSCMatrix :
31  public cuMatrix<DataType>,
32  public cCSCMatrix<DataType>
33 {
34  public:
35 
36  // Member methods
37  cuCSCMatrix();
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 ~cuCSCMatrix();
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_CSC_MATRIX_H_
virtual void transpose_dot(const DataType *device_vector, DataType *device_product)
virtual void transpose_dot_plus(const DataType *device_vector, const DataType alpha, DataType *device_product)
virtual void dot(const DataType *device_vector, DataType *device_product)
LongIndexType ** device_A_index_pointer
Definition: cu_csc_matrix.h:84
size_t * device_buffer_num_bytes
Definition: cu_csc_matrix.h:86
cuCSCMatrix()
Default constructor.
cusparseSpMatDescr_t * cusparse_matrix_A
Definition: cu_csc_matrix.h:87
virtual void dot_plus(const DataType *device_vector, const DataType alpha, DataType *device_product)
void ** device_buffer
Definition: cu_csc_matrix.h:85
DataType ** device_A_data
Definition: cu_csc_matrix.h:82
virtual void copy_host_to_device()
Copies the member data from the host memory to the device memory.
LongIndexType ** device_A_indices
Definition: cu_csc_matrix.h:83
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 ~cuCSCMatrix()
Virtual desructor.
Base class for constant matrices.
Definition: cu_matrix.h:41
int LongIndexType
Definition: types.h:60