Expression Templates Library (ETL)
logistic_noise.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 // logistic_noise prepare
26 
30 #ifdef EGBLAS_HAS_LOGISTIC_NOISE_PREPARE
31 static constexpr bool has_logistic_noise_prepare = true;
32 #else
33 static constexpr bool has_logistic_noise_prepare = false;
34 #endif
35 
40 inline void* logistic_noise_prepare() {
41 #ifdef EGBLAS_HAS_LOGISTIC_NOISE_PREPARE
42  inc_counter("egblas");
43  return egblas_logistic_noise_prepare();
44 #else
45  cpp_unreachable("Invalid call to egblas::logistic_noise_prepare");
46  return nullptr;
47 #endif
48 }
49 
53 #ifdef EGBLAS_HAS_LOGISTIC_NOISE_PREPARE_SEED
54 static constexpr bool has_logistic_noise_prepare_seed = true;
55 #else
56 static constexpr bool has_logistic_noise_prepare_seed = false;
57 #endif
58 
64 inline void* logistic_noise_prepare_seed([[maybe_unused]] size_t seed) {
65 #ifdef EGBLAS_HAS_LOGISTIC_NOISE_PREPARE_SEED
66  inc_counter("egblas");
67  return egblas_logistic_noise_prepare_seed(seed);
68 #else
69  cpp_unreachable("Invalid call to egblas::logistic_noise_prepare_seed");
70  return nullptr;
71 #endif
72 }
73 
77 #ifdef EGBLAS_HAS_LOGISTIC_NOISE_RELEASE
78 static constexpr bool has_logistic_noise_release = true;
79 #else
80 static constexpr bool has_logistic_noise_release = false;
81 #endif
82 
88 inline void logistic_noise_release([[maybe_unused]] void* state) {
89 #ifdef EGBLAS_HAS_LOGISTIC_NOISE_RELEASE
90  inc_counter("egblas");
91  egblas_logistic_noise_release(state);
92 #else
93  cpp_unreachable("Invalid call to egblas::logistic_noise_release");
94 #endif
95 }
96 
97 // logistic_noise
98 
102 #ifdef EGBLAS_HAS_SLOGISTIC_NOISE
103 static constexpr bool has_slogistic_noise = true;
104 #else
105 static constexpr bool has_slogistic_noise = false;
106 #endif
107 
117 inline void logistic_noise([[maybe_unused]] size_t n,
118  [[maybe_unused]] float alpha,
119  [[maybe_unused]] const float* A,
120  [[maybe_unused]] size_t lda,
121  [[maybe_unused]] float* C,
122  [[maybe_unused]] size_t ldc) {
123 #ifdef EGBLAS_HAS_SLOGISTIC_NOISE
124  inc_counter("egblas");
125  egblas_slogistic_noise(n, alpha, A, lda, C, ldc);
126 #else
127  cpp_unreachable("Invalid call to egblas::logistic_noise");
128 #endif
129 }
130 
134 #ifdef EGBLAS_HAS_DLOGISTIC_NOISE
135 static constexpr bool has_dlogistic_noise = true;
136 #else
137 static constexpr bool has_dlogistic_noise = false;
138 #endif
139 
149 inline void logistic_noise([[maybe_unused]] size_t n,
150  [[maybe_unused]] double alpha,
151  [[maybe_unused]] const double* A,
152  [[maybe_unused]] size_t lda,
153  [[maybe_unused]] double* C,
154  [[maybe_unused]] size_t ldc) {
155 #ifdef EGBLAS_HAS_DLOGISTIC_NOISE
156  inc_counter("egblas");
157  egblas_dlogistic_noise(n, alpha, A, lda, C, ldc);
158 #else
159  cpp_unreachable("Invalid call to egblas::logistic_noise");
160 #endif
161 }
162 
163 // logistic_noise_seed
164 
168 #ifdef EGBLAS_HAS_SLOGISTIC_NOISE_SEED
169 static constexpr bool has_slogistic_noise_seed = true;
170 #else
171 static constexpr bool has_slogistic_noise_seed = false;
172 #endif
173 
183 inline void logistic_noise_seed([[maybe_unused]] size_t n,
184  [[maybe_unused]] float alpha,
185  [[maybe_unused]] const float* A,
186  [[maybe_unused]] size_t lda,
187  [[maybe_unused]] float* C,
188  [[maybe_unused]] size_t ldc,
189  [[maybe_unused]] size_t seed) {
190 #ifdef EGBLAS_HAS_SLOGISTIC_NOISE_SEED
191  inc_counter("egblas");
192  egblas_slogistic_noise_seed(n, alpha, A, lda, C, ldc, seed);
193 #else
194  cpp_unreachable("Invalid call to egblas::logistic_noise");
195 #endif
196 }
197 
201 #ifdef EGBLAS_HAS_DLOGISTIC_NOISE_SEED
202 static constexpr bool has_dlogistic_noise_seed = true;
203 #else
204 static constexpr bool has_dlogistic_noise_seed = false;
205 #endif
206 
216 inline void logistic_noise_seed([[maybe_unused]] size_t n,
217  [[maybe_unused]] double alpha,
218  [[maybe_unused]] const double* A,
219  [[maybe_unused]] size_t lda,
220  [[maybe_unused]] double* C,
221  [[maybe_unused]] size_t ldc,
222  [[maybe_unused]] size_t seed) {
223 #ifdef EGBLAS_HAS_DLOGISTIC_NOISE_SEED
224  inc_counter("egblas");
225  egblas_dlogistic_noise_seed(n, alpha, A, lda, C, ldc, seed);
226 #else
227  cpp_unreachable("Invalid call to egblas::logistic_noise");
228 #endif
229 }
230 
231 // logistic_noise_states
232 
236 #ifdef EGBLAS_HAS_SLOGISTIC_NOISE_STATES
237 static constexpr bool has_slogistic_noise_states = true;
238 #else
239 static constexpr bool has_slogistic_noise_states = false;
240 #endif
241 
251 inline void logistic_noise_states([[maybe_unused]] size_t n,
252  [[maybe_unused]] float alpha,
253  [[maybe_unused]] const float* A,
254  [[maybe_unused]] size_t lda,
255  [[maybe_unused]] float* C,
256  [[maybe_unused]] size_t ldc,
257  [[maybe_unused]] void* states) {
258 #ifdef EGBLAS_HAS_SLOGISTIC_NOISE_STATES
259  inc_counter("egblas");
260  egblas_slogistic_noise_states(n, alpha, A, lda, C, ldc, states);
261 #else
262  cpp_unreachable("Invalid call to egblas::logistic_noise_states");
263 #endif
264 }
265 
269 #ifdef EGBLAS_HAS_DLOGISTIC_NOISE_STATES
270 static constexpr bool has_dlogistic_noise_states = true;
271 #else
272 static constexpr bool has_dlogistic_noise_states = false;
273 #endif
274 
284 inline void logistic_noise_states([[maybe_unused]] size_t n,
285  [[maybe_unused]] double alpha,
286  [[maybe_unused]] const double* A,
287  [[maybe_unused]] size_t lda,
288  [[maybe_unused]] double* C,
289  [[maybe_unused]] size_t ldc,
290  [[maybe_unused]] void* states) {
291 #ifdef EGBLAS_HAS_DLOGISTIC_NOISE_STATES
292  inc_counter("egblas");
293  egblas_dlogistic_noise_states(n, alpha, A, lda, C, ldc, states);
294 #else
295  cpp_unreachable("Invalid call to egblas::logistic_noise_states");
296 #endif
297 }
298 
299 } //end of namespace etl::impl::egblas
void logistic_noise_states([[maybe_unused]] size_t n, [[maybe_unused]] float alpha, [[maybe_unused]] const float *A, [[maybe_unused]] size_t lda, [[maybe_unused]] float *C, [[maybe_unused]] size_t ldc, [[maybe_unused]] void *states)
Wrappers for single-precision egblas logistic_noise.
Definition: logistic_noise.hpp:251
void logistic_noise_seed([[maybe_unused]] size_t n, [[maybe_unused]] float alpha, [[maybe_unused]] const float *A, [[maybe_unused]] size_t lda, [[maybe_unused]] float *C, [[maybe_unused]] size_t ldc, [[maybe_unused]] size_t seed)
Wrappers for single-precision egblas logistic_noise.
Definition: logistic_noise.hpp:183
void * logistic_noise_prepare_seed([[maybe_unused]] size_t seed)
Prepare random states for logistic_noise with the given seed.
Definition: logistic_noise.hpp:64
Definition: abs.hpp:23
auto logistic_noise(E &&value)
Add some normal noise (0, sigmoid(x)) to the given expression.
Definition: expression_builder.hpp:256
void logistic_noise_release([[maybe_unused]] void *state)
Prepare random states for logistic_noise with the given seed.
Definition: logistic_noise.hpp:88
void * logistic_noise_prepare()
Prepare random states for logistic_noise.
Definition: logistic_noise.hpp:40
void inc_counter([[maybe_unused]] const char *name)
Increase the given counter.
Definition: counters.hpp:25