1 /*******************************************************************************
2 * Copyright 2016-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_X8S8S32X_CONVOLUTION_HPP
18 #define CPU_JIT_AVX512_CORE_X8S8S32X_CONVOLUTION_HPP
20 #include "c_types_map.hpp"
21 #include "memory_tracking.hpp"
22 #include "mkldnn_thread.hpp"
25 #include "cpu_convolution_pd.hpp"
27 #include "jit_avx512_core_x8s8s32x_conv_kernel.hpp"
33 template <impl::data_type_t src_type, impl::data_type_t dst_type>
34 struct jit_avx512_core_x8s8s32x_convolution_fwd_t : public cpu_primitive_t {
35 struct pd_t : public cpu_convolution_fwd_pd_t {
36 pd_t(engine_t *engine, const convolution_desc_t *adesc,
37 const primitive_attr_t *attr,
38 const typename pd_t::base_class *hint_fwd_pd)
39 : cpu_convolution_fwd_pd_t(engine, adesc, attr, hint_fwd_pd)
44 JIT_IMPL_NAME_HELPER("jit_int8:", avx512_core, ""),
45 jit_avx512_core_x8s8s32x_convolution_fwd_t<src_type, dst_type>);
47 virtual status_t init() override {
48 using namespace prop_kind;
49 assert(this->engine()->kind() == engine_kind::cpu);
52 && utils::one_of(this->desc()->prop_kind, forward_training,
54 && utils::one_of(this->desc()->alg_kind,
55 alg_kind::convolution_auto,
56 alg_kind::convolution_direct)
57 && !this->has_zero_dim_memory()
58 && this->desc()->src_desc.data_type == src_type
59 && this->desc()->dst_desc.data_type == dst_type
60 && IMPLICATION(this->with_bias(), utils::one_of(
61 this->desc()->bias_desc.data_type, data_type::f32,
62 data_type::s32, data_type::s8, data_type::u8))
63 && this->desc()->accum_data_type == data_type::s32;
64 if (!ok) return status::unimplemented;
66 status_t status = jit_avx512_core_x8s8s32x_fwd_kernel::init_conf(
67 jcp_, *this->desc(), this->src_pd_, this->weights_pd_,
68 this->dst_pd_,this->bias_pd_, *this->attr(),
69 mkldnn_get_max_threads());
70 if (status != status::success) return status;
72 auto scratchpad = scratchpad_registry().registrar();
73 jit_avx512_core_x8s8s32x_fwd_kernel::init_scratchpad(scratchpad,
76 if (status == status::success
77 && this->desc()->alg_kind == alg_kind::convolution_auto)
78 CHECK(this->set_alg_kind(alg_kind::convolution_direct));
85 jit_avx512_core_x8s8s32x_convolution_fwd_t(const pd_t *apd,
86 const input_vector &inputs, const output_vector &outputs)
87 : cpu_primitive_t(apd, inputs, outputs)
89 kernel_ = new jit_avx512_core_x8s8s32x_fwd_kernel(pd()->jcp_,
93 ~jit_avx512_core_x8s8s32x_convolution_fwd_t() { delete kernel_; }
95 typedef typename prec_traits<src_type>::type src_data_t;
96 typedef typename prec_traits<data_type::s8>::type wei_data_t;
97 typedef typename prec_traits<dst_type>::type dst_data_t;
99 virtual void execute(event_t *e) const
101 const auto &jcp = pd()->jcp_;
102 if (pd()->ndims() == 3)
103 execute_forward_1d();
104 else if (jcp.is_depthwise)
105 execute_forward_2d_dw();
107 execute_forward_2d();
108 e->set_state(event_t::ready);
112 void execute_forward_1d() const;
113 void execute_forward_2d() const;
114 void execute_forward_2d_dw() const;
115 const pd_t *pd() const { return (const pd_t *)primitive_t::pd(); }
117 jit_avx512_core_x8s8s32x_fwd_kernel *kernel_;
126 // vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s