2 // Copyright (c) 2016 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "upsampling_kernel_base.h"
18 #include "kernel_selector_utils.h"
20 namespace kernel_selector
22 bool UpSamplingKernelBase::Validate(const Params& p, const optional_params& o) const
24 if (p.GetType() != KernelType::UPSAMPLING ||
25 o.GetType() != KernelType::UPSAMPLING)
30 const upsampling_params& params = static_cast<const upsampling_params&>(p);
32 if (params.inputs.size() == 0)
40 JitConstants UpSamplingKernelBase::GetJitConstants(const upsampling_params& params) const
42 JitConstants jit = MakeBaseParamsJitConstants(params);
44 const auto& input = params.inputs[0];
45 const auto& output = params.output;
47 auto x_ratio = (float)input.X().v / (float)output.X().v;
48 auto y_ratio = (float)input.Y().v / (float)output.Y().v;
51 MakeJitConstant(toString(params.sampleType), ""),
52 MakeJitConstant("X_RATIO", x_ratio),
53 MakeJitConstant("Y_RATIO", y_ratio),
59 KernelsData UpSamplingKernelBase::GetCommonKernelsData(const Params& params, const optional_params& options) const
61 if (!Validate(params, options))
66 KernelData kd = KernelData::Default<upsampling_params>(params);
67 upsampling_params& newParams = *static_cast<upsampling_params*>(kd.params.get());
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);
73 auto& kernel = kd.kernels[0];
75 const auto& out = newParams.output;
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);
82 kd.estimatedTime = DONT_USE_IF_HAVE_SOMETHING_ELSE;