Compute Library
 21.05
ClElementwiseKernel.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2021 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 
29 #include "src/core/CL/CLValidate.h"
32 #include "support/Cast.h"
33 #include "support/StringSupport.h"
34 #include <map>
35 
36 namespace arm_compute
37 {
38 namespace opencl
39 {
40 namespace kernels
41 {
42 namespace
43 {
44 constexpr unsigned int vector_size_byte_opencl = 16;
45 
46 std::map<ArithmeticOperation, std::string> supported_arithmetic_ops =
47 {
48  { ArithmeticOperation::ADD, "ADD" },
49  { ArithmeticOperation::SUB, "SUB" },
50  { ArithmeticOperation::DIV, "DIV" },
51  { ArithmeticOperation::SQUARED_DIFF, "SQUARED_DIFF" },
52  { ArithmeticOperation::MIN, "MIN" },
53  { ArithmeticOperation::MAX, "MAX" },
54  { ArithmeticOperation::POWER, "POWER" },
55  { ArithmeticOperation::PRELU, "PRELU" },
56 };
57 
58 std::map<ArithmeticOperation, std::string> supported_sat_arithmetic_ops =
59 {
60  { ArithmeticOperation::ADD, "ADD" },
61  { ArithmeticOperation::SUB, "SUB" },
62 };
63 
64 std::string generate_id_for_tuning_common(const std::string &kernel_name, const ITensorInfo &src1, const ITensorInfo &dst)
65 {
66  std::string config_id;
67  // Set config_id for enabling LWS tuning
68  config_id = kernel_name;
69  config_id += "_";
70  config_id += lower_string(string_from_data_type(src1.data_type()));
71  config_id += "_";
72  config_id += support::cpp11::to_string(dst.dimension(0));
73  config_id += "_";
74  config_id += support::cpp11::to_string(dst.dimension(1));
75  return config_id;
76 }
77 
78 Status validate_arguments_with_float_only_supported_rules(const ITensorInfo &src1, const ITensorInfo &src2, const ITensorInfo &dst)
79 {
84 
85  const TensorShape out_shape = TensorShape::broadcast_shape(src1.tensor_shape(), src2.tensor_shape());
86 
87  ARM_COMPUTE_RETURN_ERROR_ON_MSG(out_shape.total_size() == 0, "Inputs are not broadcast compatible");
88 
89  // Validate in case of configured dst
90  if(dst.total_size() > 0)
91  {
95  "Wrong shape for dst");
96  }
97 
98  return Status{};
99 }
100 
101 Status validate_arguments_divide_operation(const ITensorInfo* src1, const ITensorInfo* src2, const ITensorInfo* dst)
102 {
107 
108  const TensorShape out_shape = TensorShape::broadcast_shape(src1->tensor_shape(), src2->tensor_shape());
109 
110  ARM_COMPUTE_RETURN_ERROR_ON_MSG(out_shape.total_size() == 0, "Inputs are not broadcast compatible");
111 
112  // Validate in case of configured dst
113  if(dst->total_size() > 0)
114  {
118  "Wrong shape for dst");
119  }
120 
121  return Status{};
122 }
123 
124 Status validate_arguments_with_arithmetic_rules(const ITensorInfo &src1, const ITensorInfo &src2, const ITensorInfo &dst)
125 {
134 
135  const bool is_quantized = is_data_type_quantized(src1.data_type()) || is_data_type_quantized(src2.data_type());
136  if(is_quantized)
137  {
139 
140  if(is_data_type_quantized_symmetric(src1.data_type()))
141  {
142  const int32_t in1_offset = src1.quantization_info().uniform().offset;
143  const int32_t in2_offset = src2.quantization_info().uniform().offset;
144  ARM_COMPUTE_RETURN_ERROR_ON_MSG(in1_offset != 0, "For quantized symmetric, offset must be zero");
145  ARM_COMPUTE_RETURN_ERROR_ON_MSG(in2_offset != 0, "For quantized symmetric, offset must be zero");
146  }
147  }
148 
149  const TensorShape out_shape = TensorShape::broadcast_shape(src1.tensor_shape(), src2.tensor_shape());
150 
151  ARM_COMPUTE_RETURN_ERROR_ON_MSG(out_shape.total_size() == 0, "Inputs are not broadcast compatible");
152 
153  // Validate in case of configured dst
154  if(dst.total_size() > 0)
155  {
160  ARM_COMPUTE_RETURN_ERROR_ON_MSG((dst.data_type() == DataType::U8) && ((src1.data_type() != DataType::U8) || (src2.data_type() != DataType::U8)),
161  "dst can only be U8 if both inputs are U8");
163  "Wrong shape for dst");
164 
165  if(is_quantized)
166  {
168 
169  if(is_data_type_quantized_symmetric(dst.data_type()))
170  {
171  const int32_t offset = dst.quantization_info().uniform().offset;
172  ARM_COMPUTE_RETURN_ERROR_ON_MSG(offset != 0, "For quantized symmetric, offset must be zero");
173  }
174  }
175  }
176  return Status{};
177 }
178 
179 CLBuildOptions generate_build_options_with_arithmetic_rules(const ITensorInfo &src1, const ITensorInfo &src2, const ITensorInfo &dst, const std::string &operation_string)
180 {
181  CLBuildOptions build_opts;
182 
183  const unsigned int num_elems_processed_per_iteration = adjust_vec_size(vector_size_byte_opencl / dst.element_size(), dst.dimension(0));
184 
185  build_opts.add_option("-DDATA_TYPE_IN1=" + get_cl_type_from_data_type(src1.data_type()));
186  build_opts.add_option("-DDATA_TYPE_IN2=" + get_cl_type_from_data_type(src2.data_type()));
187  build_opts.add_option("-DDATA_TYPE_OUT=" + get_cl_type_from_data_type(dst.data_type()));
188  build_opts.add_option("-DVEC_SIZE_IN1=" + support::cpp11::to_string(src1.dimension(0) == 1 ? 1 : num_elems_processed_per_iteration));
189  build_opts.add_option("-DVEC_SIZE_IN2=" + support::cpp11::to_string(src2.dimension(0) == 1 ? 1 : num_elems_processed_per_iteration));
190  build_opts.add_option("-DVEC_SIZE_OUT=" + support::cpp11::to_string(num_elems_processed_per_iteration));
191  build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(dst.dimension(0) % num_elems_processed_per_iteration));
192  build_opts.add_option("-DOP=" + operation_string);
193  if(is_data_type_quantized(src1.data_type()))
194  {
195  const UniformQuantizationInfo iq1info = src1.quantization_info().uniform();
196  const UniformQuantizationInfo iq2info = src2.quantization_info().uniform();
197  const UniformQuantizationInfo oqinfo = dst.quantization_info().uniform();
198 
199  build_opts.add_option("-DOFFSET_IN1=" + support::cpp11::to_string(iq1info.offset));
200  build_opts.add_option("-DOFFSET_IN2=" + support::cpp11::to_string(iq2info.offset));
201  build_opts.add_option("-DOFFSET_OUT=" + support::cpp11::to_string(oqinfo.offset));
202  build_opts.add_option("-DSCALE_IN1=" + float_to_string_with_full_precision(iq1info.scale));
203  build_opts.add_option("-DSCALE_IN2=" + float_to_string_with_full_precision(iq2info.scale));
204  build_opts.add_option("-DSCALE_OUT=" + float_to_string_with_full_precision(oqinfo.scale));
205  }
206  build_opts.add_option_if(src1.data_type() == DataType::S32, "-DS32");
207 
208  return build_opts;
209 }
210 
211 std::pair<Status, Window> configure_window_arithmetic_common(ITensorInfo &dst)
212 {
213  const unsigned int num_elems_processed_per_iteration = adjust_vec_size(vector_size_byte_opencl / dst.element_size(), dst.dimension(0));
215  return std::make_pair(Status{}, win);
216 }
217 
218 std::pair<Status, Window> validate_and_configure_window_for_arithmetic_operators(ITensorInfo &src1, ITensorInfo &src2, ITensorInfo &dst)
219 {
220  const std::pair<TensorShape, ValidRegion> broadcast_pair = ITensorInfo::broadcast_shape_and_valid_region(src1, src2);
221  const TensorShape &out_shape = broadcast_pair.first;
222 
223  set_shape_if_empty(dst, out_shape);
224 
225  if(src1.data_type() == DataType::S16 || src2.data_type() == DataType::S16)
226  {
228  }
229  else if(src1.data_type() == DataType::F16 || src2.data_type() == DataType::F16)
230  {
232  }
233  else if(src1.data_type() == DataType::F32 || src2.data_type() == DataType::F32)
234  {
236  }
237  else if(src1.data_type() == DataType::QASYMM8 || src2.data_type() == DataType::QASYMM8)
238  {
240  }
241  else if(src1.data_type() == DataType::QASYMM8_SIGNED || src2.data_type() == DataType::QASYMM8_SIGNED)
242  {
244  }
245  else if(src1.data_type() == DataType::QSYMM16 || src2.data_type() == DataType::QSYMM16)
246  {
248  }
249 
250  return configure_window_arithmetic_common(dst);
251 }
252 
253 std::pair<Status, Window> validate_and_configure_window_for_logical_binary_operators(ITensorInfo &src1, ITensorInfo &src2, ITensorInfo &dst)
254 {
255  const std::pair<TensorShape, ValidRegion> broadcast_pair = ITensorInfo::broadcast_shape_and_valid_region(src1, src2);
256  const TensorShape &out_shape = broadcast_pair.first;
257 
258  set_shape_if_empty(dst, out_shape);
260 
261  // The arithmetic utility functions can be share
262  return configure_window_arithmetic_common(dst);
263 }
264 
265 std::pair<Status, Window> validate_and_configure_window_for_division(ITensorInfo &src1, ITensorInfo &src2, ITensorInfo &dst)
266 {
267  const std::pair<TensorShape, ValidRegion> broadcast_pair = ITensorInfo::broadcast_shape_and_valid_region(src1, src2);
268  const TensorShape &out_shape = broadcast_pair.first;
269  auto_init_if_empty(dst, out_shape, 1, src1.data_type());
270  return configure_window_arithmetic_common(dst);
271 }
272 } // namespace
273 
274 void ClElementwiseKernel::configure_common(ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst)
275 {
276  configure_common(CLKernelLibrary::get().get_compile_context(), src1, src2, dst);
277 }
278 
279 void ClElementwiseKernel::configure_common(const ClCompileContext &compile_context, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst)
280 {
281  // Configure kernel window
282  auto win_config = validate_and_configure_window(*src1, *src2, *dst);
283  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
284 
285  _src1 = src1;
286  _src2 = src2;
287  _dst = dst;
288 
289  std::string kernel_name = "elementwise_operation_" + name();
290  if(is_data_type_quantized(src1->data_type()))
291  {
292  kernel_name += "_quantized";
293  }
294 
295  // Set kernel build options
296  CLBuildOptions build_opts = generate_build_options(*src1, *src2, *dst);
297  if(_act_info.enabled())
298  {
299  build_opts.add_option("-DACTIVATION_TYPE=" + lower_string(string_from_activation_func(_act_info.activation())));
300  build_opts.add_option("-DA_VAL=" + float_to_string_with_full_precision(_act_info.a()));
301  build_opts.add_option("-DB_VAL=" + float_to_string_with_full_precision(_act_info.b()));
302  }
303 
304  // Create kernel
305  _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
306 
307  ICLKernel::configure_internal(win_config.second);
308 
309  _config_id = generate_id_for_tuning(kernel_name, *src1, *dst);
310 }
311 
312 void ClElementwiseKernel::run_op(ITensorPack &tensors, const Window &window, ::cl::CommandQueue &queue)
313 {
316 
317  const auto src_0 = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_0));
318  const auto src_1 = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_1));
319  auto dst = utils::cast::polymorphic_downcast<ICLTensor *>(tensors.get_tensor(TensorType::ACL_DST));
320 
321  const TensorShape &in_shape1 = src_0->info()->tensor_shape();
322  const TensorShape &in_shape2 = src_1->info()->tensor_shape();
323  const TensorShape &out_shape = dst->info()->tensor_shape();
324 
325  bool can_collapse = true;
326  const bool is_vector = in_shape1.num_dimensions() == 1 || in_shape2.num_dimensions() == 1;
327  if(std::min(in_shape1.total_size(), in_shape2.total_size()) > 1 && !is_vector)
328  {
329  can_collapse = (std::min(in_shape1.num_dimensions(), in_shape2.num_dimensions()) > Window::DimZ);
330  for(size_t d = Window::DimZ; can_collapse && (d < out_shape.num_dimensions()); d++)
331  {
332  can_collapse = (in_shape1[d] == in_shape2[d]);
333  }
334  }
335 
336  bool has_collapsed = false;
337  Window collapsed = can_collapse ? window.collapse_if_possible(ICLKernel::window(), Window::DimZ, &has_collapsed) : window;
338 
339  const TensorShape &in_shape1_collapsed = has_collapsed ? in_shape1.collapsed_from(Window::DimZ) : in_shape1;
340  const TensorShape &in_shape2_collapsed = has_collapsed ? in_shape2.collapsed_from(Window::DimZ) : in_shape2;
341 
342  Window slice = collapsed.first_slice_window_3D();
343  Window slice_src1 = slice.broadcast_if_dimension_le_one(in_shape1_collapsed);
344  Window slice_src2 = slice.broadcast_if_dimension_le_one(in_shape2_collapsed);
345  do
346  {
347  unsigned int idx = 0;
348  add_3D_tensor_argument(idx, src_0, slice_src1);
349  add_3D_tensor_argument(idx, src_1, slice_src2);
351 
352  enqueue(queue, *this, slice, lws_hint());
353  ARM_COMPUTE_UNUSED(collapsed.slide_window_slice_3D(slice_src1));
354  ARM_COMPUTE_UNUSED(collapsed.slide_window_slice_3D(slice_src2));
355  }
356  while(collapsed.slide_window_slice_3D(slice));
357 }
358 
359 /** Logical binary */
360 
362 {
363  ARM_COMPUTE_ERROR_ON_NULLPTR(src1, src2, dst);
365  _op = op;
366  configure_common(compile_context, src1, src2, dst);
367 }
368 
370 {
371  ARM_COMPUTE_UNUSED(op);
374 
377 
378  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_with_arithmetic_rules(*src1, *src2, *dst));
379  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_for_logical_binary_operators(*src1->clone(), *src2->clone(), *dst->clone()).first);
380 
381  return Status{};
382 }
383 
384 std::string ClLogicalBinaryKernel::name()
385 {
386  switch(_op)
387  {
389  return "AND";
391  return "OR";
393  /* fall through */
394  default:
395  ARM_COMPUTE_ASSERT(true);
396  }
397  return "";
398 }
399 
400 std::pair<Status, Window> ClLogicalBinaryKernel::validate_and_configure_window(ITensorInfo &src1, ITensorInfo &src2, ITensorInfo &dst)
401 {
402  return validate_and_configure_window_for_logical_binary_operators(src1, src2, dst);
403 }
404 
405 CLBuildOptions ClLogicalBinaryKernel::generate_build_options(const ITensorInfo &src1, const ITensorInfo &src2, const ITensorInfo &dst)
406 {
407  // The arithmetic utility functions can be share
408  return generate_build_options_with_arithmetic_rules(src1, src2, dst, name());
409 }
410 
411 std::string ClLogicalBinaryKernel::generate_id_for_tuning(const std::string &kernel_name, const ITensorInfo &src1, const ITensorInfo &dst)
412 {
413  return generate_id_for_tuning_common(kernel_name, src1, dst);
414 }
415 
416 /** Arithmetic operations with saturation*/
418  const ConvertPolicy &policy,
419  const ActivationLayerInfo &act_info)
420 {
421  ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
422  ARM_COMPUTE_ERROR_THROW_ON(ClSaturatedArithmeticKernel::validate(op, input1, input2, output, policy, act_info));
423  auto padding_info = get_padding_info({ input1, input2, output });
424 
425  _policy = policy;
426  _op = op;
427  _act_info = act_info;
428  configure_common(compile_context, input1, input2, output);
430 }
431 
433  const ActivationLayerInfo &act_info)
434 {
435  ARM_COMPUTE_UNUSED(op, policy);
436  ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output);
437  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_with_arithmetic_rules(*input1, *input2, *output));
438  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_for_arithmetic_operators(*input1->clone(), *input2->clone(), *output->clone()).first);
440 
441  return Status{};
442 }
443 
444 std::pair<Status, Window> ClSaturatedArithmeticKernel::validate_and_configure_window(ITensorInfo &input1, ITensorInfo &input2, ITensorInfo &output)
445 {
446  return validate_and_configure_window_for_arithmetic_operators(input1, input2, output);
447 }
448 
449 CLBuildOptions ClSaturatedArithmeticKernel::generate_build_options(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output)
450 {
451  const bool has_float_out = is_data_type_float(output.data_type());
452  auto build_options = generate_build_options_with_arithmetic_rules(input1, input2, output, name());
453  build_options.add_option((_policy == ConvertPolicy::WRAP || has_float_out) ? "-DWRAP" : "-DSATURATE");
454  return build_options;
455 }
456 
457 std::string ClSaturatedArithmeticKernel::generate_id_for_tuning(const std::string &kernel_name, const ITensorInfo &input1, const ITensorInfo &output)
458 {
459  auto config_id = generate_id_for_tuning_common(kernel_name, input1, output);
460  config_id += (_policy == ConvertPolicy::WRAP) ? "_wrap_" : "_saturate_";
462  return config_id;
463 }
464 
465 std::string ClSaturatedArithmeticKernel::name()
466 {
467  return supported_sat_arithmetic_ops[_op];
468 }
469 
470 /** Arithmetic operations*/
472  const ActivationLayerInfo &act_info)
473 {
474  ARM_COMPUTE_ERROR_ON_NULLPTR(src1, src2, dst);
475  ARM_COMPUTE_ERROR_THROW_ON(ClArithmeticKernel::validate(op, src1, src2, dst, act_info));
476  auto padding_info = get_padding_info({ src1, src2, dst });
477 
478  _op = op;
479  _act_info = act_info;
480  configure_common(compile_context, src1, src2, dst);
482 }
483 
485 {
487  if(op == ArithmeticOperation::DIV)
488  {
489  // Partial integer support S32/F32/F16
490  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_divide_operation(src1, src2, dst));
491  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_for_division(*src1->clone(), *src2->clone(), *dst->clone()).first);
492  }
493  else if(op == ArithmeticOperation::POWER)
494  {
495  // Power operators doesn't support integer arithmetic
496  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_with_float_only_supported_rules(*src1, *src2, *dst));
497  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_for_division(*src1->clone(), *src2->clone(), *dst->clone()).first);
498  }
499  else
500  {
501  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_with_arithmetic_rules(*src1, *src2, *dst));
502  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_for_arithmetic_operators(*src1->clone(), *src2->clone(), *dst->clone()).first);
503  }
504  ARM_COMPUTE_RETURN_ERROR_ON(act_info.enabled() && !is_data_type_float(dst->data_type()));
505 
506  return Status{};
507 }
508 std::pair<Status, Window> ClArithmeticKernel::validate_and_configure_window(ITensorInfo &src1, ITensorInfo &src2, ITensorInfo &dst)
509 {
511  {
512  // Division and Power operators don't support integer arithmetic
513  return validate_and_configure_window_for_division(src1, src2, dst);
514  }
515  else
516  {
517  return validate_and_configure_window_for_arithmetic_operators(src1, src2, dst);
518  }
519 }
520 
521 CLBuildOptions ClArithmeticKernel::generate_build_options(const ITensorInfo &src1, const ITensorInfo &src2, const ITensorInfo &dst)
522 {
523  return generate_build_options_with_arithmetic_rules(src1, src2, dst, name());
524 }
525 std::string ClArithmeticKernel::generate_id_for_tuning(const std::string &kernel_name, const ITensorInfo &src1, const ITensorInfo &dst)
526 {
527  return generate_id_for_tuning_common(kernel_name, src1, dst);
528 }
529 
530 std::string ClArithmeticKernel::name()
531 {
532  return supported_arithmetic_ops[_op];
533 }
534 } // namespace kernels
535 } // namespace opencl
536 } // namespace arm_compute
bool set_format_if_unknown(ITensorInfo &info, Format format)
Set the format, data type and number of channels to the specified value if the current data type is u...
static Status validate(LogicalOperation op, const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst)
Static function to check if the given configuration is valid for this kernel.
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Definition: Utils.h:967
static Status validate(ArithmeticOperation op, const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of ClArithmeticKernel.
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:861
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#define ARM_COMPUTE_ASSERT(cond)
Definition: Validate.h:37
ArithmeticOperation
Available element-wise operations.
Definition: Types.h:470
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
Definition: CLValidate.h:35
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
Shape of a tensor.
Definition: TensorShape.h:39
quantized, symmetric fixed-point 16-bit number
bool set_data_type_if_unknown(ITensorInfo &info, DataType data_type)
Set the data type and number of channels to the specified value if the current data type is unknown.
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:489
bool enabled() const
Check if initialised.
Definition: Types.h:1528
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:32
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:276
TensorShape collapsed_from(size_t start) const
Return a copy with collapsed dimensions starting from a given point.
Definition: TensorShape.h:161
1 channel, 1 U8 per channel
float a() const
Get the alpha value.
Definition: Types.h:1518
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
std::string to_string(T &&value)
Convert integer and float values to string.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
static TensorShape broadcast_shape(const Shapes &... shapes)
If shapes are broadcast compatible, return the broadcasted shape.
Definition: TensorShape.h:211
#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
const std::string & string_from_activation_func(ActivationLayerInfo::ActivationFunction act)
Translates a given activation function to a string.
Definition: Utils.cpp:163
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Store the tensor's metadata.
Definition: ITensorInfo.h:40
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
Status class.
Definition: Error.h:52
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:326
bool is_data_type_quantized_symmetric(DataType dt)
Check if a given data type is of symmetric quantized type.
Definition: Utils.h:1025
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
static std::pair< TensorShape, ValidRegion > broadcast_shape_and_valid_region(const Infos &... infos)
If infos are broadcast compatible tensor info's, return the broadcasted shape and the intersection of...
Definition: ITensorInfo.h:287
Activation Layer Information class.
Definition: Types.h:1478
void add_3D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx.
Definition: ICLKernel.h:172
void configure(const ClCompileContext &compile_context, ArithmeticOperation op, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, const ConvertPolicy &policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of ClSaturatedArithmeticKer...
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
1 channel, 1 S32 per channel
const std::string & config_id() const
Get the configuration ID.
Definition: ICLKernel.h:312
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
Definition: ITensorPack.cpp:45
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:403
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:135
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
Window collapse_if_possible(const Window &full_window, size_t first, size_t last, bool *has_collapsed=nullptr) const
Collapse the dimensions between first and last if possible.
Definition: Window.inl:68
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
Definition: Utils.h:1061
void run_op(ITensorPack &tensors, const Window &window, ::cl::CommandQueue &queue) override
quantized, asymmetric fixed-point 8-bit number unsigned
arm_compute::CLCompileContext ClCompileContext
std::set< std::string > build_options
static Status validate(ArithmeticOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ConvertPolicy &policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of ClSaturatedArithmeticKer...
std::string kernel_name
size_t total_size() const
Collapses all dimensions to a single linear total size.
Definition: TensorShape.h:172
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
Definition: CLHelpers.cpp:37
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...
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
bool set_shape_if_empty(ITensorInfo &info, const TensorShape &shape)
Set the shape to the specified value if the current assignment is empty.
bool have_different_dimensions(const Dimensions< T > &dim1, const Dimensions< T > &dim2, unsigned int upper_dim)
Definition: Validate.h:47
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
Definition: Window.h:335
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
1 channel, 1 S16 per channel
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:504
CLCompileContext class.
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
Definition: ITensorPack.cpp:55
const std::string & string_from_data_layout(DataLayout dl)
Convert a data layout identity into a string.
Definition: Utils.cpp:123
void configure(const ClCompileContext &compile_context, LogicalOperation op, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst)
Function to configure kernel.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
Definition: Dimensions.h:143
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:541
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:788
unsigned int num_elems_processed_per_iteration
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Definition: Error.h:244
Tensor packing service.
Definition: ITensorPack.h:37
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
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: Utils.h:1157
ActivationFunction activation() const
Get the type of activation function.
Definition: Types.h:1513
float b() const
Get the beta value.
Definition: Types.h:1523
quantized, asymmetric fixed-point 8-bit number signed
void configure(const ClCompileContext &compile_context, ArithmeticOperation op, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of ClArithmeticKernel.
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:291
LogicalOperation
List of supported logical operations.
Definition: KernelTypes.h:30
Describe a multidimensional execution window.
Definition: Window.h:39
ConvertPolicy
Policy to handle overflow.
Definition: Types.h:385
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
Definition: Utils.h:947
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.