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 "cpu_convolution_pd.hpp"
22 #include "cpu_engine.hpp"
23 #include "jit_transpose_src_utils.hpp"
24 #include "cpu_reducer.hpp"
25 #include "cpu_barrier.hpp"
27 #include "jit_avx512_core_x8s8s32x_conv_kernel.hpp"
33 template <bool with_relu, 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<with_relu> {
36 pd_t(engine_t *engine, const typename pd_t::base_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<with_relu>(engine, adesc, attr,
45 JIT_IMPL_NAME_HELPER("jit_int8:", avx512_core, ""),
46 _jit_avx512_core_x8s8s32x_convolution_fwd_t<with_relu, src_type,
49 virtual status_t init() override
51 using namespace prop_kind;
52 assert(this->engine()->kind() == engine_kind::cpu);
54 && utils::one_of(this->cdesc_().prop_kind, forward_training,
56 && this->cdesc_().alg_kind == alg_kind::convolution_direct
57 && !this->has_zero_dim_memory()
58 && this->cdesc_().src_desc.data_type == src_type
59 && this->cdesc_().dst_desc.data_type == dst_type
60 && IMPLICATION(this->with_bias(), utils::one_of(
61 this->cdesc_().bias_desc.data_type, data_type::f32,
62 data_type::s32, data_type::s8, data_type::u8))
63 && this->cdesc_().accum_data_type == data_type::s32;
65 return status::unimplemented;
67 return jit_avx512_core_x8s8s32x_fwd_kernel::init_conf(
68 jcp_, this->cdesc_(), this->src_pd_, this->weights_pd_,
69 this->dst_pd_,this->bias_pd_, *this->attr(),
70 mkldnn_get_max_threads(),
71 with_relu, this->negative_slope());
77 _jit_avx512_core_x8s8s32x_convolution_fwd_t(const pd_t *pd,
78 const input_vector &inputs, const output_vector &outputs)
79 : cpu_primitive_t(&conf_, inputs, outputs), conf_(*pd)
80 , local_scales_(nullptr)
82 kernel_ = new jit_avx512_core_x8s8s32x_fwd_kernel(conf_.jcp_,
84 if (conf_.jcp_.signed_input && conf_.jcp_.ver != ver_vnni) {
85 size_t scales_size = (conf_.attr()->output_scales_.count_ == 1)
87 : conf_.attr()->output_scales_.count_;
88 local_scales_ = (float *)malloc(sizeof(float) * scales_size, 64);
89 for (size_t i = 0; i < scales_size; i++) {
90 local_scales_[i] = conf_.attr()->output_scales_.scales_[i] *
91 (1.f / conf_.jcp_.wei_adj_scale);
96 ~_jit_avx512_core_x8s8s32x_convolution_fwd_t() {
98 if (local_scales_) free(local_scales_);
101 typedef typename prec_traits<src_type>::type src_data_t;
102 typedef typename prec_traits<data_type::s8>::type wei_data_t;
103 typedef typename prec_traits<dst_type>::type dst_data_t;
105 virtual void execute(event_t *e)
108 e->set_state(event_t::ready);
112 void execute_forward();
114 jit_avx512_core_x8s8s32x_fwd_kernel *kernel_;
115 float *local_scales_;
118 template <impl::data_type_t src_type, impl::data_type_t dst_type>
119 using jit_avx512_core_x8s8s32x_convolution_fwd_t =
120 _jit_avx512_core_x8s8s32x_convolution_fwd_t<false, src_type, dst_type>;
122 template <impl::data_type_t src_type, impl::data_type_t dst_type>
123 using jit_avx512_core_x8s8s32x_convolution_relu_t =
124 _jit_avx512_core_x8s8s32x_convolution_fwd_t<true, src_type, dst_type>;
132 // vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s