Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / src / cpu / jit_uni_roi_pooling.hpp
1 /*******************************************************************************
2 * Copyright 2017 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_ROI_POOLING_HPP
18 #define CPU_JIT_UNI_ROI_POOLING_HPP
19
20 #include <assert.h>
21 #include <mkldnn_types.h>
22
23 #include "c_types_map.hpp"
24 #include "cpu_roi_pooling_pd.hpp"
25 #include "cpu_engine.hpp"
26 #include "jit_uni_roi_pool_kernel_f32.hpp"
27 #include "type_helpers.hpp"
28 #include "utils.hpp"
29
30 namespace mkldnn {
31 namespace impl {
32 namespace cpu {
33
34 template <cpu_isa_t isa>
35 struct jit_uni_roi_pooling_fwd_t: public cpu_primitive_t {
36     struct pd_t: public cpu_roi_pooling_fwd_pd_t {
37         pd_t(engine_t *engine, const roi_pooling_desc_t *adesc,
38              const primitive_attr_t *attr,
39              const roi_pooling_fwd_pd_t *hint_fwd_pd)
40         : cpu_roi_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_roi_pooling_fwd_t<isa>);
45
46         virtual status_t init() override {
47             using namespace prop_kind;
48             using namespace alg_kind;
49             using namespace utils;
50
51             auto desired_fmt = isa == avx512_common ? memory_format::nChw16c
52                                                     : memory_format::nChw8c;
53
54             assert(engine()->kind() == engine_kind::cpu);
55             bool ok = true
56                 && mayiuse(isa)
57                 && set_default_params() == status::success
58                 && (desc()->alg_kind == mkldnn_roi_pooling_max ||
59                     desc()->alg_kind == mkldnn_roi_pooling_bilinear)
60                 && one_of(desc()->prop_kind, forward_training,
61                         forward_inference)
62                 && everyone_is(data_type::f32, src_pd()->desc()->data_type,
63                         dst_pd()->desc()->data_type)
64                 && everyone_is(desired_fmt, src_pd()->desc()->format,
65                         dst_pd()->desc()->format);
66             if (!ok) return status::unimplemented;
67
68             return jit_uni_roi_pool_kernel_f32<isa>::init_conf(jpp_, desc_,
69                     src_pd()->desc(), dst_pd()->desc());
70         }
71
72         jit_roi_pool_conf_t jpp_;
73
74     protected:
75         virtual status_t set_default_params() {
76             auto desired_fmt = isa == avx512_common ? memory_format::nChw16c
77                                                     : memory_format::nChw8c;
78
79             if (dst_pd_.desc()->format == memory_format::any)
80                CHECK(dst_pd_.set_format(desired_fmt));
81             return status::success;
82         }
83     };
84
85     jit_uni_roi_pooling_fwd_t(const pd_t *apd, const input_vector &inputs,
86             const output_vector &outputs)
87         : cpu_primitive_t(apd, inputs, outputs)
88     { kernel_ = new jit_uni_roi_pool_kernel_f32<isa>(pd()->jpp_); }
89
90     ~jit_uni_roi_pooling_fwd_t() { delete kernel_; }
91
92     typedef typename prec_traits<data_type::f32>::type data_t;
93
94     virtual void execute(event_t *e) const {
95         execute_forward();
96         e->set_state(event_t::ready);
97     }
98
99 private:
100     void execute_forward() const;
101     const pd_t *pd() const { return (const pd_t *)primitive_t::pd(); }
102     jit_uni_roi_pool_kernel_f32<isa> *kernel_;
103 };
104
105 }
106 }
107 }
108
109 #endif