10 #include "etl/expr/base_temporary_expr.hpp" 39 template <etl_4d A, etl_4d B,
bool Flipped>
63 explicit dyn_conv_4d_backward_expr(A
a, B
b,
size_t s1,
size_t s2,
size_t p1,
size_t p2) :
base_type(a, b), s1(s1), s2(s2), p1(p1), p2(p2) {
72 template <etl_4d I, etl_4d K, etl_4d C>
73 void check([[maybe_unused]]
const I& input, [[maybe_unused]]
const K& kernel, [[maybe_unused]]
const C& conv)
const {
74 cpp_assert(
etl::dim(conv, 0) ==
etl::dim(input, 0),
"Invalid dimensions for conv4_backward");
75 cpp_assert(
etl::dim(conv, 1) ==
etl::dim(kernel, 1),
"Invalid dimensions for conv4_backward");
76 cpp_assert(
etl::dim(input, 1) ==
etl::dim(kernel, 0),
"Invalid dimensions for conv4_backward");
78 cpp_assert(
etl::dim(conv, 2) == s1 * (
etl::dim(input, 2) - 1) +
etl::dim(kernel, 2) - 2 * p1,
"Invalid dimensions for conv2_backward");
79 cpp_assert(
etl::dim(conv, 3) == s2 * (
etl::dim(input, 3) - 1) +
etl::dim(kernel, 3) - 2 * p2,
"Invalid dimensions for conv2_backward");
90 auto& input = this->
a();
91 auto& kernel = this->
b();
93 check(input, kernel, conv);
96 const size_t k1 = etl::dim<2>(kernel);
97 const size_t k2 = etl::dim<3>(kernel);
99 if constexpr (Flipped) {
107 if (s1 == 1 && s2 == 1) {
108 if (p1 == 0 && p2 == 0) {
119 auto strided_input = impl::common::inner_pad(input, s1, s2);
121 if (p1 == 0 && p2 == 0) {
138 if (s1 == 1 && s2 == 1) {
139 if (p1 == 0 && p2 == 0) {
150 auto strided_input = impl::common::inner_pad(input, s1, s2);
152 if (p1 == 0 && p2 == 0) {
168 template <
typename L>
177 template <
typename L>
186 template <
typename L>
195 template <
typename L>
204 template <
typename L>
216 return os <<
"conv4_backward(" << expr.
_a <<
", " << expr.
_b <<
")";
224 template <
typename A,
typename B,
bool Flipped>
233 static constexpr
bool is_etl =
true;
238 static constexpr
bool is_linear =
false;
240 static constexpr
bool is_value =
false;
241 static constexpr
bool is_direct =
true;
242 static constexpr
bool is_generator =
false;
243 static constexpr
bool is_padded =
false;
244 static constexpr
bool is_aligned =
true;
245 static constexpr
bool is_temporary =
true;
254 template <vector_mode_t V>
255 static constexpr
bool vectorizable =
true;
313 template <etl_expr A, etl_expr B>
331 template <etl_expr A, etl_expr B, etl_expr C>
349 template <etl_expr A, etl_expr B>
351 A&&
a, B&&
b,
size_t s1,
size_t s2,
size_t p1,
size_t p2) {
368 template <etl_expr A, etl_expr B, etl_expr C>
void assign_mod_to(L &&lhs) const
Modulo the given left-hand-side expression.
Definition: dyn_conv_4d_backward_expr.hpp:205
static constexpr int complexity() noexcept
Estimate the complexity of computation.
Definition: dyn_conv_4d_backward_expr.hpp:297
B _b
The sub expression reference.
Definition: base_temporary_expr.hpp:534
value_t< A > value_type
The value type of the expression.
Definition: dyn_conv_4d_backward_expr.hpp:231
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
static void apply(const I &input, const K &kernel, C &&conv, size_t s1, size_t s2, size_t p1, size_t p2)
Apply the convolution.
Definition: conv_4d.hpp:380
static size_t size(const expr_t &e)
Returns the size of the expression.
Definition: dyn_conv_4d_backward_expr.hpp:280
value_t< A > value_type
The type of value of the expression.
Definition: dyn_conv_4d_backward_expr.hpp:41
static void apply(const I &input, const K &kernel, C &&conv)
Apply the convolution.
Definition: conv_4d.hpp:408
order
Storage order of a matrix.
Definition: order.hpp:15
constexpr bool cuda_enabled
Indicates if CUDA is available.
Definition: config.hpp:94
friend std::ostream & operator<<(std::ostream &os, const dyn_conv_4d_backward_expr &expr)
Print a representation of the expression on the given stream.
Definition: dyn_conv_4d_backward_expr.hpp:215
Abstract base class for temporary binary expression.
Definition: base_temporary_expr.hpp:529
std::decay_t< A > left_expr_t
The left sub expression type.
Definition: dyn_conv_4d_backward_expr.hpp:227
conv_4d_backward_expr< detail::build_type< A >, detail::build_type< B >, S1, S2, P1, P2, false > conv_4d_backward(A &&a, B &&b)
Creates an expression representing the transposed 2D convolution of a and b.
Definition: conv_4d_backward_expr.hpp:343
Expression representing a batch of transposed 2D convolution of an batch of image with a set of kerne...
Definition: dyn_conv_4d_backward_expr.hpp:40
std::add_lvalue_reference_t< B > b()
Returns the sub expression.
Definition: base_temporary_expr.hpp:593
const size_t s2
The stride of the second dimension.
Definition: dyn_conv_4d_backward_expr.hpp:55
void assign_sub_to(L &&lhs) const
Sub from the given left-hand-side expression.
Definition: dyn_conv_4d_backward_expr.hpp:178
const size_t p2
The padding of the second dimension.
Definition: dyn_conv_4d_backward_expr.hpp:57
constexpr bool is_fast
Traits to test if the given ETL expresion type is fast (sizes known at compile-time) ...
Definition: traits.hpp:588
dyn_conv_4d_backward_expr(A a, B b, size_t s1, size_t s2, size_t p1, size_t p2)
Construct a new expression.
Definition: dyn_conv_4d_backward_expr.hpp:63
Traits to get information about ETL types.
Definition: tmp.hpp:68
void check([[maybe_unused]] const I &input, [[maybe_unused]] const K &kernel, [[maybe_unused]] const C &conv) const
Assert that the convolution is done on correct dimensions.
Definition: dyn_conv_4d_backward_expr.hpp:73
Root namespace for the ETL library.
Definition: adapter.hpp:15
std::decay_t< B > right_expr_t
The right sub expression type.
Definition: dyn_conv_4d_backward_expr.hpp:228
conv_4d_backward_expr< detail::build_type< A >, detail::build_type< B >, S1, S2, P1, P2, true > conv_4d_backward_flipped(A &&a, B &&b)
Creates an expression representing the transposed 2D convolution of a and flipped b...
Definition: conv_4d_backward_expr.hpp:379
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
void assign_div_to(L &&lhs) const
Divide the given left-hand-side expression.
Definition: dyn_conv_4d_backward_expr.hpp:196
static constexpr bool gpu_computable
Indicates if the temporary expression can be directly evaluated using only GPU.
Definition: dyn_conv_4d_backward_expr.hpp:52
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
static size_t dim(const expr_t &e, size_t d)
Returns the dth dimension of the expression.
Definition: dyn_conv_4d_backward_expr.hpp:263
void assign_mul_to(L &&lhs) const
Multiply the given left-hand-side expression.
Definition: dyn_conv_4d_backward_expr.hpp:187
static constexpr auto storage_order
The sub storage order.
Definition: dyn_conv_4d_backward_expr.hpp:46
const size_t s1
The stride of the first dimension.
Definition: dyn_conv_4d_backward_expr.hpp:54
void std_mod_evaluate(Expr &&expr, Result &&result)
Compound modulo evaluation of the expr into result.
Definition: evaluator.hpp:1271
static void apply(const I &input, const K &kernel, C &&conv)
Apply the convolution.
Definition: conv_4d.hpp:448
static constexpr size_t dimensions()
Returns the number of dimensions of the expression.
Definition: dyn_conv_4d_backward_expr.hpp:289
void std_mul_evaluate(Expr &&expr, Result &&result)
Compound multiply evaluation of the expr into result.
Definition: evaluator.hpp:1233
const size_t p1
The padding of the first dimension.
Definition: dyn_conv_4d_backward_expr.hpp:56
constexpr bool is_transformer
Traits indicating if the given ETL type is a transformer expression.
Definition: traits.hpp:297
Selector for the convolution implementations.
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
void assign_to(C &&conv) const
Assign to a matrix.
Definition: dyn_conv_4d_backward_expr.hpp:87
void std_sub_evaluate(Expr &&expr, Result &&result)
Compound subtract evaluation of the expr into result.
Definition: evaluator.hpp:1214
constexpr bool is_thread_safe
Traits to test if the given ETL expresion type is thread safe.
Definition: traits.hpp:687
static void apply(const I &input, const K &kernel, C &&conv, size_t s1, size_t s2, size_t p1, size_t p2)
Apply the convolution.
Definition: conv_4d.hpp:352
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
void assign_add_to(L &&lhs) const
Add to the given left-hand-side expression.
Definition: dyn_conv_4d_backward_expr.hpp:169
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