Nektar++
Loading...
Searching...
No Matches
Blas.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: Blas.hpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: wrapper of functions around standard BLAS routines
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#ifndef NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_BLAS_HPP
36#define NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_BLAS_HPP
37
40
41// Translations for using Fortran version of blas
42namespace Blas
43{
44extern "C"
45{
46 // -- BLAS Level 1:
47 void F77NAME(daxpy)(const int &n, const double &alpha, const double *x,
48 const int &incx, const double *y, const int &incy);
49 void F77NAME(dscal)(const int &n, const double &alpha, double *x,
50 const int &incx);
51
52 // -- BLAS level 2
53 void F77NAME(dgemv)(const char &trans, const int &m, const int &n,
54 const double &alpha, const double *a, const int &lda,
55 const double *x, const int &incx, const double &beta,
56 double *y, const int &incy);
57 void F77NAME(sgemv)(const char &trans, const int &m, const int &n,
58 const float &alpha, const float *a, const int &lda,
59 const float *x, const int &incx, const float &beta,
60 float *y, const int &incy);
61
62 void F77NAME(dgbmv)(const char &trans, const int &m, const int &n,
63 const int &kl, const int &ku, const double &alpha,
64 const double *a, const int &lda, const double *x,
65 const int &incx, const double &beta, double *y,
66 const int &incy);
67 void F77NAME(sgbmv)(const char &trans, const int &m, const int &n,
68 const int &kl, const int &ku, const float &alpha,
69 const float *a, const int &lda, const float *x,
70 const int &incx, const float &beta, float *y,
71 const int &incy);
72
73 void F77NAME(dspmv)(const char &uplo, const int &n, const double &alpha,
74 const double *a, const double *x, const int &incx,
75 const double &beta, double *y, const int &incy);
76 void F77NAME(sspmv)(const char &uplo, const int &n, const float &alpha,
77 const float *a, const float *x, const int &incx,
78 const float &beta, float *y, const int &incy);
79
80 void F77NAME(dsbmv)(const char &uplo, const int &m, const int &k,
81 const double &alpha, const double *a, const int &lda,
82 const double *x, const int &incx, const double &beta,
83 double *y, const int &incy);
84 void F77NAME(ssbmv)(const char &uplo, const int &m, const int &k,
85 const float &alpha, const float *a, const int &lda,
86 const float *x, const int &incx, const float &beta,
87 float *y, const int &incy);
88
89 void F77NAME(dtpmv)(const char &uplo, const char &trans, const char &diag,
90 const int &n, const double *ap, double *x,
91 const int &incx);
92 void F77NAME(stpmv)(const char &uplo, const char &trans, const char &diag,
93 const int &n, const float *ap, float *x,
94 const int &incx);
95
96 void F77NAME(dger)(const int &m, const int &n, const double &alpha,
97 const double *x, const int &incx, const double *y,
98 const int &incy, double *a, const int &lda);
99 void F77NAME(sger)(const int &m, const int &n, const float &alpha,
100 const float *x, const int &incx, const float *y,
101 const int &incy, float *a, const int &lda);
102
103 // -- BLAS level 3:
104 void F77NAME(dgemm)(const char &trans, const char &transb, const int &m1,
105 const int &n, const int &k, const double &alpha,
106 const double *a, const int &lda, const double *b,
107 const int &ldb, const double &beta, double *c,
108 const int &ldc);
109 void F77NAME(sgemm)(const char &trans, const char &transb, const int &m1,
110 const int &n, const int &k, const float &alpha,
111 const float *a, const int &lda, const float *b,
112 const int &ldb, const float &beta, float *c,
113 const int &ldc);
114}
115
116/// \brief BLAS level 1: y = alpha \a x plus \a y
117static inline void Daxpy(const int &n, const double &alpha, const double *x,
118 const int &incx, const double *y, const int &incy)
119{
120 F77NAME(daxpy)(n, alpha, x, incx, y, incy);
121}
122
123/// \brief BLAS level 1: x = alpha \a x
124static inline void Dscal(const int &n, const double &alpha, double *x,
125 const int &incx)
126{
127 F77NAME(dscal)(n, alpha, x, incx);
128}
129
130/// \brief BLAS level 2: Matrix vector multiply y = alpha A \e x plus beta \a y
131/// where A[m x n]
132static inline void Gemv(const char &trans, const int &m, const int &n,
133 const double &alpha, const double *a, const int &lda,
134 const double *x, const int &incx, const double &beta,
135 double *y, const int &incy)
136{
137 F77NAME(dgemv)(trans, m, n, alpha, a, lda, x, incx, beta, y, incy);
138}
139
140/// \brief BLAS level 2: Matrix vector multiply y = alpha A \e x plus beta \a y
141/// where A[m x n]
142static inline void Gemv(const char &trans, const int &m, const int &n,
143 const float &alpha, const float *a, const int &lda,
144 const float *x, const int &incx, const float &beta,
145 float *y, const int &incy)
146{
147 F77NAME(sgemv)(trans, m, n, alpha, a, lda, x, incx, beta, y, incy);
148}
149
150/// \brief BLAS level 2: Matrix vector multiply y = alpha A \e x plus beta \a y
151/// where A[m x n]
152static inline void Dgemv(const char &trans, const int &m, const int &n,
153 const double &alpha, const double *a, const int &lda,
154 const double *x, const int &incx, const double &beta,
155 double *y, const int &incy)
156{
157 F77NAME(dgemv)(trans, m, n, alpha, a, lda, x, incx, beta, y, incy);
158}
159
160/// \brief BLAS level 2: Matrix vector multiply y = alpha A \e x plus beta \a y
161/// where A[m x n] is banded
162static inline void Gbmv(const char &trans, const int &m, const int &n,
163 const int &kl, const int &ku, const double &alpha,
164 const double *a, const int &lda, const double *x,
165 const int &incx, const double &beta, double *y,
166 const int &incy)
167{
168 F77NAME(dgbmv)(trans, m, n, kl, ku, alpha, a, lda, x, incx, beta, y, incy);
169}
170
171/// \brief BLAS level 2: Matrix vector multiply y = alpha A \e x plus beta \a y
172/// where A[m x n] is banded
173static inline void Gbmv(const char &trans, const int &m, const int &n,
174 const int &kl, const int &ku, const float &alpha,
175 const float *a, const int &lda, const float *x,
176 const int &incx, const float &beta, float *y,
177 const int &incy)
178{
179 F77NAME(sgbmv)(trans, m, n, kl, ku, alpha, a, lda, x, incx, beta, y, incy);
180}
181
182/// \brief BLAS level 2: Matrix vector multiply y = alpha A \e x plus beta \a y
183/// where A[m x n] is banded
184static inline void Dgbmv(const char &trans, const int &m, const int &n,
185 const int &kl, const int &ku, const double &alpha,
186 const double *a, const int &lda, const double *x,
187 const int &incx, const double &beta, double *y,
188 const int &incy)
189{
190 F77NAME(dgbmv)(trans, m, n, kl, ku, alpha, a, lda, x, incx, beta, y, incy);
191}
192
193/// \brief BLAS level 2: Matrix vector multiply y = alpha A \e x plus beta \a y
194/// where A[n x n] is symmetric packed
195static inline void Spmv(const char &uplo, const int &n, const double &alpha,
196 const double *a, const double *x, const int &incx,
197 const double &beta, double *y, const int &incy)
198{
199 F77NAME(dspmv)(uplo, n, alpha, a, x, incx, beta, y, incy);
200}
201
202/// \brief BLAS level 2: Matrix vector multiply y = alpha A \e x plus beta \a y
203/// where A[n x n] is symmetric packed
204static inline void Spmv(const char &uplo, const int &n, const float &alpha,
205 const float *a, const float *x, const int &incx,
206 const float &beta, float *y, const int &incy)
207{
208 F77NAME(sspmv)(uplo, n, alpha, a, x, incx, beta, y, incy);
209}
210
211/// \brief BLAS level 2: Matrix vector multiply y = alpha A \e x plus beta \a y
212/// where A[n x n] is symmetric packed
213static inline void Dspmv(const char &uplo, const int &n, const double &alpha,
214 const double *a, const double *x, const int &incx,
215 const double &beta, double *y, const int &incy)
216{
217 F77NAME(dspmv)(uplo, n, alpha, a, x, incx, beta, y, incy);
218}
219
220/// \brief BLAS level 2: Matrix vector multiply y = alpha A \e x plus beta \a y
221/// where A[m x m] is symmetric banded
222static inline void Sbmv(const char &uplo, const int &m, const int &k,
223 const double &alpha, const double *a, const int &lda,
224 const double *x, const int &incx, const double &beta,
225 double *y, const int &incy)
226{
227 F77NAME(dsbmv)(uplo, m, k, alpha, a, lda, x, incx, beta, y, incy);
228}
229
230/// \brief BLAS level 2: Matrix vector multiply y = alpha A \e x plus beta \a y
231/// where A[m x m] is symmetric banded
232static inline void Sbmv(const char &uplo, const int &m, const int &k,
233 const float &alpha, const float *a, const int &lda,
234 const float *x, const int &incx, const float &beta,
235 float *y, const int &incy)
236{
237 F77NAME(ssbmv)(uplo, m, k, alpha, a, lda, x, incx, beta, y, incy);
238}
239
240/// \brief BLAS level 2: Matrix vector multiply y = alpha A \e x plus beta \a y
241/// where A[m x m] is symmetric banded
242static inline void Dsbmv(const char &uplo, const int &m, const int &k,
243 const double &alpha, const double *a, const int &lda,
244 const double *x, const int &incx, const double &beta,
245 double *y, const int &incy)
246{
247 F77NAME(dsbmv)(uplo, m, k, alpha, a, lda, x, incx, beta, y, incy);
248}
249
250/// \brief BLAS level 2: Matrix vector multiply x = alpha A \e x where A[n x n]
251static inline void Tpmv(const char &uplo, const char &trans, const char &diag,
252 const int &n, const double *ap, double *x,
253 const int &incx)
254{
255 F77NAME(dtpmv)(uplo, trans, diag, n, ap, x, incx);
256}
257
258/// \brief BLAS level 2: Matrix vector multiply x = alpha A \e x where A[n x n]
259static inline void Tpmv(const char &uplo, const char &trans, const char &diag,
260 const int &n, const float *ap, float *x,
261 const int &incx)
262{
263 F77NAME(stpmv)(uplo, trans, diag, n, ap, x, incx);
264}
265
266/// \brief BLAS level 2: Matrix vector multiply x = alpha A \e x where A[n x n]
267static inline void Dtpmv(const char &uplo, const char &trans, const char &diag,
268 const int &n, const double *ap, double *x,
269 const int &incx)
270{
271 F77NAME(dtpmv)(uplo, trans, diag, n, ap, x, incx);
272}
273
274/// \brief BLAS level 2: Matrix vector multiply A = alpha*x*y**T + A
275/// where A[m x n]
276static inline void Ger(const int &m, const int &n, const double &alpha,
277 const double *x, const int &incx, const double *y,
278 const int &incy, double *a, const int &lda)
279{
280 F77NAME(dger)(m, n, alpha, x, incx, y, incy, a, lda);
281}
282
283/// \brief BLAS level 2: Matrix vector multiply A = alpha*x*y**T + A
284/// where A[m x n]
285static inline void Ger(const int &m, const int &n, const float &alpha,
286 const float *x, const int &incx, const float *y,
287 const int &incy, float *a, const int &lda)
288{
289 F77NAME(sger)(m, n, alpha, x, incx, y, incy, a, lda);
290}
291
292/// \brief BLAS level 3: Matrix-matrix multiply C = A x B where op(A)[m x k],
293/// op(B)[k x n], C[m x n]
294/// DGEMM performs one of the matrix-matrix operations:
295/// C := alpha*op( A )*op( B ) + beta*C,
296static inline void Gemm(const char &transa, const char &transb, const int &m,
297 const int &n, const int &k, const double &alpha,
298 const double *a, const int &lda, const double *b,
299 const int &ldb, const double &beta, double *c,
300 const int &ldc)
301{
303 (transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);
304}
305
306/// \brief BLAS level 3: Matrix-matrix multiply C = A x B where op(A)[m x k],
307/// op(B)[k x n], C[m x n]
308/// DGEMM performs one of the matrix-matrix operations:
309/// C := alpha*op( A )*op( B ) + beta*C,
310static inline void Gemm(const char &transa, const char &transb, const int &m,
311 const int &n, const int &k, const float &alpha,
312 const float *a, const int &lda, const float *b,
313 const int &ldb, const float &beta, float *c,
314 const int &ldc)
315{
317 (transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);
318}
319
320/// \brief BLAS level 3: Matrix-matrix multiply C = A x B
321/// where op(A)[m x k], op(B)[k x n], C[m x n]
322/// DGEMM performs one of the matrix-matrix operations:
323/// C := alpha*op( A )*op( B ) + beta*C,
324static inline void Dgemm(const char &transa, const char &transb, const int &m,
325 const int &n, const int &k, const double &alpha,
326 const double *a, const int &lda, const double *b,
327 const int &ldb, const double &beta, double *c,
328 const int &ldc)
329{
331 (transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc);
332}
333
334// \brief Wrapper to mutliply two (row major) matrices together C =
335// a*A*B + b*C
336static inline void Cdgemm(const int M, const int N, const int K, const double a,
337 const double *A, [[maybe_unused]] const int ldA,
338 const double *B, [[maybe_unused]] const int ldB,
339 const double b, double *C,
340 [[maybe_unused]] const int ldC)
341{
342 Dgemm('N', 'N', N, M, K, a, B, N, A, K, b, C, N);
343}
344} // namespace Blas
345#endif // NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_BLAS_HPP
#define F77NAME(x)
Fortran routines need an underscore.
Definition TransF77.hpp:46
Definition Blas.hpp:43
static void Dgemv(const char &trans, const int &m, const int &n, const double &alpha, const double *a, const int &lda, const double *x, const int &incx, const double &beta, double *y, const int &incy)
BLAS level 2: Matrix vector multiply y = alpha A x plus beta y where A[m x n].
Definition Blas.hpp:152
static void Dgbmv(const char &trans, const int &m, const int &n, const int &kl, const int &ku, const double &alpha, const double *a, const int &lda, const double *x, const int &incx, const double &beta, double *y, const int &incy)
BLAS level 2: Matrix vector multiply y = alpha A x plus beta y where A[m x n] is banded.
Definition Blas.hpp:184
void F77NAME() daxpy(const int &n, const double &alpha, const double *x, const int &incx, const double *y, const int &incy)
static void Dscal(const int &n, const double &alpha, double *x, const int &incx)
BLAS level 1: x = alpha x.
Definition Blas.hpp:124
static void Sbmv(const char &uplo, const int &m, const int &k, const double &alpha, const double *a, const int &lda, const double *x, const int &incx, const double &beta, double *y, const int &incy)
BLAS level 2: Matrix vector multiply y = alpha A x plus beta y where A[m x m] is symmetric banded.
Definition Blas.hpp:222
static void Gemm(const char &transa, const char &transb, const int &m, const int &n, const int &k, const double &alpha, const double *a, const int &lda, const double *b, const int &ldb, const double &beta, double *c, const int &ldc)
BLAS level 3: Matrix-matrix multiply C = A x B where op(A)[m x k], op(B)[k x n], C[m x n] DGEMM perfo...
Definition Blas.hpp:296
void F77NAME() dtpmv(const char &uplo, const char &trans, const char &diag, const int &n, const double *ap, double *x, const int &incx)
void F77NAME() stpmv(const char &uplo, const char &trans, const char &diag, const int &n, const float *ap, float *x, const int &incx)
static void Gemv(const char &trans, const int &m, const int &n, const double &alpha, const double *a, const int &lda, const double *x, const int &incx, const double &beta, double *y, const int &incy)
BLAS level 2: Matrix vector multiply y = alpha A x plus beta y where A[m x n].
Definition Blas.hpp:132
void F77NAME() dspmv(const char &uplo, const int &n, const double &alpha, const double *a, const double *x, const int &incx, const double &beta, double *y, const int &incy)
void F77NAME() dscal(const int &n, const double &alpha, double *x, const int &incx)
static void Gbmv(const char &trans, const int &m, const int &n, const int &kl, const int &ku, const double &alpha, const double *a, const int &lda, const double *x, const int &incx, const double &beta, double *y, const int &incy)
BLAS level 2: Matrix vector multiply y = alpha A x plus beta y where A[m x n] is banded.
Definition Blas.hpp:162
static void Dsbmv(const char &uplo, const int &m, const int &k, const double &alpha, const double *a, const int &lda, const double *x, const int &incx, const double &beta, double *y, const int &incy)
BLAS level 2: Matrix vector multiply y = alpha A x plus beta y where A[m x m] is symmetric banded.
Definition Blas.hpp:242
void F77NAME() ssbmv(const char &uplo, const int &m, const int &k, const float &alpha, const float *a, const int &lda, const float *x, const int &incx, const float &beta, float *y, const int &incy)
void F77NAME() dsbmv(const char &uplo, const int &m, const int &k, const double &alpha, const double *a, const int &lda, const double *x, const int &incx, const double &beta, double *y, const int &incy)
void F77NAME() sspmv(const char &uplo, const int &n, const float &alpha, const float *a, const float *x, const int &incx, const float &beta, float *y, const int &incy)
void F77NAME() sgbmv(const char &trans, const int &m, const int &n, const int &kl, const int &ku, const float &alpha, const float *a, const int &lda, const float *x, const int &incx, const float &beta, float *y, const int &incy)
void F77NAME() sger(const int &m, const int &n, const float &alpha, const float *x, const int &incx, const float *y, const int &incy, float *a, const int &lda)
void F77NAME() sgemv(const char &trans, const int &m, const int &n, const float &alpha, const float *a, const int &lda, const float *x, const int &incx, const float &beta, float *y, const int &incy)
void F77NAME() dgbmv(const char &trans, const int &m, const int &n, const int &kl, const int &ku, const double &alpha, const double *a, const int &lda, const double *x, const int &incx, const double &beta, double *y, const int &incy)
void F77NAME() dgemm(const char &trans, const char &transb, const int &m1, const int &n, const int &k, const double &alpha, const double *a, const int &lda, const double *b, const int &ldb, const double &beta, double *c, const int &ldc)
void F77NAME() dgemv(const char &trans, const int &m, const int &n, const double &alpha, const double *a, const int &lda, const double *x, const int &incx, const double &beta, double *y, const int &incy)
static void Cdgemm(const int M, const int N, const int K, const double a, const double *A, const int ldA, const double *B, const int ldB, const double b, double *C, const int ldC)
Definition Blas.hpp:336
static void Dgemm(const char &transa, const char &transb, const int &m, const int &n, const int &k, const double &alpha, const double *a, const int &lda, const double *b, const int &ldb, const double &beta, double *c, const int &ldc)
BLAS level 3: Matrix-matrix multiply C = A x B where op(A)[m x k], op(B)[k x n], C[m x n] DGEMM perfo...
Definition Blas.hpp:324
void F77NAME() sgemm(const char &trans, const char &transb, const int &m1, const int &n, const int &k, const float &alpha, const float *a, const int &lda, const float *b, const int &ldb, const float &beta, float *c, const int &ldc)
static void Tpmv(const char &uplo, const char &trans, const char &diag, const int &n, const double *ap, double *x, const int &incx)
BLAS level 2: Matrix vector multiply x = alpha A x where A[n x n].
Definition Blas.hpp:251
static void Dspmv(const char &uplo, const int &n, const double &alpha, const double *a, const double *x, const int &incx, const double &beta, double *y, const int &incy)
BLAS level 2: Matrix vector multiply y = alpha A x plus beta y where A[n x n] is symmetric packed.
Definition Blas.hpp:213
void F77NAME() dger(const int &m, const int &n, const double &alpha, const double *x, const int &incx, const double *y, const int &incy, double *a, const int &lda)
static void Daxpy(const int &n, const double &alpha, const double *x, const int &incx, const double *y, const int &incy)
BLAS level 1: y = alpha x plus y.
Definition Blas.hpp:117
static void Ger(const int &m, const int &n, const double &alpha, const double *x, const int &incx, const double *y, const int &incy, double *a, const int &lda)
BLAS level 2: Matrix vector multiply A = alpha*x*y**T + A where A[m x n].
Definition Blas.hpp:276
static void Spmv(const char &uplo, const int &n, const double &alpha, const double *a, const double *x, const int &incx, const double &beta, double *y, const int &incy)
BLAS level 2: Matrix vector multiply y = alpha A x plus beta y where A[n x n] is symmetric packed.
Definition Blas.hpp:195
static void Dtpmv(const char &uplo, const char &trans, const char &diag, const int &n, const double *ap, double *x, const int &incx)
BLAS level 2: Matrix vector multiply x = alpha A x where A[n x n].
Definition Blas.hpp:267