Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / actual_kernels / convolution / convolution_kernel_mmad_slm_2x14_rep4.cpp
1 /*
2 // Copyright (c) 2016 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 #include "convolution_kernel_mmad_slm_2x14_rep4.h"
18 #include "kernel_selector_utils.h"
19
20 namespace kernel_selector {
21     
22     ParamsKey ConvolutionKernel_mmad_slm_2x14_rep4::GetSupportedKey() const
23     {
24         ParamsKey k;
25         k.EnableInputDataType(Datatype::INT8);
26         k.EnableOutputDataType(Datatype::INT8);
27         k.EnableInputWeightsType(WeightsType::INT8);
28         k.EnableInputLayout(DataLayout::fs_bs_yx_bsv4_fsv32);
29         k.EnableOutputLayout(DataLayout::fs_bs_yx_bsv4_fsv32);
30         k.EnableTensorOffset();
31         k.EnableTensorPitches();
32         k.EnableBiasPerFeature();
33         k.EnableBiasPerOutput();
34         k.EnableNonBiasTerm();
35         k.EnableBatching();
36         k.EnableInt8Quantization();
37         k.EnableOutputCalibration();
38         k.DisableTuning();
39         return k;
40     }
41
42     bool ConvolutionKernel_mmad_slm_2x14_rep4::Validate(const Params& p, const optional_params& o) const
43     {
44         if (!ConvolutionKernelBase::Validate(p, o) ||
45             !CovolutionCheckInput(p, o))
46         {
47             return false;
48         }
49
50         const convolution_params& cp = static_cast<const convolution_params&>(p);
51
52         if (cp.filterSize.x != 3 || cp.filterSize.y != 3)
53             return false;
54
55         if (cp.inputs[0].X().v != 56 || cp.inputs[0].Y().v != 56)
56             return false;
57
58         if (cp.stride.x != 1 || cp.stride.y != 1)
59             return false;
60
61         return true;
62     }
63
64     ConvolutionKernelBase::DispatchData ConvolutionKernel_mmad_slm_2x14_rep4::SetDefault(const convolution_params& arg, int) const
65     {
66         DispatchData runInfo = ConvolutionKernelBase::SetDefault(arg);
67
68         runInfo.effiency = FORCE_PRIORITY_1;
69
70         const size_t rep_count = 4;
71         const size_t batch_per_wi = 1;
72         const size_t out_block_width = 14;
73         const size_t out_block_height = 2;
74         runInfo.gws0 = arg.output.Feature().v * (arg.output.Batch().v / (rep_count * batch_per_wi)); // number of tiles needed to cover output width
75         runInfo.gws1 = ((arg.inputs[0].X().v / arg.stride.x) + (out_block_width - 1)) / out_block_width;
76         runInfo.gws2 = ((arg.inputs[0].Y().v / arg.stride.y) + (out_block_height - 1)) / out_block_height;
77
78         runInfo.lws0 = 32; // depth
79         runInfo.lws1 = 1; // width
80         runInfo.lws2 = 4; // height
81
82         return runInfo;
83     }
84
85     JitConstants ConvolutionKernel_mmad_slm_2x14_rep4::GetJitConstants(const convolution_params& params, const DispatchData& runInfo) const
86     {
87         auto jit = ConvolutionKernelBase::GetJitConstants(params, runInfo);
88
89         jit.AddConstant(MakeJitConstant("SUB_GROUP_SIZE", 8));
90
91         // pitch for special block format used in this kernel
92         const size_t ifm_32_aligned = Align(params.weights.IFM().v, 32);
93         const size_t filter_ofm_block_pitch = (ifm_32_aligned / 32) * params.weights.X().v * params.weights.Y().v * 4 * 8 * 8;
94         jit.AddConstant(MakeJitConstant("FILTER_OFM_BLOCK_PITCH", filter_ofm_block_pitch));
95
96         const size_t in_x_pitch = 32 * 4;
97         const size_t in_y_pitch = 32 * 4 * params.inputs[0].X().LogicalDimPadded();
98         const size_t in_b_block_pitch = in_y_pitch * params.inputs[0].Y().LogicalDimPadded();
99         const size_t in_f_block_pitch = in_b_block_pitch * ((params.inputs[0].Batch().v + 3) / 4);
100         const size_t in_offset = in_x_pitch * params.inputs[0].X().pad.before + in_y_pitch * params.inputs[0].Y().pad.before;
101
102         jit.AddConstant(MakeJitConstant("IN_X_PITCH", in_x_pitch));
103         jit.AddConstant(MakeJitConstant("IN_Y_PITCH", in_y_pitch));
104         jit.AddConstant(MakeJitConstant("IN_B_BLOCK_PITCH", in_b_block_pitch));
105         jit.AddConstant(MakeJitConstant("IN_F_BLOCK_PITCH", in_f_block_pitch));
106         jit.AddConstant(MakeJitConstant("IN_OFFSET", in_offset));
107
108         jit.AddConstant(MakeJitConstant("OUT_BLOCK_WIDTH", 14));
109         jit.AddConstant(MakeJitConstant("OUT_BLOCK_HEIGHT", 2));
110         jit.AddConstant(MakeJitConstant("LOCAL_SIZE_X", runInfo.lws0));
111         jit.AddConstant(MakeJitConstant("LOCAL_SIZE_Y", runInfo.lws1));
112         jit.AddConstant(MakeJitConstant("LOCAL_SIZE_Z", runInfo.lws2));
113
114         return jit;
115     }
116
117     KernelsData ConvolutionKernel_mmad_slm_2x14_rep4::GetKernelsData(const Params& params, const optional_params& options) const
118     {
119         return GetCommonKernelsData(params, options, " -Dcl_intel_subgroups_char");
120     }
121 }