Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / src / cpu / ref_depthwise.hpp
1 /*******************************************************************************
2 * Copyright 2018 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_REF_DEPTHWISE_HPP
18 #define CPU_REF_DEPTHWISE_HPP
19
20 #include <assert.h>
21
22 #include "c_types_map.hpp"
23 #include "cpu_depthwise_pd.hpp"
24 #include "cpu_engine.hpp"
25 #include "type_helpers.hpp"
26 #include "utils.hpp"
27
28 namespace mkldnn {
29 namespace impl {
30 namespace cpu {
31
32 struct ref_depthwise_scalar_fwd_t {
33 public:
34     explicit ref_depthwise_scalar_fwd_t(alg_kind_t alg);
35     float compute_scalar(float s, const float* weights, const float* bias);
36
37 private:
38     alg_kind_t alg;
39 };
40
41 template <impl::data_type_t data_type>
42 struct ref_depthwise_fwd_t: public cpu_primitive_t {
43     struct pd_t: public cpu_depthwise_fwd_pd_t {
44         pd_t(engine_t *engine, const depthwise_desc_t *adesc,
45                 const primitive_attr_t *attr,
46                 const depthwise_fwd_pd_t *hint_fwd_pd)
47             : cpu_depthwise_fwd_pd_t(engine, adesc, attr, hint_fwd_pd) {}
48
49         DECLARE_COMMON_PD_T("ref:any", ref_depthwise_fwd_t);
50
51         virtual status_t init() override {
52             using namespace prop_kind;
53             assert(engine()->kind() == engine_kind::cpu);
54
55             bool ok = true
56                 && utils::one_of(desc()->prop_kind, forward_training,
57                         forward_inference)
58                 && utils::everyone_is(data_type, desc()->src_desc.data_type, desc()->dst_desc.data_type)
59                 && attr()->has_default_values();
60             if (!ok) return status::unimplemented;
61
62             return status::success;
63         }
64     };
65
66     ref_depthwise_fwd_t(const pd_t *apd, const input_vector &inputs,
67             const output_vector &outputs)
68         : cpu_primitive_t(apd, inputs, outputs) {}
69     typedef typename prec_traits<data_type>::type data_t;
70
71     virtual void execute(event_t *e) const {
72         execute_forward();
73         e->set_state(event_t::ready);
74     }
75
76 private:
77     void execute_forward() const;
78     const pd_t *pd() const { return (const pd_t *)primitive_t::pd(); }
79 };
80
81 }
82 }
83 }
84
85 #endif