1/*******************************************************************************
2* Copyright 2016-2022 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_X64_JIT_AVX2_1X1_CONV_KERNEL_F32_HPP
18#define CPU_X64_JIT_AVX2_1X1_CONV_KERNEL_F32_HPP
19
20#include "common/c_types_map.hpp"
21#include "common/memory.hpp"
22#include "common/memory_tracking.hpp"
23
24#include "cpu/x64/injectors/jit_uni_postops_injector.hpp"
25#include "cpu/x64/jit_generator.hpp"
26#include "cpu/x64/jit_primitive_conf.hpp"
27
28namespace dnnl {
29namespace impl {
30namespace cpu {
31namespace x64 {
32
33struct jit_avx2_1x1_conv_kernel_f32 : public jit_generator {
34 DECLARE_CPU_JIT_AUX_FUNCTIONS(jit_avx2_1x1_conv_kernel_f32)
35
36 jit_avx2_1x1_conv_kernel_f32(const jit_1x1_conv_conf_t &ajcp,
37 const primitive_attr_t &attr, const memory_desc_t &dst_md);
38
39 static status_t init_conf(jit_1x1_conv_conf_t &jcp,
40 const convolution_desc_t &cd, const memory_desc_wrapper &src_d,
41 const memory_desc_wrapper &weights_d,
42 const memory_desc_wrapper &dst_d, const primitive_attr_t &attr);
43
44 static void init_scratchpad(memory_tracking::registrar_t &scratchpad,
45 const jit_1x1_conv_conf_t &jcp);
46
47 jit_1x1_conv_conf_t jcp;
48 const primitive_attr_t &attr_;
49
50private:
51 std::unique_ptr<injector::jit_uni_postops_injector_t<avx2>>
52 postops_injector_;
53
54 constexpr static int isa_simd_width_
55 = cpu_isa_traits<avx2>::vlen / sizeof(float);
56 using reg64_t = const Xbyak::Reg64;
57 using ymm_t = const Xbyak::Ymm;
58
59 reg64_t reg_bcast_data = rax;
60 reg64_t reg_load_data = rsi;
61 reg64_t reg_output_data = rbx;
62 reg64_t aux_reg_bcast_data = rdx;
63 reg64_t aux1_reg_bcast_data = abi_not_param1;
64 reg64_t aux_reg_load_data = abi_param1;
65 reg64_t aux_reg_output_data = rbp;
66 reg64_t reg_load_loop_work = r9;
67 reg64_t reg_bcast_loop_work = r10;
68 reg64_t reg_reduce_loop_work = r11;
69 reg64_t load_loop_iter = r13;
70 reg64_t bcast_loop_iter = r14;
71 reg64_t reduce_loop_iter = r15;
72 reg64_t reg_reduce_pos_flag = r8;
73 reg64_t reg_output_stride = r12;
74 reg64_t reg_bias_data = r12;
75 reg64_t reg_diff_bias_data = bcast_loop_iter;
76 reg64_t reg_tmp_output_stride = reg_bcast_data;
77 reg64_t reg_tmp = aux_reg_bcast_data;
78 reg64_t reg_output_stride_scale = load_loop_iter;
79 reg64_t reg_long_offt = reg_bcast_data;
80
81 constexpr static int reg64_size_ = sizeof(int64_t);
82 constexpr static int reg_diff_bias_data_stack_offt = 0;
83 constexpr static int reg_binary_post_op_acc_off = 1 * reg64_size_;
84 constexpr static int reg_abi_param1_backup = 2 * reg64_size_;
85 constexpr static int reg_bcast_data_off = 3 * reg64_size_;
86 constexpr static int stack_space_needed = 4 * reg64_size_;
87
88 ymm_t vreg_bcast = ymm_t(15);
89 ymm_t vtmp = ymm_t(14);
90
91 void apply_postops(
92 const int load_loop_blk, const int ur, const int load_dim_tail);
93 void generate_bcast_loop(int load_loop_blk);
94 void generate_reduce_loop(int load_loop_blk, int ur);
95 void generate_diff_bias_loop(int load_loop_blk);
96
97 void generate() override;
98};
99
100} // namespace x64
101} // namespace cpu
102} // namespace impl
103} // namespace dnnl
104
105#endif
106