xref: /aosp_15_r20/external/ComputeLibrary/src/core/CL/kernels/CLDepthwiseConvolutionLayerNativeKernel.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2019-2023 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "src/core/CL/kernels/CLDepthwiseConvolutionLayerNativeKernel.h"
25 
26 #include "arm_compute/core/CL/CLHelpers.h"
27 #include "arm_compute/core/CL/CLKernelLibrary.h"
28 #include "arm_compute/core/CL/ICLTensor.h"
29 #include "arm_compute/core/Helpers.h"
30 #include "arm_compute/core/TensorInfo.h"
31 #include "arm_compute/core/Utils.h"
32 #include "arm_compute/core/utils/misc/ShapeCalculator.h"
33 #include "arm_compute/core/utils/quantization/AsymmHelpers.h"
34 #include "src/core/CL/CLUtils.h"
35 #include "src/core/CL/CLValidate.h"
36 #include "src/core/CL/ICLKernel.h"
37 #include "src/core/helpers/AutoConfiguration.h"
38 #include "src/core/helpers/WindowHelpers.h"
39 #include "src/gpu/cl/kernels/gemm/ClGemmHelpers.h"
40 #include "support/StringSupport.h"
41 
42 namespace arm_compute
43 {
44 namespace
45 {
validate_arguments(const ITensorInfo * input,const ITensorInfo * weights,const ITensorInfo * biases,const ITensorInfo * output,const DWCComputeKernelInfo & dwc_info,const ConvolutionInfo & conv_info,const ITensorInfo * output_multipliers,const ITensorInfo * output_shifts)46 Status validate_arguments(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const DWCComputeKernelInfo &dwc_info,
47                           const ConvolutionInfo &conv_info, const ITensorInfo *output_multipliers, const ITensorInfo *output_shifts)
48 {
49     ARM_COMPUTE_UNUSED(dwc_info);
50     bool in_place = false;
51     if(output == nullptr || output == input)
52     {
53         in_place = true;
54         output   = input;
55     }
56     ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, weights);
57     ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(input);
58     ARM_COMPUTE_RETURN_ERROR_ON_DATA_LAYOUT_NOT_IN(input, DataLayout::NHWC);
59     ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::QASYMM8, DataType::QASYMM8_SIGNED, DataType::F16, DataType::F32);
60     ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.stride().first > 1 && dwc_info.m0 != 1);
61     ARM_COMPUTE_RETURN_ERROR_ON(conv_info.dilation.x() > 1 && dwc_info.m0 != 1);
62     ARM_COMPUTE_RETURN_ERROR_ON((dwc_info.export_input_to_cl_image == true));
63     ARM_COMPUTE_RETURN_ERROR_ON_MSG((dwc_info.export_weights_to_cl_image == true) && (export_to_cl_image(weights) == false), "Weights cannot be exported to cl_image!");
64     ARM_COMPUTE_RETURN_ERROR_ON((dwc_info.export_weights_to_cl_image == true) && ((dwc_info.n0 % 4) != 0));
65     ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.stride().first < 1);
66     ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.stride().second < 1);
67     ARM_COMPUTE_RETURN_ERROR_ON((conv_info.dilation.x() < 1) || (conv_info.dilation.y() < 1));
68     const size_t idx_c = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::CHANNEL);
69     ARM_COMPUTE_UNUSED(idx_c);
70     ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(idx_c) != (input->dimension(idx_c) * conv_info.depth_multiplier));
71 
72     // In place restrictions
73     if(in_place)
74     {
75         const int weights_width_idx  = get_data_layout_dimension_index(weights->data_layout(), DataLayoutDimension::WIDTH);
76         const int weights_height_idx = get_data_layout_dimension_index(weights->data_layout(), DataLayoutDimension::HEIGHT);
77         ARM_COMPUTE_RETURN_ERROR_ON(weights->tensor_shape()[weights_width_idx] != 1U || weights->tensor_shape()[weights_height_idx] != 1U);
78         ARM_COMPUTE_RETURN_ERROR_ON(conv_info.depth_multiplier != 1U);
79         ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.stride() != std::make_pair(1U, 1U));
80         ARM_COMPUTE_RETURN_ERROR_ON(conv_info.dilation != Size2D(1U, 1U));
81         ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.has_padding()); // Note that in princple padding can be supported with in_place but we choose not to support it
82     }
83 
84     const ConvolutionInfo info{ conv_info.pad_stride_info, conv_info.depth_multiplier, ActivationLayerInfo(), conv_info.dilation };
85     const TensorShape     output_shape = arm_compute::misc::shape_calculator::compute_depthwise_convolution_shape(*input, *weights, conv_info);
86 
87     if(conv_info.depth_multiplier > 1 && dwc_info.n0 > 1)
88     {
89         ARM_COMPUTE_RETURN_ERROR_ON((conv_info.depth_multiplier % dwc_info.n0) != 0);
90     }
91 
92     const bool is_quantized = is_data_type_quantized(input->data_type());
93 
94     if(biases != nullptr)
95     {
96         ARM_COMPUTE_RETURN_ERROR_ON(biases->dimension(0) != output_shape[idx_c]);
97         ARM_COMPUTE_RETURN_ERROR_ON(biases->num_dimensions() > 1);
98 
99         if(is_quantized)
100         {
101             ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(biases, 1, DataType::S32);
102         }
103         else
104         {
105             ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, biases);
106         }
107     }
108 
109     if(is_quantized)
110     {
111         ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output_multipliers, output_shifts);
112         ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output_multipliers, 1, DataType::S32);
113         ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output_shifts, 1, DataType::S32);
114         ARM_COMPUTE_RETURN_ERROR_ON(output_multipliers->num_dimensions() > 1);
115         ARM_COMPUTE_RETURN_ERROR_ON(output_shifts->num_dimensions() > 1);
116 
117         if(is_data_type_quantized_per_channel(weights->data_type()))
118         {
119             ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(weights, 1, DataType::QSYMM8_PER_CHANNEL);
120             ARM_COMPUTE_RETURN_ERROR_ON(output_shape[idx_c] != output_multipliers->dimension(0));
121             ARM_COMPUTE_RETURN_ERROR_ON(output_shape[idx_c] != output_shifts->dimension(0));
122         }
123         else
124         {
125             ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights);
126             ARM_COMPUTE_RETURN_ERROR_ON(1 != output_multipliers->dimension(0));
127             ARM_COMPUTE_RETURN_ERROR_ON(1 != output_shifts->dimension(0));
128         }
129     }
130     else
131     {
132         ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, weights);
133     }
134 
135     if(output->total_size() != 0)
136     {
137         ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(output->tensor_shape(), output_shape);
138         ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
139     }
140 
141     if(is_data_type_quantized(input->data_type()))
142     {
143         const UniformQuantizationInfo iq_info = input->quantization_info().uniform();
144         const UniformQuantizationInfo wq_info = weights->quantization_info().uniform();
145         const UniformQuantizationInfo oq_info = (output->total_size() != 0) ? output->quantization_info().uniform() : iq_info;
146 
147         float multiplier        = iq_info.scale * wq_info.scale / oq_info.scale;
148         int   output_multiplier = 0;
149         int   output_shift      = 0;
150         ARM_COMPUTE_RETURN_ON_ERROR(quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift));
151     }
152 
153     return Status{};
154 }
155 } // namespace
156 
CLDepthwiseConvolutionLayerNativeKernel()157 CLDepthwiseConvolutionLayerNativeKernel::CLDepthwiseConvolutionLayerNativeKernel()
158     : _input(nullptr),
159       _weights(nullptr),
160       _biases(nullptr),
161       _output(nullptr),
162       _depth_multiplier(1),
163       _output_multipliers(nullptr),
164       _output_shifts(nullptr),
165       _export_input_to_cl_image(false),
166       _export_weights_to_cl_image(false),
167       _is_quantized(false)
168 {
169     _type = CLKernelType::DEPTHWISE;
170 }
171 
configure(ICLTensor * input,const ICLTensor * weights,const ICLTensor * biases,ICLTensor * output,const DWCComputeKernelInfo & dwc_info,const ConvolutionInfo & conv_info,const ICLTensor * output_multipliers,const ICLTensor * output_shifts)172 void CLDepthwiseConvolutionLayerNativeKernel::configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output,
173                                                         const DWCComputeKernelInfo &dwc_info, const ConvolutionInfo &conv_info,
174                                                         const ICLTensor *output_multipliers, const ICLTensor *output_shifts)
175 {
176     configure(CLKernelLibrary::get().get_compile_context(), input, weights, biases, output, dwc_info, conv_info, output_multipliers, output_shifts);
177 }
178 
configure(const CLCompileContext & compile_context,ICLTensor * input,const ICLTensor * weights,const ICLTensor * biases,ICLTensor * output,const DWCComputeKernelInfo & dwc_info,const ConvolutionInfo & conv_info,const ICLTensor * output_multipliers,const ICLTensor * output_shifts)179 void CLDepthwiseConvolutionLayerNativeKernel::configure(const CLCompileContext &compile_context, ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output,
180                                                         const DWCComputeKernelInfo &dwc_info, const ConvolutionInfo &conv_info,
181                                                         const ICLTensor *output_multipliers, const ICLTensor *output_shifts)
182 {
183     ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights);
184     if(output == nullptr)
185     {
186         // In-place
187         output = input;
188     }
189     ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), weights->info(), (biases != nullptr) ? biases->info() : nullptr, output->info(),
190                                                   dwc_info, conv_info, (output_multipliers != nullptr) ? output_multipliers->info() : nullptr, (output_shifts != nullptr) ? output_shifts->info() : nullptr));
191 
192     auto padding_info = get_padding_info({ input, output });
193 
194     const TensorShape output_shape = arm_compute::misc::shape_calculator::compute_depthwise_convolution_shape(*(input->info()), *(weights->info()), conv_info);
195     auto_init_if_empty(*(output->info()), input->info()->clone()->set_tensor_shape(output_shape).set_quantization_info(output->info()->quantization_info()));
196 
197     _input                      = input;
198     _output                     = output;
199     _weights                    = weights;
200     _biases                     = biases;
201     _depth_multiplier           = conv_info.depth_multiplier;
202     _output_multipliers         = output_multipliers;
203     _output_shifts              = output_shifts;
204     _export_input_to_cl_image   = dwc_info.export_input_to_cl_image;
205     _export_weights_to_cl_image = dwc_info.export_weights_to_cl_image;
206     _is_quantized               = is_data_type_quantized(input->info()->data_type());
207 
208     const unsigned int n0          = adjust_vec_size(dwc_info.n0, output->info()->dimension(0));
209     const unsigned int m0          = std::min(dwc_info.m0, (unsigned int)output->info()->dimension(1));
210     std::string        kernel_name = "";
211 
212     CLBuildOptions build_opts;
213 
214     // Update the padding for the input/weights tensor if we can export to cl_image
215     if(_export_input_to_cl_image)
216     {
217         arm_compute::opencl::kernels::gemm::update_padding_for_cl_image(input->info());
218     }
219 
220     if(_export_weights_to_cl_image)
221     {
222         arm_compute::opencl::kernels::gemm::update_padding_for_cl_image(weights->info());
223     }
224 
225     // Conditions of -cl-fast-relaxed-math causing accuracy issues can be traced from COMPMID-5324
226     const GPUTarget gpu_target    = get_target();
227     const auto      act_function  = conv_info.act_info.activation();
228     const auto      dst_data_type = _output->info()->data_type();
229 
230     if((gpu_target != GPUTarget::G71 && (gpu_target & GPUTarget::GPU_ARCH_MASK) == GPUTarget::BIFROST)
231        && (act_function == ActivationLayerInfo::ActivationFunction::BOUNDED_RELU || act_function == ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU)
232        && (dst_data_type == DataType::F32 || dst_data_type == DataType::F16))
233     {
234         // -cl-fast-relaxed-math also sets -cl-finite-math-only and -cl-unsafe-math-optimizations
235         // to disable -cl-finite-math-only, we only include -cl-unsafe-math-optimizations
236         build_opts.add_option("-cl-unsafe-math-optimizations");
237     }
238     else
239     {
240         build_opts.add_option("-cl-fast-relaxed-math");
241     }
242 
243     build_opts.add_option("-DACTIVATION_TYPE=" + lower_string(string_from_activation_func(act_function)));
244     build_opts.add_option("-DDEPTH_MULTIPLIER=" + support::cpp11::to_string(conv_info.depth_multiplier));
245     build_opts.add_option_if_else(_export_input_to_cl_image, "-DSRC_TENSOR_TYPE=IMAGE", "-DSRC_TENSOR_TYPE=BUFFER");
246     // Note: SRC_DATA_TYPE must have the same data type of WEI_DATA_TYPE. In quantized, we could
247     // have a case where the data types for the activation and weights are different. However, since the implementation
248     // only works when both have same data type, we have to change the offset to take into account this aspect
249     build_opts.add_option("-DSRC_DATA_TYPE=" + get_cl_type_from_data_type(_input->info()->data_type()));
250     build_opts.add_option("-DDST_TENSOR_TYPE=BUFFER");
251     build_opts.add_option("-DDST_DATA_TYPE=" + get_cl_type_from_data_type(dst_data_type));
252     build_opts.add_option_if_else(_export_weights_to_cl_image, "-DWEI_TENSOR_TYPE=IMAGE", "-DWEI_TENSOR_TYPE=BUFFER");
253     build_opts.add_option("-DSRC_WIDTH=" + support::cpp11::to_string(_input->info()->dimension(1)));
254     build_opts.add_option("-DSRC_HEIGHT=" + support::cpp11::to_string(_input->info()->dimension(2)));
255     build_opts.add_option("-DDST_WIDTH=" + support::cpp11::to_string(_output->info()->dimension(1)));
256     build_opts.add_option("-DDST_HEIGHT=" + support::cpp11::to_string(_output->info()->dimension(2)));
257     build_opts.add_option("-DWEI_WIDTH=" + support::cpp11::to_string(_weights->info()->dimension(1)));
258     build_opts.add_option("-DWEI_HEIGHT=" + support::cpp11::to_string(_weights->info()->dimension(2)));
259     build_opts.add_option("-DWEI_DATA_TYPE=" + get_cl_type_from_data_type(_weights->info()->data_type()));
260     build_opts.add_option("-DPAD_TOP=" + support::cpp11::to_string(conv_info.pad_stride_info.pad_top()));
261     build_opts.add_option("-DPAD_LEFT=" + support::cpp11::to_string(conv_info.pad_stride_info.pad_left()));
262     build_opts.add_option("-DSTRIDE_X=" + support::cpp11::to_string(conv_info.pad_stride_info.stride().first));
263     build_opts.add_option("-DSTRIDE_Y=" + support::cpp11::to_string(conv_info.pad_stride_info.stride().second));
264     build_opts.add_option("-DDILATION_X=" + support::cpp11::to_string(conv_info.dilation.x()));
265     build_opts.add_option("-DDILATION_Y=" + support::cpp11::to_string(conv_info.dilation.y()));
266     build_opts.add_option("-DN0=" + support::cpp11::to_string(n0));
267     build_opts.add_option("-DM0=" + support::cpp11::to_string(m0));
268     build_opts.add_option("-DM0_A=" + support::cpp11::to_string(_weights->info()->dimension(1) + m0 - 1));
269     build_opts.add_option_if_else(conv_info.depth_multiplier > 1, "-DN0_A=1", "-DN0_A=" + support::cpp11::to_string(n0));
270     build_opts.add_option("-DPARTIAL_N0=" + support::cpp11::to_string(_output->info()->dimension(0) % n0));
271     build_opts.add_option_if(_input->info()->num_dimensions() > 3, "-DBATCHED_EXECUTION");
272 
273     // Force unroll with pragma when any of the following values exceed the maximum number of manual unroll
274     set_unroll_with_pragma(build_opts, { static_cast<int>(_weights->info()->dimension(1) + m0 - 1),
275                                          static_cast<int>(_weights->info()->dimension(1)),
276                                          static_cast<int>(_weights->info()->dimension(2))
277                                        });
278 
279     if(biases != nullptr)
280     {
281         build_opts.add_option(std::string("-DHAS_BIAS"));
282         build_opts.add_option(std::string("-DBIA_DATA_TYPE=" + get_cl_type_from_data_type(biases->info()->data_type())));
283     }
284 
285     if(_is_quantized)
286     {
287         kernel_name                          = "dwc_native_quantized_nhwc";
288         const UniformQuantizationInfo iqinfo = input->info()->quantization_info().uniform();
289         const UniformQuantizationInfo wqinfo = weights->info()->quantization_info().uniform();
290         const UniformQuantizationInfo oqinfo = output->info()->quantization_info().uniform();
291 
292         PixelValue zero_value = PixelValue(0, input->info()->data_type(), input->info()->quantization_info());
293         int        zero_value_s32;
294         zero_value.get(zero_value_s32);
295 
296         float multiplier        = iqinfo.scale * wqinfo.scale / oqinfo.scale;
297         int   output_multiplier = 0;
298         int   output_shift      = 0;
299         quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift);
300         build_opts.add_option("-DDST_MULTIPLIER=" + support::cpp11::to_string(output_multiplier));
301         build_opts.add_option("-DDST_SHIFT=" + support::cpp11::to_string(output_shift));
302         build_opts.add_option("-DSRC_OFFSET=" + support::cpp11::to_string(-iqinfo.offset));
303         build_opts.add_option("-DWEI_OFFSET=" + support::cpp11::to_string(-wqinfo.offset));
304         build_opts.add_option("-DDST_OFFSET=" + support::cpp11::to_string(oqinfo.offset));
305         build_opts.add_option("-DZERO_VALUE=" + support::cpp11::to_string(zero_value_s32));
306         build_opts.add_option("-DACC_DATA_TYPE=" + get_cl_type_from_data_type(DataType::S32));
307         build_opts.add_option("-DDST_MULTIPLIERS_DATA_TYPE=" + get_cl_type_from_data_type(_output_multipliers->info()->data_type()));
308         build_opts.add_option("-DDST_SHIFTS_DATA_TYPE=" + get_cl_type_from_data_type(_output_shifts->info()->data_type()));
309         build_opts.add_option_if_else(weights->info()->data_type() == DataType::QSYMM8_PER_CHANNEL, "-DQUANTIZATION_TYPE=PER_CHANNEL", "-DQUANTIZATION_TYPE=PER_TENSOR");
310         // Note: We expect the input and output tensors to always adopt a per-tensor quantization approach
311         int a_val{};
312         int b_val{};
313         std::tie(b_val, a_val) = get_quantized_activation_min_max(conv_info.act_info, input->info()->data_type(), oqinfo);
314 
315         build_opts.add_option_if(conv_info.act_info.enabled(), "-DA_VAL=" + support::cpp11::to_string(a_val));
316         build_opts.add_option_if(conv_info.act_info.enabled(), "-DB_VAL=" + support::cpp11::to_string(b_val));
317     }
318     else
319     {
320         kernel_name = "dwc_native_fp_nhwc";
321         build_opts.add_option("-DACC_DATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type()));
322         build_opts.add_option_if(conv_info.act_info.enabled(), "-DA_VAL=" + float_to_string_with_full_precision(conv_info.act_info.a()));
323         build_opts.add_option_if(conv_info.act_info.enabled(), "-DB_VAL=" + float_to_string_with_full_precision(conv_info.act_info.b()));
324     }
325 
326     Window win = calculate_max_window(*(output->info()), Steps(n0, m0));
327     ICLKernel::configure_internal(win);
328 
329     _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
330 
331     ARM_COMPUTE_ERROR_ON(has_padding_changed(padding_info));
332 
333     // Set config_id for enabling LWS tuning
334     _config_id = kernel_name;
335     _config_id += "_";
336     _config_id += support::cpp11::to_string(input->info()->dimension(0));
337     _config_id += "_";
338     _config_id += support::cpp11::to_string(input->info()->dimension(1));
339     _config_id += "_";
340     _config_id += support::cpp11::to_string(input->info()->dimension(2));
341     _config_id += "_";
342     _config_id += support::cpp11::to_string(output->info()->dimension(0));
343     _config_id += "_";
344     _config_id += support::cpp11::to_string(output->info()->dimension(1));
345     _config_id += "_";
346     _config_id += support::cpp11::to_string(output->info()->dimension(2));
347     _config_id += "_";
348     _config_id += string_from_data_type(input->info()->data_type());
349 }
350 
validate(const ITensorInfo * input,const ITensorInfo * weights,const ITensorInfo * biases,const ITensorInfo * output,const DWCComputeKernelInfo & dwc_info,const ConvolutionInfo & conv_info,const ITensorInfo * output_multipliers,const ITensorInfo * output_shifts)351 Status CLDepthwiseConvolutionLayerNativeKernel::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output,
352                                                          const DWCComputeKernelInfo &dwc_info, const ConvolutionInfo &conv_info, const ITensorInfo *output_multipliers, const ITensorInfo *output_shifts)
353 {
354     ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, weights, biases, output, dwc_info, conv_info, output_multipliers, output_shifts));
355     return Status{};
356 }
357 
run(const Window & window,cl::CommandQueue & queue)358 void CLDepthwiseConvolutionLayerNativeKernel::run(const Window &window, cl::CommandQueue &queue)
359 {
360     ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
361     ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window);
362 
363     // Collapse window
364     Window window_collapsed = window.collapse(ICLKernel::window(), Window::DimZ);
365 
366     Window slice = window_collapsed.first_slice_window_4D();
367 
368     cl::Image2D input_cl_image;
369     cl::Image2D weights_cl_image;
370 
371     if(_export_input_to_cl_image || _export_weights_to_cl_image)
372     {
373         // Export cl_buffer to cl_image
374         if(_export_input_to_cl_image)
375         {
376             const size_t      image_w = _input->info()->dimension(0) / 4;
377             const size_t      image_h = _input->info()->dimension(1) * _input->info()->dimension(2) * _input->info()->dimension(3);
378             const TensorShape shape2d(image_w, image_h);
379             const size_t      image_row_pitch = _input->info()->strides_in_bytes()[1];
380             input_cl_image                    = create_image2d_from_buffer(CLKernelLibrary::get().context(), _input->cl_buffer(), shape2d, _input->info()->data_type(), image_row_pitch, CLImage2DType::ReadOnly);
381         }
382 
383         if(_export_weights_to_cl_image)
384         {
385             const size_t      image_w = _weights->info()->dimension(0) / 4;
386             const size_t      image_h = _weights->info()->dimension(1) * _weights->info()->dimension(2) * _weights->info()->dimension(3);
387             const TensorShape shape2d(image_w, image_h);
388             const size_t      image_row_pitch = _weights->info()->strides_in_bytes()[1];
389             weights_cl_image                  = create_image2d_from_buffer(CLKernelLibrary::get().context(), _weights->cl_buffer(), shape2d, _weights->info()->data_type(), image_row_pitch,
390                                                                            CLImage2DType::ReadOnly);
391         }
392     }
393 
394     unsigned int idx = 0;
395     if(_export_input_to_cl_image)
396     {
397         _kernel.setArg(idx++, input_cl_image);
398     }
399     add_4d_tensor_nhwc_argument(idx, _input);
400     add_4d_tensor_nhwc_argument(idx, _output);
401     if(_export_weights_to_cl_image)
402     {
403         _kernel.setArg(idx++, weights_cl_image);
404     }
405     add_4d_tensor_nhwc_argument(idx, _weights);
406     if(_is_quantized)
407     {
408         add_1D_tensor_argument(idx, _output_multipliers, slice);
409         add_1D_tensor_argument(idx, _output_shifts, slice);
410     }
411     if(_biases != nullptr)
412     {
413         add_1D_tensor_argument(idx, _biases, slice);
414     }
415     enqueue(queue, *this, slice, lws_hint());
416 }
417 } // namespace arm_compute
418