Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / src / cpu / cpu_binary_convolution_pd.hpp
1 /*******************************************************************************
2 * Copyright 2019 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_BINARY_CONVOLUTION_FWD_PD_HPP
18 #define CPU_BINARY_CONVOLUTION_FWD_PD_HPP
19
20 #include <assert.h>
21
22 #include "c_types_map.hpp"
23 #include "binary_convolution_pd.hpp"
24 #include "cpu_engine.hpp"
25 #include "cpu_memory.hpp"
26 #include "cpu_primitive.hpp"
27 #include "type_helpers.hpp"
28 #include "utils.hpp"
29
30 namespace mkldnn {
31 namespace impl {
32 namespace cpu {
33
34 struct _cpu_binary_convolution_fwd_pd_t: public _binary_convolution_fwd_pd_t {
35     using cpu_memory_pd_t = cpu_memory_t::pd_t;
36
37     _cpu_binary_convolution_fwd_pd_t(engine_t *engine,
38             const typename _cpu_binary_convolution_fwd_pd_t::base_desc_t *adesc,
39             const primitive_attr_t *attr,
40             const typename _cpu_binary_convolution_fwd_pd_t::base_class *hint_fwd_pd)
41         : _binary_convolution_fwd_pd_t(engine, adesc, attr, hint_fwd_pd)
42         , src_pd_(this->engine_, &this->cdesc_().src_desc)
43         , dst_pd_(this->engine_, &this->cdesc_().dst_desc)
44         , weights_pd_(this->engine_, &this->cdesc_().weights_desc) {}
45     virtual ~_cpu_binary_convolution_fwd_pd_t() {}
46
47     virtual const cpu_memory_pd_t *src_pd(int index = 0) const override
48     { return index == 0 ? &src_pd_ : nullptr; }
49     virtual const cpu_memory_pd_t *dst_pd(int index = 0) const override
50     { return index == 0 ? &dst_pd_ : nullptr; }
51     virtual const cpu_memory_pd_t *weights_pd(int index = 0) const override {
52         if (index == 0) return &weights_pd_;
53         return nullptr;
54     }
55
56 protected:
57     cpu_memory_pd_t src_pd_, dst_pd_;
58     cpu_memory_pd_t weights_pd_;
59
60     inline memory_format_t src_format()
61     {
62         using namespace memory_format;
63         return utils::pick(this->cdesc_().src_desc.ndims - 3, ncw, nchw, ncdhw);
64     }
65     inline memory_format_t wei_format()
66     {
67         using namespace memory_format;
68         return this->with_groups()
69             ? utils::pick(this->cdesc_().src_desc.ndims - 3, goiw, goihw, goidhw)
70             : utils::pick(this->cdesc_().src_desc.ndims - 3, oiw, oihw, oidhw);
71     }
72
73     virtual status_t set_default_params() {
74         using namespace memory_format;
75         if (src_pd_.desc()->format == any)
76             CHECK(src_pd_.set_format(src_format()));
77         if (dst_pd_.desc()->format == any)
78             CHECK(dst_pd_.set_format(src_pd_.desc()->format));
79         if (weights_pd_.desc()->format == any)
80             CHECK(weights_pd_.set_format(wei_format()));
81         return status::success;
82     }
83 };
84
85 using cpu_binary_convolution_fwd_pd_t = _cpu_binary_convolution_fwd_pd_t;
86
87 }
88 }
89 }
90
91 #endif