Expression Templates Library (ETL)
max.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 
28 #ifdef EGBLAS_HAS_SMAX
29 static constexpr bool has_smax = true;
30 #else
31 static constexpr bool has_smax = false;
32 #endif
33 
43 inline void max([[maybe_unused]] size_t n,
44  [[maybe_unused]] float alpha,
45  [[maybe_unused]] float* A,
46  [[maybe_unused]] size_t lda,
47  [[maybe_unused]] float* B,
48  [[maybe_unused]] size_t ldb) {
49 #ifdef EGBLAS_HAS_SMAX
50  inc_counter("egblas");
51  egblas_smax(n, alpha, A, lda, B, ldb);
52 #else
53  cpp_unreachable("Invalid call to egblas::max");
54 #endif
55 }
56 
60 #ifdef EGBLAS_HAS_DMAX
61 static constexpr bool has_dmax = true;
62 #else
63 static constexpr bool has_dmax = false;
64 #endif
65 
75 inline void max([[maybe_unused]] size_t n,
76  [[maybe_unused]] double alpha,
77  [[maybe_unused]] double* A,
78  [[maybe_unused]] size_t lda,
79  [[maybe_unused]] double* B,
80  [[maybe_unused]] size_t ldb) {
81 #ifdef EGBLAS_HAS_DMAX
82  inc_counter("egblas");
83  egblas_dmax(n, alpha, A, lda, B, ldb);
84 #else
85  cpp_unreachable("Invalid call to egblas::max");
86 #endif
87 }
88 
92 #ifdef EGBLAS_HAS_CMAX
93 static constexpr bool has_cmax = true;
94 #else
95 static constexpr bool has_cmax = false;
96 #endif
97 
107 inline void max([[maybe_unused]] size_t n,
108  [[maybe_unused]] std::complex<float> alpha,
109  [[maybe_unused]] std::complex<float>* A,
110  [[maybe_unused]] size_t lda,
111  [[maybe_unused]] std::complex<float>* B,
112  [[maybe_unused]] size_t ldb) {
113 #ifdef EGBLAS_HAS_CMAX
114  inc_counter("egblas");
115  egblas_cmax(n, complex_cast(alpha), reinterpret_cast<cuComplex*>(A), lda, reinterpret_cast<cuComplex*>(B), ldb);
116 #else
117  cpp_unreachable("Invalid call to egblas::max");
118 #endif
119 }
120 
130 inline void max([[maybe_unused]] size_t n,
131  [[maybe_unused]] etl::complex<float> alpha,
132  [[maybe_unused]] etl::complex<float>* A,
133  [[maybe_unused]] size_t lda,
134  [[maybe_unused]] etl::complex<float>* B,
135  [[maybe_unused]] size_t ldb) {
136 #ifdef EGBLAS_HAS_CMAX
137  inc_counter("egblas");
138  egblas_cmax(n, complex_cast(alpha), reinterpret_cast<cuComplex*>(A), lda, reinterpret_cast<cuComplex*>(B), ldb);
139 #else
140  cpp_unreachable("Invalid call to egblas::max");
141 #endif
142 }
143 
147 #ifdef EGBLAS_HAS_ZMAX
148 static constexpr bool has_zmax = true;
149 #else
150 static constexpr bool has_zmax = false;
151 #endif
152 
162 inline void max([[maybe_unused]] size_t n,
163  [[maybe_unused]] std::complex<double> alpha,
164  [[maybe_unused]] std::complex<double>* A,
165  [[maybe_unused]] size_t lda,
166  [[maybe_unused]] std::complex<double>* B,
167  [[maybe_unused]] size_t ldb) {
168 #ifdef EGBLAS_HAS_ZMAX
169  inc_counter("egblas");
170  egblas_zmax(n, complex_cast(alpha), reinterpret_cast<cuDoubleComplex*>(A), lda, reinterpret_cast<cuDoubleComplex*>(B), ldb);
171 #else
172  cpp_unreachable("Invalid call to egblas::max");
173 #endif
174 }
175 
185 inline void max([[maybe_unused]] size_t n,
186  [[maybe_unused]] etl::complex<double> alpha,
187  [[maybe_unused]] etl::complex<double>* A,
188  [[maybe_unused]] size_t lda,
189  [[maybe_unused]] etl::complex<double>* B,
190  [[maybe_unused]] size_t ldb) {
191 #ifdef EGBLAS_HAS_ZMAX
192  inc_counter("egblas");
193  egblas_zmax(n, complex_cast(alpha), reinterpret_cast<cuDoubleComplex*>(A), lda, reinterpret_cast<cuDoubleComplex*>(B), ldb);
194 #else
195  cpp_unreachable("Invalid call to egblas::max");
196 #endif
197 }
198 
202 #ifdef EGBLAS_HAS_SMAX3
203 static constexpr bool has_smax3 = true;
204 #else
205 static constexpr bool has_smax3 = false;
206 #endif
207 
217 inline void max([[maybe_unused]] size_t n,
218  [[maybe_unused]] float alpha,
219  [[maybe_unused]] float* A,
220  [[maybe_unused]] size_t lda,
221  [[maybe_unused]] float* B,
222  [[maybe_unused]] size_t ldb,
223  [[maybe_unused]] float* C,
224  [[maybe_unused]] size_t ldc) {
225 #ifdef EGBLAS_HAS_SMAX3
226  inc_counter("egblas");
227  egblas_smax(n, alpha, A, lda, B, ldb, C, ldc);
228 #else
229  cpp_unreachable("Invalid call to egblas::max");
230 #endif
231 }
232 
236 #ifdef EGBLAS_HAS_DMAX3
237 static constexpr bool has_dmax3 = true;
238 #else
239 static constexpr bool has_dmax3 = false;
240 #endif
241 
251 inline void max([[maybe_unused]] size_t n,
252  [[maybe_unused]] double alpha,
253  [[maybe_unused]] double* A,
254  [[maybe_unused]] size_t lda,
255  [[maybe_unused]] double* B,
256  [[maybe_unused]] size_t ldb,
257  [[maybe_unused]] double* C,
258  [[maybe_unused]] size_t ldc) {
259 #ifdef EGBLAS_HAS_DMAX3
260  inc_counter("egblas");
261  egblas_dmax(n, alpha, A, lda, B, ldb, C, ldc);
262 #else
263  cpp_unreachable("Invalid call to egblas::max");
264 #endif
265 }
266 
270 #ifdef EGBLAS_HAS_CMAX3
271 static constexpr bool has_cmax3 = true;
272 #else
273 static constexpr bool has_cmax3 = false;
274 #endif
275 
285 inline void max([[maybe_unused]] size_t n,
286  [[maybe_unused]] std::complex<float> alpha,
287  [[maybe_unused]] std::complex<float>* A,
288  [[maybe_unused]] size_t lda,
289  [[maybe_unused]] std::complex<float>* B,
290  [[maybe_unused]] size_t ldb,
291  [[maybe_unused]] std::complex<float>* C,
292  [[maybe_unused]] size_t ldc) {
293 #ifdef EGBLAS_HAS_CMAX3
294  inc_counter("egblas");
295  egblas_cmax(n, complex_cast(alpha), reinterpret_cast<cuComplex*>(A), lda, reinterpret_cast<cuComplex*>(B), ldb, reinterpret_cast<cuComplex*>(C), ldc);
296 #else
297  cpp_unreachable("Invalid call to egblas::max");
298 #endif
299 }
300 
310 inline void max([[maybe_unused]] size_t n,
311  [[maybe_unused]] etl::complex<float> alpha,
312  [[maybe_unused]] etl::complex<float>* A,
313  [[maybe_unused]] size_t lda,
314  [[maybe_unused]] etl::complex<float>* B,
315  [[maybe_unused]] size_t ldb,
316  [[maybe_unused]] etl::complex<float>* C,
317  [[maybe_unused]] size_t ldc) {
318 #ifdef EGBLAS_HAS_CMAX3
319  inc_counter("egblas");
320  egblas_cmax(n, complex_cast(alpha), reinterpret_cast<cuComplex*>(A), lda, reinterpret_cast<cuComplex*>(B), ldb, reinterpret_cast<cuComplex*>(C), ldc);
321 #else
322  cpp_unreachable("Invalid call to egblas::max");
323 #endif
324 }
325 
329 #ifdef EGBLAS_HAS_ZMAX3
330 static constexpr bool has_zmax3 = true;
331 #else
332 static constexpr bool has_zmax3 = false;
333 #endif
334 
344 inline void max([[maybe_unused]] size_t n,
345  [[maybe_unused]] std::complex<double> alpha,
346  [[maybe_unused]] std::complex<double>* A,
347  [[maybe_unused]] size_t lda,
348  [[maybe_unused]] std::complex<double>* B,
349  [[maybe_unused]] size_t ldb,
350  [[maybe_unused]] std::complex<double>* C,
351  [[maybe_unused]] size_t ldc) {
352 #ifdef EGBLAS_HAS_ZMAX3
353  inc_counter("egblas");
354  egblas_zmax(n, complex_cast(alpha), reinterpret_cast<cuDoubleComplex*>(A), lda, reinterpret_cast<cuDoubleComplex*>(B), ldb,
355  reinterpret_cast<cuDoubleComplex*>(C), ldc);
356 #else
357  cpp_unreachable("Invalid call to egblas::max");
358 #endif
359 }
360 
370 inline void max([[maybe_unused]] size_t n,
371  [[maybe_unused]] etl::complex<double> alpha,
372  [[maybe_unused]] etl::complex<double>* A,
373  [[maybe_unused]] size_t lda,
374  [[maybe_unused]] etl::complex<double>* B,
375  [[maybe_unused]] size_t ldb,
376  [[maybe_unused]] etl::complex<double>* C,
377  [[maybe_unused]] size_t ldc) {
378 #ifdef EGBLAS_HAS_ZMAX3
379  inc_counter("egblas");
380  egblas_zmax(n, complex_cast(alpha), reinterpret_cast<cuDoubleComplex*>(A), lda, reinterpret_cast<cuDoubleComplex*>(B), ldb,
381  reinterpret_cast<cuDoubleComplex*>(C), ldc);
382 #else
383  cpp_unreachable("Invalid call to egblas::max");
384 #endif
385 }
386 
387 } //end of namespace etl::impl::egblas
auto max(L &&lhs, R &&rhs)
Create an expression with the max value of lhs or rhs.
Definition: expression_builder.hpp:65
Complex number implementation.
Definition: complex.hpp:31
Definition: abs.hpp:23
void inc_counter([[maybe_unused]] const char *name)
Increase the given counter.
Definition: counters.hpp:25