Expression Templates Library (ETL)
axmy.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2014-2023 Baptiste Wicht
3 // Distributed under the terms of the MIT License.
4 // (See accompanying file LICENSE or copy at
5 // http://opensource.org/licenses/MIT)
6 //=======================================================================
7 
13 #pragma once
14 
15 #ifdef ETL_EGBLAS_MODE
16 
17 #include "etl/impl/cublas/cuda.hpp"
18 
19 #include <egblas.hpp>
20 
21 #endif
22 
23 namespace etl::impl::egblas {
24 
25 #ifdef EGBLAS_HAS_SAXMY
26 static constexpr bool has_saxmy = true;
27 #else
28 static constexpr bool has_saxmy = false;
29 #endif
30 
40 inline void axmy([[maybe_unused]] size_t n,
41  [[maybe_unused]] float alpha,
42  [[maybe_unused]] const float* A,
43  [[maybe_unused]] size_t lda,
44  [[maybe_unused]] float* B,
45  [[maybe_unused]] size_t ldb) {
46 #ifdef EGBLAS_HAS_SAXMY
47  inc_counter("egblas");
48  egblas_saxmy(n, alpha, A, lda, B, ldb);
49 #else
50  cpp_unreachable("Invalid call to egblas::axmy");
51 #endif
52 }
53 
54 #ifdef EGBLAS_HAS_DAXMY
55 static constexpr bool has_daxmy = true;
56 #else
57 static constexpr bool has_daxmy = false;
58 #endif
59 
69 inline void axmy([[maybe_unused]] size_t n,
70  [[maybe_unused]] double alpha,
71  [[maybe_unused]] const double* A,
72  [[maybe_unused]] size_t lda,
73  [[maybe_unused]] double* B,
74  [[maybe_unused]] size_t ldb) {
75 #ifdef EGBLAS_HAS_DAXMY
76  inc_counter("egblas");
77  egblas_daxmy(n, alpha, A, lda, B, ldb);
78 #else
79  cpp_unreachable("Invalid call to egblas::axmy");
80 #endif
81 }
82 
83 #ifdef EGBLAS_HAS_CAXMY
84 static constexpr bool has_caxmy = true;
85 #else
86 static constexpr bool has_caxmy = false;
87 #endif
88 
98 inline void axmy([[maybe_unused]] size_t n,
99  [[maybe_unused]] std::complex<float> alpha,
100  [[maybe_unused]] const std::complex<float>* A,
101  [[maybe_unused]] size_t lda,
102  [[maybe_unused]] std::complex<float>* B,
103  [[maybe_unused]] size_t ldb) {
104 #ifdef EGBLAS_HAS_CAXMY
105  inc_counter("egblas");
106  egblas_caxmy(n, complex_cast(alpha), reinterpret_cast<cuComplex*>(A), lda, reinterpret_cast<cuComplex*>(B), ldb);
107 #else
108  cpp_unreachable("Invalid call to egblas::axmy");
109 #endif
110 }
111 
121 inline void axmy([[maybe_unused]] size_t n,
122  [[maybe_unused]] etl::complex<float> alpha,
123  [[maybe_unused]] const etl::complex<float>* A,
124  [[maybe_unused]] size_t lda,
125  [[maybe_unused]] etl::complex<float>* B,
126  [[maybe_unused]] size_t ldb) {
127 #ifdef EGBLAS_HAS_CAXMY
128  inc_counter("egblas");
129  egblas_caxmy(n, complex_cast(alpha), reinterpret_cast<cuComplex*>(A), lda, reinterpret_cast<cuComplex*>(B), ldb);
130 #else
131  cpp_unreachable("Invalid call to egblas::axmy");
132 #endif
133 }
134 
135 #ifdef EGBLAS_HAS_ZAXMY
136 static constexpr bool has_zaxmy = true;
137 #else
138 static constexpr bool has_zaxmy = false;
139 #endif
140 
150 inline void axmy([[maybe_unused]] size_t n,
151  [[maybe_unused]] std::complex<double> alpha,
152  [[maybe_unused]] const std::complex<double>* A,
153  [[maybe_unused]] size_t lda,
154  [[maybe_unused]] std::complex<double>* B,
155  [[maybe_unused]] size_t ldb) {
156 #ifdef EGBLAS_HAS_ZAXMY
157  inc_counter("egblas");
158  egblas_zaxmy(n, complex_cast(alpha), reinterpret_cast<cuDoubleComplex*>(A), lda, reinterpret_cast<cuDoubleComplex*>(B), ldb);
159 #else
160  cpp_unreachable("Invalid call to egblas::axmy");
161 #endif
162 }
163 
173 inline void axmy([[maybe_unused]] size_t n,
174  [[maybe_unused]] etl::complex<double> alpha,
175  [[maybe_unused]] const etl::complex<double>* A,
176  [[maybe_unused]] size_t lda,
177  [[maybe_unused]] etl::complex<double>* B,
178  [[maybe_unused]] size_t ldb) {
179 #ifdef EGBLAS_HAS_ZAXMY
180  inc_counter("egblas");
181  egblas_zaxmy(n, complex_cast(alpha), reinterpret_cast<cuDoubleComplex*>(A), lda, reinterpret_cast<cuDoubleComplex*>(B), ldb);
182 #else
183  cpp_unreachable("Invalid call to egblas::axmy");
184 #endif
185 }
186 
187 } //end of namespace etl::impl::egblas
Complex number implementation.
Definition: complex.hpp:31
Definition: abs.hpp:23
void axmy([[maybe_unused]] size_t n, [[maybe_unused]] float alpha, [[maybe_unused]] const float *A, [[maybe_unused]] size_t lda, [[maybe_unused]] float *B, [[maybe_unused]] size_t ldb)
Wrappers for single-precision egblas axmy operation.
Definition: axmy.hpp:40
void inc_counter([[maybe_unused]] const char *name)
Increase the given counter.
Definition: counters.hpp:25