1 /*******************************************************************************
2 * Copyright 2017 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_JIT_UNI_ROI_POOLING_HPP
18 #define CPU_JIT_UNI_ROI_POOLING_HPP
21 #include <mkldnn_types.h>
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"
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) {}
43 JIT_IMPL_NAME_HELPER("jit:", isa, ""),
44 jit_uni_roi_pooling_fwd_t<isa>);
46 virtual status_t init() override {
47 using namespace prop_kind;
48 using namespace alg_kind;
49 using namespace utils;
51 auto desired_fmt = isa == avx512_common ? memory_format::nChw16c
52 : memory_format::nChw8c;
54 assert(engine()->kind() == engine_kind::cpu);
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,
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;
68 return jit_uni_roi_pool_kernel_f32<isa>::init_conf(jpp_, desc_,
69 src_pd()->desc(), dst_pd()->desc());
72 jit_roi_pool_conf_t jpp_;
75 virtual status_t set_default_params() {
76 auto desired_fmt = isa == avx512_common ? memory_format::nChw16c
77 : memory_format::nChw8c;
79 if (dst_pd_.desc()->format == memory_format::any)
80 CHECK(dst_pd_.set_format(desired_fmt));
81 return status::success;
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_); }
90 ~jit_uni_roi_pooling_fwd_t() { delete kernel_; }
92 typedef typename prec_traits<data_type::f32>::type data_t;
94 virtual void execute(event_t *e) const {
96 e->set_state(event_t::ready);
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_;