2 // Copyright (c) 2018 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 "convolution_grad_weights_kernel_base.h"
18 #include "kernel_selector_utils.h"
20 namespace kernel_selector
22 std::string convolution_grad_weights_params::to_string() const
26 s << base_params::to_string() << "_";
29 s << "no_bias" << "_";
33 s << "bias_" << 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 ConvolutionGradWeightsKernelBase::GetJitConstants(const convolution_grad_weights_params& cp) const
46 JitConstants jit = training_kernel_base::GetJitConstants(cp);
47 const auto& padding = cp.padding;
48 const auto& input = cp.inputs[0];
50 int64_t input_offset_with_padding = (int64_t)input.GetFirstElementOffset() - (cp.filterSize.x - 1 + padding.x)*input.X().pitch - (cp.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", cp.stride),
55 MakeJitConstant("PADDING", cp.padding),
56 MakeJitConstant("DILATION", cp.dilation),
57 MakeJitConstant("FILTER_ARRAY_NUM", cp.split),
58 MakeJitConstant("INPUT0_OFFSET_WITH_PADDING", input_offset_with_padding),
59 MakeJitConstant("DEPTHWISE_SEPARABLE_OPT", cp.depthwiseSeparableOpt),
65 ConvolutionGradWeightsKernelBase::DispatchData ConvolutionGradWeightsKernelBase::SetDefault(const convolution_grad_weights_params& params) const
67 auto input_features = params.weights.IFM().v;
68 auto output_features = params.weights.OFM().v;
72 kd.fp16UnitUsed = params.inputs[0].GetDType() == Datatype::F16;
73 size_t gws0 = output_features * input_features;
74 size_t lws0 = std::min(gws0, static_cast<size_t>(32));
80 kd.gws1 = params.weights.X().v;
81 kd.gws2 = params.weights.Y().v;
85 kd.effiency = DONT_USE_IF_HAVE_SOMETHING_ELSE;
89 KernelsData ConvolutionGradWeightsKernelBase::GetKernelsData(const Params& params, const optional_params& options) const
91 assert(params.GetType() == KernelType::CONVOLUTION_GRAD_WEIGHTS);
93 if (!Validate(params, options))
98 const convolution_grad_weights_params& orgParams = static_cast<const convolution_grad_weights_params&>(params);
100 const std::vector<WeightsLayout> weightsLayouts = {
107 DispatchData runInfo = SetDefault(orgParams);
108 KernelData kd = KernelData::Default<convolution_grad_weights_params>(params);
109 convolution_grad_weights_params& newParams = *static_cast<convolution_grad_weights_params*>(kd.params.get());
111 bool succeed = UpdateWeightsParams(
115 kd.weightsReorderParams);
122 auto cldnn_jit = GetJitConstants(orgParams);
123 auto entry_point = GetEntryPoint(kernelName, orgParams.layerID, options);
124 auto jit = CreateJit(kernelName, cldnn_jit, entry_point);
126 auto& kernel = kd.kernels[0];
127 FillCLKernelData(kernel, runInfo, kernelName, jit, entry_point, ROUND_ROBIN, true, !orgParams.bias.empty());
128 if (newParams.use_momentum)
130 kernel.arguments.push_back({ ArgumentDescriptor::Types::PREV_WEIGHTS_GRADIENT, 0 });
131 if (!newParams.bias.empty())
132 kernel.arguments.push_back({ ArgumentDescriptor::Types::PREV_BIAS_GRADIENT, 0 });
134 kernel.arguments.push_back({ ArgumentDescriptor::Types::INPUT, 1 });
135 kernel.arguments.push_back({ ArgumentDescriptor::Types::SPLIT, 0 });
136 kernel.arguments.push_back({ ArgumentDescriptor::Types::LEARNING_RATE, 0 });
138 kd.estimatedTime = runInfo.effiency;