imate
C++/CUDA Reference
Loading...
Searching...
No Matches
cblas_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
12#ifndef _C_BASIC_ALGEBRA_CBLAS_API_H_
13#define _C_BASIC_ALGEBRA_CBLAS_API_H_
14
15
16// =======
17// Headers
18// =======
19
20#include "../_definitions/definitions.h" // USE_CBLAS, USE_MKL, USE_ANY_CBLAS
21
22#if defined(USE_ANY_CBLAS) && (USE_ANY_CBLAS == 1)
23
24#if defined(USE_CBLAS) && (USE_CBLAS == 1)
25 // Using OpenBLAS or similar
26 #include <cblas.h> // CBLAS_LAYOUT, CBLAS_TRANSPOSE, cblas_sgemv,
27 // cblas_dgemv, cblas_ssymv, cblas_dsymv, cblas_scopy,
28 // cblas_dcopy, cblas_saxpy, cblas_daxpy, cblas_snrm2,
29 // cblas_dnrm2, cblas_sscal, cblas_dscal
30#elif defined(USE_MKL) && (USE_MKL == 1)
31 // Using MKL
32 #include <mkl_cblas.h> // CBLAS_LAYOUT, CBLAS_TRANSPOSE, cblas_sgemv,
33 // cblas_dgemv, cblas_ssymv, cblas_dsymv,
34 // cblas_scopy, cblas_dcopy, cblas_saxpy,
35 // cblas_daxpy, cblas_snrm2, cblas_dnrm2,
36 // cblas_sscal, cblas_dscal
37#endif
38
39typedef CBLAS_ORDER CBLAS_LAYOUT; // backward compatibility with CBLAS_LAYOUT
40
41// Restrict qualifier
42#if defined(_MSC_VER)
43 #define RESTRICT __restrict
44#elif defined(__INTEL_COMPILER)
45 #define RESTRICT __restrict
46#elif defined(__CUDA__) || defined(__GNUC__) || defined(__clang__)
47 #define RESTRICT __restrict__
48#else
49 #define RESTRICT
50#endif
51
52
53// ===============
54// cblas interface
55// ===============
56
60
61namespace cblas_api
62{
63 // cblas xgemv
64 template <typename DataType>
65 void xgemv(
66 const CBLAS_LAYOUT layout,
67 const CBLAS_TRANSPOSE TransA,
68 const int M,
69 const int N,
70 const DataType alpha,
71 const DataType* RESTRICT A,
72 const int lda,
73 const DataType* RESTRICT X,
74 const int incX,
75 const DataType beta,
76 DataType* RESTRICT Y,
77 const int incY);
78
79 // cblas xsymv
80 template <typename DataType>
81 void xsymv(
82 const CBLAS_LAYOUT layout,
83 const CBLAS_UPLO Uplo,
84 const int N,
85 const DataType alpha,
86 const DataType* RESTRICT A,
87 const int lda,
88 const DataType* RESTRICT X,
89 const int incX,
90 const DataType beta,
91 DataType* RESTRICT Y,
92 const int incY);
93
94 // cblas xcopy
95 template <typename DataType>
96 void xcopy(
97 const int N,
98 const DataType* RESTRICT X,
99 const int incX,
100 DataType* RESTRICT Y,
101 const int incY);
102
103 // cblas xaxpy
104 template <typename DataType>
105 void xaxpy(
106 const int N,
107 const DataType alpha,
108 const DataType* RESTRICT X,
109 const int incX,
110 DataType* RESTRICT Y,
111 const int incY);
112
113 // cblas xdot
114 template <typename DataType>
115 DataType xdot(
116 const int N,
117 const DataType* RESTRICT X,
118 const int incX,
119 const DataType* RESTRICT Y,
120 const int incY);
121
122 // cblas xnrm2
123 template <typename DataType>
124 DataType xnrm2(
125 const int N,
126 const DataType* RESTRICT X,
127 const int incX);
128
129 // cblas xscal
130 template <typename DataType>
131 void xscal(
132 const int N,
133 const DataType alpha,
134 DataType* RESTRICT X,
135 const int incX);
136
137} // namespace cblas_api
138
139#endif // USE_ANY_CBLAS
140#endif // _C_BASIC_ALGEBRA_CBLAS_API_H_
#define RESTRICT