Publishing R3
[platform/upstream/dldt.git] / inference-engine / thirdparty / mkl-dnn / src / cpu / jit_avx2_1x1_conv_kernel_f32.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 JIT_AVX2_1x1_CONV_KERNEL_F32_HPP
18 #define JIT_AVX2_1x1_CONV_KERNEL_F32_HPP
19
20 #include "c_types_map.hpp"
21 #include "jit_generator.hpp"
22 #include "jit_primitive_conf.hpp"
23 #include "jit_uni_eltwise.hpp"
24
25 namespace mkldnn {
26 namespace impl {
27 namespace cpu {
28
29 struct jit_avx2_1x1_conv_kernel_f32: public jit_generator {
30     DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_avx2_1x1_conv_kernel_f32)
31
32     jit_avx2_1x1_conv_kernel_f32(jit_1x1_conv_conf_t ajcp,
33            const primitive_attr_t &attr): jcp(ajcp), attr_(attr)
34     {
35         this->generate();
36         jit_ker = (void (*)(jit_1x1_conv_call_s *))this->getCode();
37     }
38
39     static bool post_ops_ok(jit_1x1_conv_conf_t &jcp,
40             const primitive_attr_t &attr);
41
42     static status_t init_conf(jit_1x1_conv_conf_t &jcp,
43             const convolution_desc_t &cd,
44             const memory_desc_wrapper &src_d,
45             const memory_desc_wrapper &weights_d,
46             const memory_desc_wrapper &dst_d,
47             const primitive_attr_t &attr,
48             bool with_relu, float relu_negative_slope);
49
50     static status_t init_conf(jit_1x1_conv_conf_t &jcp,
51             const convolution_desc_t &cd,
52             const memory_desc_wrapper &src_d,
53             const memory_desc_wrapper &weights_d,
54             const memory_desc_wrapper &dst_d,
55             const primitive_attr_t &attr)
56     {
57         return init_conf(jcp, cd, src_d, weights_d, dst_d, attr, false, 0.0);
58     }
59
60     jit_1x1_conv_conf_t jcp;
61     const primitive_attr_t &attr_;
62     void (*jit_ker)(jit_1x1_conv_call_s *);
63
64 private:
65     using reg64_t = const Xbyak::Reg64;
66     using ymm_t = const Xbyak::Ymm;
67
68     reg64_t reg_bcast_data = rax;
69     reg64_t reg_load_data = rsi;
70     reg64_t reg_output_data = rbx;
71     reg64_t aux_reg_bcast_data = rdx;
72     reg64_t aux1_reg_bcast_data = abi_not_param1;
73     reg64_t aux_reg_load_data = abi_param1;
74     reg64_t aux_reg_output_data = rbp;
75     reg64_t reg_load_loop_work = r9;
76     reg64_t reg_bcast_loop_work = r10;
77     reg64_t reg_reduce_loop_work = r11;
78     reg64_t load_loop_iter = r13;
79     reg64_t bcast_loop_iter = r14;
80     reg64_t reduce_loop_iter = r15;
81     reg64_t imm_addr64 = reduce_loop_iter;
82     reg64_t reg_reduce_pos_flag = r8;
83     reg64_t reg_output_stride = r12;
84     reg64_t reg_bias_data = r12;
85     reg64_t reg_diff_bias_data = bcast_loop_iter;
86
87     int reg_diff_bias_data_stack_offt = 0;
88     int stack_space_needed = 8;
89
90     ymm_t vreg_bcast = ymm_t(15);
91
92     Xbyak::Label l_table;
93     jit_uni_eltwise_vector_f32<avx2> eltwise_generator;
94
95     void bcast_loop(int load_loop_blk, char load_loop_tag);
96     void reduce_loop(int load_loop_blk, int ur, char load_loop_tag,
97             char bcast_loop_tag);
98     void diff_bias_loop(int load_loop_blk, char load_loop_tag);
99
100     void generate();
101 };
102
103 }
104 }
105 }
106
107 #endif