Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / src / cpu / jit_uni_i8i8_pooling.hpp
1 /*******************************************************************************
2 * Copyright 2017-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_JIT_UNI_I8I8_POOLING_HPP
18 #define CPU_JIT_UNI_I8I8_POOLING_HPP
19
20 #include "c_types_map.hpp"
21 #include "cpu_isa_traits.hpp"
22 #include "cpu_pooling_pd.hpp"
23 #include "cpu_engine.hpp"
24
25 #include "jit_primitive_conf.hpp"
26
27 namespace mkldnn {
28 namespace impl {
29 namespace cpu {
30
31 template <cpu_isa_t isa>
32 struct jit_uni_i8i8_pooling_fwd_ker_t;
33
34 template <cpu_isa_t isa>
35 struct jit_uni_i8i8_pooling_fwd_t : public cpu_primitive_t {
36     struct pd_t : public cpu_pooling_fwd_pd_t {
37         pd_t(engine_t *engine, const pooling_desc_t  *adesc,
38                 const primitive_attr_t *attr,
39                 const pooling_fwd_pd_t  *hint_fwd_pd)
40         : cpu_pooling_fwd_pd_t(engine, adesc, attr, hint_fwd_pd) {}
41
42         DECLARE_COMMON_PD_T(
43                 JIT_IMPL_NAME_HELPER("jit:", isa, ""),
44                 jit_uni_i8i8_pooling_fwd_t<isa>);
45
46         virtual status_t init() override {
47             assert(this->engine()->kind() == engine_kind::cpu);
48             bool ok = true
49                 && mayiuse(isa)
50                 && desc()->src_desc.ndims == 4
51                 && set_default_params() == status::success
52                 && desc()->prop_kind == prop_kind::forward_inference
53                 && utils::one_of(desc()->alg_kind, alg_kind::pooling_max,
54                         alg_kind::pooling_avg_include_padding,
55                         alg_kind::pooling_avg_exclude_padding)
56                 && utils::one_of(src_pd()->desc()->data_type, data_type::s32,
57                         data_type::s8, data_type::u8)
58                 && src_pd()->desc()->data_type == dst_pd()->desc()->data_type
59                 && utils::everyone_is(memory_format::nhwc,
60                         src_pd()->desc()->format, dst_pd()->desc()->format)
61                 && attr()->has_default_values();
62             if (!ok) return status::unimplemented;
63
64             return jit_conf();
65         }
66
67         jit_pool_conf_t jpp_;
68
69     protected:
70         status_t jit_conf();
71
72         virtual status_t set_default_params() override {
73             using namespace memory_format;
74             if (dst_pd_.desc()->format == any)
75                 CHECK(dst_pd_.set_format(nhwc));
76             return status::success;
77         }
78     };
79
80     jit_uni_i8i8_pooling_fwd_t(const pd_t *apd,
81             const input_vector &inputs, const output_vector &outputs);
82     ~jit_uni_i8i8_pooling_fwd_t();
83
84     virtual void execute(event_t *e) const {
85         execute_forward();
86         e->set_state(event_t::ready);
87     }
88
89 private:
90     void execute_forward() const;
91     const pd_t *pd() const { return (const pd_t *)primitive_t::pd(); }
92
93     jit_uni_i8i8_pooling_fwd_ker_t<isa> *ker_;
94 };
95
96 }
97 }
98 }
99
100 #endif