10 #include "etl/expr/base_temporary_expr.hpp" 24 template <etl_2d A, etl_1d B>
53 static void check([[maybe_unused]]
const A&
a, [[maybe_unused]]
const B&
b, [[maybe_unused]]
const C& c) {
54 if constexpr (all_fast<A, B, C>) {
55 static_assert(etl::dim<1, A>() == etl::dim<0, B>(),
"Invalid dimensions for bias_add_2d");
57 static_assert(etl::dim<0, A>() == etl::dim<0, C>(),
"Invalid dimensions for bias_add_2d");
58 static_assert(etl::dim<1, A>() == etl::dim<1, C>(),
"Invalid dimensions for bias_add_2d");
60 cpp_assert(etl::dim<1>(a) == etl::dim<0>(b),
"Invalid dimensions for bias_add_2d");
62 cpp_assert(etl::dim<0>(a) == etl::dim<0>(c),
"Invalid dimensions for bias_add_2d");
63 cpp_assert(etl::dim<1>(a) == etl::dim<1>(c),
"Invalid dimensions for bias_add_2d");
82 constexpr_select
auto impl = select_impl<L>();
102 e_x.ensure_gpu_up_to_date();
103 e_b.ensure_gpu_up_to_date();
104 e_y.ensure_gpu_allocated();
106 impl::egblas::bias_add_2d(etl::dim<0>(
a), etl::dim<1>(
a), e_x.gpu_memory(), 1, e_b.gpu_memory(), 1, e_y.gpu_memory(), 1);
109 e_y.invalidate_cpu();
117 cpp_unreachable(
"Invalid bias_add_2d selection");
125 template <
typename L>
134 template <
typename L>
143 template <
typename L>
152 template <
typename L>
161 template <
typename L>
173 return os <<
"bias_add_2d(" << expr.
_a <<
"," << expr.
_b <<
")";
186 template <
typename C>
188 constexpr
bool homo = all_homogeneous<A, B, C>;
190 constexpr
bool cudnn_possible =
cudnn_enabled && all_floating<A, B, C> && homo;
192 if (homo && is_single_precision<A> && impl::egblas::has_sbias_add_2d) {
196 if (homo && is_double_precision<A> && impl::egblas::has_dbias_add_2d) {
200 if (cudnn_possible && !no_gpu) {
211 #ifdef ETL_MANUAL_SELECT 218 template <
typename C>
230 C> || !((is_single_precision<A> && impl::egblas::has_sbias_add_2d) || (is_double_precision<A> && impl::egblas::has_sbias_add_2d))
232 std::cerr <<
"Forced selection to EGBLAS bias_add implementation, but not possible for this expression" << std::endl;
241 std::cerr <<
"Forced selection to cUDNN bias_add implementation, but not possible for this expression" << std::endl;
250 std::cerr <<
"Forced selection to VEC bias_add_2d implementation, but not possible for this expression" << std::endl;
274 template <
typename C>
276 return select_default_impl<C>(
false);
287 template <
typename A,
typename B>
294 static constexpr
bool is_etl =
true;
298 static constexpr
bool is_fast = all_fast<A, B>;
299 static constexpr
bool is_linear =
true;
301 static constexpr
bool is_value =
false;
302 static constexpr
bool is_direct =
true;
303 static constexpr
bool is_generator =
false;
304 static constexpr
bool is_padded =
false;
305 static constexpr
bool is_aligned =
true;
306 static constexpr
bool is_temporary =
true;
315 template <vector_mode_t V>
316 static constexpr
bool vectorizable =
true;
323 static constexpr
size_t dim() {
324 return sub_traits::template dim<DD>();
343 return sub_traits::size(e.
_a);
350 static constexpr
size_t size() {
351 return sub_traits::size();
377 template <etl_2d E, etl_1d B>
static constexpr size_t dim()
Returns the DDth dimension of the expression.
Definition: bias_add_2d_expr.hpp:323
constexpr bool all_homogeneous
Traits to test if all the given ETL expresion types are padded.
Definition: traits.hpp:741
value_t< A > value_type
The type of value of the expression.
Definition: bias_add_2d_expr.hpp:26
std::decay_t< A > sub_expr_t
The sub expression type.
Definition: bias_add_2d_expr.hpp:290
B _b
The sub expression reference.
Definition: base_temporary_expr.hpp:534
constexpr bool is_magic_view
Traits indicating if the given ETL type is a magic view expression.
Definition: traits.hpp:311
A _a
The sub expression reference.
Definition: base_temporary_expr.hpp:533
Convolution implementations with NVidia cuDNN library.
value_t< A > value_type
The value type of the expression.
Definition: bias_add_2d_expr.hpp:292
constexpr bool vectorize_impl
Indicates if the implementations can be automatically vectorized by ETL.
Definition: config.hpp:35
constexpr bool vec_enabled
Indicates if vectorization is available in any format.
Definition: config.hpp:220
order
Storage order of a matrix.
Definition: order.hpp:15
void assign_mod_to(L &&lhs) const
Modulo the given left-hand-side expression.
Definition: bias_add_2d_expr.hpp:162
constexpr bool cuda_enabled
Indicates if CUDA is available.
Definition: config.hpp:94
Abstract base class for temporary binary expression.
Definition: base_temporary_expr.hpp:529
bias_add_impl
Enumeration describing the different implementations of bias_add.
Definition: bias_add_impl.hpp:21
Standard implementation of the outer product.
std::add_lvalue_reference_t< B > b()
Returns the sub expression.
Definition: base_temporary_expr.hpp:593
A transposition expression.
Definition: bias_add_2d_expr.hpp:25
void assign_add_to(L &&lhs) const
Add to the given left-hand-side expression.
Definition: bias_add_2d_expr.hpp:126
constexpr bool is_fast
Traits to test if the given ETL expresion type is fast (sizes known at compile-time) ...
Definition: traits.hpp:588
friend std::ostream & operator<<(std::ostream &os, const bias_add_2d_expr &expr)
Print a representation of the expression on the given stream.
Definition: bias_add_2d_expr.hpp:172
static size_t dim(const expr_t &e, size_t d)
Returns the dth dimension of the expression.
Definition: bias_add_2d_expr.hpp:333
Traits to get information about ETL types.
Definition: tmp.hpp:68
Root namespace for the ETL library.
Definition: adapter.hpp:15
static constexpr auto storage_order
The sub storage order.
Definition: bias_add_2d_expr.hpp:31
context & local_context()
Return the configuration context of the current thread.
Definition: context.hpp:50
auto dim(E &&value, size_t i) -> detail::identity_helper< E, dim_view< detail::build_identity_type< E >, D >>
Return a view representing the ith Dth dimension.
Definition: view_expression_builder.hpp:25
EGBLAS wrappers for the bias_add_2d operation.
std::conditional_t< is_etl_value< T >, const std::decay_t< T > &, std::decay_t< T > > build_type
Helper to build the type for a sub expression.
Definition: expression_helpers.hpp:24
static size_t size(const expr_t &e)
Returns the size of the expression.
Definition: bias_add_2d_expr.hpp:342
constexpr bool cudnn_enabled
Indicates if the NVIDIA CUDNN library is available for ETL.
Definition: config.hpp:114
bool cpu
Force CPU evaluation.
Definition: context.hpp:29
static void check([[maybe_unused]] const A &a, [[maybe_unused]] const B &b, [[maybe_unused]] const C &c)
Validate the transposition dimensions.
Definition: bias_add_2d_expr.hpp:53
void std_mod_evaluate(Expr &&expr, Result &&result)
Compound modulo evaluation of the expr into result.
Definition: evaluator.hpp:1271
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
Standard implementation of the bias_add computation.
void std_mul_evaluate(Expr &&expr, Result &&result)
Compound multiply evaluation of the expr into result.
Definition: evaluator.hpp:1233
constexpr bool is_transformer
Traits indicating if the given ETL type is a transformer expression.
Definition: traits.hpp:297
decltype(auto) smart_forward_gpu(E &expr)
Smart forwarding for a temporary expression that will be computed in GPU.
Definition: helpers.hpp:343
constexpr bool is_view
Traits indicating if the given ETL type is a view expression.
Definition: traits.hpp:304
static constexpr int complexity() noexcept
Estimate the complexity of computation.
Definition: bias_add_2d_expr.hpp:366
void assign_to(L &&lhs) const
Assign to a matrix of the same storage order.
Definition: bias_add_2d_expr.hpp:74
void std_sub_evaluate(Expr &&expr, Result &&result)
Compound subtract evaluation of the expr into result.
Definition: evaluator.hpp:1214
decltype(auto) smart_forward(E &expr)
Smart forwarding for a temporary expression.
Definition: helpers.hpp:323
static constexpr bool gpu_computable
Indicates if the temporary expression can be directly evaluated using only GPU.
Definition: bias_add_2d_expr.hpp:37
bias_add_2d_expr(A a, B b)
Construct a new expression.
Definition: bias_add_2d_expr.hpp:43
void assign_div_to(L &&lhs) const
Divide the given left-hand-side expression.
Definition: bias_add_2d_expr.hpp:153
constexpr bool is_thread_safe
Traits to test if the given ETL expresion type is thread safe.
Definition: traits.hpp:687
void assign_sub_to(L &&lhs) const
Sub from the given left-hand-side expression.
Definition: bias_add_2d_expr.hpp:135
typename decay_traits< E >::value_type value_t
Traits to extract the value type out of an ETL type.
Definition: tmp.hpp:81
void std_div_evaluate(Expr &&expr, Result &&result)
Compound divide evaluation of the expr into result.
Definition: evaluator.hpp:1252
void inc_counter([[maybe_unused]] const char *name)
Increase the given counter.
Definition: counters.hpp:25
std::add_lvalue_reference_t< A > a()
Returns the sub expression.
Definition: base_temporary_expr.hpp:577
static constexpr size_t dimensions()
Returns the number of dimensions of the expression.
Definition: bias_add_2d_expr.hpp:358
static constexpr size_t size()
Returns the size of the expression.
Definition: bias_add_2d_expr.hpp:350
void std_add_evaluate(Expr &&expr, Result &&result)
Compound add evaluation of the expr into result.
Definition: evaluator.hpp:1195
void assign_mul_to(L &&lhs) const
Multiply the given left-hand-side expression.
Definition: bias_add_2d_expr.hpp:144