Expression Templates Library (ETL)
bias_add.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/counters.hpp"
19 
20 #include <egblas.hpp>
21 
22 #endif
23 
24 namespace etl::impl::egblas {
25 
29 #ifdef EGBLAS_HAS_SBIAS_ADD_2D
30 static constexpr bool has_sbias_add_2d = true;
31 #else
32 static constexpr bool has_sbias_add_2d = false;
33 #endif
34 
46 inline void bias_add_2d([[maybe_unused]] size_t m,
47  [[maybe_unused]] size_t n,
48  [[maybe_unused]] const float* x,
49  [[maybe_unused]] size_t incx,
50  [[maybe_unused]] const float* b,
51  [[maybe_unused]] size_t incb,
52  [[maybe_unused]] float* y,
53  [[maybe_unused]] size_t incy) {
54 #ifdef EGBLAS_HAS_SBIAS_ADD_2D
55  inc_counter("egblas");
56  egblas_sbias_add_2d(m, n, x, incx, b, incb, y, incy);
57 #else
58  cpp_unreachable("Invalid call to egblas::bias_add_2d");
59 #endif
60 }
61 
65 #ifdef EGBLAS_HAS_DBIAS_ADD_2D
66 static constexpr bool has_dbias_add_2d = true;
67 #else
68 static constexpr bool has_dbias_add_2d = false;
69 #endif
70 
82 inline void bias_add_2d([[maybe_unused]] size_t m,
83  [[maybe_unused]] size_t n,
84  [[maybe_unused]] const double* x,
85  [[maybe_unused]] size_t incx,
86  [[maybe_unused]] const double* b,
87  [[maybe_unused]] size_t incb,
88  [[maybe_unused]] double* y,
89  [[maybe_unused]] size_t incy) {
90 #ifdef EGBLAS_HAS_DBIAS_ADD_2D
91  inc_counter("egblas");
92  egblas_dbias_add_2d(m, n, x, incx, b, incb, y, incy);
93 #else
94  cpp_unreachable("Invalid call to egblas::bias_add_2d");
95 #endif
96 }
97 
101 #ifdef EGBLAS_HAS_SBIAS_ADD_4D
102 static constexpr bool has_sbias_add_4d = true;
103 #else
104 static constexpr bool has_sbias_add_4d = false;
105 #endif
106 
118 inline void bias_add_4d([[maybe_unused]] size_t m,
119  [[maybe_unused]] size_t n,
120  [[maybe_unused]] size_t o,
121  [[maybe_unused]] size_t p,
122  [[maybe_unused]] const float* x,
123  [[maybe_unused]] size_t incx,
124  [[maybe_unused]] const float* b,
125  [[maybe_unused]] size_t incb,
126  [[maybe_unused]] float* y,
127  [[maybe_unused]] size_t incy) {
128 #ifdef EGBLAS_HAS_SBIAS_ADD_4D
129  inc_counter("egblas");
130  egblas_sbias_add_4d(m, n, o, p, x, incx, b, incb, y, incy);
131 #else
132  cpp_unreachable("Invalid call to egblas::bias_add_4d");
133 #endif
134 }
135 
139 #ifdef EGBLAS_HAS_DBIAS_ADD_4D
140 static constexpr bool has_dbias_add_4d = true;
141 #else
142 static constexpr bool has_dbias_add_4d = false;
143 #endif
144 
156 inline void bias_add_4d([[maybe_unused]] size_t m,
157  [[maybe_unused]] size_t n,
158  [[maybe_unused]] size_t o,
159  [[maybe_unused]] size_t p,
160  [[maybe_unused]] const double* x,
161  [[maybe_unused]] size_t incx,
162  [[maybe_unused]] const double* b,
163  [[maybe_unused]] size_t incb,
164  [[maybe_unused]] double* y,
165  [[maybe_unused]] size_t incy) {
166 #ifdef EGBLAS_HAS_DBIAS_ADD_4D
167  inc_counter("egblas");
168  egblas_dbias_add_4d(m, n, o, p, x, incx, b, incb, y, incy);
169 #else
170  cpp_unreachable("Invalid call to egblas::bias_add_4d");
171 #endif
172 }
173 
174 } //end of namespace etl::impl::egblas
Definition: abs.hpp:23
bias_add_2d_expr< detail::build_type< E >, detail::build_type< B > > bias_add_2d(const E &x, const B &biases)
Returns the result of adding the bias [K] to the 4D matrix [N1, K, N2, N3].
Definition: bias_add_2d_expr.hpp:378
bias_add_4d_expr< detail::build_type< E >, detail::build_type< B > > bias_add_4d(const E &x, const B &biases)
Returns the result of adding the bias [K] to the 4D matrix [N1, K, N2, N3].
Definition: bias_add_4d_expr.hpp:388
void inc_counter([[maybe_unused]] const char *name)
Increase the given counter.
Definition: counters.hpp:25