1 /*******************************************************************************
2 * Copyright 2018 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_AVX512_CORE_U8S8S32X_DECONVOLUTION_HPP
18 #define CPU_JIT_AVX512_CORE_U8S8S32X_DECONVOLUTION_HPP
21 #include "c_types_map.hpp"
22 #include "cpu_engine.hpp"
23 #include "cpu_memory.hpp"
24 #include "mkldnn_thread.hpp"
25 #include "type_helpers.hpp"
29 #include "cpu_deconvolution_pd.hpp"
30 #include "jit_generator.hpp"
31 #include "jit_primitive_conf.hpp"
44 struct jit_avx512_core_u8s8s32x_deconv_fwd_kernel : public jit_generator {
45 DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_avx512_core_u8s8s32x_deconv_fwd_ker_t);
47 jit_avx512_core_u8s8s32x_deconv_fwd_kernel(jit_conv_conf_t ajcp,
48 const primitive_attr_t &attr) : jcp(ajcp), attr_(attr) {
50 jit_ker = (void (*)(jit_deconv_call_s *))getCode();
53 static status_t init_conf(jit_conv_conf_t &jcp,
54 const deconvolution_desc_t &cd,
55 cpu_memory_t::pd_t &src_pd,
56 cpu_memory_t::pd_t &weights_pd,
57 cpu_memory_t::pd_t &dst_pd,
59 cpu_memory_t::pd_t &bias_pd,
60 const primitive_attr_t &attr);
63 const primitive_attr_t &attr_;
64 void (*jit_ker)(jit_deconv_call_s *);
66 using reg64_t = const Xbyak::Reg64;
67 using zmm_t = const Xbyak::Zmm;
68 using xmm_t = const Xbyak::Xmm;
71 reg64_t reg_filt = r9;
72 reg64_t reg_dst = r10;
73 reg64_t param1 = abi_param1;
74 reg64_t reg_kh = abi_not_param1;
75 reg64_t reg_nur_w = rbx;
76 reg64_t reg_bias = rdx;
77 reg64_t reg_icb = reg_bias;
78 reg64_t reg_ptr_scales = rax;
79 reg64_t reg_oc_blocks = rsi;
81 reg64_t reg_scratch = r14;
82 reg64_t aux_reg_src = r11;
83 reg64_t aux_reg_filt = r12;
86 Xbyak::Opmask ktail_mask = Xbyak::Opmask(2);
87 zmm_t zmm_tmp = zmm_t(29);
88 zmm_t zmm_one = zmm_t(30);
89 zmm_t zmm_zero = zmm_t(31);
90 zmm_t zmm_wei = zmm_t(31);
92 zmm_t zmm_out(int i_ur, int i_oc) {
93 int idx = i_ur * jcp.nb_oc_blocking + i_oc;
97 zmm_t zmm_inp(int i_ic, int nb_x_blocking) {
98 int idx = i_ic + nb_x_blocking * jcp.ur_w;
103 int get_ow_start(int ki, int l_overflow) {
104 int res = (jcp.ow - 1 + jcp.r_pad) % jcp.stride_w
105 + l_overflow * jcp.stride_w
106 - (jcp.kw - 1 - ki) * (jcp.dilate_w + 1);
112 int get_ow_end(int ur_w, int ki, int r_overflow) {
113 if (utils::one_of(ur_w, jcp.ow, jcp.ur_w_tail))
114 ur_w += nstl::min(0, jcp.r_pad);
115 int res = (ur_w - 1 + jcp.l_pad) % jcp.stride_w
116 + r_overflow * jcp.stride_w - ki * (jcp.dilate_w + 1);
122 void prepare_output(int ur_w);
123 void store_output(int ur_w, bool last_oc_block);
124 void compute_ker(int ur_w, int pad_l, int pad_r, ker_block_t last_ker_block);
125 void compute_loop(int ur_w, int pad_l, int pad_r, bool last_block);
127 void cvt2ps(data_type_t type_in, zmm_t zmm_in, const Xbyak::Operand &op,
131 template <impl::data_type_t dst_type>
132 struct _jit_avx512_core_u8s8s32x_deconvolution_fwd_t : public cpu_primitive_t {
133 struct pd_t : public cpu_deconvolution_fwd_pd_t {
134 pd_t(engine_t *engine,
135 const deconvolution_desc_t *adesc,
136 const primitive_attr_t *attr,
137 const deconvolution_fwd_pd_t *hint_fwd_pd)
138 : cpu_deconvolution_fwd_pd_t(engine, adesc, attr, hint_fwd_pd) {}
140 DECLARE_COMMON_PD_T(JIT_IMPL_NAME_HELPER("jit_deconvolution:", avx512_core, ""),
141 _jit_avx512_core_u8s8s32x_deconvolution_fwd_t<dst_type>);
143 virtual status_t init() override {
144 assert(this->engine()->kind() == engine_kind::cpu);
147 && utils::one_of(this->desc()->prop_kind, prop_kind::forward_training,
148 prop_kind::forward_inference)
149 && this->desc()->alg_kind & alg_kind::deconvolution_direct
150 && this->desc()->dst_desc.data_type == dst_type
151 && IMPLICATION(this->with_bias(), utils::one_of(
152 this->desc()->bias_desc.data_type, data_type::f32,
153 data_type::s32, data_type::s8, data_type::u8))
154 && this->desc()->accum_data_type == data_type::s32;
155 if (!ok) return status::unimplemented;
157 /*TODO: support signed input and postops */
158 return jit_avx512_core_u8s8s32x_deconv_fwd_kernel::init_conf(
159 jcp_, *this->desc(), this->src_pd_,
160 this->weights_pd_, this->dst_pd_,
161 this->with_bias(), this->bias_pd_,
164 jit_conv_conf_t jcp_;
167 _jit_avx512_core_u8s8s32x_deconvolution_fwd_t(const pd_t *pd,
168 const input_vector &inputs, const output_vector &outputs)
169 : cpu_primitive_t(&conf_, inputs, outputs), conf_(*pd) {
170 kernel_ = new jit_avx512_core_u8s8s32x_deconv_fwd_kernel(conf_.jcp_,
174 ~_jit_avx512_core_u8s8s32x_deconvolution_fwd_t() {
178 typedef typename prec_traits<data_type::u8>::type src_data_t;
179 typedef typename prec_traits<data_type::s8>::type wei_data_t;
180 typedef typename prec_traits<dst_type>::type dst_data_t;
182 virtual void execute(event_t *e)
185 e->set_state(event_t::ready);
189 void execute_forward();
191 jit_avx512_core_u8s8s32x_deconv_fwd_kernel *kernel_;
201 // vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s