Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / actual_kernels / convolution / convolution_kernel_bfyx_1x1.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_1x1.h"
18
19 namespace kernel_selector {
20     
21     ParamsKey ConvolutionKernel_bfyx_1x1::GetSupportedKey() const
22     {
23         ParamsKey k;
24         k.EnableInputDataType(Datatype::F16);
25         k.EnableInputDataType(Datatype::F32);
26         k.EnableOutputDataType(Datatype::F16);
27         k.EnableOutputDataType(Datatype::F32);
28         k.EnableInputWeightsType(WeightsType::F16);
29         k.EnableInputWeightsType(WeightsType::F32);
30         k.EnableInputLayout(DataLayout::bf8_xy16);
31         k.EnableInputLayout(DataLayout::bfyx);
32         k.EnableOutputLayout(DataLayout::bfyx);
33         k.EnableOutputLayout(DataLayout::yxfb);
34         k.EnableOutputLayout(DataLayout::bf8_xy16);
35         k.EnableTensorOffset();
36         k.EnableTensorPitches();
37         k.EnableDilation();
38         k.EnableBiasPerFeature();
39         k.EnableBiasPerOutput();
40         k.EnableNonBiasTerm();
41         k.EnableBatching();
42         k.EnableSplitSupport();
43         k.EnableDepthwiseSeparableOpt();
44         return k;
45     }
46
47     ConvolutionKernelBase::DispatchData ConvolutionKernel_bfyx_1x1::SetDefault(const convolution_params& params, int) const
48     {
49         DispatchData kd = ConvolutionKernelBase::SetDefault(params);
50
51         const auto& out = params.output;
52
53         auto x = out.X().v;
54         auto y = out.Y().v;
55         auto f = out.Feature().v;
56         auto b = out.Batch().v;
57
58         kd.gws0 = Align(x * y, 16) / 16;
59         kd.gws1 = Align(f, 16);
60         kd.gws2 = b;
61
62         kd.lws0 = 1;
63         kd.lws1 = 16;
64         kd.lws2 = 1;
65
66         kd.effiency = FORCE_PRIORITY_2;
67
68         return kd;
69     }
70
71     bool ConvolutionKernel_bfyx_1x1::Validate(const Params& p, const optional_params& o) const
72     {
73         if (!ConvolutionKernelBase::Validate(p, o))
74         {
75             return false;
76         }
77
78         const auto& params = static_cast<const convolution_params&>(p);
79
80         const auto &input = params.inputs[0];
81         const auto &output = params.output;
82
83         const bool bOutputSizes = output.X().v != input.X().v || output.Y().v != input.Y().v;
84         const bool bPad = input.X().pad.Total() != 0 || input.Y().pad.Total() != 0 || input.Feature().pad.Total() != 0 || input.Batch().pad.Total() != 0;
85         const bool bFilterSize = params.filterSize.x != 1 || params.filterSize.y != 1;
86         const bool bStride = params.stride.x != 1 || params.stride.y != 1;
87         const bool bInputSizes = input.GetLayout() == DataLayout::bfyx && (input.X().v * input.Y().v != 16 || (input.Feature().v % 8) != 0);
88
89         if(bOutputSizes || bPad || bFilterSize || bStride || bInputSizes)
90         {
91             return false;
92         }
93
94         return true;
95     }
96
97     JitConstants ConvolutionKernel_bfyx_1x1::GetJitConstants(const convolution_params& params, const DispatchData& runInfo) const
98     {
99         auto jit = Parent::GetJitConstants(params, runInfo);
100
101         if (params.output.Feature().v % 16)
102             jit.AddConstant(MakeJitConstant("LEFTOVERS", 1));
103
104         return jit;
105     }
106
107     KernelsData ConvolutionKernel_bfyx_1x1::GetKernelsData(const Params& params, const optional_params& options) const
108     {
109         return GetTunedKernelsDataByIndex(params, options);
110     }
111 }