Expression Templates Library (ETL)
scalar_mul.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_SCALAR_SMUL
26 
27 static constexpr bool has_scalar_smul = true;
28 
36 inline void scalar_mul(float* x, size_t n, size_t s, const float beta) {
37  inc_counter("egblas");
38  egblas_scalar_smul(x, n, s, beta);
39 }
40 
41 #else
42 
43 static constexpr bool has_scalar_smul = false;
44 
45 #endif
46 
47 #ifdef EGBLAS_HAS_SCALAR_DMUL
48 
49 static constexpr bool has_scalar_dmul = true;
50 
58 inline void scalar_mul(double* x, size_t n, size_t s, const double beta) {
59  inc_counter("egblas");
60  egblas_scalar_dmul(x, n, s, beta);
61 }
62 
63 #else
64 
65 static constexpr bool has_scalar_dmul = false;
66 
67 #endif
68 
69 #ifdef EGBLAS_HAS_SCALAR_CMUL
70 
71 static constexpr bool has_scalar_cmul = true;
72 
80 inline void scalar_mul(etl::complex<float>* x, size_t n, size_t s, const etl::complex<float> beta) {
81  inc_counter("egblas");
82  egblas_scalar_cmul(reinterpret_cast<cuComplex*>(x), n, s, complex_cast(beta));
83 }
84 
92 inline void scalar_mul(std::complex<float>* x, size_t n, size_t s, const std::complex<float> beta) {
93  inc_counter("egblas");
94  egblas_scalar_cmul(reinterpret_cast<cuComplex*>(x), n, s, complex_cast(beta));
95 }
96 
97 #else
98 
99 static constexpr bool has_scalar_cmul = false;
100 
101 #endif
102 
103 #ifdef EGBLAS_HAS_SCALAR_ZMUL
104 
105 static constexpr bool has_scalar_zmul = true;
106 
114 inline void scalar_mul(etl::complex<double>* x, size_t n, size_t s, const etl::complex<double> beta) {
115  inc_counter("egblas");
116  egblas_scalar_zmul(reinterpret_cast<cuDoubleComplex*>(x), n, s, complex_cast(beta));
117 }
118 
126 inline void scalar_mul(std::complex<double>* x, size_t n, size_t s, const std::complex<double> beta) {
127  inc_counter("egblas");
128  egblas_scalar_zmul(reinterpret_cast<cuDoubleComplex*>(x), n, s, complex_cast(beta));
129 }
130 
131 #else
132 
133 static constexpr bool has_scalar_zmul = false;
134 
135 #endif
136 
137 #ifndef ETL_EGBLAS_MODE
138 
146 template <typename T>
147 inline void scalar_mul([[maybe_unused]] T* x, [[maybe_unused]] size_t n, [[maybe_unused]] size_t s, [[maybe_unused]] const T beta) {
148  cpp_unreachable("Invalid call to egblas::scalar_mul");
149 }
150 
151 #endif
152 
153 } //end of namespace etl::impl::egblas
auto s(T &&value)
Force the evaluation of the given expression.
Definition: stop.hpp:18
Complex number implementation.
Definition: complex.hpp:31
void scalar_mul([[maybe_unused]] T *x, [[maybe_unused]] size_t n, [[maybe_unused]] size_t s, [[maybe_unused]] const T beta)
Muls the scalar beta to each element of the single-precision vector x.
Definition: scalar_mul.hpp:147
Definition: abs.hpp:23
void inc_counter([[maybe_unused]] const char *name)
Increase the given counter.
Definition: counters.hpp:25