Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / actual_kernels / roi_pooling / roi_pooling_kernel_base.cpp
1 /*
2 // Copyright (c) 2019 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 "roi_pooling_kernel_base.h"
18
19 namespace kernel_selector {
20
21     static ROIPoolingKernelBase::DispatchData SetDefault(const roi_pooling_params& params)
22     {
23         ROIPoolingKernelBase::DispatchData kd;
24
25         kd.fp16UnitUsed = (params.inputs[0].GetDType() == Datatype::F16);
26
27         // Determine global work sizes.
28         kd.gws0 = params.output.LogicalSize();
29         kd.gws1 = 1;
30         kd.gws2 = 1;
31
32         // Find largest positive local work size that is divider for global work size.
33         kd.lws0 = std::min(std::max(kd.gws0, static_cast<size_t>(1)), static_cast<size_t>(32));
34         while (kd.gws0 % kd.lws0 != 0)
35         {
36             --kd.lws0;
37         }
38         kd.lws1 = 1;
39         kd.lws2 = 1;
40
41         return kd;
42     }
43
44     JitConstants ROIPoolingKernelBase::GetJitConstants(const roi_pooling_params& rp) const
45     {
46         JitConstants jit = MakeBaseParamsJitConstants(rp);
47
48         jit.AddConstants({
49             MakeJitConstant("POOLED_HEIGHT",     rp.pooledHeight),
50             MakeJitConstant("POOLED_WIDTH",      rp.pooledWidth),
51             MakeJitConstant("SPATIAL_SCALE",     rp.spatialScale),
52             MakeJitConstant(toString(rp.mode) + "_POOLING", 1),
53         });
54
55         return jit;
56     }
57
58     KernelsData ROIPoolingKernelBase::GetCommonKernelsData(const Params& params, const optional_params& options, float estimatedTime) const
59     {
60         assert(params.GetType() == KernelType::ROI_POOLING);
61         const roi_pooling_params& orgParams = static_cast<const roi_pooling_params&>(params);
62
63         if (orgParams.activation.function != ActivationFunction::NONE)
64         {
65             return{};
66         }
67
68         DispatchData runInfo = SetDefault(orgParams);
69         KernelData kd = KernelData::Default<roi_pooling_params>(params);
70
71         auto cldnn_jit = GetJitConstants(orgParams);
72         auto entry_point = GetEntryPoint(kernelName, orgParams.layerID, options);
73         auto jit = CreateJit(kernelName, cldnn_jit, entry_point);
74
75         auto& kernel = kd.kernels[0];
76         FillCLKernelData(kernel, runInfo, params.engineInfo, kernelName, jit, entry_point);
77         kernel.arguments.push_back({ ArgumentDescriptor::Types::INPUT, 1 });
78
79         kd.estimatedTime = estimatedTime;
80
81         return{ kd };
82     }
83 }