imate
C++/CUDA Reference
cusparse_interface.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 #ifndef _CU_BASIC_ALGEBRA_CUSPARSE_INTERFACE_H_
12 #define _CU_BASIC_ALGEBRA_CUSPARSE_INTERFACE_H_
13 
14 
15 // =======
16 // Headers
17 // =======
18 
19 #include <cusparse.h> // cusparseSpMatDescr_t, cusparseDnVecDescr_t,
20  // CusparseStatus_t, CUSPARSE_STATUS_SUCCESS,
21  // cusparseCreateCsr, cusparseCreateDnVec,
22  // cusparseDestroySpMat, cusparseDestroyDnVec,
23  // CUDA_R_32F, CUDA_R_64F, CUSPARSE_INDEX_32I,
24  // CUSPARSE_INDEX_BASE_ZERO, cusparseHandle_t,
25  // cusparseSpMVAlg_t, cusparseSpMV_buffer_size
26 #include "../_definitions/types.h" // LongIndexType
27 
28 
29 // ==================
30 // cusparse interface
31 // ==================
32 
36 
37 namespace cusparse_interface
38 {
39  // create cusparse matrix
40  template <typename DataType>
42  cusparseSpMatDescr_t& cusparse_matrix,
43  const LongIndexType num_rows,
44  const LongIndexType num_columns,
45  const LongIndexType nnz,
46  DataType* device_A_data,
47  LongIndexType* device_A_indices,
48  LongIndexType* device_A_index_pointer);
49 
50  // create cusparse vector
51  template <typename DataType>
53  cusparseDnVecDescr_t& cusparse_vector,
54  const LongIndexType vector_size,
55  DataType* device_vector);
56 
57  // destroy cusparse matrix
59  cusparseSpMatDescr_t& cusparse_matrix);
60 
61  // destroy cusparse vector
63  cusparseDnVecDescr_t& cusparse_vector);
64 
65  // cusparse matrix buffer size
66  template <typename DataType>
68  cusparseHandle_t cusparse_handle,
69  cusparseOperation_t cusparse_operation,
70  const DataType alpha,
71  cusparseSpMatDescr_t cusparse_matrix,
72  cusparseDnVecDescr_t cusparse_input_vector,
73  const DataType beta,
74  cusparseDnVecDescr_t cusparse_output_vector,
75  cusparseSpMVAlg_t algorithm,
76  size_t* buffer_size);
77 
78  // cusparse matvec
79  template <typename DataType>
81  cusparseHandle_t cusparse_handle,
82  cusparseOperation_t cusparse_operation,
83  const DataType alpha,
84  cusparseSpMatDescr_t cusparse_matrix,
85  cusparseDnVecDescr_t cusparse_input_vector,
86  const DataType beta,
87  cusparseDnVecDescr_t cusparse_output_vector,
88  cusparseSpMVAlg_t algorithm,
89  void* external_buffer);
90 } // namespace cusparse_interface
91 
92 
93 #endif // _CU_BASIC_ALGEBRA_CUSPARSE_INTERFACE_H_
A collection of templates to wrapper cusparse functions.
void create_cusparse_matrix(cusparseSpMatDescr_t &cusparse_matrix, const LongIndexType num_rows, const LongIndexType num_columns, const LongIndexType nnz, DataType *device_A_data, LongIndexType *device_A_indices, LongIndexType *device_A_index_pointer)
void destroy_cusparse_matrix(cusparseSpMatDescr_t &cusparse_matrix)
Destroys cusparse matrix.
void destroy_cusparse_vector(cusparseDnVecDescr_t &cusparse_vector)
Destroys cusparse vector.
void cusparse_matvec(cusparseHandle_t cusparse_handle, cusparseOperation_t cusparse_operation, const DataType alpha, cusparseSpMatDescr_t cusparse_matrix, cusparseDnVecDescr_t cusparse_input_vector, const DataType beta, cusparseDnVecDescr_t cusparse_output_vector, cusparseSpMVAlg_t algorithm, void *external_buffer)
void create_cusparse_vector(cusparseDnVecDescr_t &cusparse_vector, const LongIndexType vector_size, DataType *device_vector)
void cusparse_matrix_buffer_size(cusparseHandle_t cusparse_handle, cusparseOperation_t cusparse_operation, const DataType alpha, cusparseSpMatDescr_t cusparse_matrix, cusparseDnVecDescr_t cusparse_input_vector, const DataType beta, cusparseDnVecDescr_t cusparse_output_vector, cusparseSpMVAlg_t algorithm, size_t *buffer_size)
int LongIndexType
Definition: types.h:60