Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / actual_kernels / convolution / convolution_kernel_bfyx_direct_10_12_16.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_bfyx_direct_10_12_16.h"
18
19 namespace kernel_selector {
20
21     ParamsKey ConvolutionKernel_bfyx_Direct_10_10_12::GetSupportedKey() const
22     {
23         ParamsKey k;
24         k.EnableInputDataType(Datatype::F16);
25         k.EnableOutputDataType(Datatype::F16);
26         k.EnableInputWeightsType(WeightsType::F16);
27         k.EnableInputWeightsType(WeightsType::F32);
28         k.EnableInputLayout(DataLayout::bfyx);
29         k.EnableOutputLayout(DataLayout::bfyx);
30         k.EnableTensorOffset();
31         k.EnableTensorPitches();
32         k.EnableSubGroup();
33         k.EnableSubGroupShort();
34         k.EnableBiasPerFeature();
35         k.EnableBiasPerOutput();
36         k.EnableNonBiasTerm();
37         k.EnableBatching();
38         k.EnableSplitSupport();
39         return k;
40     }
41
42     JitConstants ConvolutionKernel_bfyx_Direct_10_10_12::GetJitConstants(const convolution_params& cp, const DispatchData& runInfo) const
43     {
44         JitConstants jit = Parent::GetJitConstants(cp, runInfo);
45
46         jit.AddConstants({
47             MakeJitConstant("ALIGNED_OFM",                  RoundUp(cp.output.Feature().v, runInfo.gemmStyle.subBlockDimN)),
48             MakeJitConstant("DX",                           runInfo.gemmStyle.globalWorkSizeDX),
49             MakeJitConstant("DY",                           runInfo.gemmStyle.globalWorkSizeDY),
50             MakeJitConstant("KERNEL_SLICE_DIV2",            (cp.filterSize.x * cp.filterSize.y) / 2),
51             MakeJitConstant("RIGHT_PARTIAL_TILE_K",         cp.output.X().v % runInfo.gemmStyle.globalWorkSizeDX),
52             MakeJitConstant("INPUT_BUFFER_WIDTH_PADDED",    ""),    // TODO: enable non padding path again
53             MakeJitConstant("INPUT_BUFFER_HEIGHT_PADDED",   ""),
54         });
55
56         return jit;
57     }
58
59     ConvolutionKernel_bfyx_Direct_10_10_12::Parent::DispatchData ConvolutionKernel_bfyx_Direct_10_10_12::SetDefault(const convolution_params& arg, int) const
60     {
61         Parent::DispatchData runInfo = Parent::SetDefault(arg);
62
63         constexpr uint32_t TILE_N = 16;
64
65         if (arg.filterSize.x == 5)
66         {
67             runInfo.gemmStyle = { 1, 1, TILE_N, /*GWS DX*/ 4, /*GWS DY*/ 4, 1 };
68         }
69         else
70         {
71             runInfo.gemmStyle = { 1, 1, TILE_N, /*GWS DX*/ 4, /*GWS DY*/ 3, 1 };
72         }
73
74         runInfo.gws0 = RoundUp(arg.output.X().v, runInfo.gemmStyle.globalWorkSizeDX) / runInfo.gemmStyle.globalWorkSizeDX;
75         runInfo.gws1 = RoundUp(arg.output.Y().v, runInfo.gemmStyle.globalWorkSizeDY) / runInfo.gemmStyle.globalWorkSizeDY;
76         runInfo.gws2 = RoundUp(arg.output.Feature().v, TILE_N) * arg.output.Batch().v;
77
78         runInfo.lws0 = 1;
79         runInfo.lws1 = 1;
80         runInfo.lws2 = TILE_N;
81
82         runInfo.effiency = FORCE_PRIORITY_4;
83
84         return runInfo;
85     }
86
87     bool ConvolutionKernel_bfyx_Direct_10_10_12::Validate(const Params& p, const optional_params& o) const
88     {
89         if (!Parent::Validate(p, o) || 
90             !CovolutionCheckInput(p, o))
91         {
92             return false;
93         }
94
95         const convolution_params& cp = static_cast<const convolution_params&>(p);
96
97         const bool bStrideOK = (cp.stride.x == 1 && cp.stride.y == 1);
98         const bool bFilter3x3 = (cp.filterSize.x == 3 && cp.filterSize.y == 3);
99         const bool bFilter5x5 = (cp.filterSize.x == 5 && cp.filterSize.y == 5);
100         const bool bFilterOK = bFilter3x3 || bFilter5x5;
101
102         if (!bFilterOK || !bStrideOK)
103         {
104             return false;
105         }
106
107         return true;
108     }
109
110     KernelsData ConvolutionKernel_bfyx_Direct_10_10_12::GetKernelsData(const Params& params, const optional_params& options) const
111     {
112         return GetTunedKernelsDataByIndex(params, options);
113     }
114 }