Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / actual_kernels / convolution / convolution_kernel_base.h
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 #pragma once
18
19 #include "weight_bias_kernel_base.h"
20 #include "convolution_params.h"
21
22 namespace kernel_selector 
23 {
24     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
25     // ConvolutionKernelBase
26     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
27     class ConvolutionKernelBase : public WeightBiasKernelBase
28     {
29     public:
30         using WeightBiasKernelBase::WeightBiasKernelBase;
31         virtual ~ConvolutionKernelBase() {}
32
33         struct DispatchData : public CommonDispatchData
34         {
35             struct CLDNNStyle
36             {
37                 size_t blockWidth, blockHeight; // used for kernels processing blocks
38                 size_t prefetch;
39                 size_t inputBlockArraySize;     // Number of elements in array of UNIT_TYPE that must be specified in kernel to store/cache input block.
40                 size_t inputBlockWidth;         // Number of elements in X dimension stored/cached in input block.
41             };
42
43             struct GEMMStyle
44             {
45                 size_t subBlockDimM;
46                 size_t subBlockDimK;
47                 size_t subBlockDimN;
48                 size_t globalWorkSizeDX;
49                 size_t globalWorkSizeDY;
50                 size_t globalWorkSizeDZ;
51             };
52
53             union
54             {
55                 CLDNNStyle cldnnStyle;
56                 GEMMStyle  gemmStyle;
57             };
58         };
59         
60         std::string GetAutoTuneOptions(int autoTuneIndex) const;
61         std::vector<std::string> autoTuneOptions = { DEFAULT, NO_PRERA_SCH, AGE_BASED };
62         virtual KernelsData GetKernelsDataForAutoTune(const Params& params, const optional_params& options) const override;
63         virtual KernelsData GetTunedKernelsDataByIndex(const Params& params, const optional_params& options, int autoTuneIndex = -1) const override;
64     
65     protected:
66         virtual std::vector<WeightsLayout> GetSupportedWeightLayouts(const convolution_params&) const = 0;
67         virtual std::string GetKernelName(const convolution_params&) const { return kernelName; }
68         virtual bool NeedPaddedInput() const { return false; }
69         virtual bool Validate(const Params& p, const optional_params& o) const override;
70         virtual JitConstants GetJitConstants(const convolution_params& params, const DispatchData& kd) const;
71         virtual DispatchData SetDefault(const convolution_params& params, int autoTuneIndex = -1) const;
72         static bool CheckWorkGroups(const DispatchData&);
73         static bool CheckPitchForSplitOnly(const convolution_params& params);
74         KernelsData GetCommonKernelsData(const Params& params, const optional_params& options, const std::string exeMode = DEFAULT, int autoTuneIndex = -1) const;
75     };
76
77     bool CovolutionCheckInput(const Params& p, const optional_params& o);
78     bool CheckConvolutionPaddedInputDesc(const convolution_params& params, const DataTensor& reqDesc);
79     bool CovolutionUpdateInputParams(convolution_params& params);
80
81 }