Debian Codegraph @

packages/kokkos-kernels/blas/tpls/KokkosBlas_Host_tpl.cpp

raw
1 //@HEADER
2 // ************************************************************************
3 //
4 // Kokkos v. 4.0
5 // Copyright (2022) National Technology & Engineering
6 // Solutions of Sandia, LLC (NTESS).
7 //
8 // Under the terms of Contract DE-NA0003525 with NTESS,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12 // See https://kokkos.org/LICENSE for license information.
13 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //
15 //@HEADER
16 /// \file KokkosBlas_Host_tpl.cpp
17 /// \brief BLAS wrapper for host tpls
18 /// \author Kyungjoo Kim ([email protected])
19
20 #include "KokkosKernels_config.h"
21 #include "KokkosBlas_Host_tpl.hpp"
22
23 #if defined(KOKKOSKERNELS_ENABLE_TPL_BLAS)
24
25 using KokkosBlas::Impl::KK_INT;
26
27 /// Fortran headers
28 extern "C" {
29
30 ///
31 /// scal
32 ///
33 void F77_BLAS_MANGLE(sscal, SSCAL)(const KK_INT* N, const float* alpha,
34 /* */ float* x, const KK_INT* x_inc);
35 void F77_BLAS_MANGLE(dscal, DSCAL)(const KK_INT* N, const double* alpha,
36 /* */ double* x, const KK_INT* x_inc);
37 void F77_BLAS_MANGLE(cscal, CSCAL)(const KK_INT* N, const std::complex<float>* alpha,
38 /* */ std::complex<float>* x, const KK_INT* x_inc);
39 void F77_BLAS_MANGLE(zscal, ZSCAL)(const KK_INT* N, const std::complex<double>* alpha,
40 /* */ std::complex<double>* x, const KK_INT* x_inc);
41
42 ///
43 /// max
44 ///
45 KK_INT F77_BLAS_MANGLE(isamax, ISAMAX)(const KK_INT* N, const float* x, const KK_INT* x_inc);
46 KK_INT F77_BLAS_MANGLE(idamax, IDAMAX)(const KK_INT* N, const double* x, const KK_INT* x_inc);
47 KK_INT F77_BLAS_MANGLE(icamax, ICAMAX)(const KK_INT* N, const std::complex<float>* x, const KK_INT* x_inc);
48 KK_INT F77_BLAS_MANGLE(izamax, IZAMAX)(const KK_INT* N, const std::complex<double>* x, const KK_INT* x_inc);
49
50 ///
51 /// nrm2
52 ///
53 float F77_BLAS_MANGLE(snrm2, SNRM2)(const KK_INT* N, const float* x, const KK_INT* x_inc);
54 double F77_BLAS_MANGLE(dnrm2, DNRM2)(const KK_INT* N, const double* x, const KK_INT* x_inc);
55 float F77_BLAS_MANGLE(scnrm2, SCNRM2)(const KK_INT* N, const std::complex<float>* x, const KK_INT* x_inc);
56 double F77_BLAS_MANGLE(dznrm2, DZNRM2)(const KK_INT* N, const std::complex<double>* x, const KK_INT* x_inc);
57
58 ///
59 /// sum
60 ///
61 float F77_BLAS_MANGLE(sasum, SASUM)(const KK_INT* N, const float* x, const KK_INT* x_inc);
62 double F77_BLAS_MANGLE(dasum, DASUM)(const KK_INT* N, const double* x, const KK_INT* x_inc);
63 float F77_BLAS_MANGLE(scasum, SCASUM)(const KK_INT* N, const std::complex<float>* x, const KK_INT* x_inc);
64 double F77_BLAS_MANGLE(dzasum, DZASUM)(const KK_INT* N, const std::complex<double>* x, const KK_INT* x_inc);
65
66 ///
67 /// dot
68 ///
69 float F77_BLAS_MANGLE(sdot, SDOT)(const KK_INT* N, const float* x, const KK_INT* x_inc, const float* y,
70 const KK_INT* y_inc);
71 double F77_BLAS_MANGLE(ddot, DDOT)(const KK_INT* N, const double* x, const KK_INT* x_inc, const double* y,
72 const KK_INT* y_inc);
73 #if defined(KOKKOSKERNELS_TPL_BLAS_RETURN_COMPLEX)
74 // clang-format off
75 // For the return type, don't use std::complex, otherwise compiler will complain
76 // error: 'cdotu_' has C-linkage specified, but returns user-defined type 'std::complex' which is incompatible with C [-Werror,-Wreturn-type-c-linkage]"
77 // But with float _Complex, I got error: '_Complex' is a C99 extension [-Werror,-Wc99-extensions].
78 // So I just use a C struct.
79 // clang-format on
80 typedef struct {
81 float vals[2];
82 } _kk_float2;
83 typedef struct {
84 double vals[2];
85 } _kk_double2;
86
87 _kk_float2 F77_BLAS_MANGLE(cdotu, CDOTU)(const KK_INT* N, const std::complex<float>* x, const KK_INT* x_inc,
88 const std::complex<float>* y, const KK_INT* y_inc);
89 _kk_double2 F77_BLAS_MANGLE(zdotu, ZDOTU)(const KK_INT* N, const std::complex<double>* x, const KK_INT* x_inc,
90 const std::complex<double>* y, const KK_INT* y_inc);
91 _kk_float2 F77_BLAS_MANGLE(cdotc, CDOTC)(const KK_INT* N, const std::complex<float>* x, const KK_INT* x_inc,
92 const std::complex<float>* y, const KK_INT* y_inc);
93 _kk_double2 F77_BLAS_MANGLE(zdotc, ZDOTC)(const KK_INT* N, const std::complex<double>* x, const KK_INT* x_inc,
94 const std::complex<double>* y, const KK_INT* y_inc);
95 #else
96 void F77_BLAS_MANGLE(cdotu, CDOTU)(std::complex<float>* res, const KK_INT* N, const std::complex<float>* x,
97 const KK_INT* x_inc, const std::complex<float>* y, const KK_INT* y_inc);
98 void F77_BLAS_MANGLE(zdotu, ZDOTU)(std::complex<double>* res, const KK_INT* N, const std::complex<double>* x,
99 const KK_INT* x_inc, const std::complex<double>* y, const KK_INT* y_inc);
100 void F77_BLAS_MANGLE(cdotc, CDOTC)(std::complex<float>* res, const KK_INT* N, const std::complex<float>* x,
101 const KK_INT* x_inc, const std::complex<float>* y, const KK_INT* y_inc);
102 void F77_BLAS_MANGLE(zdotc, ZDOTC)(std::complex<double>* res, const KK_INT* N, const std::complex<double>* x,
103 const KK_INT* x_inc, const std::complex<double>* y, const KK_INT* y_inc);
104 #endif
105
106 ///
107 /// axpy
108 ///
109 void F77_BLAS_MANGLE(saxpy, SAXPY)(const KK_INT* N, const float* alpha, const float* x, const KK_INT* x_inc,
110 /* */ float* y, const KK_INT* y_inc);
111 void F77_BLAS_MANGLE(daxpy, DAXPY)(const KK_INT* N, const double* alpha, const double* x, const KK_INT* x_inc,
112 /* */ double* y, const KK_INT* y_inc);
113 void F77_BLAS_MANGLE(caxpy, CAXPY)(const KK_INT* N, const std::complex<float>* alpha, const std::complex<float>* x,
114 const KK_INT* x_inc,
115 /* */ std::complex<float>* y, const KK_INT* y_inc);
116 void F77_BLAS_MANGLE(zaxpy, ZAXPY)(const KK_INT* N, const std::complex<double>* alpha, const std::complex<double>* x,
117 const KK_INT* x_inc,
118 /* */ std::complex<double>* y, const KK_INT* y_inc);
119
120 ///
121 /// rot
122 ///
123 void F77_BLAS_MANGLE(srot, SROT)(KK_INT const* N, float* X, KK_INT const* incx, float* Y, KK_INT const* incy, float* c,
124 float* s);
125 void F77_BLAS_MANGLE(drot, DROT)(KK_INT const* N, double* X, KK_INT const* incx, double* Y, KK_INT const* incy,
126 double* c, double* s);
127 void F77_BLAS_MANGLE(crot, CROT)(KK_INT const* N, std::complex<float>* X, KK_INT const* incx, std::complex<float>* Y,
128 KK_INT const* incy, float* c, float* s);
129 void F77_BLAS_MANGLE(zrot, ZROT)(KK_INT const* N, std::complex<double>* X, KK_INT const* incx, std::complex<double>* Y,
130 KK_INT const* incy, double* c, double* s);
131
132 ///
133 /// rotg
134 ///
135 void F77_BLAS_MANGLE(srotg, SROTG)(float* a, float* b, float* c, float* s);
136 void F77_BLAS_MANGLE(drotg, DROTG)(double* a, double* b, double* c, double* s);
137 void F77_BLAS_MANGLE(crotg, CROTG)(std::complex<float>* a, std::complex<float>* b, float* c, std::complex<float>* s);
138 void F77_BLAS_MANGLE(zrotg, ZROTG)(std::complex<double>* a, std::complex<double>* b, double* c,
139 std::complex<double>* s);
140
141 ///
142 /// rotm
143 ///
144 void F77_BLAS_MANGLE(srotm, SROTM)(const KK_INT* n, float* X, const KK_INT* incx, float* Y, const KK_INT* incy,
145 float const* param);
146 void F77_BLAS_MANGLE(drotm, DROTM)(const KK_INT* n, double* X, const KK_INT* incx, double* Y, const KK_INT* incy,
147 double const* param);
148
149 ///
150 /// rotmg
151 ///
152 void F77_BLAS_MANGLE(srotmg, SROTMG)(float* d1, float* d2, float* x1, const float* y1, float* param);
153 void F77_BLAS_MANGLE(drotmg, DROTMG)(double* d1, double* d2, double* x1, const double* y1, double* param);
154
155 ///
156 /// swap
157 ///
158 void F77_BLAS_MANGLE(sswap, SSWAP)(KK_INT const* N, float* X, KK_INT const* incx, float* Y, KK_INT const* incy);
159 void F77_BLAS_MANGLE(dswap, DSWAP)(KK_INT const* N, double* X, KK_INT const* incx, double* Y, KK_INT const* incy);
160 void F77_BLAS_MANGLE(cswap, CSWAP)(KK_INT const* N, std::complex<float>* X, KK_INT const* incx, std::complex<float>* Y,
161 KK_INT const* incy);
162 void F77_BLAS_MANGLE(zswap, ZSWAP)(KK_INT const* N, std::complex<double>* X, KK_INT const* incx,
163 std::complex<double>* Y, KK_INT const* incy);
164
165 ///
166 /// Gemv
167 ///
168 void F77_BLAS_MANGLE(sgemv, SGEMV)(const char*, KK_INT*, KK_INT*, const float*, const float*, KK_INT*, const float*,
169 KK_INT*, const float*,
170 /* */ float*, KK_INT*);
171 void F77_BLAS_MANGLE(dgemv, DGEMV)(const char*, KK_INT*, KK_INT*, const double*, const double*, KK_INT*, const double*,
172 KK_INT*, const double*,
173 /* */ double*, KK_INT*);
174 void F77_BLAS_MANGLE(cgemv, CGEMV)(const char*, KK_INT*, KK_INT*, const std::complex<float>*,
175 const std::complex<float>*, KK_INT*, const std::complex<float>*, KK_INT*,
176 const std::complex<float>*,
177 /* */ std::complex<float>*, KK_INT*);
178 void F77_BLAS_MANGLE(zgemv, ZGEMV)(const char*, KK_INT*, KK_INT*, const std::complex<double>*,
179 const std::complex<double>*, KK_INT*, const std::complex<double>*, KK_INT*,
180 const std::complex<double>*,
181 /* */ std::complex<double>*, KK_INT*);
182
183 ///
184 /// Ger
185 ///
186 void F77_BLAS_MANGLE(sger, SGER)(KK_INT*, KK_INT*, const float*, const float*, KK_INT*, const float*, KK_INT*, float*,
187 KK_INT*);
188 void F77_BLAS_MANGLE(dger, DGER)(KK_INT*, KK_INT*, const double*, const double*, KK_INT*, const double*, KK_INT*,
189 double*, KK_INT*);
190 void F77_BLAS_MANGLE(cgeru, CGERU)(KK_INT*, KK_INT*, const std::complex<float>*, const std::complex<float>*, KK_INT*,
191 const std::complex<float>*, KK_INT*, std::complex<float>*, KK_INT*);
192 void F77_BLAS_MANGLE(zgeru, ZGERU)(KK_INT*, KK_INT*, const std::complex<double>*, const std::complex<double>*, KK_INT*,
193 const std::complex<double>*, KK_INT*, std::complex<double>*, KK_INT*);
194 void F77_BLAS_MANGLE(cgerc, CGERC)(KK_INT*, KK_INT*, const std::complex<float>*, const std::complex<float>*, KK_INT*,
195 const std::complex<float>*, KK_INT*, std::complex<float>*, KK_INT*);
196 void F77_BLAS_MANGLE(zgerc, ZGERC)(KK_INT*, KK_INT*, const std::complex<double>*, const std::complex<double>*, KK_INT*,
197 const std::complex<double>*, KK_INT*, std::complex<double>*, KK_INT*);
198
199 ///
200 /// Syr
201 ///
202 void F77_BLAS_MANGLE(ssyr, SSYR)(const char*, KK_INT*, const float*, const float*, KK_INT*, float*, KK_INT*);
203 void F77_BLAS_MANGLE(dsyr, DSYR)(const char*, KK_INT*, const double*, const double*, KK_INT*, double*, KK_INT*);
204 // Although there is a cgeru, there is no csyru
205 // Although there is a zgeru, there is no zsyru
206 // Although there is a cgerc, there is no csyrc, but there is cher (see below)
207 // Although there is a zgerc, there is no zsyrc, but there is zher (see below)
208
209 ///
210 /// Her
211 ///
212
213 void F77_BLAS_MANGLE(cher, CHER)(const char*, KK_INT*, const float*, const std::complex<float>*, KK_INT*,
214 /* */ std::complex<float>*, KK_INT*);
215 void F77_BLAS_MANGLE(zher, ZHER)(const char*, KK_INT*, const double*, const std::complex<double>*, KK_INT*,
216 /* */ std::complex<double>*, KK_INT*);
217
218 ///
219 /// Syr2
220 ///
221 void F77_BLAS_MANGLE(ssyr2, SSYR2)(const char*, KK_INT*, const float*, const float*, const KK_INT*, const float*,
222 KK_INT*, float*, KK_INT*);
223 void F77_BLAS_MANGLE(dsyr2, DSYR2)(const char*, KK_INT*, const double*, const double*, const KK_INT*, const double*,
224 KK_INT*, double*, KK_INT*);
225 // Although there is a cgeru, there is no csyr2u
226 // Although there is a zgeru, there is no zsyr2u
227 // Although there is a cgerc, there is no csyr2c, but there is cher2 (see below)
228 // Although there is a zgerc, there is no zsyr2c, but there is zher2 (see below)
229
230 ///
231 /// Her2
232 ///
233
234 void F77_BLAS_MANGLE(cher2, CHER2)(const char*, KK_INT*, const std::complex<float>*, const std::complex<float>*,
235 KK_INT*, const std::complex<float>*, KK_INT*,
236 /* */ std::complex<float>*, KK_INT*);
237 void F77_BLAS_MANGLE(zher2, ZHER2)(const char*, KK_INT*, const std::complex<double>*, const std::complex<double>*,
238 KK_INT*, const std::complex<double>*, KK_INT*,
239 /* */ std::complex<double>*, KK_INT*);
240
241 ///
242 /// Trsv
243 ///
244
245 void F77_BLAS_MANGLE(strsv, STRSV)(const char*, const char*, const char*, KK_INT*, const float*, KK_INT*,
246 /* */ float*, KK_INT*);
247 void F77_BLAS_MANGLE(dtrsv, DTRSV)(const char*, const char*, const char*, KK_INT*, const double*, KK_INT*,
248 /* */ double*, KK_INT*);
249 void F77_BLAS_MANGLE(ctrsv, CTRSV)(const char*, const char*, const char*, KK_INT*, const std::complex<float>*, KK_INT*,
250 /* */ std::complex<float>*, KK_INT*);
251 void F77_BLAS_MANGLE(ztrsv, ZTRSV)(const char*, const char*, const char*, KK_INT*, const std::complex<double>*, KK_INT*,
252 /* */ std::complex<double>*, KK_INT*);
253
254 ///
255 /// Gemm
256 ///
257
258 void F77_BLAS_MANGLE(sgemm, SGEMM)(const char*, const char*, KK_INT*, KK_INT*, KK_INT*, const float*, const float*,
259 KK_INT*, const float*, KK_INT*, const float*,
260 /* */ float*, KK_INT*);
261 void F77_BLAS_MANGLE(dgemm, DGEMM)(const char*, const char*, KK_INT*, KK_INT*, KK_INT*, const double*, const double*,
262 KK_INT*, const double*, KK_INT*, const double*,
263 /* */ double*, KK_INT*);
264 void F77_BLAS_MANGLE(cgemm, CGEMM)(const char*, const char*, KK_INT*, KK_INT*, KK_INT*, const std::complex<float>*,
265 const std::complex<float>*, KK_INT*, const std::complex<float>*, KK_INT*,
266 const std::complex<float>*,
267 /* */ std::complex<float>*, KK_INT*);
268 void F77_BLAS_MANGLE(zgemm, ZGEMM)(const char*, const char*, KK_INT*, KK_INT*, KK_INT*, const std::complex<double>*,
269 const std::complex<double>*, KK_INT*, const std::complex<double>*, KK_INT*,
270 const std::complex<double>*,
271 /* */ std::complex<double>*, KK_INT*);
272
273 ///
274 /// Herk
275 ///
276
277 void F77_BLAS_MANGLE(ssyrk, SSYRK)(const char*, const char*, KK_INT*, KK_INT*, const float*, const float*, KK_INT*,
278 const float*,
279 /* */ float*, KK_INT*);
280 void F77_BLAS_MANGLE(dsyrk, DSYRK)(const char*, const char*, KK_INT*, KK_INT*, const double*, const double*, KK_INT*,
281 const double*,
282 /* */ double*, KK_INT*);
283 void F77_BLAS_MANGLE(cherk, CHERK)(const char*, const char*, KK_INT*, KK_INT*, const std::complex<float>*,
284 const std::complex<float>*, KK_INT*, const std::complex<float>*,
285 /* */ std::complex<float>*, KK_INT*);
286 void F77_BLAS_MANGLE(zherk, ZHERK)(const char*, const char*, KK_INT*, KK_INT*, const std::complex<double>*,
287 const std::complex<double>*, KK_INT*, const std::complex<double>*,
288 /* */ std::complex<double>*, KK_INT*);
289
290 ///
291 /// Trmm
292 ///
293
294 void F77_BLAS_MANGLE(strmm, STRMM)(const char*, const char*, const char*, const char*, KK_INT*, KK_INT*, const float*,
295 const float*, KK_INT*,
296 /* */ float*, KK_INT*);
297 void F77_BLAS_MANGLE(dtrmm, DTRMM)(const char*, const char*, const char*, const char*, KK_INT*, KK_INT*, const double*,
298 const double*, KK_INT*,
299 /* */ double*, KK_INT*);
300 void F77_BLAS_MANGLE(ctrmm, CTRMM)(const char*, const char*, const char*, const char*, KK_INT*, KK_INT*,
301 const std::complex<float>*, const std::complex<float>*, KK_INT*,
302 /* */ std::complex<float>*, KK_INT*);
303 void F77_BLAS_MANGLE(ztrmm, ZTRMM)(const char*, const char*, const char*, const char*, KK_INT*, KK_INT*,
304 const std::complex<double>*, const std::complex<double>*, KK_INT*,
305 /* */ std::complex<double>*, KK_INT*);
306
307 ///
308 /// Trsm
309 ///
310
311 void F77_BLAS_MANGLE(strsm, STRSM)(const char*, const char*, const char*, const char*, KK_INT*, KK_INT*, const float*,
312 const float*, KK_INT*,
313 /* */ float*, KK_INT*);
314 void F77_BLAS_MANGLE(dtrsm, DTRSM)(const char*, const char*, const char*, const char*, KK_INT*, KK_INT*, const double*,
315 const double*, KK_INT*,
316 /* */ double*, KK_INT*);
317 void F77_BLAS_MANGLE(ctrsm, CTRSM)(const char*, const char*, const char*, const char*, KK_INT*, KK_INT*,
318 const std::complex<float>*, const std::complex<float>*, KK_INT*,
319 /* */ std::complex<float>*, KK_INT*);
320 void F77_BLAS_MANGLE(ztrsm, ZTRSM)(const char*, const char*, const char*, const char*, KK_INT*, KK_INT*,
321 const std::complex<double>*, const std::complex<double>*, KK_INT*,
322 /* */ std::complex<double>*, KK_INT*);
323 }
324
325 void F77_BLAS_MANGLE(sscal, SSCAL)(const KK_INT* N, const float* alpha,
326 /* */ float* x, const KK_INT* x_inc);
327 void F77_BLAS_MANGLE(dscal, DSCAL)(const KK_INT* N, const double* alpha,
328 /* */ double* x, const KK_INT* x_inc);
329 void F77_BLAS_MANGLE(cscal, CSCAL)(const KK_INT* N, const std::complex<float>* alpha,
330 /* */ std::complex<float>* x, const KK_INT* x_inc);
331 void F77_BLAS_MANGLE(zscal, ZSCAL)(const KK_INT* N, const std::complex<double>* alpha,
332 /* */ std::complex<double>* x, const KK_INT* x_inc);
333
334 #define F77_FUNC_SSCAL F77_BLAS_MANGLE(sscal, SSCAL)
335 #define F77_FUNC_DSCAL F77_BLAS_MANGLE(dscal, DSCAL)
336 #define F77_FUNC_CSCAL F77_BLAS_MANGLE(cscal, CSCAL)
337 #define F77_FUNC_ZSCAL F77_BLAS_MANGLE(zscal, ZSCAL)
338
339 #define F77_FUNC_ISAMAX F77_BLAS_MANGLE(isamax, ISAMAX)
340 #define F77_FUNC_IDAMAX F77_BLAS_MANGLE(idamax, IDAMAX)
341 #define F77_FUNC_ICAMAX F77_BLAS_MANGLE(icamax, ICAMAX)
342 #define F77_FUNC_IZAMAX F77_BLAS_MANGLE(izamax, IZAMAX)
343
344 #define F77_FUNC_SNRM2 F77_BLAS_MANGLE(snrm2, SNRM2)
345 #define F77_FUNC_DNRM2 F77_BLAS_MANGLE(dnrm2, DNRM2)
346 #define F77_FUNC_SCNRM2 F77_BLAS_MANGLE(scnrm2, SCNRM2)
347 #define F77_FUNC_DZNRM2 F77_BLAS_MANGLE(dznrm2, DZNRM2)
348
349 #define F77_FUNC_SASUM F77_BLAS_MANGLE(sasum, SASUM)
350 #define F77_FUNC_DASUM F77_BLAS_MANGLE(dasum, DASUM)
351 #define F77_FUNC_SCASUM F77_BLAS_MANGLE(scasum, SCASUM)
352 #define F77_FUNC_DZASUM F77_BLAS_MANGLE(dzasum, DZASUM)
353
354 #define F77_FUNC_SDOT F77_BLAS_MANGLE(sdot, SDOT)
355 #define F77_FUNC_DDOT F77_BLAS_MANGLE(ddot, DDOT)
356 #define F77_FUNC_CDOTU F77_BLAS_MANGLE(cdotu, CDOTU)
357 #define F77_FUNC_ZDOTU F77_BLAS_MANGLE(zdotu, ZDOTU)
358 #define F77_FUNC_CDOTC F77_BLAS_MANGLE(cdotc, CDOTC)
359 #define F77_FUNC_ZDOTC F77_BLAS_MANGLE(zdotc, ZDOTC)
360
361 #define F77_FUNC_SAXPY F77_BLAS_MANGLE(saxpy, SAXPY)
362 #define F77_FUNC_DAXPY F77_BLAS_MANGLE(daxpy, DAXPY)
363 #define F77_FUNC_CAXPY F77_BLAS_MANGLE(caxpy, CAXPY)
364 #define F77_FUNC_ZAXPY F77_BLAS_MANGLE(zaxpy, ZAXPY)
365
366 #define F77_FUNC_SROT F77_BLAS_MANGLE(srot, SROT)
367 #define F77_FUNC_DROT F77_BLAS_MANGLE(drot, DROT)
368 #define F77_FUNC_CROT F77_BLAS_MANGLE(crot, CROT)
369 #define F77_FUNC_ZROT F77_BLAS_MANGLE(zrot, ZROT)
370
371 #define F77_FUNC_SROTG F77_BLAS_MANGLE(srotg, SROTG)
372 #define F77_FUNC_DROTG F77_BLAS_MANGLE(drotg, DROTG)
373 #define F77_FUNC_CROTG F77_BLAS_MANGLE(crotg, CROTG)
374 #define F77_FUNC_ZROTG F77_BLAS_MANGLE(zrotg, ZROTG)
375
376 #define F77_FUNC_SROTM F77_BLAS_MANGLE(srotm, SROTM)
377 #define F77_FUNC_DROTM F77_BLAS_MANGLE(drotm, DROTM)
378
379 #define F77_FUNC_SROTMG F77_BLAS_MANGLE(srotmg, SROTMG)
380 #define F77_FUNC_DROTMG F77_BLAS_MANGLE(drotmg, DROTMG)
381
382 #define F77_FUNC_SSWAP F77_BLAS_MANGLE(sswap, SSWAP)
383 #define F77_FUNC_DSWAP F77_BLAS_MANGLE(dswap, DSWAP)
384 #define F77_FUNC_CSWAP F77_BLAS_MANGLE(cswap, CSWAP)
385 #define F77_FUNC_ZSWAP F77_BLAS_MANGLE(zswap, ZSWAP)
386
387 #define F77_FUNC_SGEMV F77_BLAS_MANGLE(sgemv, SGEMV)
388 #define F77_FUNC_DGEMV F77_BLAS_MANGLE(dgemv, DGEMV)
389 #define F77_FUNC_CGEMV F77_BLAS_MANGLE(cgemv, CGEMV)
390 #define F77_FUNC_ZGEMV F77_BLAS_MANGLE(zgemv, ZGEMV)
391
392 #define F77_FUNC_SGER F77_BLAS_MANGLE(sger, SGER)
393 #define F77_FUNC_DGER F77_BLAS_MANGLE(dger, DGER)
394 #define F77_FUNC_CGERU F77_BLAS_MANGLE(cgeru, CGERU)
395 #define F77_FUNC_ZGERU F77_BLAS_MANGLE(zgeru, ZGERU)
396 #define F77_FUNC_CGERC F77_BLAS_MANGLE(cgerc, CGERC)
397 #define F77_FUNC_ZGERC F77_BLAS_MANGLE(zgerc, ZGERC)
398
399 #define F77_FUNC_SSYR F77_BLAS_MANGLE(ssyr, SSYR)
400 #define F77_FUNC_DSYR F77_BLAS_MANGLE(dsyr, DSYR)
401
402 #define F77_FUNC_CHER F77_BLAS_MANGLE(cher, CHER)
403 #define F77_FUNC_ZHER F77_BLAS_MANGLE(zher, ZHER)
404
405 #define F77_FUNC_SSYR2 F77_BLAS_MANGLE(ssyr2, SSYR2)
406 #define F77_FUNC_DSYR2 F77_BLAS_MANGLE(dsyr2, DSYR2)
407
408 #define F77_FUNC_CHER2 F77_BLAS_MANGLE(cher2, CHER2)
409 #define F77_FUNC_ZHER2 F77_BLAS_MANGLE(zher2, ZHER2)
410
411 #define F77_FUNC_STRSV F77_BLAS_MANGLE(strsv, STRSV)
412 #define F77_FUNC_DTRSV F77_BLAS_MANGLE(dtrsv, DTRSV)
413 #define F77_FUNC_CTRSV F77_BLAS_MANGLE(ctrsv, CTRSV)
414 #define F77_FUNC_ZTRSV F77_BLAS_MANGLE(ztrsv, ZTRSV)
415
416 #define F77_FUNC_SGEMM F77_BLAS_MANGLE(sgemm, SGEMM)
417 #define F77_FUNC_DGEMM F77_BLAS_MANGLE(dgemm, DGEMM)
418 #define F77_FUNC_CGEMM F77_BLAS_MANGLE(cgemm, CGEMM)
419 #define F77_FUNC_ZGEMM F77_BLAS_MANGLE(zgemm, ZGEMM)
420
421 #define F77_FUNC_SSYRK F77_BLAS_MANGLE(ssyrk, SSYRK)
422 #define F77_FUNC_DSYRK F77_BLAS_MANGLE(dsyrk, DSYRK)
423 #define F77_FUNC_CHERK F77_BLAS_MANGLE(cherk, CHERK)
424 #define F77_FUNC_ZHERK F77_BLAS_MANGLE(zherk, ZHERK)
425
426 #define F77_FUNC_STRMM F77_BLAS_MANGLE(strmm, STRMM)
427 #define F77_FUNC_DTRMM F77_BLAS_MANGLE(dtrmm, DTRMM)
428 #define F77_FUNC_CTRMM F77_BLAS_MANGLE(ctrmm, CTRMM)
429 #define F77_FUNC_ZTRMM F77_BLAS_MANGLE(ztrmm, ZTRMM)
430
431 #define F77_FUNC_STRSM F77_BLAS_MANGLE(strsm, STRSM)
432 #define F77_FUNC_DTRSM F77_BLAS_MANGLE(dtrsm, DTRSM)
433 #define F77_FUNC_CTRSM F77_BLAS_MANGLE(ctrsm, CTRSM)
434 #define F77_FUNC_ZTRSM F77_BLAS_MANGLE(ztrsm, ZTRSM)
435
436 namespace KokkosBlas {
437 namespace Impl {
438
439 ///
440 /// float
441 ///
442
443 template <>
444 void HostBlas<float>::scal(KK_INT n, const float alpha,
445 /* */ float* x, KK_INT x_inc) {
446 F77_FUNC_SSCAL(&n, &alpha, x, &x_inc);
447 }
448 template <>
449 KK_INT HostBlas<float>::iamax(KK_INT n, const float* x, KK_INT x_inc) {
450 return F77_FUNC_ISAMAX(&n, x, &x_inc);
451 }
452 template <>
453 float HostBlas<float>::nrm2(KK_INT n, const float* x, KK_INT x_inc) {
454 return F77_FUNC_SNRM2(&n, x, &x_inc);
455 }
456 template <>
457 float HostBlas<float>::asum(KK_INT n, const float* x, KK_INT x_inc) {
458 return F77_FUNC_SASUM(&n, x, &x_inc);
459 }
460 template <>
461 float HostBlas<float>::dot(KK_INT n, const float* x, KK_INT x_inc, const float* y, KK_INT y_inc) {
462 return F77_FUNC_SDOT(&n, x, &x_inc, y, &y_inc);
463 }
464 template <>
465 void HostBlas<float>::axpy(KK_INT n, const float alpha, const float* x, KK_INT x_inc,
466 /* */ float* y, KK_INT y_inc) {
467 F77_FUNC_SAXPY(&n, &alpha, x, &x_inc, y, &y_inc);
468 }
469 template <>
470 void HostBlas<float>::rot(KK_INT const N, float* X, KK_INT const incx, float* Y, KK_INT const incy, float* c,
471 float* s) {
472 F77_FUNC_SROT(&N, X, &incx, Y, &incy, c, s);
473 }
474 template <>
475 void HostBlas<float>::rotg(float* a, float* b, float* c, float* s) {
476 F77_FUNC_SROTG(a, b, c, s);
477 }
478 template <>
479 void HostBlas<float>::rotm(const KK_INT n, float* X, const KK_INT incx, float* Y, const KK_INT incy,
480 const float* param) {
481 F77_FUNC_SROTM(&n, X, &incx, Y, &incy, param);
482 }
483 template <>
484 void HostBlas<float>::rotmg(float* d1, float* d2, float* x1, const float* y1, float* param) {
485 F77_FUNC_SROTMG(d1, d2, x1, y1, param);
486 }
487 template <>
488 void HostBlas<float>::swap(KK_INT const N, float* X, KK_INT const incx, float* Y, KK_INT const incy) {
489 F77_FUNC_SSWAP(&N, X, &incx, Y, &incy);
490 }
491 template <>
492 void HostBlas<float>::gemv(const char trans, KK_INT m, KK_INT n, const float alpha, const float* a, KK_INT lda,
493 const float* b, KK_INT ldb, const float beta,
494 /* */ float* c, KK_INT ldc) {
495 F77_FUNC_SGEMV(&trans, &m, &n, &alpha, a, &lda, b, &ldb, &beta, c, &ldc);
496 }
497 template <>
498 void HostBlas<float>::ger(KK_INT m, KK_INT n, const float alpha, const float* x, KK_INT incx, const float* y,
499 KK_INT incy, float* a, KK_INT lda) {
500 F77_FUNC_SGER(&m, &n, &alpha, x, &incx, y, &incy, a, &lda);
501 }
502 template <>
503 void HostBlas<float>::syr(const char uplo, KK_INT n, const float alpha, const float* x, KK_INT incx, float* a,
504 KK_INT lda) {
505 F77_FUNC_SSYR(&uplo, &n, &alpha, x, &incx, a, &lda);
506 }
507 template <>
508 void HostBlas<float>::syr2(const char uplo, KK_INT n, const float alpha, const float* x, KK_INT incx, const float* y,
509 KK_INT incy, float* a, KK_INT lda) {
510 F77_FUNC_SSYR2(&uplo, &n, &alpha, x, &incx, y, &incy, a, &lda);
511 }
512 template <>
513 void HostBlas<float>::trsv(const char uplo, const char transa, const char diag, KK_INT m, const float* a, KK_INT lda,
514 /* */ float* b, KK_INT ldb) {
515 F77_FUNC_STRSV(&uplo, &transa, &diag, &m, a, &lda, b, &ldb);
516 }
517 template <>
518 void HostBlas<float>::gemm(const char transa, const char transb, KK_INT m, KK_INT n, KK_INT k, const float alpha,
519 const float* a, KK_INT lda, const float* b, KK_INT ldb, const float beta,
520 /* */ float* c, KK_INT ldc) {
521 F77_FUNC_SGEMM(&transa, &transb, &m, &n, &k, &alpha, a, &lda, b, &ldb, &beta, c, &ldc);
522 }
523 template <>
524 void HostBlas<float>::herk(const char transa, const char transb, KK_INT n, KK_INT k, const float alpha, const float* a,
525 KK_INT lda, const float beta,
526 /* */ float* c, KK_INT ldc) {
527 F77_FUNC_SSYRK(&transa, &transb, &n, &k, &alpha, a, &lda, &beta, c, &ldc);
528 }
529 template <>
530 void HostBlas<float>::trmm(const char side, const char uplo, const char transa, const char diag, KK_INT m, KK_INT n,
531 const float alpha, const float* a, KK_INT lda,
532 /* */ float* b, KK_INT ldb) {
533 F77_FUNC_STRMM(&side, &uplo, &transa, &diag, &m, &n, &alpha, a, &lda, b, &ldb);
534 }
535 template <>
536 void HostBlas<float>::trsm(const char side, const char uplo, const char transa, const char diag, KK_INT m, KK_INT n,
537 const float alpha, const float* a, KK_INT lda,
538 /* */ float* b, KK_INT ldb) {
539 F77_FUNC_STRSM(&side, &uplo, &transa, &diag, &m, &n, &alpha, a, &lda, b, &ldb);
540 }
541
542 ///
543 /// double
544 ///
545
546 template <>
547 void HostBlas<double>::scal(KK_INT n, const double alpha,
548 /* */ double* x, KK_INT x_inc) {
549 F77_FUNC_DSCAL(&n, &alpha, x, &x_inc);
550 }
551 template <>
552 KK_INT HostBlas<double>::iamax(KK_INT n, const double* x, KK_INT x_inc) {
553 return F77_FUNC_IDAMAX(&n, x, &x_inc);
554 }
555 template <>
556 double HostBlas<double>::nrm2(KK_INT n, const double* x, KK_INT x_inc) {
557 return F77_FUNC_DNRM2(&n, x, &x_inc);
558 }
559 template <>
560 double HostBlas<double>::asum(KK_INT n, const double* x, KK_INT x_inc) {
561 return F77_FUNC_DASUM(&n, x, &x_inc);
562 }
563 template <>
564 double HostBlas<double>::dot(KK_INT n, const double* x, KK_INT x_inc, const double* y, KK_INT y_inc) {
565 return F77_FUNC_DDOT(&n, x, &x_inc, y, &y_inc);
566 }
567 template <>
568 void HostBlas<double>::axpy(KK_INT n, const double alpha, const double* x, KK_INT x_inc,
569 /* */ double* y, KK_INT y_inc) {
570 F77_FUNC_DAXPY(&n, &alpha, x, &x_inc, y, &y_inc);
571 }
572 template <>
573 void HostBlas<double>::rot(KK_INT const N, double* X, KK_INT const incx, double* Y, KK_INT const incy, double* c,
574 double* s) {
575 F77_FUNC_DROT(&N, X, &incx, Y, &incy, c, s);
576 }
577 template <>
578 void HostBlas<double>::rotg(double* a, double* b, double* c, double* s) {
579 F77_FUNC_DROTG(a, b, c, s);
580 }
581 template <>
582 void HostBlas<double>::rotm(const KK_INT n, double* X, const KK_INT incx, double* Y, const KK_INT incy,
583 const double* param) {
584 F77_FUNC_DROTM(&n, X, &incx, Y, &incy, param);
585 }
586 template <>
587 void HostBlas<double>::rotmg(double* d1, double* d2, double* x1, const double* y1, double* param) {
588 F77_FUNC_DROTMG(d1, d2, x1, y1, param);
589 }
590 template <>
591 void HostBlas<double>::swap(KK_INT const N, double* X, KK_INT const incx, double* Y, KK_INT const incy) {
592 F77_FUNC_DSWAP(&N, X, &incx, Y, &incy);
593 }
594 template <>
595 void HostBlas<double>::gemv(const char trans, KK_INT m, KK_INT n, const double alpha, const double* a, KK_INT lda,
596 const double* b, KK_INT ldb, const double beta,
597 /* */ double* c, KK_INT ldc) {
598 F77_FUNC_DGEMV(&trans, &m, &n, &alpha, a, &lda, b, &ldb, &beta, c, &ldc);
599 }
600 template <>
601 void HostBlas<double>::ger(KK_INT m, KK_INT n, const double alpha, const double* x, KK_INT incx, const double* y,
602 KK_INT incy, double* a, KK_INT lda) {
603 F77_FUNC_DGER(&m, &n, &alpha, x, &incx, y, &incy, a, &lda);
604 }
605 template <>
606 void HostBlas<double>::syr(const char uplo, KK_INT n, const double alpha, const double* x, KK_INT incx, double* a,
607 KK_INT lda) {
608 F77_FUNC_DSYR(&uplo, &n, &alpha, x, &incx, a, &lda);
609 }
610 template <>
611 void HostBlas<double>::syr2(const char uplo, KK_INT n, const double alpha, const double* x, KK_INT incx,
612 const double* y, KK_INT incy, double* a, KK_INT lda) {
613 F77_FUNC_DSYR2(&uplo, &n, &alpha, x, &incx, y, &incy, a, &lda);
614 }
615 template <>
616 void HostBlas<double>::trsv(const char uplo, const char transa, const char diag, KK_INT m, const double* a, KK_INT lda,
617 /* */ double* b, KK_INT ldb) {
618 F77_FUNC_DTRSV(&uplo, &transa, &diag, &m, a, &lda, b, &ldb);
619 }
620 template <>
621 void HostBlas<double>::gemm(const char transa, const char transb, KK_INT m, KK_INT n, KK_INT k, const double alpha,
622 const double* a, KK_INT lda, const double* b, KK_INT ldb, const double beta,
623 /* */ double* c, KK_INT ldc) {
624 F77_FUNC_DGEMM(&transa, &transb, &m, &n, &k, &alpha, a, &lda, b, &ldb, &beta, c, &ldc);
625 }
626 template <>
627 void HostBlas<double>::herk(const char transa, const char transb, KK_INT n, KK_INT k, const double alpha,
628 const double* a, KK_INT lda, const double beta,
629 /* */ double* c, KK_INT ldc) {
630 F77_FUNC_DSYRK(&transa, &transb, &n, &k, &alpha, a, &lda, &beta, c, &ldc);
631 }
632 template <>
633 void HostBlas<double>::trmm(const char side, const char uplo, const char transa, const char diag, KK_INT m, KK_INT n,
634 const double alpha, const double* a, KK_INT lda,
635 /* */ double* b, KK_INT ldb) {
636 F77_FUNC_DTRMM(&side, &uplo, &transa, &diag, &m, &n, &alpha, a, &lda, b, &ldb);
637 }
638 template <>
639 void HostBlas<double>::trsm(const char side, const char uplo, const char transa, const char diag, KK_INT m, KK_INT n,
640 const double alpha, const double* a, KK_INT lda,
641 /* */ double* b, KK_INT ldb) {
642 F77_FUNC_DTRSM(&side, &uplo, &transa, &diag, &m, &n, &alpha, a, &lda, b, &ldb);
643 }
644
645 ///
646 /// std::complex<float>
647 ///
648
649 template <>
650 void HostBlas<std::complex<float> >::scal(KK_INT n, const std::complex<float> alpha,
651 /* */ std::complex<float>* x, KK_INT x_inc) {
652 F77_FUNC_CSCAL(&n, &alpha, x, &x_inc);
653 }
654 template <>
655 KK_INT HostBlas<std::complex<float> >::iamax(KK_INT n, const std::complex<float>* x, KK_INT x_inc) {
656 return F77_FUNC_ICAMAX(&n, x, &x_inc);
657 }
658 template <>
659 float HostBlas<std::complex<float> >::nrm2(KK_INT n, const std::complex<float>* x, KK_INT x_inc) {
660 return F77_FUNC_SCNRM2(&n, x, &x_inc);
661 }
662 template <>
663 float HostBlas<std::complex<float> >::asum(KK_INT n, const std::complex<float>* x, KK_INT x_inc) {
664 return F77_FUNC_SCASUM(&n, x, &x_inc);
665 }
666 template <>
667 std::complex<float> HostBlas<std::complex<float> >::dot(KK_INT n, const std::complex<float>* x, KK_INT x_inc,
668 const std::complex<float>* y, KK_INT y_inc) {
669 #if defined(KOKKOSKERNELS_TPL_BLAS_RETURN_COMPLEX)
670 _kk_float2 res = F77_FUNC_CDOTC(&n, x, &x_inc, y, &y_inc);
671 return std::complex<float>(res.vals[0], res.vals[1]);
672 #else
673 std::complex<float> res;
674 F77_FUNC_CDOTC(&res, &n, x, &x_inc, y, &y_inc);
675 return res;
676 #endif
677 }
678 template <>
679 void HostBlas<std::complex<float> >::axpy(KK_INT n, const std::complex<float> alpha, const std::complex<float>* x,
680 KK_INT x_inc,
681 /* */ std::complex<float>* y, KK_INT y_inc) {
682 F77_FUNC_CAXPY(&n, &alpha, x, &x_inc, y, &y_inc);
683 }
684 template <>
685 void HostBlas<std::complex<float> >::rot(KK_INT const N, std::complex<float>* X, KK_INT const incx,
686 std::complex<float>* Y, KK_INT const incy, float* c, float* s) {
687 F77_FUNC_CROT(&N, X, &incx, Y, &incy, c, s);
688 }
689 template <>
690 void HostBlas<std::complex<float> >::rotg(std::complex<float>* a, std::complex<float>* b, float* c,
691 std::complex<float>* s) {
692 F77_FUNC_CROTG(a, b, c, s);
693 }
694 template <>
695 void HostBlas<std::complex<float> >::swap(KK_INT const N, std::complex<float>* X, KK_INT const incx,
696 std::complex<float>* Y, KK_INT const incy) {
697 F77_FUNC_CSWAP(&N, X, &incx, Y, &incy);
698 }
699 template <>
700 void HostBlas<std::complex<float> >::gemv(const char trans, KK_INT m, KK_INT n, const std::complex<float> alpha,
701 const std::complex<float>* a, KK_INT lda, const std::complex<float>* b,
702 KK_INT ldb, const std::complex<float> beta,
703 /* */ std::complex<float>* c, KK_INT ldc) {
704 F77_FUNC_CGEMV(&trans, &m, &n, &alpha, (const std::complex<float>*)a, &lda, (const std::complex<float>*)b, &ldb,
705 &beta, (std::complex<float>*)c, &ldc);
706 }
707 template <>
708 void HostBlas<std::complex<float> >::geru(KK_INT m, KK_INT n, const std::complex<float> alpha,
709 const std::complex<float>* x, KK_INT incx, const std::complex<float>* y,
710 KK_INT incy, std::complex<float>* a, KK_INT lda) {
711 F77_FUNC_CGERU(&m, &n, &alpha, (const std::complex<float>*)x, &incx, (const std::complex<float>*)y, &incy,
712 (std::complex<float>*)a, &lda);
713 }
714 template <>
715 void HostBlas<std::complex<float> >::gerc(KK_INT m, KK_INT n, const std::complex<float> alpha,
716 const std::complex<float>* x, KK_INT incx, const std::complex<float>* y,
717 KK_INT incy, std::complex<float>* a, KK_INT lda) {
718 F77_FUNC_CGERC(&m, &n, &alpha, (const std::complex<float>*)x, &incx, (const std::complex<float>*)y, &incy,
719 (std::complex<float>*)a, &lda);
720 }
721 template <>
722 template <>
723 void HostBlas<std::complex<float> >::her<float>(const char uplo, KK_INT n, const float alpha,
724 const std::complex<float>* x, KK_INT incx, std::complex<float>* a,
725 KK_INT lda) {
726 F77_FUNC_CHER(&uplo, &n, &alpha, (const std::complex<float>*)x, &incx, (std::complex<float>*)a, &lda);
727 }
728 template <>
729 void HostBlas<std::complex<float> >::her2(const char uplo, KK_INT n, const std::complex<float> alpha,
730 const std::complex<float>* x, KK_INT incx, const std::complex<float>* y,
731 KK_INT incy, std::complex<float>* a, KK_INT lda) {
732 F77_FUNC_CHER2(&uplo, &n, &alpha, (const std::complex<float>*)x, &incx, (const std::complex<float>*)y, &incy,
733 (std::complex<float>*)a, &lda);
734 }
735 template <>
736 void HostBlas<std::complex<float> >::trsv(const char uplo, const char transa, const char diag, KK_INT m,
737 const std::complex<float>* a, KK_INT lda,
738 /* */ std::complex<float>* b, KK_INT ldb) {
739 F77_FUNC_CTRSV(&uplo, &transa, &diag, &m, (const std::complex<float>*)a, &lda, (std::complex<float>*)b, &ldb);
740 }
741 template <>
742 void HostBlas<std::complex<float> >::gemm(const char transa, const char transb, KK_INT m, KK_INT n, KK_INT k,
743 const std::complex<float> alpha, const std::complex<float>* a, KK_INT lda,
744 const std::complex<float>* b, KK_INT ldb, const std::complex<float> beta,
745 /* */ std::complex<float>* c, KK_INT ldc) {
746 F77_FUNC_CGEMM(&transa, &transb, &m, &n, &k, &alpha, (const std::complex<float>*)a, &lda,
747 (const std::complex<float>*)b, &ldb, &beta, (std::complex<float>*)c, &ldc);
748 }
749 template <>
750 void HostBlas<std::complex<float> >::herk(const char transa, const char transb, KK_INT n, KK_INT k,
751 const std::complex<float> alpha, const std::complex<float>* a, KK_INT lda,
752 const std::complex<float> beta,
753 /* */ std::complex<float>* c, KK_INT ldc) {
754 F77_FUNC_CHERK(&transa, &transb, &n, &k, &alpha, (const std::complex<float>*)a, &lda, &beta, (std::complex<float>*)c,
755 &ldc);
756 }
757 template <>
758 void HostBlas<std::complex<float> >::trmm(const char side, const char uplo, const char transa, const char diag,
759 KK_INT m, KK_INT n, const std::complex<float> alpha,
760 const std::complex<float>* a, KK_INT lda,
761 /* */ std::complex<float>* b, KK_INT ldb) {
762 F77_FUNC_CTRMM(&side, &uplo, &transa, &diag, &m, &n, &alpha, (const std::complex<float>*)a, &lda,
763 (std::complex<float>*)b, &ldb);
764 }
765 template <>
766 void HostBlas<std::complex<float> >::trsm(const char side, const char uplo, const char transa, const char diag,
767 KK_INT m, KK_INT n, const std::complex<float> alpha,
768 const std::complex<float>* a, KK_INT lda,
769 /* */ std::complex<float>* b, KK_INT ldb) {
770 F77_FUNC_CTRSM(&side, &uplo, &transa, &diag, &m, &n, &alpha, (const std::complex<float>*)a, &lda,
771 (std::complex<float>*)b, &ldb);
772 }
773
774 ///
775 /// std::complex<double>
776 ///
777
778 template <>
779 void HostBlas<std::complex<double> >::scal(KK_INT n, const std::complex<double> alpha,
780 /* */ std::complex<double>* x, KK_INT x_inc) {
781 F77_FUNC_ZSCAL(&n, &alpha, x, &x_inc);
782 }
783 template <>
784 KK_INT HostBlas<std::complex<double> >::iamax(KK_INT n, const std::complex<double>* x, KK_INT x_inc) {
785 return F77_FUNC_IZAMAX(&n, x, &x_inc);
786 }
787 template <>
788 double HostBlas<std::complex<double> >::nrm2(KK_INT n, const std::complex<double>* x, KK_INT x_inc) {
789 return F77_FUNC_DZNRM2(&n, x, &x_inc);
790 }
791 template <>
792 double HostBlas<std::complex<double> >::asum(KK_INT n, const std::complex<double>* x, KK_INT x_inc) {
793 // see issue 2005
794 // On some platforms with OpenBLAS < 0.3.26, dzasum on vectors less than 16 entries is producing 0.
795 // this has been observed on some (not all) systems with:
796 // clang 14.0.6 / 15.0.7 AND OpenBLAS 0.3.23 AND Sapphire Rapids CPU
797 // unfortunately, it's not clear exactly what the trigger is
798 if (n > 0 && n < 16) {
799 double ret = 0.0;
800 for (int i = 0; i < n; ++i) {
801 ret += Kokkos::abs(x[i].real()) + Kokkos::abs(x[i].imag());
802 }
803 return ret;
804 }
805 return F77_FUNC_DZASUM(&n, x, &x_inc);
806 }
807 template <>
808 std::complex<double> HostBlas<std::complex<double> >::dot(KK_INT n, const std::complex<double>* x, KK_INT x_inc,
809 const std::complex<double>* y, KK_INT y_inc) {
810 #if defined(KOKKOSKERNELS_TPL_BLAS_RETURN_COMPLEX)
811 _kk_double2 res = F77_FUNC_ZDOTC(&n, x, &x_inc, y, &y_inc);
812 return std::complex<double>(res.vals[0], res.vals[1]);
813 #else
814 std::complex<double> res;
815 F77_FUNC_ZDOTC(&res, &n, x, &x_inc, y, &y_inc);
816 return res;
817 #endif
818 }
819 template <>
820 void HostBlas<std::complex<double> >::axpy(KK_INT n, const std::complex<double> alpha, const std::complex<double>* x,
821 KK_INT x_inc,
822 /* */ std::complex<double>* y, KK_INT y_inc) {
823 F77_FUNC_ZAXPY(&n, &alpha, x, &x_inc, y, &y_inc);
824 }
825 template <>
826 void HostBlas<std::complex<double> >::rot(KK_INT const N, std::complex<double>* X, KK_INT const incx,
827 std::complex<double>* Y, KK_INT const incy, double* c, double* s) {
828 F77_FUNC_ZROT(&N, X, &incx, Y, &incy, c, s);
829 }
830 template <>
831 void HostBlas<std::complex<double> >::rotg(std::complex<double>* a, std::complex<double>* b, double* c,
832 std::complex<double>* s) {
833 F77_FUNC_ZROTG(a, b, c, s);
834 }
835 template <>
836 void HostBlas<std::complex<double> >::swap(KK_INT const N, std::complex<double>* X, KK_INT const incx,
837 std::complex<double>* Y, KK_INT const incy) {
838 F77_FUNC_ZSWAP(&N, X, &incx, Y, &incy);
839 }
840 template <>
841 void HostBlas<std::complex<double> >::gemv(const char trans, KK_INT m, KK_INT n, const std::complex<double> alpha,
842 const std::complex<double>* a, KK_INT lda, const std::complex<double>* b,
843 KK_INT ldb, const std::complex<double> beta,
844 /* */ std::complex<double>* c, KK_INT ldc) {
845 F77_FUNC_ZGEMV(&trans, &m, &n, &alpha, (const std::complex<double>*)a, &lda, (const std::complex<double>*)b, &ldb,
846 &beta, (std::complex<double>*)c, &ldc);
847 }
848 template <>
849 void HostBlas<std::complex<double> >::geru(KK_INT m, KK_INT n, const std::complex<double> alpha,
850 const std::complex<double>* x, KK_INT incx, const std::complex<double>* y,
851 KK_INT incy, std::complex<double>* a, KK_INT lda) {
852 F77_FUNC_ZGERU(&m, &n, &alpha, (const std::complex<double>*)x, &incx, (const std::complex<double>*)y, &incy,
853 (std::complex<double>*)a, &lda);
854 }
855 template <>
856 void HostBlas<std::complex<double> >::gerc(KK_INT m, KK_INT n, const std::complex<double> alpha,
857 const std::complex<double>* x, KK_INT incx, const std::complex<double>* y,
858 KK_INT incy, std::complex<double>* a, KK_INT lda) {
859 F77_FUNC_ZGERC(&m, &n, &alpha, (const std::complex<double>*)x, &incx, (const std::complex<double>*)y, &incy,
860 (std::complex<double>*)a, &lda);
861 }
862 template <>
863 template <>
864 void HostBlas<std::complex<double> >::her<double>(const char uplo, KK_INT n, const double alpha,
865 const std::complex<double>* x, KK_INT incx, std::complex<double>* a,
866 KK_INT lda) {
867 F77_FUNC_ZHER(&uplo, &n, &alpha, (const std::complex<double>*)x, &incx, (std::complex<double>*)a, &lda);
868 }
869 template <>
870 void HostBlas<std::complex<double> >::her2(const char uplo, KK_INT n, const std::complex<double> alpha,
871 const std::complex<double>* x, KK_INT incx, const std::complex<double>* y,
872 KK_INT incy, std::complex<double>* a, KK_INT lda) {
873 F77_FUNC_ZHER2(&uplo, &n, &alpha, (const std::complex<double>*)x, &incx, (const std::complex<double>*)y, &incy,
874 (std::complex<double>*)a, &lda);
875 }
876 template <>
877 void HostBlas<std::complex<double> >::trsv(const char uplo, const char transa, const char diag, KK_INT m,
878 const std::complex<double>* a, KK_INT lda,
879 /* */ std::complex<double>* b, KK_INT ldb) {
880 F77_FUNC_ZTRSV(&uplo, &transa, &diag, &m, (const std::complex<double>*)a, &lda, (std::complex<double>*)b, &ldb);
881 }
882
883 template <>
884 void HostBlas<std::complex<double> >::gemm(const char transa, const char transb, KK_INT m, KK_INT n, KK_INT k,
885 const std::complex<double> alpha, const std::complex<double>* a, KK_INT lda,
886 const std::complex<double>* b, KK_INT ldb, const std::complex<double> beta,
887 /* */ std::complex<double>* c, KK_INT ldc) {
888 F77_FUNC_ZGEMM(&transa, &transb, &m, &n, &k, &alpha, (const std::complex<double>*)a, &lda,
889 (const std::complex<double>*)b, &ldb, &beta, (std::complex<double>*)c, &ldc);
890 }
891 template <>
892 void HostBlas<std::complex<double> >::herk(const char transa, const char transb, KK_INT n, KK_INT k,
893 const std::complex<double> alpha, const std::complex<double>* a, KK_INT lda,
894 const std::complex<double> beta,
895 /* */ std::complex<double>* c, KK_INT ldc) {
896 F77_FUNC_ZHERK(&transa, &transb, &n, &k, &alpha, (const std::complex<double>*)a, &lda, &beta,
897 (std::complex<double>*)c, &ldc);
898 }
899 template <>
900 void HostBlas<std::complex<double> >::trmm(const char side, const char uplo, const char transa, const char diag,
901 KK_INT m, KK_INT n, const std::complex<double> alpha,
902 const std::complex<double>* a, KK_INT lda,
903 /* */ std::complex<double>* b, KK_INT ldb) {
904 F77_FUNC_ZTRMM(&side, &uplo, &transa, &diag, &m, &n, &alpha, (const std::complex<double>*)a, &lda,
905 (std::complex<double>*)b, &ldb);
906 }
907 template <>
908 void HostBlas<std::complex<double> >::trsm(const char side, const char uplo, const char transa, const char diag,
909 KK_INT m, KK_INT n, const std::complex<double> alpha,
910 const std::complex<double>* a, KK_INT lda,
911 /* */ std::complex<double>* b, KK_INT ldb) {
912 F77_FUNC_ZTRSM(&side, &uplo, &transa, &diag, &m, &n, &alpha, (const std::complex<double>*)a, &lda,
913 (std::complex<double>*)b, &ldb);
914 }
915
916 } // namespace Impl
917 } // namespace KokkosBlas
918 #endif // KOKKOSKERNELS_ENABLE_TPL_BLAS