Expression Templates Library (ETL)
clip_value.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 #include "etl/util/complex_cast.hpp"
19 #include "etl/util/safe_cast.hpp"
20 
21 #include <egblas.hpp>
22 
23 #endif
24 
25 namespace etl::impl::egblas {
26 
30 #ifdef EGBLAS_HAS_SCLIP_VALUE
31 static constexpr bool has_sclip_value = true;
32 #else
33 static constexpr bool has_sclip_value = false;
34 #endif
35 
45 inline void clip_value([[maybe_unused]] size_t n,
46  [[maybe_unused]] const float alpha,
47  [[maybe_unused]] float A,
48  [[maybe_unused]] float B,
49  [[maybe_unused]] float* C,
50  [[maybe_unused]] size_t ldc) {
51 #ifdef EGBLAS_HAS_SCLIP_VALUE
52  inc_counter("egblas");
53  egblas_sclip_value(n, alpha, A, B, C, ldc);
54 #else
55  cpp_unreachable("Invalid call to egblas::clip_value");
56 #endif
57 }
58 
62 #ifdef EGBLAS_HAS_DCLIP_VALUE
63 static constexpr bool has_dclip_value = true;
64 #else
65 static constexpr bool has_dclip_value = false;
66 #endif
67 
77 inline void clip_value([[maybe_unused]] size_t n,
78  [[maybe_unused]] double alpha,
79  [[maybe_unused]] double A,
80  [[maybe_unused]] double B,
81  [[maybe_unused]] double* C,
82  [[maybe_unused]] size_t ldc) {
83 #ifdef EGBLAS_HAS_DCLIP_VALUE
84  inc_counter("egblas");
85  egblas_dclip_value(n, alpha, A, B, C, ldc);
86 #else
87  cpp_unreachable("Invalid call to egblas::clip_value");
88 #endif
89 }
90 
94 #ifdef EGBLAS_HAS_CCLIP_VALUE
95 static constexpr bool has_cclip_value = true;
96 #else
97 static constexpr bool has_cclip_value = false;
98 #endif
99 
109 inline void clip_value([[maybe_unused]] size_t n,
110  [[maybe_unused]] const std::complex<float> alpha,
111  [[maybe_unused]] std::complex<float> A,
112  [[maybe_unused]] std::complex<float> B,
113  [[maybe_unused]] std::complex<float>* C,
114  [[maybe_unused]] size_t ldc) {
115 #ifdef EGBLAS_HAS_CCLIP_VALUE
116  inc_counter("egblas");
117  egblas_cclip_value(n, complex_cast(alpha), complex_cast(A), complex_cast(B), reinterpret_cast<cuComplex*>(C), ldc);
118 #else
119  cpp_unreachable("Invalid call to egblas::clip_value");
120 #endif
121 }
122 
132 inline void clip_value([[maybe_unused]] size_t n,
133  [[maybe_unused]] const etl::complex<float> alpha,
134  [[maybe_unused]] etl::complex<float> A,
135  [[maybe_unused]] etl::complex<float> B,
136  [[maybe_unused]] etl::complex<float>* C,
137  [[maybe_unused]] size_t ldc) {
138 #ifdef EGBLAS_HAS_CCLIP_VALUE
139  inc_counter("egblas");
140  egblas_cclip_value(n, complex_cast(alpha), complex_cast(A), complex_cast(B), reinterpret_cast<cuComplex*>(C), ldc);
141 #else
142  cpp_unreachable("Invalid call to egblas::clip_value");
143 #endif
144 }
145 
149 #ifdef EGBLAS_HAS_ZCLIP_VALUE
150 static constexpr bool has_zclip_value = true;
151 #else
152 static constexpr bool has_zclip_value = false;
153 #endif
154 
164 inline void clip_value([[maybe_unused]] size_t n,
165  [[maybe_unused]] const std::complex<double> alpha,
166  [[maybe_unused]] std::complex<double> A,
167  [[maybe_unused]] std::complex<double> B,
168  [[maybe_unused]] std::complex<double>* C,
169  [[maybe_unused]] size_t ldc) {
170 #ifdef EGBLAS_HAS_ZCLIP_VALUE
171  inc_counter("egblas");
172  egblas_zclip_value(n, complex_cast(alpha), complex_cast(A), complex_cast(B), reinterpret_cast<cuDoubleComplex*>(C), ldc);
173 #else
174  cpp_unreachable("Invalid call to egblas::clip_value");
175 #endif
176 }
177 
187 inline void clip_value([[maybe_unused]] size_t n,
188  [[maybe_unused]] const etl::complex<double> alpha,
189  [[maybe_unused]] etl::complex<double> A,
190  [[maybe_unused]] etl::complex<double> B,
191  [[maybe_unused]] etl::complex<double>* C,
192  [[maybe_unused]] size_t ldc) {
193 #ifdef EGBLAS_HAS_ZCLIP_VALUE
194  inc_counter("egblas");
195  egblas_zclip_value(n, complex_cast(alpha), complex_cast(A), complex_cast(B), reinterpret_cast<cuDoubleComplex*>(C), ldc);
196 #else
197  cpp_unreachable("Invalid call to egblas::clip_value");
198 #endif
199 }
200 
201 } //end of namespace etl::impl::egblas
Complex number implementation.
Definition: complex.hpp:31
Definition: abs.hpp:23
void clip_value([[maybe_unused]] size_t n, [[maybe_unused]] const float alpha, [[maybe_unused]] float A, [[maybe_unused]] float B, [[maybe_unused]] float *C, [[maybe_unused]] size_t ldc)
Wrappers for single-precision egblas clip_value operation.
Definition: clip_value.hpp:45
void inc_counter([[maybe_unused]] const char *name)
Increase the given counter.
Definition: counters.hpp:25