1 /*******************************************************************************
2 * Copyright 2018-2019 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_X8S8S32X_CONVOLUTION_HPP
18 #define CPU_JIT_UNI_X8S8S32X_CONVOLUTION_HPP
20 #include "c_types_map.hpp"
21 #include "cpu_convolution_pd.hpp"
22 #include "cpu_engine.hpp"
23 #include "cpu_reducer.hpp"
24 #include "jit_primitive_conf.hpp"
25 #include "jit_uni_x8s8s32x_conv_kernel.hpp"
26 #include "jit_generator.hpp"
27 #include "mkldnn_thread.hpp"
28 #include "jit_uni_depthwise.hpp"
34 template <cpu_isa_t isa, impl::data_type_t src_type, impl::data_type_t dst_type>
35 struct _jit_uni_x8s8s32x_convolution_fwd_t: public cpu_primitive_t {
36 struct pd_t: public cpu_convolution_fwd_pd_t {
37 pd_t(engine_t *engine, const convolution_desc_t *adesc,
38 const primitive_attr_t *attr,
39 const typename pd_t::base_class *hint_fwd_pd)
40 : cpu_convolution_fwd_pd_t(engine, adesc, attr, hint_fwd_pd)
41 , jcp_(), jcp_dw_() {}
44 JIT_IMPL_NAME_HELPER("jit:", isa, ""),
45 _jit_uni_x8s8s32x_convolution_fwd_t<isa, src_type, dst_type>);
47 virtual status_t init() override {
48 using namespace prop_kind;
49 assert(this->engine()->kind() == engine_kind::cpu);
51 && utils::one_of(this->desc()->prop_kind, forward_training,
53 && this->desc()->alg_kind == alg_kind::convolution_direct
54 && IMPLICATION(this->with_bias(), utils::one_of(
55 this->desc()->bias_desc.data_type, data_type::f32,
56 data_type::s32, data_type::s8, data_type::u8))
57 && this->desc()->accum_data_type == data_type::s32
58 && this->desc()->src_desc.data_type == src_type
59 && this->desc()->dst_desc.data_type == dst_type;
60 if (!ok) return status::unimplemented;
62 status_t sts = jit_uni_x8s8s32x_conv_fwd_kernel<isa>::init_conf(jcp_, *this->desc(),
63 this->src_pd_, this->weights_pd_,
64 this->dst_pd_, this->bias_pd_, *this->attr());
65 if (sts != status::success) return sts;
67 if (jcp_.with_dw_conv) {
68 status_t sts_dw = jit_uni_dw_conv_row_f32<isa>::init_conf(jcp_, jcp_dw_, *this->attr());
69 if (sts_dw != status::success) return sts_dw;
72 auto scratchpad = scratchpad_registry().registrar();
73 jit_uni_x8s8s32x_conv_fwd_kernel<isa>::init_scratchpad(scratchpad, jcp_, jcp_dw_, *this->attr());
75 return status::success;
79 jit_conv_conf_t jcp_dw_;
82 _jit_uni_x8s8s32x_convolution_fwd_t(const pd_t *apd,
83 const input_vector &inputs, const output_vector &outputs)
84 : cpu_primitive_t(apd, inputs, outputs) {
85 kernel_ = new jit_uni_x8s8s32x_conv_fwd_kernel<isa>(pd()->jcp_, pd()->jcp_dw_, *pd()->attr());
87 if (pd()->jcp_.with_dw_conv) {
88 kernel_dw_ = new jit_uni_dw_conv_row_f32<isa>(pd()->jcp_dw_, *pd()->attr(), pd()->jcp_dw_.oc);
92 ~_jit_uni_x8s8s32x_convolution_fwd_t() {
95 if (pd()->jcp_.with_dw_conv) {
100 typedef typename prec_traits<data_type::u8>::type src_data_t;
101 typedef typename prec_traits<data_type::s8>::type wei_data_t;
102 typedef typename prec_traits<data_type::f32>::type bia_data_t;
103 typedef typename prec_traits<dst_type>::type dst_data_t;
105 virtual void execute(event_t *e) const {
106 if (pd()->jcp_.with_dw_conv)
107 execute_forward_with_dw_conv();
111 e->set_state(event_t::ready);
115 void execute_forward() const;
116 void execute_forward_with_dw_conv() const;
117 const pd_t *pd() const { return (const pd_t *)primitive_t::pd(); }
118 jit_uni_x8s8s32x_conv_fwd_kernel<isa> *kernel_;
119 jit_uni_dw_conv_row_f32<isa> *kernel_dw_;
122 template <impl::data_type_t src_type, impl::data_type_t dst_type>
123 using jit_avx2_x8s8s32x_convolution_fwd_t = _jit_uni_x8s8s32x_convolution_fwd_t<avx2, src_type, dst_type>;
125 template <impl::data_type_t src_type, impl::data_type_t dst_type>
126 using jit_sse42_x8s8s32x_convolution_fwd_t = _jit_uni_x8s8s32x_convolution_fwd_t<sse42, src_type, dst_type>;