imate
C++/CUDA Reference
Loading...
Searching...
No Matches
cusparse_api.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_API_H_
12#define _CU_BASIC_ALGEBRA_CUSPARSE_API_H_
13
14
15// =======
16// Headers
17// =======
18
19#include <cusparse.h> // cusparseSpMatDescr_t, cusparseDnVecDescr_t,
20 // CusparseStatus_t, CUSPARSE_STATUS_SUCCESS,
21 // cusparseCreateCsr, cusparseCreateCsc,
22 // cusparseCreateDnVec, cusparseDestroySpMat,
23 // cusparseDestroyDnVec, CUSPARSE_INDEX_BASE_ZERO,
24 // CUDA_R_16F, CUDA_R_32F, CUDA_R_64F,
25 // CUSPARSE_INDEX_32I, CUSPARSE_INDEX_64I,
26 // cusparseHandle_t, cusparseSpMVAlg_t,
27 // cusparseSpMV_buffer_size, int32_t, int64_t
28#include "../_definitions/types.h" // LongIndexType
29
30// Restrict qualifier
31#if defined(_MSC_VER)
32 #define RESTRICT __restrict
33#elif defined(__INTEL_COMPILER)
34 #define RESTRICT __restrict
35#elif defined(__CUDA__) || defined(__GNUC__) || defined(__clang__)
36 #define RESTRICT __restrict__
37#else
38 #define RESTRICT
39#endif
40
41
42// ============
43// cusparse api
44// ============
45
49
50namespace cusparse_api
51{
52 // create cusparse csr matrix
53 template <typename DataType, typename DataIndexType>
55 cusparseSpMatDescr_t& cusparse_matrix,
56 const DataIndexType num_rows,
57 const DataIndexType num_columns,
58 const DataIndexType nnz,
59 DataType* RESTRICT device_A_data,
60 DataIndexType* RESTRICT device_A_indices,
61 DataIndexType* RESTRICT device_A_index_pointer);
62
63 // create cusparse csc matrix
64 template <typename DataType, typename DataIndexType>
66 cusparseSpMatDescr_t& cusparse_matrix,
67 const DataIndexType num_rows,
68 const DataIndexType num_columns,
69 const DataIndexType nnz,
70 DataType* RESTRICT device_A_data,
71 DataIndexType* RESTRICT device_A_indices,
72 DataIndexType* RESTRICT device_A_index_pointer);
73
74 // create cusparse vector
75 template <typename DataType>
77 cusparseDnVecDescr_t& cusparse_vector,
78 const LongIndexType vector_size,
79 DataType* RESTRICT device_vector);
80
81 // destroy cusparse matrix
83 cusparseSpMatDescr_t& cusparse_matrix);
84
85 // destroy cusparse vector
87 cusparseDnVecDescr_t& cusparse_vector);
88
89 // cusparse matrix buffer size
90 template <typename DataType>
92 cusparseHandle_t cusparse_handle,
93 cusparseOperation_t cusparse_operation,
94 const DataType alpha,
95 cusparseSpMatDescr_t cusparse_matrix,
96 cusparseDnVecDescr_t cusparse_input_vector,
97 const DataType beta,
98 cusparseDnVecDescr_t cusparse_output_vector,
99 cusparseSpMVAlg_t algorithm,
100 size_t* buffer_size);
101
102 // cusparse matvec
103 template <typename DataType>
105 cusparseHandle_t cusparse_handle,
106 cusparseOperation_t cusparse_operation,
107 const DataType alpha,
108 cusparseSpMatDescr_t cusparse_matrix,
109 cusparseDnVecDescr_t cusparse_input_vector,
110 const DataType beta,
111 cusparseDnVecDescr_t cusparse_output_vector,
112 cusparseSpMVAlg_t algorithm,
113 void* external_buffer);
114
115} // namespace cusparse_api
116
117
118#endif // _CU_BASIC_ALGEBRA_CUSPARSE_API_H_
#define RESTRICT
A collection of templates to wrapper cusparse functions.
void create_cusparse_csc_matrix(cusparseSpMatDescr_t &cusparse_matrix, const DataIndexType num_rows, const DataIndexType num_columns, const DataIndexType nnz, DataType *RESTRICT device_A_data, DataIndexType *RESTRICT device_A_indices, DataIndexType *RESTRICT device_A_index_pointer)
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 destroy_cusparse_matrix(cusparseSpMatDescr_t &cusparse_matrix)
Destroy cusparse matrix.
void create_cusparse_vector(cusparseDnVecDescr_t &cusparse_vector, const LongIndexType vector_size, DataType *RESTRICT device_vector)
void destroy_cusparse_vector(cusparseDnVecDescr_t &cusparse_vector)
Destroys cusparse 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)
void create_cusparse_csr_matrix(cusparseSpMatDescr_t &cusparse_matrix, const DataIndexType num_rows, const DataIndexType num_columns, const DataIndexType nnz, DataType *RESTRICT device_A_data, DataIndexType *RESTRICT device_A_indices, DataIndexType *RESTRICT device_A_index_pointer)
int LongIndexType
Definition types.h:60