10 #include "etl/expr/base_temporary_expr.hpp" 24 template <etl_4d 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");
57 static_assert(etl::dim<0, A>() == etl::dim<0, C>(),
"Invalid dimensions for bias_add");
58 static_assert(etl::dim<1, A>() == etl::dim<1, C>(),
"Invalid dimensions for bias_add");
59 static_assert(etl::dim<2, A>() == etl::dim<2, C>(),
"Invalid dimensions for bias_add");
60 static_assert(etl::dim<3, A>() == etl::dim<3, C>(),
"Invalid dimensions for bias_add");
62 cpp_assert(etl::dim<1>(a) == etl::dim<0>(b),
"Invalid dimensions for bias_add");
64 cpp_assert(etl::dim<0>(a) == etl::dim<0>(c),
"Invalid dimensions for bias_add");
65 cpp_assert(etl::dim<1>(a) == etl::dim<1>(c),
"Invalid dimensions for bias_add");
66 cpp_assert(etl::dim<2>(a) == etl::dim<2>(c),
"Invalid dimensions for bias_add");
67 cpp_assert(etl::dim<3>(a) == etl::dim<3>(c),
"Invalid dimensions for bias_add");
91 constexpr_select
auto impl = select_impl<L>();
111 e_x.ensure_gpu_up_to_date();
112 e_b.ensure_gpu_up_to_date();
113 e_y.ensure_gpu_allocated();
115 impl::egblas::bias_add_4d(etl::dim<0>(
a), etl::dim<1>(
a), etl::dim<2>(
a), etl::dim<3>(
a), e_x.gpu_memory(), 1, e_b.gpu_memory(), 1,
116 e_y.gpu_memory(), 1);
119 e_y.invalidate_cpu();
127 cpp_unreachable(
"Invalid bias_add selection");
183 return os <<
"bias_add(" << expr.
_a <<
"," << expr.
_b <<
")";
196 template <
typename C>
198 constexpr
bool homo = all_homogeneous<A, B, C>;
200 constexpr
bool cudnn_possible =
cudnn_enabled && all_floating<A, B, C> && homo;
202 if (homo && is_single_precision<A> && impl::egblas::has_sbias_add_4d) {
206 if (homo && is_double_precision<A> && impl::egblas::has_dbias_add_4d) {
210 if (cudnn_possible && !no_gpu) {
221 #ifdef ETL_MANUAL_SELECT 228 template <
typename C>
240 C> || !((is_single_precision<A> && impl::egblas::has_sbias_add_4d) || (is_double_precision<A> && impl::egblas::has_sbias_add_4d))
242 std::cerr <<
"Forced selection to EGBLAS bias_add implementation, but not possible for this expression" << std::endl;
251 std::cerr <<
"Forced selection to cUDNN bias_add implementation, but not possible for this expression" << std::endl;
260 std::cerr <<
"Forced selection to VEC bias_add implementation, but not possible for this expression" << std::endl;
284 template <
typename C>
286 return select_default_impl<C>(
false);
297 template <
typename A,
typename B>
304 static constexpr
bool is_etl =
true;
308 static constexpr
bool is_fast = all_fast<A, B>;
309 static constexpr
bool is_linear =
true;
311 static constexpr
bool is_value =
false;
312 static constexpr
bool is_direct =
true;
313 static constexpr
bool is_generator =
false;
314 static constexpr
bool is_padded =
false;
315 static constexpr
bool is_aligned =
true;
316 static constexpr
bool is_temporary =
true;
325 template <vector_mode_t V>
326 static constexpr
bool vectorizable =
true;
333 static constexpr
size_t dim() {
334 return sub_traits::template dim<DD>();
353 return sub_traits::size(e.
_a);
360 static constexpr
size_t size() {
361 return sub_traits::size();
387 template <etl_4d E, etl_1d B>
static size_t dim(const expr_t &e, size_t d)
Returns the dth dimension of the expression.
Definition: bias_add_4d_expr.hpp:343
constexpr bool all_homogeneous
Traits to test if all the given ETL expresion types are padded.
Definition: traits.hpp:741
static constexpr size_t size()
Returns the size of the expression.
Definition: bias_add_4d_expr.hpp:360
void assign_add_to(L &&lhs) const
Add to the given left-hand-side expression.
Definition: bias_add_4d_expr.hpp:136
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
friend std::ostream & operator<<(std::ostream &os, const bias_add_4d_expr &expr)
Print a representation of the expression on the given stream.
Definition: bias_add_4d_expr.hpp:182
Convolution implementations with NVidia cuDNN library.
void assign_sub_to(L &&lhs) const
Sub from the given left-hand-side expression.
Definition: bias_add_4d_expr.hpp:145
A transposition expression.
Definition: bias_add_4d_expr.hpp:25
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
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
std::decay_t< A > sub_expr_t
The sub expression type.
Definition: bias_add_4d_expr.hpp:300
Standard implementation of the outer product.
std::add_lvalue_reference_t< B > b()
Returns the sub expression.
Definition: base_temporary_expr.hpp:593
static constexpr bool gpu_computable
Indicates if the temporary expression can be directly evaluated using only GPU.
Definition: bias_add_4d_expr.hpp:37
constexpr bool is_fast
Traits to test if the given ETL expresion type is fast (sizes known at compile-time) ...
Definition: traits.hpp:588
bool is_evaluated() const noexcept
Indicates if the temporary has been evaluated.
Definition: base_temporary_expr.hpp:140
value_t< A > value_type
The type of value of the expression.
Definition: bias_add_4d_expr.hpp:26
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_4d_expr.hpp:53
Traits to get information about ETL types.
Definition: tmp.hpp:68
Root namespace for the ETL library.
Definition: adapter.hpp:15
context & local_context()
Return the configuration context of the current thread.
Definition: context.hpp:50
static constexpr int complexity() noexcept
Estimate the complexity of computation.
Definition: bias_add_4d_expr.hpp:376
void assign_to(L &&lhs) const
Assign to a matrix of the same storage order.
Definition: bias_add_4d_expr.hpp:78
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.
value_t< A > value_type
The value type of the expression.
Definition: bias_add_4d_expr.hpp:302
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
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
void std_mod_evaluate(Expr &&expr, Result &&result)
Compound modulo evaluation of the expr into result.
Definition: evaluator.hpp:1271
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
static constexpr size_t dim()
Returns the DDth dimension of the expression.
Definition: bias_add_4d_expr.hpp:333
void assign_div_to(L &&lhs) const
Divide the given left-hand-side expression.
Definition: bias_add_4d_expr.hpp:163
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
void assign_mod_to(L &&lhs) const
Modulo the given left-hand-side expression.
Definition: bias_add_4d_expr.hpp:172
constexpr bool is_view
Traits indicating if the given ETL type is a view expression.
Definition: traits.hpp:304
static size_t size(const expr_t &e)
Returns the size of the expression.
Definition: bias_add_4d_expr.hpp:352
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
static constexpr auto storage_order
The sub storage order.
Definition: bias_add_4d_expr.hpp:31
bias_add_4d_expr(A a, B b)
Construct a new expression.
Definition: bias_add_4d_expr.hpp:43
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
void assign_mul_to(L &&lhs) const
Multiply the given left-hand-side expression.
Definition: bias_add_4d_expr.hpp:154
constexpr bool is_thread_safe
Traits to test if the given ETL expresion type is thread safe.
Definition: traits.hpp:687
static constexpr size_t dimensions()
Returns the number of dimensions of the expression.
Definition: bias_add_4d_expr.hpp:368
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
void std_add_evaluate(Expr &&expr, Result &&result)
Compound add evaluation of the expr into result.
Definition: evaluator.hpp:1195