updated readme files (#54)
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / src / cpu / jit_avx512_core_u8s8s32x_convolution.hpp
1 /*******************************************************************************
2 * Copyright 2016-2018 Intel Corporation
3 *
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
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
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 *******************************************************************************/
16
17 #ifndef CPU_JIT_AVX512_CORE_U8S8S32X_CONVOLUTION_HPP
18 #define CPU_JIT_AVX512_CORE_U8S8S32X_CONVOLUTION_HPP
19
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"
26
27 #include "jit_avx512_core_u8s8s32x_conv_kernel.hpp"
28
29 namespace mkldnn {
30 namespace impl {
31 namespace cpu {
32
33 template <bool with_relu, impl::data_type_t dst_type>
34 struct _jit_avx512_core_u8s8s32x_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,
40                     hint_fwd_pd)
41             , jcp_()
42         {
43         }
44         DECLARE_COMMON_PD_T(
45                 JIT_IMPL_NAME_HELPER("jit:", avx512_core, ""),
46                 _jit_avx512_core_u8s8s32x_convolution_fwd_t<with_relu,
47                 dst_type>);
48
49         virtual status_t init() override
50         {
51             using namespace prop_kind;
52             assert(this->engine()->kind() == engine_kind::cpu);
53             bool ok = true
54                     && utils::one_of(this->cdesc_().prop_kind, forward_training,
55                                forward_inference)
56                     && this->cdesc_().alg_kind == alg_kind::convolution_direct
57                     && !this->has_zero_dim_memory()
58                     && this->cdesc_().dst_desc.data_type == dst_type
59                     && utils::implication(this->with_bias(), utils::one_of(
60                             this->cdesc_().bias_desc.data_type, data_type::f32,
61                             data_type::s32, data_type::s8, data_type::u8))
62                     && this->cdesc_().accum_data_type == data_type::s32;
63             if (!ok)
64                 return status::unimplemented;
65
66             return jit_avx512_core_u8s8s32x_fwd_kernel::init_conf(
67                     jcp_, this->cdesc_(), this->src_pd_, this->weights_pd_,
68                     this->dst_pd_,this->bias_pd_, *this->attr(),
69                     with_relu, this->negative_slope());
70         }
71
72         jit_conv_conf_t jcp_;
73     };
74
75     _jit_avx512_core_u8s8s32x_convolution_fwd_t(const pd_t *pd,
76             const input_vector &inputs, const output_vector &outputs)
77         : cpu_primitive_t(&conf_, inputs, outputs), conf_(*pd)
78     {
79         kernel_ = new jit_avx512_core_u8s8s32x_fwd_kernel(conf_.jcp_,
80                     *conf_.attr());
81     }
82
83     ~_jit_avx512_core_u8s8s32x_convolution_fwd_t() {
84         delete kernel_;
85     };
86
87     typedef typename prec_traits<data_type::u8>::type src_data_t;
88     typedef typename prec_traits<data_type::s8>::type wei_data_t;
89     typedef typename prec_traits<dst_type>::type dst_data_t;
90
91     virtual void execute(event_t *e)
92     {
93         execute_forward();
94         e->set_state(event_t::ready);
95     }
96
97 private:
98     void execute_forward();
99     pd_t conf_;
100     jit_avx512_core_u8s8s32x_fwd_kernel *kernel_;
101 };
102
103 template <impl::data_type_t dst_type>
104 using jit_avx512_core_u8s8s32x_convolution_fwd_t =
105     _jit_avx512_core_u8s8s32x_convolution_fwd_t<false, dst_type>;
106
107 template <impl::data_type_t dst_type>
108 using jit_avx512_core_u8s8s32x_convolution_relu_t =
109     _jit_avx512_core_u8s8s32x_convolution_fwd_t<true, dst_type>;
110
111 }
112 }
113 }
114
115 #endif
116
117 // vim: et ts=4 sw=4 cindent cino^=l0,\:0,N-s