Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / actual_kernels / pooling / pooling_kernel_gpu_average_opt.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 "pooling_kernel_gpu_average_opt.h"
18  
19 namespace kernel_selector 
20 {
21     ParamsKey PoolingKernelGPUAverageOpt::GetSupportedKey() const
22     {
23         ParamsKey k;
24         k.EnableInputDataType(Datatype::F32);
25         k.EnableOutputDataType(Datatype::F32);
26         k.EnableInputLayout(DataLayout::bfyx);
27         k.EnableOutputLayout(DataLayout::bfyx);
28         k.EnablePoolType(PoolType::AVG);
29         k.EnablePoolRemainder(PoolRemainder::FLOOR);
30         k.EnablePoolRemainder(PoolRemainder::CEIL);
31         k.EnablePoolKernelDividerMode(KernelDividerMode::FIXED);
32         return k;
33     }
34
35     bool PoolingKernelGPUAverageOpt::Validate(const Params& p, const optional_params& o) const
36     {
37         if (!PoolingKernelBase::Validate(p, o))
38         {
39             return false;
40         }
41
42         const pooling_params& params = static_cast<const pooling_params&>(p);
43
44         if (params.activation.function != ActivationFunction::NONE)
45         {
46             return{};
47         }
48
49         if ((params.poolSize.x != 3) ||
50             (params.poolSize.y != 3) ||
51             (params.poolStride.x != 1) ||
52             (params.poolStride.y != 1) ||
53             (params.poolPad.x != 1) ||
54             (params.poolPad.y != 1) ||
55             !(params.inputs[0] == params.output) ||
56             params.inputs[0].PitchesDifferFromLogicalDims() ||
57             params.output.PitchesDifferFromLogicalDims())
58         {
59             return false;
60         }
61
62         return true;
63     }
64
65     static uSize GetTileDimentions()
66     {
67         constexpr int simdSize = 16;
68
69         return{ simdSize - 2, 7 };
70     }
71
72     PoolingKernelBase::DispatchData PoolingKernelGPUAverageOpt::SetDefault(const pooling_params& params) const
73     {
74         constexpr int simdSize = 16;
75
76         DispatchData runInfo = PoolingKernelBase::SetDefault(params);
77
78         auto tileDims = GetTileDimentions();
79
80         const int numTilesX = static_cast<int>(std::ceil(static_cast<float>(params.inputs[0].X().v) / static_cast<float>(tileDims.x)));
81         const int numTilesY = static_cast<int>(std::ceil(static_cast<float>(params.inputs[0].Y().v) / static_cast<float>(tileDims.y)));
82
83         runInfo.gws0 = numTilesX * simdSize;
84         runInfo.gws1 = numTilesY;
85         runInfo.gws2 = params.inputs[0].Feature().v;
86         runInfo.lws0 = simdSize;
87         runInfo.lws1 = 1;
88         runInfo.lws2 = 1;
89
90         return runInfo;
91     }
92
93     JitConstants PoolingKernelGPUAverageOpt::GetJitConstants(const pooling_params& params, DispatchData kd) const
94     {
95         auto tileDims = GetTileDimentions();
96         auto mem_consts = PoolingKernelBase::GetJitConstants(params, kd);
97
98         if (tileDims.y != 0 && tileDims.x != 0)
99         {
100             mem_consts.AddConstant(MakeJitConstant("SUB_GROUP_SIZE", kd.lws0));
101             mem_consts.AddConstant(MakeJitConstant("TILE_HEIGHT", tileDims.y));
102             mem_consts.AddConstant(MakeJitConstant("TILE_WIDTH", tileDims.x));
103             mem_consts.AddConstant(MakeJitConstant("ONE_OVER_POOL_SIZE", 1.f / (params.poolSize.x * params.poolSize.y)));
104         }
105
106         return mem_consts;
107     }
108
109     KernelsData PoolingKernelGPUAverageOpt::GetKernelsData(const Params& params, const optional_params& options) const
110     {
111         return GetCommonKernelsData(params, options, FORCE_PRIORITY_7);
112     }
113 }