Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / actual_kernels / upsampling / upsampling_kernel_base.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 "upsampling_kernel_base.h"
18 #include "kernel_selector_utils.h" 
19
20 namespace kernel_selector
21 {
22     bool UpSamplingKernelBase::Validate(const Params& p, const optional_params& o) const
23     {
24         if (p.GetType() != KernelType::UPSAMPLING ||
25             o.GetType() != KernelType::UPSAMPLING)
26         {
27             return false;
28         }
29
30         const upsampling_params& params = static_cast<const upsampling_params&>(p);
31
32         if (params.inputs.size() == 0)
33         {
34             return false;
35         }
36
37         return true;
38     }
39
40     JitConstants UpSamplingKernelBase::GetJitConstants(const upsampling_params& params) const
41     {
42         JitConstants jit = MakeBaseParamsJitConstants(params);
43
44         const auto& input = params.inputs[0];
45         const auto& output = params.output;
46
47         auto x_ratio = (float)input.X().v / (float)output.X().v;
48         auto y_ratio = (float)input.Y().v / (float)output.Y().v;
49
50         jit.AddConstants({
51             MakeJitConstant(toString(params.sampleType), ""),
52             MakeJitConstant("X_RATIO", x_ratio),
53             MakeJitConstant("Y_RATIO", y_ratio),
54         });
55
56         return jit;
57     }
58
59     KernelsData UpSamplingKernelBase::GetCommonKernelsData(const Params& params, const optional_params& options) const
60     {
61         if (!Validate(params, options))
62         {
63             return{};
64         }
65
66         KernelData kd = KernelData::Default<upsampling_params>(params);
67         upsampling_params& newParams = *static_cast<upsampling_params*>(kd.params.get());
68
69         auto entry_point = GetEntryPoint(kernelName, newParams.layerID, options);
70         auto cldnn_jit = GetJitConstants(newParams);
71         std::string jit = CreateJit(kernelName, cldnn_jit, entry_point);
72
73         auto& kernel = kd.kernels[0];
74
75         const auto& out = newParams.output;
76
77         kernel.workGroups.global = { out.X().v, out.Y().v, out.Feature().v * out.Batch().v };
78         kernel.workGroups.local = GetOptimalLocalWorkGroupSizes(kernel.workGroups.global);
79         kernel.kernelString = GetKernelString(kernelName, jit, entry_point, params.engineInfo, DEFAULT);
80         kernel.arguments = GetArgsDesc((uint32_t)newParams.inputs.size(), false, false);
81
82         kd.estimatedTime = DONT_USE_IF_HAVE_SOMETHING_ELSE;
83
84         return{ kd };
85     }
86 }