1/*******************************************************************************
2* Copyright 2016-2021 Intel Corporation
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*******************************************************************************/
16
17#ifndef CPU_CPU_CONVOLUTION_PD_HPP
18#define CPU_CPU_CONVOLUTION_PD_HPP
19
20#include <assert.h>
21
22#include "common/c_types_map.hpp"
23#include "common/convolution_pd.hpp"
24#include "common/type_helpers.hpp"
25#include "common/utils.hpp"
26#include "cpu/cpu_eltwise_pd.hpp"
27#include "cpu/cpu_engine.hpp"
28
29namespace dnnl {
30namespace impl {
31namespace cpu {
32
33struct cpu_convolution_fwd_pd_t : public convolution_fwd_pd_t {
34 using convolution_fwd_pd_t::convolution_fwd_pd_t;
35
36 bool has_padded_dst() const {
37 memory_desc_wrapper dst_d(&dst_md_);
38 return OC() != dst_d.padded_dims()[1];
39 }
40
41 bool wants_padded_bias() const {
42 if (!with_bias()) return false;
43 return has_padded_dst();
44 }
45
46 bool wants_zero_pad_dst() const {
47 if (!has_padded_dst()) return false;
48 bool is_zero_preserved = true;
49 const auto &po = attr()->post_ops_;
50 for (int i = 0; i < po.len(); i++) {
51 const auto &entry = po.entry_[i];
52 if (entry.is_eltwise()) {
53 const auto &ee = entry.eltwise;
54 is_zero_preserved = is_zero_preserved
55 && cpu_eltwise_fwd_pd_t::eltwise_preserves_zero(
56 ee.alg, ee.alpha, ee.beta);
57 }
58 }
59 return !is_zero_preserved;
60 }
61};
62
63struct cpu_convolution_bwd_data_pd_t : public convolution_bwd_data_pd_t {
64 using convolution_bwd_data_pd_t::convolution_bwd_data_pd_t;
65};
66
67struct cpu_convolution_bwd_weights_pd_t : public convolution_bwd_weights_pd_t {
68 using convolution_bwd_weights_pd_t::convolution_bwd_weights_pd_t;
69
70 bool wants_padded_bias() const {
71 if (!with_bias()) return false;
72 memory_desc_wrapper diff_dst_d(&diff_dst_md_);
73 return OC() != diff_dst_d.padded_dims()[1];
74 }
75};
76
77} // namespace cpu
78} // namespace impl
79} // namespace dnnl
80
81#endif
82
83// vim: et ts=4 sw=4 cindent cino+=l0,\:4,N-s
84