imate
C++/CUDA Reference
Loading...
Searching...
No Matches
cusparse_symbols.cpp
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// =======
13// Headers
14// =======
15
16#include "./cusparse_symbols.h"
17#include <cusparse.h> // CUSPARSE_VER_MAJOR
18#include <cstdlib> // NULL
19#include <sstream> // std::ostringstream
20#include "./dynamic_loading.h" // dynamic_loading
21
22
23// =========================
24// Initialize static members
25// =========================
26
36
37
38// ============
39// get lib name
40// ============
41
44
46{
47 // Get the extension name of a shared library depending on OS
48 std::string lib_extension;
49
50 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32) || \
51 defined(__NT__)
52 lib_extension = "lib";
53 #elif defined(__APPLE__)
54 lib_extension = "dylib";
55 #elif defined(__linux__)
56 lib_extension = "so";
57 #else
58 #error "Unknown compiler"
59 #endif
60
61 // Check cusparse version
62 #ifndef CUSPARSE_VER_MAJOR
63 #error "CUSPARSE_VER_MAJOR is not defined."
64 #endif
65
66 // cusparse shared library base name
67 std::string lib_base_name = "libcusparse";
68
69 // Construct the lib name
70 std::ostringstream oss;
71 // oss << lib_base_name << "." << lib_extension;
72 oss << lib_base_name << "." << lib_extension << "." \
73 << CUSPARSE_VER_MAJOR;
74
75 std::string lib_name = oss.str();
76
77 return lib_name;
78}
79
80
81#ifdef __cplusplus
82 extern "C" {
83#endif
84
85
86// ===============
87// cusparse Create
88// ===============
89
92
93cusparseStatus_t cusparseCreate(cusparseHandle_t* handle)
94{
96 {
97 std::string lib_name = cusparseSymbols::get_lib_name();
98 const char* symbol_name = "cusparseCreate";
99
101 dynamic_loading::load_symbol<cusparseCreate_type>(
102 lib_name.c_str(),
103 symbol_name);
104 }
105
106 return cusparseSymbols::cusparseCreate(handle);
107}
108
109
110// ================
111// cusparse Destroy
112// ================
113
116
117cusparseStatus_t cusparseDestroy(cusparseHandle_t handle)
118{
120 {
121 std::string lib_name = cusparseSymbols::get_lib_name();
122 const char* symbol_name = "cusparseDestroy";
123
125 dynamic_loading::load_symbol<cusparseDestroy_type>(
126 lib_name.c_str(),
127 symbol_name);
128 }
129
131}
132
133
134// =================
135// cusparseCreateCsr
136// =================
137
140
141cusparseStatus_t cusparseCreateCsr(
142 cusparseSpMatDescr_t* spMatDescr,
143 int64_t rows,
144 int64_t cols,
145 int64_t nnz,
146 void* csrRowOffsets,
147 void* csrColInd,
148 void* csrValues,
149 cusparseIndexType_t csrRowOffsetsType,
150 cusparseIndexType_t csrColIndType,
151 cusparseIndexBase_t idxBase,
152 cudaDataType valueType)
153{
155 {
156 std::string lib_name = cusparseSymbols::get_lib_name();
157 const char* symbol_name = "cusparseCreateCsr";
158
160 dynamic_loading::load_symbol<cusparseCreateCsr_type>(
161 lib_name.c_str(),
162 symbol_name);
163 }
164
166 spMatDescr, rows, cols, nnz, csrRowOffsets, csrColInd, csrValues,
167 csrRowOffsetsType, csrColIndType, idxBase, valueType);
168}
169
170
171// =================
172// cusparseCreateCsc
173// =================
174
177
178cusparseStatus_t cusparseCreateCsc(
179 cusparseSpMatDescr_t* spMatDescr,
180 int64_t rows,
181 int64_t cols,
182 int64_t nnz,
183 void* csrRowOffsets,
184 void* csrColInd,
185 void* csrValues,
186 cusparseIndexType_t csrRowOffsetsType,
187 cusparseIndexType_t csrColIndType,
188 cusparseIndexBase_t idxBase,
189 cudaDataType valueType)
190{
192 {
193 std::string lib_name = cusparseSymbols::get_lib_name();
194 const char* symbol_name = "cusparseCreateCsc";
195
197 dynamic_loading::load_symbol<cusparseCreateCsc_type>(
198 lib_name.c_str(),
199 symbol_name);
200 }
201
203 spMatDescr, rows, cols, nnz, csrRowOffsets, csrColInd, csrValues,
204 csrRowOffsetsType, csrColIndType, idxBase, valueType);
205}
206
207
208// ===================
209// cusparseCreateDnVec
210// ===================
211
214
215cusparseStatus_t cusparseCreateDnVec(
216 cusparseDnVecDescr_t* dnVecDescr,
217 int64_t size,
218 void* values,
219 cudaDataType valueType)
220{
222 {
223 std::string lib_name = cusparseSymbols::get_lib_name();
224 const char* symbol_name = "cusparseCreateDnVec";
225
227 dynamic_loading::load_symbol<cusparseCreateDnVec_type>(
228 lib_name.c_str(),
229 symbol_name);
230 }
231
233 dnVecDescr, size, values, valueType);
234}
235
236
237// ====================
238// cusparseDestroySpMat
239// ====================
240
243
244cusparseStatus_t cusparseDestroySpMat(
245 cusparseConstSpMatDescr_t spMatDescr)
246{
248 {
249 std::string lib_name = cusparseSymbols::get_lib_name();
250 const char* symbol_name = "cusparseDestroySpMat";
251
253 dynamic_loading::load_symbol<cusparseDestroySpMat_type>(
254 lib_name.c_str(),
255 symbol_name);
256 }
257
258 return cusparseSymbols::cusparseDestroySpMat(spMatDescr);
259}
260
261
262// ====================
263// cusparseDestroyDnVec
264// ====================
265
268
269cusparseStatus_t cusparseDestroyDnVec(
270 cusparseConstDnVecDescr_t dnVecDescr)
271{
273 {
274 std::string lib_name = cusparseSymbols::get_lib_name();
275 const char* symbol_name = "cusparseDestroyDnVec";
276
278 dynamic_loading::load_symbol<cusparseDestroyDnVec_type>(
279 lib_name.c_str(),
280 symbol_name);
281 }
282
283 return cusparseSymbols::cusparseDestroyDnVec(dnVecDescr);
284}
285
286
287// =======================
288// cusparseSpMV_bufferSize
289// =======================
290
293
294cusparseStatus_t cusparseSpMV_bufferSize(
295 cusparseHandle_t handle,
296 cusparseOperation_t opA,
297 const void* alpha,
300 const void* beta,
301 cusparseDnVecDescr_t vecY,
302 cudaDataType computeType,
303 cusparseSpMVAlg_t alg,
304 size_t* bufferSize)
305{
307 {
308 std::string lib_name = cusparseSymbols::get_lib_name();
309 const char* symbol_name = "cusparseSpMV_bufferSize";
310
312 dynamic_loading::load_symbol<cusparseSpMV_bufferSize_type>(
313 lib_name.c_str(),
314 symbol_name);
315 }
316
318 handle, opA, alpha, matA, vecX, beta, vecY, computeType, alg,
319 bufferSize);
320}
321
322
323// ============
324// cusparseSpMV
325// ============
326
329
330cusparseStatus_t cusparseSpMV(
331 cusparseHandle_t handle,
332 cusparseOperation_t opA,
333 const void* alpha,
336 const void* beta,
337 cusparseDnVecDescr_t vecY,
338 cudaDataType computeType,
339 cusparseSpMVAlg_t alg,
340 void* externalBuffer)
341{
343 {
344 std::string lib_name = cusparseSymbols::get_lib_name();
345 const char* symbol_name = "cusparseSpMV";
346
348 dynamic_loading::load_symbol<cusparseSpMV_type>(
349 lib_name.c_str(),
350 symbol_name);
351 }
352
354 handle, opA, alpha, matA, vecX, beta, vecY, computeType, alg,
355 externalBuffer);
356}
357
358
359#ifdef __cplusplus
360 }
361#endif
static cusparseCreateDnVec_type cusparseCreateDnVec
static cusparseCreateCsr_type cusparseCreateCsr
static cusparseDestroyDnVec_type cusparseDestroyDnVec
static cusparseSpMV_type cusparseSpMV
static cusparseDestroy_type cusparseDestroy
static std::string get_lib_name()
Returns the name of cusparse shared library.
static cusparseSpMV_bufferSize_type cusparseSpMV_bufferSize
static cusparseCreateCsc_type cusparseCreateCsc
static cusparseDestroySpMat_type cusparseDestroySpMat
static cusparseCreate_type cusparseCreate
cusparseStatus_t cusparseDestroy(cusparseHandle_t handle)
Definition of CUDA's cusparseDestroy function using dynamically loaded cublas library.
cusparseStatus_t cusparseSpMV(cusparseHandle_t handle, cusparseOperation_t opA, const void *alpha, cusparseConstSpMatDescr_t matA, cusparseConstDnVecDescr_t vecX, const void *beta, cusparseDnVecDescr_t vecY, cudaDataType computeType, cusparseSpMVAlg_t alg, void *externalBuffer)
Definition of CUDA's cusparseSmMV function using dynamically loaded cublas library.
cusparseStatus_t cusparseCreateCsc(cusparseSpMatDescr_t *spMatDescr, int64_t rows, int64_t cols, int64_t nnz, void *csrRowOffsets, void *csrColInd, void *csrValues, cusparseIndexType_t csrRowOffsetsType, cusparseIndexType_t csrColIndType, cusparseIndexBase_t idxBase, cudaDataType valueType)
Definition of CUDA's cusparseCreateCsc function using dynamically loaded cublas library.
cusparseStatus_t cusparseDestroySpMat(cusparseConstSpMatDescr_t spMatDescr)
Definition of CUDA's cusparseDestroySpMat function using dynamically loaded cublas library.
cusparseStatus_t cusparseCreate(cusparseHandle_t *handle)
Definition of CUDA's cusparseCreate function using dynamically loaded cublas library.
cusparseStatus_t cusparseCreateDnVec(cusparseDnVecDescr_t *dnVecDescr, int64_t size, void *values, cudaDataType valueType)
Definition of CUDA's cusparseCreateDnVec function using dynamically loaded cublas library.
cusparseStatus_t cusparseSpMV_bufferSize(cusparseHandle_t handle, cusparseOperation_t opA, const void *alpha, cusparseConstSpMatDescr_t matA, cusparseConstDnVecDescr_t vecX, const void *beta, cusparseDnVecDescr_t vecY, cudaDataType computeType, cusparseSpMVAlg_t alg, size_t *bufferSize)
Definition of CUDA's cusparseSpMV_bufferSize function using dynamically loaded cublas library.
cusparseStatus_t cusparseCreateCsr(cusparseSpMatDescr_t *spMatDescr, int64_t rows, int64_t cols, int64_t nnz, void *csrRowOffsets, void *csrColInd, void *csrValues, cusparseIndexType_t csrRowOffsetsType, cusparseIndexType_t csrColIndType, cusparseIndexBase_t idxBase, cudaDataType valueType)
Definition of CUDA's cusparseCreateCsr function using dynamically loaded cublas library.
cusparseStatus_t cusparseDestroyDnVec(cusparseConstDnVecDescr_t dnVecDescr)
Definition of CUDA's cusparseDestroyDnVec function using dynamically loaded cublas library.
cusparseStatus_t(* cusparseSpMV_type)(cusparseHandle_t handle, cusparseOperation_t opA, const void *alpha, cusparseConstSpMatDescr_t matA, cusparseConstDnVecDescr_t vecX, const void *beta, cusparseDnVecDescr_t vecY, cudaDataType computeType, cusparseSpMVAlg_t alg, void *externalBuffer)
cusparseStatus_t(* cusparseCreate_type)(cusparseHandle_t *handle)
cusparseStatus_t(* cusparseDestroy_type)(cusparseHandle_t handle)
cusparseStatus_t(* cusparseCreateDnVec_type)(cusparseDnVecDescr_t *dnVecDescr, int64_t size, void *values, cudaDataType valueType)
cusparseStatus_t(* cusparseCreateCsc_type)(cusparseSpMatDescr_t *spMatDescr, int64_t rows, int64_t cols, int64_t nnz, void *cscRowOffsets, void *cscColInd, void *cscValues, cusparseIndexType_t cscRowOffsetsType, cusparseIndexType_t cscColIndType, cusparseIndexBase_t idxBase, cudaDataType valueType)
#define cusparseConstDnVecDescr_t
cusparseStatus_t(* cusparseDestroyDnVec_type)(cusparseConstDnVecDescr_t dnVecDescr)
#define cusparseConstSpMatDescr_t
cusparseStatus_t(* cusparseSpMV_bufferSize_type)(cusparseHandle_t handle, cusparseOperation_t opA, const void *alpha, cusparseConstSpMatDescr_t matA, cusparseConstDnVecDescr_t vecX, const void *beta, cusparseDnVecDescr_t vecY, cudaDataType computeType, cusparseSpMVAlg_t alg, size_t *bufferSize)
cusparseStatus_t(* cusparseDestroySpMat_type)(cusparseConstSpMatDescr_t spMatDescr)
cusparseStatus_t(* cusparseCreateCsr_type)(cusparseSpMatDescr_t *spMatDescr, int64_t rows, int64_t cols, int64_t nnz, void *csrRowOffsets, void *csrColInd, void *csrValues, cusparseIndexType_t csrRowOffsetsType, cusparseIndexType_t csrColIndType, cusparseIndexBase_t idxBase, cudaDataType valueType)