Compute Library
 20.05
CLElementwiseOperationKernel.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020 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 "support/StringSupport.h"
30 #include <map>
31 
32 namespace arm_compute
33 {
34 namespace
35 {
36 constexpr unsigned int num_elems_processed_per_iteration = 16;
37 
38 std::map<ArithmeticOperation, std::string> supported_arithmetic_ops =
39 {
40  { ArithmeticOperation::ADD, "ADD" },
41  { ArithmeticOperation::SUB, "SUB" },
42  { ArithmeticOperation::DIV, "DIV" },
43  { ArithmeticOperation::SQUARED_DIFF, "SQUARED_DIFF" },
44  { ArithmeticOperation::MIN, "MIN" },
45  { ArithmeticOperation::MAX, "MAX" },
46  { ArithmeticOperation::POWER, "POWER" },
47  { ArithmeticOperation::PRELU, "PRELU" },
48 };
49 
50 std::map<ArithmeticOperation, std::string> supported_sat_arithmetic_ops =
51 {
52  { ArithmeticOperation::ADD, "ADD" },
53  { ArithmeticOperation::SUB, "SUB" },
54 };
55 
56 std::string generate_id_for_tuning_common(const std::string &kernel_name, const ITensorInfo &input1, const ITensorInfo &output)
57 {
58  std::string config_id;
59  // Set config_id for enabling LWS tuning
60  config_id = kernel_name;
61  config_id += "_";
62  config_id += lower_string(string_from_data_type(input1.data_type()));
63  config_id += "_";
64  config_id += support::cpp11::to_string(output.dimension(0));
65  config_id += "_";
66  config_id += support::cpp11::to_string(output.dimension(1));
67  return config_id;
68 }
69 
70 Status validate_arguments_with_float_only_supported_rules(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output)
71 {
72  ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(&input1, &input2, &output);
76 
77  const TensorShape out_shape = TensorShape::broadcast_shape(input1.tensor_shape(), input2.tensor_shape());
78 
79  ARM_COMPUTE_RETURN_ERROR_ON_MSG(out_shape.total_size() == 0, "Inputs are not broadcast compatible");
80 
81  // Validate in case of configured output
82  if(output.total_size() > 0)
83  {
86  ARM_COMPUTE_RETURN_ERROR_ON_MSG(detail::have_different_dimensions(out_shape, output.tensor_shape(), 0),
87  "Wrong shape for output");
88  }
89 
90  return Status{};
91 }
92 
93 Status validate_arguments_with_arithmetic_rules(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output)
94 {
99 
100  const bool is_quantized = is_data_type_quantized(input1.data_type()) || is_data_type_quantized(input2.data_type());
101  if(is_quantized)
102  {
104 
105  if(is_data_type_quantized_symmetric(input1.data_type()))
106  {
107  const int32_t in1_offset = input1.quantization_info().uniform().offset;
108  const int32_t in2_offset = input2.quantization_info().uniform().offset;
109  ARM_COMPUTE_RETURN_ERROR_ON_MSG(in1_offset != 0, "For quantized symmetric, offset must be zero");
110  ARM_COMPUTE_RETURN_ERROR_ON_MSG(in2_offset != 0, "For quantized symmetric, offset must be zero");
111  }
112  }
113 
114  const TensorShape out_shape = TensorShape::broadcast_shape(input1.tensor_shape(), input2.tensor_shape());
115 
116  ARM_COMPUTE_RETURN_ERROR_ON_MSG(out_shape.total_size() == 0, "Inputs are not broadcast compatible");
117 
118  // Validate in case of configured output
119  if(output.total_size() > 0)
120  {
123  ARM_COMPUTE_RETURN_ERROR_ON_MSG((output.data_type() == DataType::U8) && ((input1.data_type() != DataType::U8) || (input2.data_type() != DataType::U8)),
124  "Output can only be U8 if both inputs are U8");
125  ARM_COMPUTE_RETURN_ERROR_ON_MSG(detail::have_different_dimensions(out_shape, output.tensor_shape(), 0),
126  "Wrong shape for output");
127 
128  if(is_quantized)
129  {
131 
132  if(is_data_type_quantized_symmetric(output.data_type()))
133  {
134  const int32_t offset = output.quantization_info().uniform().offset;
135  ARM_COMPUTE_RETURN_ERROR_ON_MSG(offset != 0, "For quantized symmetric, offset must be zero");
136  }
137  }
138  }
139  return Status{};
140 }
141 
142 CLBuildOptions generate_build_options_with_arithmetic_rules(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output, const std::string &operation_string)
143 {
144  CLBuildOptions build_opts;
145 
146  build_opts.add_option("-DDATA_TYPE_IN1=" + get_cl_type_from_data_type(input1.data_type()));
147  build_opts.add_option("-DDATA_TYPE_IN2=" + get_cl_type_from_data_type(input2.data_type()));
148  build_opts.add_option("-DDATA_TYPE_OUT=" + get_cl_type_from_data_type(output.data_type()));
149  build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(num_elems_processed_per_iteration));
150  build_opts.add_option("-DOP=" + operation_string);
151  if(is_data_type_quantized(input1.data_type()))
152  {
153  const UniformQuantizationInfo iq1info = input1.quantization_info().uniform();
154  const UniformQuantizationInfo iq2info = input2.quantization_info().uniform();
155  const UniformQuantizationInfo oqinfo = output.quantization_info().uniform();
156 
157  build_opts.add_option("-DOFFSET_IN1=" + support::cpp11::to_string(iq1info.offset));
158  build_opts.add_option("-DOFFSET_IN2=" + support::cpp11::to_string(iq2info.offset));
159  build_opts.add_option("-DOFFSET_OUT=" + support::cpp11::to_string(oqinfo.offset));
160  build_opts.add_option("-DSCALE_IN1=" + float_to_string_with_full_precision(iq1info.scale));
161  build_opts.add_option("-DSCALE_IN2=" + float_to_string_with_full_precision(iq2info.scale));
162  build_opts.add_option("-DSCALE_OUT=" + float_to_string_with_full_precision(oqinfo.scale));
163  }
164  return build_opts;
165 }
166 
167 std::pair<Status, Window> configure_window_arithmetic_common(const ValidRegion &valid_region, ITensorInfo &input1, ITensorInfo &input2, ITensorInfo &output)
168 {
170  Window win_input1 = win.broadcast_if_dimension_le_one(input1);
171  Window win_input2 = win.broadcast_if_dimension_le_one(input2);
172 
173  AccessWindowHorizontal input1_access(&input1, 0, num_elems_processed_per_iteration);
174  AccessWindowHorizontal input2_access(&input2, 0, num_elems_processed_per_iteration);
175  AccessWindowHorizontal output_access(&output, 0, num_elems_processed_per_iteration);
176 
177  bool window_changed = update_window_and_padding(win_input1, input1_access)
178  || update_window_and_padding(win_input2, input2_access)
179  || update_window_and_padding(win, output_access);
180 
181  output_access.set_valid_region(win, valid_region);
182 
183  Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
184  return std::make_pair(err, win);
185 }
186 
187 std::pair<Status, Window> validate_and_configure_window_for_arithmetic_operators(ITensorInfo &input1, ITensorInfo &input2, ITensorInfo &output)
188 {
189  const std::pair<TensorShape, ValidRegion> broadcast_pair = ITensorInfo::broadcast_shape_and_valid_region(input1, input2);
190  const TensorShape &out_shape = broadcast_pair.first;
191  const ValidRegion &valid_region = broadcast_pair.second;
192 
193  set_shape_if_empty(output, out_shape);
194 
195  if(input1.data_type() == DataType::S16 || input2.data_type() == DataType::S16)
196  {
198  }
199  else if(input1.data_type() == DataType::F16 || input2.data_type() == DataType::F16)
200  {
202  }
203  else if(input1.data_type() == DataType::F32 || input2.data_type() == DataType::F32)
204  {
206  }
207  else if(input1.data_type() == DataType::QASYMM8 || input2.data_type() == DataType::QASYMM8)
208  {
210  }
211  else if(input1.data_type() == DataType::QASYMM8_SIGNED || input2.data_type() == DataType::QASYMM8_SIGNED)
212  {
214  }
215  else if(input1.data_type() == DataType::QSYMM16 || input2.data_type() == DataType::QSYMM16)
216  {
218  }
219 
220  return configure_window_arithmetic_common(valid_region, input1, input2, output);
221 }
222 
223 std::pair<Status, Window> validate_and_configure_window_for_division(ITensorInfo &input1, ITensorInfo &input2, ITensorInfo &output)
224 {
225  const std::pair<TensorShape, ValidRegion> broadcast_pair = ITensorInfo::broadcast_shape_and_valid_region(input1, input2);
226  const TensorShape &out_shape = broadcast_pair.first;
227  const ValidRegion &valid_region = broadcast_pair.second;
228  auto_init_if_empty(output, out_shape, 1, input1.data_type());
229  return configure_window_arithmetic_common(valid_region, input1, input2, output);
230 }
231 } // namespace
232 
234  : _act_info(), _input1(nullptr), _input2(nullptr), _output(nullptr)
235 {
236 }
237 
238 void CLElementwiseOperationKernel::configure_common(const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output)
239 {
240  configure_common(CLKernelLibrary::get().get_compile_context(), input1, input2, output);
241 }
242 
243 void CLElementwiseOperationKernel::configure_common(const CLCompileContext &compile_context, const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output)
244 {
245  ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
246  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(*input1->info(), *input2->info(), *output->info()));
247 
248  // Configure kernel window
249  auto win_config = validate_and_configure_window(*input1->info(), *input2->info(), *output->info());
250  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
251 
252  _input1 = input1;
253  _input2 = input2;
254  _output = output;
255 
256  std::string kernel_name = "elementwise_operation_" + name();
257  if(is_data_type_quantized(input1->info()->data_type()))
258  {
259  kernel_name += "_quantized";
260  }
261 
262  // Set kernel build options
263  CLBuildOptions build_opts = generate_build_options(*input1->info(), *input2->info(), *output->info());
264  if(_act_info.enabled())
265  {
266  build_opts.add_option("-DACTIVATION_TYPE=" + lower_string(string_from_activation_func(_act_info.activation())));
267  build_opts.add_option("-DA_VAL=" + float_to_string_with_full_precision(_act_info.a()));
268  build_opts.add_option("-DB_VAL=" + float_to_string_with_full_precision(_act_info.b()));
269  }
270 
271  // Create kernel
272  _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
273 
274  ICLKernel::configure_internal(win_config.second);
275 
276  _config_id = generate_id_for_tuning(kernel_name, *input1->info(), *output->info());
277 }
278 
279 void CLElementwiseOperationKernel::run(const Window &window, cl::CommandQueue &queue)
280 {
283 
284  const TensorShape &in_shape1 = _input1->info()->tensor_shape();
285  const TensorShape &in_shape2 = _input2->info()->tensor_shape();
286  const TensorShape &out_shape = _output->info()->tensor_shape();
287 
288  bool can_collapse = true;
289  const bool is_vector = in_shape1.num_dimensions() == 1 || in_shape2.num_dimensions() == 1;
290  if(std::min(in_shape1.total_size(), in_shape2.total_size()) > 1 && !is_vector)
291  {
292  can_collapse = (std::min(in_shape1.num_dimensions(), in_shape2.num_dimensions()) > Window::DimZ);
293  for(size_t d = Window::DimZ; can_collapse && (d < out_shape.num_dimensions()); d++)
294  {
295  can_collapse = (in_shape1[d] == in_shape2[d]);
296  }
297  }
298 
299  bool has_collapsed = false;
300  Window collapsed = can_collapse ? window.collapse_if_possible(ICLKernel::window(), Window::DimZ, &has_collapsed) : window;
301 
302  const TensorShape &in_shape1_collapsed = has_collapsed ? in_shape1.collapsed_from(Window::DimZ) : in_shape1;
303  const TensorShape &in_shape2_collapsed = has_collapsed ? in_shape2.collapsed_from(Window::DimZ) : in_shape2;
304 
305  Window slice = collapsed.first_slice_window_3D();
306  Window slice_input1 = slice.broadcast_if_dimension_le_one(in_shape1_collapsed);
307  Window slice_input2 = slice.broadcast_if_dimension_le_one(in_shape2_collapsed);
308 
309  do
310  {
311  unsigned int idx = 0;
312 
313  add_3D_tensor_argument(idx, _input1, slice_input1);
314  add_3D_tensor_argument(idx, _input2, slice_input2);
315  add_3D_tensor_argument(idx, _output, slice);
316 
317  enqueue(queue, *this, slice, lws_hint());
318 
319  ARM_COMPUTE_UNUSED(collapsed.slide_window_slice_3D(slice_input1));
320  ARM_COMPUTE_UNUSED(collapsed.slide_window_slice_3D(slice_input2));
321  }
322  while(collapsed.slide_window_slice_3D(slice));
323 }
324 
326 {
327  const unsigned int replicateSize = _output->info()->dimension(0) - std::min(_input1->info()->dimension(0), _input2->info()->dimension(0));
328  const unsigned int border = std::min<unsigned int>(num_elems_processed_per_iteration - 1U, replicateSize);
329  return BorderSize{ 0, border, 0, 0 };
330 }
331 
332 /** Arithmetic operations with saturation*/
333 
335  const ActivationLayerInfo &act_info)
336 {
337  configure(CLKernelLibrary::get().get_compile_context(), op, input1, input2, output, policy, act_info);
338 }
339 
340 void CLSaturatedArithmeticOperationKernel::configure(const CLCompileContext &compile_context, ArithmeticOperation op, const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output,
341  const ConvertPolicy &policy,
342  const ActivationLayerInfo &act_info)
343 {
344  _policy = policy;
345  _op = op;
346  _act_info = act_info;
347  configure_common(compile_context, input1, input2, output);
348 }
349 
351  const ActivationLayerInfo &act_info)
352 {
354  ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output);
355  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_with_arithmetic_rules(*input1, *input2, *output));
356  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_for_arithmetic_operators(*input1->clone(), *input2->clone(), *output->clone()).first);
358 
359  return Status{};
360 }
361 
362 std::pair<Status, Window> CLSaturatedArithmeticOperationKernel::validate_and_configure_window(ITensorInfo &input1, ITensorInfo &input2, ITensorInfo &output)
363 {
364  return validate_and_configure_window_for_arithmetic_operators(input1, input2, output);
365 }
366 
367 Status CLSaturatedArithmeticOperationKernel::validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output)
368 {
369  return validate_arguments_with_arithmetic_rules(input1, input2, output);
370 }
371 
372 CLBuildOptions CLSaturatedArithmeticOperationKernel::generate_build_options(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output)
373 {
374  const bool has_float_out = is_data_type_float(output.data_type());
375  auto build_options = generate_build_options_with_arithmetic_rules(input1, input2, output, name());
376  build_options.add_option((_policy == ConvertPolicy::WRAP || has_float_out) ? "-DWRAP" : "-DSATURATE");
377  return build_options;
378 }
379 std::string CLSaturatedArithmeticOperationKernel::generate_id_for_tuning(const std::string &kernel_name, const ITensorInfo &input1, const ITensorInfo &output)
380 {
381  auto config_id = generate_id_for_tuning_common(kernel_name, input1, output);
382  config_id += (_policy == ConvertPolicy::WRAP) ? "_wrap_" : "_saturate_";
383  config_id += lower_string(string_from_data_layout(input1.data_layout()));
384  return config_id;
385 }
386 
387 std::string CLSaturatedArithmeticOperationKernel::name()
388 {
389  return supported_sat_arithmetic_ops[_op];
390 }
391 
392 /** Arithmetic operations*/
393 
394 void CLArithmeticOperationKernel::configure(ArithmeticOperation op, const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info)
395 {
396  configure(CLKernelLibrary::get().get_compile_context(), op, input1, input2, output, act_info);
397 }
398 
399 void CLArithmeticOperationKernel::configure(const CLCompileContext &compile_context, ArithmeticOperation op, const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output,
400  const ActivationLayerInfo &act_info)
401 {
402  _op = op;
403  _act_info = act_info;
404  configure_common(compile_context, input1, input2, output);
405 }
406 
408 {
409  ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input1, input2, output);
411  {
412  // Division and Power operators don't support integer arithmetic
413  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_with_float_only_supported_rules(*input1, *input2, *output));
414  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_for_division(*input1->clone(), *input2->clone(), *output->clone()).first);
415  }
416  else
417  {
418  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_with_arithmetic_rules(*input1, *input2, *output));
419  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_for_arithmetic_operators(*input1->clone(), *input2->clone(), *output->clone()).first);
420  }
422 
423  return Status{};
424 }
425 std::pair<Status, Window> CLArithmeticOperationKernel::validate_and_configure_window(ITensorInfo &input1, ITensorInfo &input2, ITensorInfo &output)
426 {
428  {
429  // Division and Power operators don't support integer arithmetic
430  return validate_and_configure_window_for_division(input1, input2, output);
431  }
432  else
433  {
434  return validate_and_configure_window_for_arithmetic_operators(input1, input2, output);
435  }
436 }
437 Status CLArithmeticOperationKernel::validate_arguments(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output)
438 {
440  {
441  // Division and Power operators don't support integer arithmetic
442  return validate_arguments_with_float_only_supported_rules(input1, input2, output);
443  }
444  else
445  {
446  return validate_arguments_with_arithmetic_rules(input1, input2, output);
447  }
448 }
449 
450 CLBuildOptions CLArithmeticOperationKernel::generate_build_options(const ITensorInfo &input1, const ITensorInfo &input2, const ITensorInfo &output)
451 {
452  return generate_build_options_with_arithmetic_rules(input1, input2, output, name());
453 }
454 std::string CLArithmeticOperationKernel::generate_id_for_tuning(const std::string &kernel_name, const ITensorInfo &input1, const ITensorInfo &output)
455 {
456  return generate_id_for_tuning_common(kernel_name, input1, output);
457 }
458 
459 std::string CLArithmeticOperationKernel::name()
460 {
461  return supported_arithmetic_ops[_op];
462 }
463 } // namespace arm_compute
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Definition: Utils.h:1131
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:510
ArithmeticOperation
Available element-wise operations.
Definition: Types.h:511
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
Definition: CLValidate.h:34
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 enabled() const
Check if initialised.
Definition: Types.h:1567
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
Container for 2D border size.
Definition: Types.h:272
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:39
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:545
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:247
TensorShape collapsed_from(size_t start) const
Return a copy with collapsed dimensions starting from a given point.
Definition: TensorShape.h:160
1 channel, 1 U8 per channel
float a() const
Get the alpha value.
Definition: Types.h:1557
#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.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:792
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:210
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:1189
#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:259
Activation Layer Information class.
Definition: Types.h:1517
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.
Definition: Helpers.inl:257
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps=Steps(), bool skip_border=false, BorderSize border_size=BorderSize())
Calculate the maximum window for a given tensor shape and border setting.
Definition: Helpers.cpp:28
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:158
Copyright (c) 2017-2020 ARM Limited.
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: Helpers.inl:202
1 channel, 1 F16 per channel
void add_option(std::string option)
Adds option to the existing build option list.
const std::string & config_id() const
Get the configuration ID.
Definition: ICLKernel.h:262
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:387
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:135
static Status validate(ArithmeticOperation op, const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of CLArithmeticOperationKer...
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: Helpers.h:437
#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:1225
void run(const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
void configure(ArithmeticOperation op, const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output, const ConvertPolicy &policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of CLSaturatedArithmeticOpe...
quantized, asymmetric fixed-point 8-bit number unsigned
std::set< std::string > build_options
std::string kernel_name
size_t total_size() const
Collapses all dimensions to a single linear total size.
Definition: TensorShape.h:171
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
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
bool have_different_dimensions(const Dimensions< T > &dim1, const Dimensions< T > &dim2, unsigned int upper_dim)
Definition: Validate.h:51
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
Definition: Window.h:333
1 channel, 1 S16 per channel
CLCompileContext class.
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 CLSaturatedArithmeticOpe...
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
const std::string & string_from_data_layout(DataLayout dl)
Convert a data layout identity into a string.
Definition: Utils.cpp:123
#define ARM_COMPUTE_CREATE_ERROR(error_code, msg)
Creates an error with a given message.
Definition: Error.h:159
BorderSize border_size() const override
The size of the border for that 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:122
bool set_shape_if_empty(ITensorInfo &info, const TensorShape &shape)
Set the shape to the specified value if the current assignment is empty.
Definition: Helpers.inl:235
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
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...
Definition: Helpers.inl:246
ActivationFunction activation() const
Get the type of activation function.
Definition: Types.h:1552
float b() const
Get the beta value.
Definition: Types.h:1562
quantized, asymmetric fixed-point 8-bit number signed
void configure(ArithmeticOperation op, const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of CLArithmeticOperationKer...
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:289
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
Describe a multidimensional execution window.
Definition: Window.h:39
ConvertPolicy
Policy to handle overflow.
Definition: Types.h:362
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
Definition: Utils.h:1111
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)