10 #include "etl/expr/base_temporary_expr.hpp" 39 template <etl_expr A, etl_expr B,
bool Flipped>
63 explicit dyn_conv_2d_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_2d I, etl_2d K, etl_2d 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) == s1 * (
etl::dim(input, 0) - 1) +
etl::dim(kernel, 0) - 2 * p1,
"Invalid dimensions for conv2_backward");
75 cpp_assert(
etl::dim(conv, 1) == s2 * (
etl::dim(input, 1) - 1) +
etl::dim(kernel, 1) - 2 * p2,
"Invalid dimensions for conv2_backward");
86 auto& input = this->
a();
87 auto& kernel = this->
b();
89 check(input, kernel, conv);
92 const size_t k1 = etl::dim<0>(kernel);
93 const size_t k2 = etl::dim<1>(kernel);
95 if constexpr (Flipped) {
97 if (s1 == 1 && s2 == 1) {
98 if (p1 == 0 && p2 == 0) {
109 auto strided_input = impl::common::inner_pad(input, s1, s2);
111 if (p1 == 0 && p2 == 0) {
121 if (s1 == 1 && s2 == 1) {
122 if (p1 == 0 && p2 == 0) {
133 auto strided_input = impl::common::inner_pad(input, s1, s2);
135 if (p1 == 0 && p2 == 0) {
150 template <etl_expr L>
159 template <etl_expr L>
168 template <etl_expr L>
177 template <etl_expr L>
186 template <etl_expr L>
198 return os <<
"conv2_backward(" << expr.
_a <<
", " << expr.
_b <<
")";
206 template <etl_expr A, etl_expr B,
bool Flipped>
215 static constexpr
bool is_etl =
true;
220 static constexpr
bool is_linear =
false;
222 static constexpr
bool is_value =
false;
223 static constexpr
bool is_direct =
true;
224 static constexpr
bool is_generator =
false;
225 static constexpr
bool is_padded =
false;
226 static constexpr
bool is_aligned =
true;
227 static constexpr
bool is_temporary =
true;
236 template <vector_mode_t V>
237 static constexpr
bool vectorizable =
true;
295 template <etl_expr A, etl_expr B>
318 template <etl_expr A, etl_expr B, etl_expr C>
341 template <etl_expr A, etl_expr B>
343 A&&
a, B&&
b,
size_t s1,
size_t s2,
size_t p1,
size_t p2) {
365 template <etl_expr A, etl_expr B, etl_expr C>
B _b
The sub expression reference.
Definition: base_temporary_expr.hpp:534
void assign_mul_to(L &&lhs) const
Multiply the given left-hand-side expression.
Definition: dyn_conv_2d_backward_expr.hpp:169
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
value_t< A > value_type
The value type of the expression.
Definition: dyn_conv_2d_backward_expr.hpp:213
static constexpr size_t dimensions()
Returns the number of dimensions of the expression.
Definition: dyn_conv_2d_backward_expr.hpp:266
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
static void apply(const I &input, const K &kernel, C &conv)
Apply the convolution.
Definition: conv_2d.hpp:28
std::add_lvalue_reference_t< B > b()
Returns the sub expression.
Definition: base_temporary_expr.hpp:593
conv_2d_backward_expr< detail::build_type< A >, detail::build_type< B >, S1, S2, P1, P2, false > conv_2d_backward(A &&a, B &&b)
Creates an expression representing the transposed 2D convolution of a and b.
Definition: conv_2d_backward_expr.hpp:317
constexpr bool is_fast
Traits to test if the given ETL expresion type is fast (sizes known at compile-time) ...
Definition: traits.hpp:588
static size_t size(const expr_t &e)
Returns the size of the expression.
Definition: dyn_conv_2d_backward_expr.hpp:258
dyn_conv_2d_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_2d_backward_expr.hpp:63
static void apply(const I &input, const K &kernel, C &conv)
Apply the convolution.
Definition: conv_2d.hpp:78
Traits to get information about ETL types.
Definition: tmp.hpp:68
Root namespace for the ETL library.
Definition: adapter.hpp:15
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_2d_backward_expr.hpp:73
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_2d.hpp:256
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
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
void assign_mod_to(L &&lhs) const
Modulo the given left-hand-side expression.
Definition: dyn_conv_2d_backward_expr.hpp:187
value_t< A > value_type
The type of value of the expression.
Definition: dyn_conv_2d_backward_expr.hpp:41
conv_2d_backward_expr< detail::build_type< A >, detail::build_type< B >, S1, S2, P1, P2, true > conv_2d_backward_flipped(A &&a, B &&b)
Creates an expression representing the 'backward' 1D convolution of a and flipped b...
Definition: conv_2d_backward_expr.hpp:363
static size_t dim(const expr_t &e, size_t d)
Returns the dth dimension of the expression.
Definition: dyn_conv_2d_backward_expr.hpp:245
void std_mod_evaluate(Expr &&expr, Result &&result)
Compound modulo evaluation of the expr into result.
Definition: evaluator.hpp:1271
friend std::ostream & operator<<(std::ostream &os, const dyn_conv_2d_backward_expr &expr)
Print a representation of the expression on the given stream.
Definition: dyn_conv_2d_backward_expr.hpp:197
const size_t s2
The stride of the second dimension.
Definition: dyn_conv_2d_backward_expr.hpp:55
void std_mul_evaluate(Expr &&expr, Result &&result)
Compound multiply evaluation of the expr into result.
Definition: evaluator.hpp:1233
std::decay_t< A > left_expr_t
The left sub expression type.
Definition: dyn_conv_2d_backward_expr.hpp:209
constexpr bool is_transformer
Traits indicating if the given ETL type is a transformer expression.
Definition: traits.hpp:297
void assign_add_to(L &&lhs) const
Add to the given left-hand-side expression.
Definition: dyn_conv_2d_backward_expr.hpp:151
Selector for the convolution implementations.
void assign_to(C &&conv) const
Assign to a matrix.
Definition: dyn_conv_2d_backward_expr.hpp:83
constexpr bool is_view
Traits indicating if the given ETL type is a view expression.
Definition: traits.hpp:304
static constexpr auto storage_order
The sub storage order.
Definition: dyn_conv_2d_backward_expr.hpp:46
void std_sub_evaluate(Expr &&expr, Result &&result)
Compound subtract evaluation of the expr into result.
Definition: evaluator.hpp:1214
std::decay_t< B > right_expr_t
The right sub expression type.
Definition: dyn_conv_2d_backward_expr.hpp:210
static constexpr int complexity() noexcept
Estimate the complexity of computation.
Definition: dyn_conv_2d_backward_expr.hpp:274
constexpr bool is_thread_safe
Traits to test if the given ETL expresion type is thread safe.
Definition: traits.hpp:687
Expression representing the transposed 2D convolution of an image with a kernel.
Definition: dyn_conv_2d_backward_expr.hpp:40
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
const size_t p2
The padding of the second dimension.
Definition: dyn_conv_2d_backward_expr.hpp:57
const size_t p1
The padding of the first dimension.
Definition: dyn_conv_2d_backward_expr.hpp:56
void assign_sub_to(L &&lhs) const
Sub from the given left-hand-side expression.
Definition: dyn_conv_2d_backward_expr.hpp:160
void assign_div_to(L &&lhs) const
Divide the given left-hand-side expression.
Definition: dyn_conv_2d_backward_expr.hpp:178
void std_add_evaluate(Expr &&expr, Result &&result)
Compound add evaluation of the expr into result.
Definition: evaluator.hpp:1195
static constexpr bool gpu_computable
Indicates if the temporary expression can be directly evaluated using only GPU.
Definition: dyn_conv_2d_backward_expr.hpp:52
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_2d.hpp:289
const size_t s1
The stride of the first dimension.
Definition: dyn_conv_2d_backward_expr.hpp:54