Expression Templates Library (ETL)
clip.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_SCLIP
29 static constexpr bool has_sclip = true;
30 #else
31 static constexpr bool has_sclip = false;
32 #endif
33 
45 inline void clip([[maybe_unused]] size_t n, [[maybe_unused]] const float alpha, [[maybe_unused]] const float* A, [[maybe_unused]] size_t lda, [[maybe_unused]] const float* B, [[maybe_unused]] size_t ldb, [[maybe_unused]] float* C, [[maybe_unused]] size_t ldc) {
46 #ifdef EGBLAS_HAS_SCLIP
47  inc_counter("egblas");
48  egblas_sclip(n, alpha, A, lda, B, ldb, C, ldc);
49 #else
50  cpp_unreachable("Invalid call to egblas::clip");
51 #endif
52 }
53 
57 #ifdef EGBLAS_HAS_DCLIP
58 static constexpr bool has_dclip = true;
59 #else
60 static constexpr bool has_dclip = false;
61 #endif
62 
74 inline void clip([[maybe_unused]] size_t n, [[maybe_unused]] double alpha, [[maybe_unused]] const double* A, [[maybe_unused]] size_t lda, [[maybe_unused]] const double* B, [[maybe_unused]] size_t ldb, [[maybe_unused]] double* C, [[maybe_unused]] size_t ldc) {
75 #ifdef EGBLAS_HAS_DCLIP
76  inc_counter("egblas");
77  egblas_dclip(n, alpha, A, lda, B, ldb, C, ldc);
78 #else
79  cpp_unreachable("Invalid call to egblas::clip");
80 #endif
81 }
82 
86 #ifdef EGBLAS_HAS_CCLIP
87 static constexpr bool has_cclip = true;
88 #else
89 static constexpr bool has_cclip = false;
90 #endif
91 
103 inline void clip([[maybe_unused]] size_t n,
104  [[maybe_unused]] const std::complex<float> alpha,
105  [[maybe_unused]] const std::complex<float>* A,
106  [[maybe_unused]] size_t lda,
107  [[maybe_unused]] const std::complex<float>* B,
108  [[maybe_unused]] size_t ldb,
109  [[maybe_unused]] std::complex<float>* C,
110  [[maybe_unused]] size_t ldc) {
111 #ifdef EGBLAS_HAS_CCLIP
112  inc_counter("egblas");
113  egblas_cclip(n, complex_cast(alpha), reinterpret_cast<const cuComplex*>(A), lda, reinterpret_cast<const cuComplex*>(B), ldb,
114  reinterpret_cast<cuComplex*>(C), ldc);
115 #else
116  cpp_unreachable("Invalid call to egblas::clip");
117 #endif
118 }
119 
131 inline void clip([[maybe_unused]] size_t n,
132  [[maybe_unused]] const etl::complex<float> alpha,
133  [[maybe_unused]] const etl::complex<float>* A,
134  [[maybe_unused]] size_t lda,
135  [[maybe_unused]] const etl::complex<float>* B,
136  [[maybe_unused]] size_t ldb,
137  [[maybe_unused]] etl::complex<float>* C,
138  [[maybe_unused]] size_t ldc) {
139 #ifdef EGBLAS_HAS_CCLIP
140  inc_counter("egblas");
141  egblas_cclip(n, complex_cast(alpha), reinterpret_cast<const cuComplex*>(A), lda, reinterpret_cast<const cuComplex*>(B), ldb,
142  reinterpret_cast<cuComplex*>(C), ldc);
143 #else
144  cpp_unreachable("Invalid call to egblas::clip");
145 #endif
146 }
147 
151 #ifdef EGBLAS_HAS_ZCLIP
152 static constexpr bool has_zclip = true;
153 #else
154 static constexpr bool has_zclip = false;
155 #endif
156 
168 inline void clip([[maybe_unused]] size_t n,
169  [[maybe_unused]] const std::complex<double> alpha,
170  [[maybe_unused]] const std::complex<double>* A,
171  [[maybe_unused]] size_t lda,
172  [[maybe_unused]] const std::complex<double>* B,
173  [[maybe_unused]] size_t ldb,
174  [[maybe_unused]] std::complex<double>* C,
175  [[maybe_unused]] size_t ldc) {
176 #ifdef EGBLAS_HAS_ZCLIP
177  inc_counter("egblas");
178  egblas_zclip(n, complex_cast(alpha), reinterpret_cast<const cuDoubleComplex*>(A), lda, reinterpret_cast<const cuDoubleComplex*>(B), ldb,
179  reinterpret_cast<cuDoubleComplex*>(C), ldc);
180 #else
181  cpp_unreachable("Invalid call to egblas::clip");
182 #endif
183 }
184 
196 inline void clip([[maybe_unused]] size_t n,
197  [[maybe_unused]] const etl::complex<double> alpha,
198  [[maybe_unused]] const etl::complex<double>* A,
199  [[maybe_unused]] size_t lda,
200  [[maybe_unused]] const etl::complex<double>* B,
201  [[maybe_unused]] size_t ldb,
202  [[maybe_unused]] etl::complex<double>* C,
203  [[maybe_unused]] size_t ldc) {
204 #ifdef EGBLAS_HAS_ZCLIP
205  inc_counter("egblas");
206  egblas_zclip(n, complex_cast(alpha), reinterpret_cast<const cuDoubleComplex*>(A), lda, reinterpret_cast<const cuDoubleComplex*>(B), ldb,
207  reinterpret_cast<cuDoubleComplex*>(C), ldc);
208 #else
209  cpp_unreachable("Invalid call to egblas::clip");
210 #endif
211 }
212 
213 } //end of namespace etl::impl::egblas
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
auto clip(E &&value, T min, T max)
Clip each values of the ETL expression between min and max.
Definition: expression_builder.hpp:110