Compute Library
 23.11
CLDepthwiseConvolutionLayerNativeKernel.cpp
Go to the documentation of this file.
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  */
25 
36 
37 #include "src/core/CL/CLUtils.h"
38 #include "src/core/CL/CLValidate.h"
39 #include "src/core/CL/ICLKernel.h"
43 #include "support/StringSupport.h"
44 
45 namespace arm_compute
46 {
47 namespace
48 {
49 Status validate_arguments(const ITensorInfo *input,
50  const ITensorInfo *weights,
51  const ITensorInfo *biases,
52  const ITensorInfo *output,
53  const DWCComputeKernelInfo &dwc_info,
54  const ConvolutionInfo &conv_info,
55  const ITensorInfo *output_multipliers,
56  const ITensorInfo *output_shifts)
57 {
58  ARM_COMPUTE_UNUSED(dwc_info);
59  bool in_place = false;
60  if (output == nullptr || output == input)
61  {
62  in_place = true;
63  output = input;
64  }
70  ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.stride().first > 1 && dwc_info.m0 != 1);
71  ARM_COMPUTE_RETURN_ERROR_ON(conv_info.dilation.x() > 1 && dwc_info.m0 != 1);
72  ARM_COMPUTE_RETURN_ERROR_ON((dwc_info.export_input_to_cl_image == true));
73  ARM_COMPUTE_RETURN_ERROR_ON_MSG((dwc_info.export_weights_to_cl_image == true) &&
74  (export_to_cl_image(weights) == false),
75  "Weights cannot be exported to cl_image!");
76  ARM_COMPUTE_RETURN_ERROR_ON((dwc_info.export_weights_to_cl_image == true) && ((dwc_info.n0 % 4) != 0));
77  ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.stride().first < 1);
78  ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.stride().second < 1);
79  ARM_COMPUTE_RETURN_ERROR_ON((conv_info.dilation.x() < 1) || (conv_info.dilation.y() < 1));
80  const size_t idx_c = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::CHANNEL);
81  ARM_COMPUTE_UNUSED(idx_c);
82  ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(idx_c) != (input->dimension(idx_c) * conv_info.depth_multiplier));
83 
84  // In place restrictions
85  if (in_place)
86  {
87  const int weights_width_idx =
89  const int weights_height_idx =
91  ARM_COMPUTE_RETURN_ERROR_ON(weights->tensor_shape()[weights_width_idx] != 1U ||
92  weights->tensor_shape()[weights_height_idx] != 1U);
93  ARM_COMPUTE_RETURN_ERROR_ON(conv_info.depth_multiplier != 1U);
94  ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.stride() != std::make_pair(1U, 1U));
95  ARM_COMPUTE_RETURN_ERROR_ON(conv_info.dilation != Size2D(1U, 1U));
97  conv_info.pad_stride_info
98  .has_padding()); // Note that in princple padding can be supported with in_place but we choose not to support it
99  }
100 
101  const ConvolutionInfo info{conv_info.pad_stride_info, conv_info.depth_multiplier, ActivationLayerInfo(),
102  conv_info.dilation};
103  const TensorShape output_shape =
105 
106  if (conv_info.depth_multiplier > 1 && dwc_info.n0 > 1)
107  {
108  ARM_COMPUTE_RETURN_ERROR_ON((conv_info.depth_multiplier % dwc_info.n0) != 0);
109  }
110 
111  const bool is_quantized = is_data_type_quantized(input->data_type());
112 
113  if (biases != nullptr)
114  {
115  ARM_COMPUTE_RETURN_ERROR_ON(biases->dimension(0) != output_shape[idx_c]);
116  ARM_COMPUTE_RETURN_ERROR_ON(biases->num_dimensions() > 1);
117 
118  if (is_quantized)
119  {
121  }
122  else
123  {
125  }
126  }
127 
128  if (is_quantized)
129  {
130  ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output_multipliers, output_shifts);
133  ARM_COMPUTE_RETURN_ERROR_ON(output_multipliers->num_dimensions() > 1);
134  ARM_COMPUTE_RETURN_ERROR_ON(output_shifts->num_dimensions() > 1);
135 
136  if (is_data_type_quantized_per_channel(weights->data_type()))
137  {
139  ARM_COMPUTE_RETURN_ERROR_ON(output_shape[idx_c] != output_multipliers->dimension(0));
140  ARM_COMPUTE_RETURN_ERROR_ON(output_shape[idx_c] != output_shifts->dimension(0));
141  }
142  else
143  {
145  ARM_COMPUTE_RETURN_ERROR_ON(1 != output_multipliers->dimension(0));
146  ARM_COMPUTE_RETURN_ERROR_ON(1 != output_shifts->dimension(0));
147  }
148  }
149  else
150  {
152  }
153 
154  if (output->total_size() != 0)
155  {
158  }
159 
160  if (is_data_type_quantized(input->data_type()))
161  {
162  const UniformQuantizationInfo iq_info = input->quantization_info().uniform();
163  const UniformQuantizationInfo wq_info = weights->quantization_info().uniform();
164  const UniformQuantizationInfo oq_info =
165  (output->total_size() != 0) ? output->quantization_info().uniform() : iq_info;
166 
167  float multiplier = iq_info.scale * wq_info.scale / oq_info.scale;
168  int output_multiplier = 0;
169  int output_shift = 0;
171  quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift));
172  }
173 
174  return Status{};
175 }
176 } // namespace
177 
179  : _input(nullptr),
180  _weights(nullptr),
181  _biases(nullptr),
182  _output(nullptr),
183  _depth_multiplier(1),
184  _output_multipliers(nullptr),
185  _output_shifts(nullptr),
186  _export_input_to_cl_image(false),
187  _export_weights_to_cl_image(false),
188  _is_quantized(false)
189 {
190  _type = CLKernelType::DEPTHWISE;
191 }
192 
194  const ICLTensor *weights,
195  const ICLTensor *biases,
196  ICLTensor *output,
197  const DWCComputeKernelInfo &dwc_info,
198  const ConvolutionInfo &conv_info,
199  const ICLTensor *output_multipliers,
200  const ICLTensor *output_shifts)
201 {
202  configure(CLKernelLibrary::get().get_compile_context(), input, weights, biases, output, dwc_info, conv_info,
203  output_multipliers, output_shifts);
204 }
205 
207  ICLTensor *input,
208  const ICLTensor *weights,
209  const ICLTensor *biases,
210  ICLTensor *output,
211  const DWCComputeKernelInfo &dwc_info,
212  const ConvolutionInfo &conv_info,
213  const ICLTensor *output_multipliers,
214  const ICLTensor *output_shifts)
215 {
217  if (output == nullptr)
218  {
219  // In-place
220  output = input;
221  }
223  input->info(), weights->info(), (biases != nullptr) ? biases->info() : nullptr, output->info(), dwc_info,
224  conv_info, (output_multipliers != nullptr) ? output_multipliers->info() : nullptr,
225  (output_shifts != nullptr) ? output_shifts->info() : nullptr));
226 
227  auto padding_info = get_padding_info({input, output});
228 
230  *(input->info()), *(weights->info()), conv_info);
231  auto_init_if_empty(*(output->info()), input->info()
232  ->clone()
233  ->set_tensor_shape(output_shape)
234  .set_quantization_info(output->info()->quantization_info()));
235 
236  _input = input;
237  _output = output;
238  _weights = weights;
239  _biases = biases;
240  _depth_multiplier = conv_info.depth_multiplier;
241  _output_multipliers = output_multipliers;
242  _output_shifts = output_shifts;
243  _export_input_to_cl_image = dwc_info.export_input_to_cl_image;
244  _export_weights_to_cl_image = dwc_info.export_weights_to_cl_image;
245  _is_quantized = is_data_type_quantized(input->info()->data_type());
246 
247  const unsigned int n0 = adjust_vec_size(dwc_info.n0, output->info()->dimension(0));
248  const unsigned int m0 = std::min(dwc_info.m0, (unsigned int)output->info()->dimension(1));
249  std::string kernel_name = "";
250 
251  CLBuildOptions build_opts;
252 
253  // Update the padding for the input/weights tensor if we can export to cl_image
254  if (_export_input_to_cl_image)
255  {
257  }
258 
259  if (_export_weights_to_cl_image)
260  {
262  }
263 
264  // Conditions of -cl-fast-relaxed-math causing accuracy issues can be traced from COMPMID-5324
265  const GPUTarget gpu_target = get_target();
266  const auto act_function = conv_info.act_info.activation();
267  const auto dst_data_type = _output->info()->data_type();
268 
269  if ((gpu_target != GPUTarget::G71 && (gpu_target & GPUTarget::GPU_ARCH_MASK) == GPUTarget::BIFROST) &&
270  (act_function == ActivationLayerInfo::ActivationFunction::BOUNDED_RELU ||
271  act_function == ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU) &&
272  (dst_data_type == DataType::F32 || dst_data_type == DataType::F16))
273  {
274  // -cl-fast-relaxed-math also sets -cl-finite-math-only and -cl-unsafe-math-optimizations
275  // to disable -cl-finite-math-only, we only include -cl-unsafe-math-optimizations
276  build_opts.add_option("-cl-unsafe-math-optimizations");
277  }
278  else
279  {
280  build_opts.add_option("-cl-fast-relaxed-math");
281  }
282 
283  build_opts.add_option("-DACTIVATION_TYPE=" + lower_string(string_from_activation_func(act_function)));
284  build_opts.add_option("-DDEPTH_MULTIPLIER=" + support::cpp11::to_string(conv_info.depth_multiplier));
285  build_opts.add_option_if_else(_export_input_to_cl_image, "-DSRC_TENSOR_TYPE=IMAGE", "-DSRC_TENSOR_TYPE=BUFFER");
286  // Note: SRC_DATA_TYPE must have the same data type of WEI_DATA_TYPE. In quantized, we could
287  // have a case where the data types for the activation and weights are different. However, since the implementation
288  // only works when both have same data type, we have to change the offset to take into account this aspect
289  build_opts.add_option("-DSRC_DATA_TYPE=" + get_cl_type_from_data_type(_input->info()->data_type()));
290  build_opts.add_option("-DDST_TENSOR_TYPE=BUFFER");
291  build_opts.add_option("-DDST_DATA_TYPE=" + get_cl_type_from_data_type(dst_data_type));
292  build_opts.add_option_if_else(_export_weights_to_cl_image, "-DWEI_TENSOR_TYPE=IMAGE", "-DWEI_TENSOR_TYPE=BUFFER");
293  build_opts.add_option("-DSRC_WIDTH=" + support::cpp11::to_string(_input->info()->dimension(1)));
294  build_opts.add_option("-DSRC_HEIGHT=" + support::cpp11::to_string(_input->info()->dimension(2)));
295  build_opts.add_option("-DDST_WIDTH=" + support::cpp11::to_string(_output->info()->dimension(1)));
296  build_opts.add_option("-DDST_HEIGHT=" + support::cpp11::to_string(_output->info()->dimension(2)));
297  build_opts.add_option("-DWEI_WIDTH=" + support::cpp11::to_string(_weights->info()->dimension(1)));
298  build_opts.add_option("-DWEI_HEIGHT=" + support::cpp11::to_string(_weights->info()->dimension(2)));
299  build_opts.add_option("-DWEI_DATA_TYPE=" + get_cl_type_from_data_type(_weights->info()->data_type()));
300  build_opts.add_option("-DPAD_TOP=" + support::cpp11::to_string(conv_info.pad_stride_info.pad_top()));
301  build_opts.add_option("-DPAD_LEFT=" + support::cpp11::to_string(conv_info.pad_stride_info.pad_left()));
302  build_opts.add_option("-DSTRIDE_X=" + support::cpp11::to_string(conv_info.pad_stride_info.stride().first));
303  build_opts.add_option("-DSTRIDE_Y=" + support::cpp11::to_string(conv_info.pad_stride_info.stride().second));
304  build_opts.add_option("-DDILATION_X=" + support::cpp11::to_string(conv_info.dilation.x()));
305  build_opts.add_option("-DDILATION_Y=" + support::cpp11::to_string(conv_info.dilation.y()));
306  build_opts.add_option("-DN0=" + support::cpp11::to_string(n0));
307  build_opts.add_option("-DM0=" + support::cpp11::to_string(m0));
308  build_opts.add_option("-DM0_A=" + support::cpp11::to_string(_weights->info()->dimension(1) + m0 - 1));
309  build_opts.add_option_if_else(conv_info.depth_multiplier > 1, "-DN0_A=1",
310  "-DN0_A=" + support::cpp11::to_string(n0));
311  build_opts.add_option("-DPARTIAL_N0=" + support::cpp11::to_string(_output->info()->dimension(0) % n0));
312  build_opts.add_option_if(_input->info()->num_dimensions() > 3, "-DBATCHED_EXECUTION");
313 
314  // Force unroll with pragma when any of the following values exceed the maximum number of manual unroll
315  set_unroll_with_pragma(build_opts, {static_cast<int>(_weights->info()->dimension(1) + m0 - 1),
316  static_cast<int>(_weights->info()->dimension(1)),
317  static_cast<int>(_weights->info()->dimension(2))});
318 
319  if (biases != nullptr)
320  {
321  build_opts.add_option(std::string("-DHAS_BIAS"));
322  build_opts.add_option(
323  std::string("-DBIA_DATA_TYPE=" + get_cl_type_from_data_type(biases->info()->data_type())));
324  }
325 
326  if (_is_quantized)
327  {
328  kernel_name = "dwc_native_quantized_nhwc";
329  const UniformQuantizationInfo iqinfo = input->info()->quantization_info().uniform();
330  const UniformQuantizationInfo wqinfo = weights->info()->quantization_info().uniform();
331  const UniformQuantizationInfo oqinfo = output->info()->quantization_info().uniform();
332 
333  PixelValue zero_value = PixelValue(0, input->info()->data_type(), input->info()->quantization_info());
334  int zero_value_s32;
335  zero_value.get(zero_value_s32);
336 
337  float multiplier = iqinfo.scale * wqinfo.scale / oqinfo.scale;
338  int output_multiplier = 0;
339  int output_shift = 0;
340  quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift);
341  build_opts.add_option("-DDST_MULTIPLIER=" + support::cpp11::to_string(output_multiplier));
342  build_opts.add_option("-DDST_SHIFT=" + support::cpp11::to_string(output_shift));
343  build_opts.add_option("-DSRC_OFFSET=" + support::cpp11::to_string(-iqinfo.offset));
344  build_opts.add_option("-DWEI_OFFSET=" + support::cpp11::to_string(-wqinfo.offset));
345  build_opts.add_option("-DDST_OFFSET=" + support::cpp11::to_string(oqinfo.offset));
346  build_opts.add_option("-DZERO_VALUE=" + support::cpp11::to_string(zero_value_s32));
347  build_opts.add_option("-DACC_DATA_TYPE=" + get_cl_type_from_data_type(DataType::S32));
348  build_opts.add_option("-DDST_MULTIPLIERS_DATA_TYPE=" +
349  get_cl_type_from_data_type(_output_multipliers->info()->data_type()));
350  build_opts.add_option("-DDST_SHIFTS_DATA_TYPE=" +
351  get_cl_type_from_data_type(_output_shifts->info()->data_type()));
353  "-DQUANTIZATION_TYPE=PER_CHANNEL", "-DQUANTIZATION_TYPE=PER_TENSOR");
354  // Note: We expect the input and output tensors to always adopt a per-tensor quantization approach
355  int a_val{};
356  int b_val{};
357  std::tie(b_val, a_val) =
358  get_quantized_activation_min_max(conv_info.act_info, input->info()->data_type(), oqinfo);
359 
360  build_opts.add_option_if(conv_info.act_info.enabled(), "-DA_VAL=" + support::cpp11::to_string(a_val));
361  build_opts.add_option_if(conv_info.act_info.enabled(), "-DB_VAL=" + support::cpp11::to_string(b_val));
362  }
363  else
364  {
365  kernel_name = "dwc_native_fp_nhwc";
366  build_opts.add_option("-DACC_DATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type()));
367  build_opts.add_option_if(conv_info.act_info.enabled(),
368  "-DA_VAL=" + float_to_string_with_full_precision(conv_info.act_info.a()));
369  build_opts.add_option_if(conv_info.act_info.enabled(),
370  "-DB_VAL=" + float_to_string_with_full_precision(conv_info.act_info.b()));
371  }
372 
373  Window win = calculate_max_window(*(output->info()), Steps(n0, m0));
374  ICLKernel::configure_internal(win);
375 
376  _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
377 
379 
380  // Set config_id for enabling LWS tuning
381  _config_id = kernel_name;
382  _config_id += "_";
383  _config_id += support::cpp11::to_string(input->info()->dimension(0));
384  _config_id += "_";
385  _config_id += support::cpp11::to_string(input->info()->dimension(1));
386  _config_id += "_";
387  _config_id += support::cpp11::to_string(input->info()->dimension(2));
388  _config_id += "_";
389  _config_id += support::cpp11::to_string(output->info()->dimension(0));
390  _config_id += "_";
391  _config_id += support::cpp11::to_string(output->info()->dimension(1));
392  _config_id += "_";
393  _config_id += support::cpp11::to_string(output->info()->dimension(2));
394  _config_id += "_";
395  _config_id += string_from_data_type(input->info()->data_type());
396 }
397 
399  const ITensorInfo *weights,
400  const ITensorInfo *biases,
401  const ITensorInfo *output,
402  const DWCComputeKernelInfo &dwc_info,
403  const ConvolutionInfo &conv_info,
404  const ITensorInfo *output_multipliers,
405  const ITensorInfo *output_shifts)
406 {
408  validate_arguments(input, weights, biases, output, dwc_info, conv_info, output_multipliers, output_shifts));
409  return Status{};
410 }
411 
412 void CLDepthwiseConvolutionLayerNativeKernel::run(const Window &window, cl::CommandQueue &queue)
413 {
416 
417  // Collapse window
418  Window window_collapsed = window.collapse(ICLKernel::window(), Window::DimZ);
419 
420  Window slice = window_collapsed.first_slice_window_4D();
421 
422  cl::Image2D input_cl_image;
423  cl::Image2D weights_cl_image;
424 
425  if (_export_input_to_cl_image || _export_weights_to_cl_image)
426  {
427  // Export cl_buffer to cl_image
428  if (_export_input_to_cl_image)
429  {
430  const size_t image_w = _input->info()->dimension(0) / 4;
431  const size_t image_h =
432  _input->info()->dimension(1) * _input->info()->dimension(2) * _input->info()->dimension(3);
433  const TensorShape shape2d(image_w, image_h);
434  const size_t image_row_pitch = _input->info()->strides_in_bytes()[1];
435  input_cl_image =
437  _input->info()->data_type(), image_row_pitch, CLImage2DType::ReadOnly);
438  }
439 
440  if (_export_weights_to_cl_image)
441  {
442  const size_t image_w = _weights->info()->dimension(0) / 4;
443  const size_t image_h =
444  _weights->info()->dimension(1) * _weights->info()->dimension(2) * _weights->info()->dimension(3);
445  const TensorShape shape2d(image_w, image_h);
446  const size_t image_row_pitch = _weights->info()->strides_in_bytes()[1];
447  weights_cl_image =
449  _weights->info()->data_type(), image_row_pitch, CLImage2DType::ReadOnly);
450  }
451  }
452 
453  unsigned int idx = 0;
454  if (_export_input_to_cl_image)
455  {
456  _kernel.setArg(idx++, input_cl_image);
457  }
458  add_4d_tensor_nhwc_argument(idx, _input);
459  add_4d_tensor_nhwc_argument(idx, _output);
460  if (_export_weights_to_cl_image)
461  {
462  _kernel.setArg(idx++, weights_cl_image);
463  }
464  add_4d_tensor_nhwc_argument(idx, _weights);
465  if (_is_quantized)
466  {
467  add_1D_tensor_argument(idx, _output_multipliers, slice);
468  add_1D_tensor_argument(idx, _output_shifts, slice);
469  }
470  if (_biases != nullptr)
471  {
472  add_1D_tensor_argument(idx, _biases, slice);
473  }
474  enqueue(queue, *this, slice, lws_hint());
475 }
476 } // namespace arm_compute
arm_compute::Steps
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
arm_compute::support::cpp11::to_string
std::string to_string(T &&value)
Convert integer and float values to string.
Definition: StringSupport.h:168
arm_compute::DataType::QSYMM8_PER_CHANNEL
@ QSYMM8_PER_CHANNEL
quantized, symmetric per channel fixed-point 8-bit number
StringSupport.h
arm_compute::CLBuildOptions::add_option_if_else
void add_option_if_else(bool cond, std::string option_true, std::string option_false)
Adds first option if condition is true else the second one.
Definition: CLCompileContext.cpp:54
arm_compute::UniformQuantizationInfo::offset
int32_t offset
Definition: QuantizationInfo.h:63
arm_compute::ICLKernel::add_1D_tensor_argument
void add_1D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx.
Definition: ICLKernel.h:186
AdjustVecSize.h
arm_compute::export_to_cl_image
bool export_to_cl_image(const ITensorInfo *tensor)
Definition: CLHelpers.cpp:449
ICLTensor.h
arm_compute::PixelValue
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:35
Helpers.h
arm_compute::DataLayoutDimension::CHANNEL
@ CHANNEL
channel
arm_compute::CLBuildOptions::options
const StringSet & options() const
Gets the current options list set.
Definition: CLCompileContext.cpp:72
arm_compute::calculate_max_window
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
Definition: WindowHelpers.cpp:29
arm_compute::test::validation::output_shape
TensorShape output_shape
Definition: LSTMLayerQuantized.cpp:469
arm_compute::misc::shape_calculator::compute_depthwise_convolution_shape
TensorShape compute_depthwise_convolution_shape(const ITensorInfo &input, const ITensorInfo &weights, const ConvolutionInfo &info)
Calculate the depthwise convolution output shape of a tensor.
Definition: ShapeCalculator.h:434
arm_compute::DataLayout::NHWC
@ NHWC
Num samples, height, width, channels.
arm_compute::DWCComputeKernelInfo::n0
unsigned int n0
Number of columns processed by each thread.
Definition: KernelDescriptors.h:117
arm_compute::DataType::QASYMM8
@ QASYMM8
quantized, asymmetric fixed-point 8-bit number unsigned
arm_compute::PixelValue::get
void get(uint8_t &v) const
Interpret the pixel value as a U8.
Definition: PixelValue.h:228
arm_compute::TensorShape
Shape of a tensor.
Definition: TensorShape.h:39
arm_compute::lower_string
std::string lower_string(const std::string &val)
Lower a given string.
Definition: StringUtils.cpp:38
arm_compute::cpu::kernels::validate_arguments
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
Definition: CpuDirectConv2dKernel.cpp:57
ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:1079
arm_compute::get_quantized_activation_min_max
std::pair< int32_t, int32_t > get_quantized_activation_min_max(const ActivationLayerInfo &act_info, DataType data_type, UniformQuantizationInfo oq_info)
Returns a pair of minimum and maximum values for a quantized activation.
Definition: Utils.cpp:442
arm_compute::DEPTHWISE
@ DEPTHWISE
Depthwise CL kernel type.
Definition: CLTypes.h:81
arm_compute::ICLTensor
Interface for OpenCL tensor.
Definition: ICLTensor.h:41
arm_compute::ICLTensor::cl_buffer
virtual const cl::Buffer & cl_buffer() const =0
Interface to be implemented by the child class to return a reference to the OpenCL buffer containing ...
TensorInfo.h
ClGemmHelpers.h
arm_compute::string_from_data_type
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: DataTypeUtils.cpp:31
arm_compute::ICLKernel::get_target
GPUTarget get_target() const
Get the targeted GPU architecture.
Definition: ICLKernel.h:443
arm_compute::UniformQuantizationInfo
Quantization info when assuming per layer quantization.
Definition: QuantizationInfo.h:42
arm_compute::DWCComputeKernelInfo::m0
unsigned int m0
Number of rows processed by each thread.
Definition: KernelDescriptors.h:118
arm_compute::CLKernelLibrary::get
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Definition: CLKernelLibrary.cpp:41
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:677
arm_compute::DataLayoutDimension::WIDTH
@ WIDTH
width
ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:952
CLKernelLibrary.h
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context.
StringUtils.h
ARM_COMPUTE_RETURN_ON_ERROR
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:205
arm_compute::ITensorInfo::dimension
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
arm_compute::GPUTarget::BIFROST
@ BIFROST
CLUtils.h
ARM_COMPUTE_ERROR_ON_NULLPTR
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
arm_compute::ITensor::info
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
ICLKernel.h
ARM_COMPUTE_ERROR_ON
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
ARM_COMPUTE_ERROR_THROW_ON
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
arm_compute::CLDepthwiseConvolutionLayerNativeKernel::run
void run(const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.
Definition: CLDepthwiseConvolutionLayerNativeKernel.cpp:412
arm_compute::CLBuildOptions::add_option
void add_option(std::string option)
Adds option to the existing build option list.
Definition: CLCompileContext.cpp:41
arm_compute::CLCompileContext
CLCompileContext class.
Definition: CLCompileContext.h:204
arm_compute::CLImage2DType::ReadOnly
@ ReadOnly
arm_compute::DataLayoutDimension::HEIGHT
@ HEIGHT
height
arm_compute::Window::collapse
Window collapse(const Window &full_window, size_t first, size_t last=Coordinates::num_max_dimensions) const
Collapse the dimensions between first and last.
Definition: Window.inl:125
ARM_COMPUTE_RETURN_ERROR_ON
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:298
arm_compute::auto_init_if_empty
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
Definition: AutoConfiguration.h:43
ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
Definition: CLValidate.h:36
arm_compute::create_kernel
cl::Kernel create_kernel(const CLCompileContext &ctx, const std::string &kernel_name, const std::set< std::string > &build_opts=std::set< std::string >())
Creates an opencl kernel using a compile context.
Definition: CLHelpers.cpp:409
arm_compute::Status
Status class.
Definition: Error.h:52
arm_compute::DataType::QASYMM8_SIGNED
@ QASYMM8_SIGNED
quantized, asymmetric fixed-point 8-bit number signed
WindowHelpers.h
arm_compute::CLBuildOptions::add_option_if
void add_option_if(bool cond, std::string option)
Adds option if a given condition is true;.
Definition: CLCompileContext.cpp:46
ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:203
arm_compute::float_to_string_with_full_precision
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
Definition: StringUtils.cpp:52
arm_compute::ITensorInfo::data_type
virtual DataType data_type() const =0
Data type used for each element of the tensor.
arm_compute::is_data_type_quantized_per_channel
bool is_data_type_quantized_per_channel(DataType dt)
Check if a given data type is of per channel type.
Definition: DataTypeUtils.h:401
arm_compute::CLDepthwiseConvolutionLayerNativeKernel::validate
static Status 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=nullptr, const ITensorInfo *output_shifts=nullptr)
Static function to check if given info will lead to a valid configuration of CLDepthwiseConvolutionLa...
Definition: CLDepthwiseConvolutionLayerNativeKernel.cpp:398
arm_compute::QuantizationInfo::uniform
UniformQuantizationInfo uniform() const
Return per layer quantization info.
Definition: QuantizationInfo.h:140
arm_compute::DWCComputeKernelInfo::export_input_to_cl_image
bool export_input_to_cl_image
Export input to cl_image.
Definition: KernelDescriptors.h:119
ARM_COMPUTE_UNUSED
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:151
arm_compute::DWCComputeKernelInfo::export_weights_to_cl_image
bool export_weights_to_cl_image
Export the weights to cl_image.
Definition: KernelDescriptors.h:120
arm_compute::test::validation::context
auto context
Definition: DirectConv2d.cpp:156
ARM_COMPUTE_RETURN_ERROR_ON_DATA_LAYOUT_NOT_IN
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_LAYOUT_NOT_IN(t,...)
Definition: Validate.h:890
AutoConfiguration.h
ActivationFunctionUtils.h
arm_compute::opencl::kernels::gemm::update_padding_for_cl_image
void update_padding_for_cl_image(ITensorInfo *tensor)
Update padding required to export the OpenCL buffer to OpenCL image2d.
Definition: ClGemmHelpers.cpp:100
arm_compute::ITensorInfo::quantization_info
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
CLValidate.h
AsymmHelpers.h
arm_compute::IKernel::window
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
arm_compute::get_cl_type_from_data_type
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
Definition: CLHelpers.cpp:41
arm_compute::GPUTarget
GPUTarget
Available GPU Targets.
Definition: GPUTarget.h:34
arm_compute::get_data_layout_dimension_index
size_t get_data_layout_dimension_index(const DataLayout &data_layout, const DataLayoutDimension &data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:201
ShapeCalculator.h
arm_compute::ICLKernel::add_4d_tensor_nhwc_argument
void add_4d_tensor_nhwc_argument(unsigned int &idx, const ICLTensor *tensor)
Add the passed NHWC 4D tensor's parameters to the object's kernel's arguments by passing strides,...
Definition: ICLKernel.cpp:145
arm_compute::UniformQuantizationInfo::scale
float scale
Definition: QuantizationInfo.h:62
arm_compute::CLDepthwiseConvolutionLayerNativeKernel::CLDepthwiseConvolutionLayerNativeKernel
CLDepthwiseConvolutionLayerNativeKernel()
Default Constructor.
Definition: CLDepthwiseConvolutionLayerNativeKernel.cpp:178
arm_compute::Window
Describe a multidimensional execution window.
Definition: Window.h:39
arm_compute::create_image2d_from_buffer
cl::Image2D create_image2d_from_buffer(const cl::Context &ctx, const cl::Buffer &buffer, const TensorShape &shape2d, DataType data_type, size_t image_row_pitch, CLImage2DType image_type)
Create a cl::Image2D object from an OpenCL buffer.
Definition: CLUtils.cpp:62
ARM_COMPUTE_RETURN_ERROR_ON_MSG
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Definition: Error.h:245
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::test::validation::conv_info
conv_info
Definition: DirectConvolutionLayer.cpp:547
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(...)
Definition: Validate.h:294
arm_compute::DataType::F16
@ F16
16-bit floating-point number
arm_compute::ConvolutionInfo
Definition: ConvolutionInfo.h:33
arm_compute::GPUTarget::GPU_ARCH_MASK
@ GPU_ARCH_MASK
arm_compute::adjust_vec_size
unsigned int adjust_vec_size(unsigned int vec_size, size_t dim0)
Returns the adjusted vector size in case it is less than the input's first dimension,...
Definition: AdjustVecSize.h:38
arm_compute::has_padding_changed
bool has_padding_changed(const std::unordered_map< const ITensorInfo *, PaddingSize > &padding_map)
Check if the previously stored padding info has changed after configuring a kernel.
Definition: Utils.cpp:491
arm_compute::Window::DimZ
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
arm_compute::DWCComputeKernelInfo
Compute descriptor used by the depthwise convolution native kernel.
Definition: KernelDescriptors.h:115
arm_compute::DataType::S32
@ S32
signed 32-bit number
arm_compute::ITensorInfo::strides_in_bytes
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
arm_compute::ICLKernel::lws_hint
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:383
ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
arm_compute::quantization::calculate_quantized_multiplier
Status calculate_quantized_multiplier(float multiplier, int32_t *quant_multiplier, int32_t *shift, bool ignore_epsilon=false)
Calculate quantized representation of multiplier.
Definition: AsymmHelpers.cpp:43
arm_compute::string_from_activation_func
const std::string & string_from_activation_func(const ActivationFunction &act)
Translates a given activation function to a string.
Definition: ActivationFunctionUtils.cpp:31
arm_compute::is_data_type_quantized
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Definition: DataTypeUtils.h:324
arm_compute::GPUTarget::G71
@ G71
arm_compute::ITensorInfo
Store the tensor's metadata.
Definition: ITensorInfo.h:44
arm_compute::Window::first_slice_window_4D
Window first_slice_window_4D() const
First 4D slice of the window.
Definition: Window.h:314
arm_compute::DataType::F32
@ F32
32-bit floating-point number
CLDepthwiseConvolutionLayerNativeKernel.h
arm_compute::test::validation::info
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
arm_compute::CLBuildOptions
Build options.
Definition: CLCompileContext.h:38
arm_compute::CLDepthwiseConvolutionLayerNativeKernel::configure
void 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=nullptr, const ICLTensor *output_shifts=nullptr)
Initialize the function's source, destination and parameters.
Definition: CLDepthwiseConvolutionLayerNativeKernel.cpp:206
arm_compute::get_padding_info
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo * > infos)
Stores padding information before configuring a kernel.
Definition: Utils.cpp:476
arm_compute::test::validation::reference::slice
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
Definition: SliceOperations.cpp:38
arm_compute::set_unroll_with_pragma
void set_unroll_with_pragma(CLBuildOptions &built_opts, std::initializer_list< int > values)
Definition: CLHelpers.cpp:487
arm_compute::test::validation::input
auto input
Definition: LSTMLayerQuantized.cpp:486
arm_compute::ITensorInfo::num_dimensions
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
CLHelpers.h
kernel_name
std::string kernel_name
Definition: ClIm2ColKernel.cpp:58
arm_compute::enqueue
void enqueue(cl::CommandQueue &queue, ICLKernel &kernel, const Window &window, const cl::NDRange &lws_hint=CLKernelLibrary::get().default_ndrange(), bool use_dummy_work_items=false)
Add the kernel to the command queue with the given window.
Definition: ICLKernel.cpp:33