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 "deconvolution_kernel_base.h"
18 #include "kernel_selector_utils.h"
20 namespace kernel_selector
22 std::string deconvolution_params::to_string() const
26 s << base_params::to_string() << "_";
29 s << "no_bias" << "_";
33 s << "bias_size:" << bias[0].PhysicalSize() << "_";
35 s << filterSize.x << "_" << filterSize.y << "_";
36 s << stride.x << "_" << stride.y << "_";
37 s << dilation.x << "_" << dilation.y << "_";
38 s << padding.x << "_" << padding.y << "_";
44 JitConstants DeconvolutionKernelBase::GetJitConstants(const deconvolution_params& dp) const
46 JitConstants jit = WeightBiasKernelBase::GetJitConstants(dp);
47 const auto& padding = dp.padding;
48 const auto& input = dp.inputs[0];
50 int64_t input_offset_with_padding = (int64_t)input.GetFirstElementOffset() - (dp.filterSize.x - 1 + padding.x)*input.X().pitch - (dp.filterSize.y - 1 + padding.y)*input.Y().pitch;
51 input_offset_with_padding = std::max(input_offset_with_padding, (int64_t)0);
54 MakeJitConstant("STRIDE", dp.stride),
55 MakeJitConstant("PADDING", dp.padding),
56 MakeJitConstant("DILATION", dp.dilation),
57 MakeJitConstant("FILTER_ARRAY_NUM", dp.split),
58 MakeJitConstant("INPUT0_OFFSET_WITH_PADDING", input_offset_with_padding),
59 MakeJitConstant("DEPTHWISE_SEPARABLE_OPT", dp.depthwise_separable_opt),
60 MakeJitConstant("FUSED_ELTWISE", dp.fused_eltwise),
61 MakeJitConstant("GROUPED", (dp.groups > 1) ? 1 : 0)
67 DeconvolutionKernelBase::DispatchData DeconvolutionKernelBase::SetDefault(const deconvolution_params& params) const
69 auto batch_size = params.output.Batch().v;
70 auto output_features = params.output.Feature().v;
74 kd.fp16UnitUsed = params.inputs[0].GetDType() == Datatype::F16;
75 size_t gws0 = output_features * batch_size;
76 size_t lws0 = std::min(gws0, static_cast<size_t>(32));
82 kd.gws1 = params.output.X().v;
83 kd.gws2 = params.output.Y().v;
87 kd.effiency = DONT_USE_IF_HAVE_SOMETHING_ELSE;
91 KernelsData DeconvolutionKernelBase::GetKernelsData(const Params& params, const optional_params& options) const
93 assert(params.GetType() == KernelType::DECONVOLUTION);
95 const deconvolution_params& orgParams = static_cast<const deconvolution_params&>(params);
97 const std::vector<WeightsLayout> weightsLayouts = {
104 DispatchData runInfo = SetDefault(orgParams);
105 KernelData kd = KernelData::Default<deconvolution_params>(params);
106 deconvolution_params& newParams = *static_cast<deconvolution_params*>(kd.params.get());
108 bool succeed = UpdateWeightsParams(
112 kd.weightsReorderParams);
119 auto cldnn_jit = GetJitConstants(newParams);
120 auto entry_point = GetEntryPoint(kernelName, newParams.layerID, options);
121 auto jit = CreateJit(kernelName, cldnn_jit, entry_point);
123 auto& kernel = kd.kernels[0];
124 FillCLKernelData(kernel, runInfo, params.engineInfo, kernelName, jit, entry_point, DEFAULT, true, !newParams.bias.empty());
125 kernel.arguments.push_back({ ArgumentDescriptor::Types::SPLIT, 0 });
126 if (orgParams.fused_eltwise)
127 kernel.arguments.push_back({ ArgumentDescriptor::Types::INPUT, 1 });
129 kd.estimatedTime = runInfo.effiency;