1 /*******************************************************************************
2 * Copyright 2018 Intel Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *******************************************************************************/
17 #ifndef CPU_DEPTHWISE_PD_HPP
18 #define CPU_DEPTHWISE_PD_HPP
22 #include "c_types_map.hpp"
23 #include "depthwise_pd.hpp"
24 #include "cpu_engine.hpp"
25 #include "cpu_memory.hpp"
26 #include "cpu_primitive.hpp"
27 #include "type_helpers.hpp"
34 struct cpu_depthwise_fwd_pd_t: public depthwise_fwd_pd_t {
35 using cpu_memory_pd_t = cpu_memory_t::pd_t;
37 cpu_depthwise_fwd_pd_t(engine_t *engine, const depthwise_desc_t *adesc,
38 const primitive_attr_t *attr, const depthwise_fwd_pd_t *hint_fwd_pd)
39 : depthwise_fwd_pd_t(engine, adesc, attr, hint_fwd_pd)
40 , src_pd_(engine_, &desc_.src_desc)
41 , dst_pd_(engine_, &desc_.dst_desc)
42 , weights_pd_(engine_, &desc_.weights_desc)
43 , bias_pd_(engine_, &desc_.bias_desc) {}
44 virtual ~cpu_depthwise_fwd_pd_t() {}
46 virtual const cpu_memory_pd_t *src_pd(int index = 0) const override
47 { return index == 0 ? &src_pd_ : nullptr; }
48 virtual const cpu_memory_pd_t *dst_pd(int index = 0) const override
49 { return index == 0 ? &dst_pd_ : nullptr; }
50 virtual const cpu_memory_pd_t *weights_pd(int index = 0) const override {
51 if (index == 0) return &weights_pd_;
52 if (index == 1 && this->with_bias()) return &bias_pd_;
56 bool want_padded_weights() const {
57 memory_desc_wrapper dst_d(&dst_pd_);
58 if (dst_d.format() == memory_format::nc) {
60 return this->C() % simd_w != 0;
63 if (!dst_d.is_blocking_desc()) return false;
64 return this->C() != dst_d.blocking_desc().padding_dims[1];
68 cpu_memory_pd_t src_pd_, dst_pd_, weights_pd_, bias_pd_;
70 virtual status_t set_default_params() {
71 using namespace memory_format;
72 if (src_pd_.desc()->format == any)
73 CHECK(src_pd_.set_format(nchw));
74 if (dst_pd_.desc()->format == any)
75 CHECK(dst_pd_.set_format(nchw));
76 if (weights_pd_.desc()->format == any)
77 CHECK(weights_pd_.set_format(x));
78 if (bias_pd_.desc()->format == any)
79 CHECK(bias_pd_.set_format(x));
80 return status::success;
83 virtual status_t init() = 0;
92 // vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s