Compute Library
 22.02
Utils.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-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  */
24 
26 
27 #include "arm_compute/core/Utils.h"
28 
29 #include <algorithm>
30 #include <cmath>
31 #include <cstdint>
32 #include <fstream>
33 #include <map>
34 #include <string>
35 
36 namespace arm_compute
37 {
38 std::string read_file(const std::string &filename, bool binary)
39 {
40  std::string out;
41  std::ifstream fs;
42 
43 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
44  try
45  {
46 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
47  fs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
48  std::ios_base::openmode mode = std::ios::in;
49 
50  if(binary)
51  {
52  mode |= std::ios::binary;
53  }
54 
55  fs.open(filename, mode);
56 
57  // Go to the end of the file
58  fs.seekg(0, std::ios::end);
59  // Reserve the memory required to store the file's content
60  out.reserve(fs.tellg());
61  // Go back to the beginning of the file
62  fs.seekg(0, std::ios::beg);
63  // Copy the content of the file
64  out.assign(std::istreambuf_iterator<char>(fs), std::istreambuf_iterator<char>());
65 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
66  }
67  catch(const std::ifstream::failure &e)
68  {
69  ARM_COMPUTE_ERROR_VAR("Accessing %s: %s", filename.c_str(), e.what());
70  }
71 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
72 
73  return out;
74 }
75 
76 const std::string &string_from_format(Format format)
77 {
78  static std::map<Format, const std::string> formats_map =
79  {
80  { Format::UNKNOWN, "UNKNOWN" },
81  { Format::U8, "U8" },
82  { Format::S16, "S16" },
83  { Format::U16, "U16" },
84  { Format::S32, "S32" },
85  { Format::U32, "U32" },
86  { Format::F16, "F16" },
87  { Format::F32, "F32" },
88  { Format::UV88, "UV88" },
89  { Format::RGB888, "RGB888" },
90  { Format::RGBA8888, "RGBA8888" },
91  { Format::YUV444, "YUV444" },
92  { Format::YUYV422, "YUYV422" },
93  { Format::NV12, "NV12" },
94  { Format::NV21, "NV21" },
95  { Format::IYUV, "IYUV" },
96  { Format::UYVY422, "UYVY422" }
97  };
98 
99  return formats_map[format];
100 }
101 
102 const std::string &string_from_channel(Channel channel)
103 {
104  static std::map<Channel, const std::string> channels_map =
105  {
106  { Channel::UNKNOWN, "UNKNOWN" },
107  { Channel::R, "R" },
108  { Channel::G, "G" },
109  { Channel::B, "B" },
110  { Channel::A, "A" },
111  { Channel::Y, "Y" },
112  { Channel::U, "U" },
113  { Channel::V, "V" },
114  { Channel::C0, "C0" },
115  { Channel::C1, "C1" },
116  { Channel::C2, "C2" },
117  { Channel::C3, "C3" }
118  };
119 
120  return channels_map[channel];
121 }
122 
123 const std::string &string_from_data_layout(DataLayout dl)
124 {
125  static std::map<DataLayout, const std::string> dl_map =
126  {
127  { DataLayout::UNKNOWN, "UNKNOWN" },
128  { DataLayout::NCHW, "NCHW" },
129  { DataLayout::NHWC, "NHWC" },
130  };
131 
132  return dl_map[dl];
133 }
134 
135 const std::string &string_from_data_type(DataType dt)
136 {
137  static std::map<DataType, const std::string> dt_map =
138  {
139  { DataType::UNKNOWN, "UNKNOWN" },
140  { DataType::S8, "S8" },
141  { DataType::U8, "U8" },
142  { DataType::S16, "S16" },
143  { DataType::U16, "U16" },
144  { DataType::S32, "S32" },
145  { DataType::U32, "U32" },
146  { DataType::S64, "S64" },
147  { DataType::U64, "U64" },
148  { DataType::F16, "F16" },
149  { DataType::F32, "F32" },
150  { DataType::F64, "F64" },
151  { DataType::SIZET, "SIZET" },
152  { DataType::QSYMM8, "QSYMM8" },
153  { DataType::QSYMM8_PER_CHANNEL, "QSYMM8_PER_CHANNEL" },
154  { DataType::QASYMM8, "QASYMM8" },
155  { DataType::QASYMM8_SIGNED, "QASYMM8_SIGNED" },
156  { DataType::QSYMM16, "QSYMM16" },
157  { DataType::QASYMM16, "QASYMM16" },
158  };
159 
160  return dt_map[dt];
161 }
162 
164 {
165  static std::map<ActivationLayerInfo::ActivationFunction, const std::string> act_map =
166  {
181 
182  };
183 
184  return act_map[act];
185 }
186 
188 {
189  static std::map<InterpolationPolicy, const std::string> interpolation_policy_map =
190  {
191  { InterpolationPolicy::AREA, "AREA" },
192  { InterpolationPolicy::BILINEAR, "BILINEAR" },
193  { InterpolationPolicy::NEAREST_NEIGHBOR, "NEAREST_NEIGHBOUR" },
194  };
195 
196  return interpolation_policy_map[policy];
197 }
198 
199 const std::string &string_from_border_mode(BorderMode border_mode)
200 {
201  static std::map<BorderMode, const std::string> border_mode_map =
202  {
203  { BorderMode::UNDEFINED, "UNDEFINED" },
204  { BorderMode::CONSTANT, "CONSTANT" },
205  { BorderMode::REPLICATE, "REPLICATE" },
206  };
207 
208  return border_mode_map[border_mode];
209 }
210 
212 {
213  static std::map<NormType, const std::string> norm_type_map =
214  {
215  { NormType::IN_MAP_1D, "IN_MAP_1D" },
216  { NormType::IN_MAP_2D, "IN_MAP_2D" },
217  { NormType::CROSS_MAP, "CROSS_MAP" },
218  };
219 
220  return norm_type_map[type];
221 }
222 
224 {
225  static std::map<PoolingType, const std::string> pool_type_map =
226  {
227  { PoolingType::MAX, "MAX" },
228  { PoolingType::AVG, "AVG" },
229  { PoolingType::L2, "L2" },
230  };
231 
232  return pool_type_map[type];
233 }
234 
236 {
237  if(info.is_global_pooling || info.exclude_padding || info.pool_size.x() == 0 || info.pool_size.y() == 0)
238  {
239  return false;
240  }
241  const auto ps = info.pad_stride_info;
242  const auto pool_le_padding_x = info.pool_size.x() <= std::max({ ps.pad_left(), ps.pad_right() });
243  const auto pool_le_padding_y = info.pool_size.y() <= std::max({ ps.pad_top(), ps.pad_bottom() });
244  return pool_le_padding_x || pool_le_padding_y;
245 }
246 
248 {
249  static std::map<GEMMLowpOutputStageType, const std::string> output_stage_map =
250  {
252  { GEMMLowpOutputStageType::QUANTIZE_DOWN, "quantize_down" },
253  { GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT, "quantize_down_fixedpoint" },
254  { GEMMLowpOutputStageType::QUANTIZE_DOWN_FLOAT, "quantize_down_float" }
255  };
256 
257  return output_stage_map[output_stage];
258 }
259 
260 std::string string_from_pixel_value(const PixelValue &value, const DataType data_type)
261 {
262  std::stringstream ss;
263  std::string converted_string;
264 
265  switch(data_type)
266  {
267  case DataType::U8:
268  case DataType::QASYMM8:
269  // Needs conversion to 32 bit, otherwise interpreted as ASCII values
270  ss << uint32_t(value.get<uint8_t>());
271  converted_string = ss.str();
272  break;
273  case DataType::S8:
276  // Needs conversion to 32 bit, otherwise interpreted as ASCII values
277  ss << int32_t(value.get<int8_t>());
278  converted_string = ss.str();
279  break;
280  case DataType::U16:
281  case DataType::QASYMM16:
282  ss << value.get<uint16_t>();
283  converted_string = ss.str();
284  break;
285  case DataType::S16:
286  case DataType::QSYMM16:
287  ss << value.get<int16_t>();
288  converted_string = ss.str();
289  break;
290  case DataType::U32:
291  ss << value.get<uint32_t>();
292  converted_string = ss.str();
293  break;
294  case DataType::S32:
295  ss << value.get<int32_t>();
296  converted_string = ss.str();
297  break;
298  case DataType::F32:
299  converted_string = float_to_string_with_full_precision(value.get<float>());
300  break;
301  case DataType::F16:
302  static_assert(sizeof(half) == 2, "Half must be 16 bit");
303  ss << value.get<half>();
304  converted_string = ss.str();
305  break;
306  default:
307  ARM_COMPUTE_ERROR("Not handled");
308  }
309 
310  return converted_string;
311 }
312 
313 DataType data_type_from_name(const std::string &name)
314 {
315  static const std::map<std::string, DataType> data_types =
316  {
317  { "f16", DataType::F16 },
318  { "f32", DataType::F32 },
319  { "qasymm8", DataType::QASYMM8 },
320  { "qasymm8_signed", DataType::QASYMM8_SIGNED },
321  };
322 
323 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
324  try
325  {
326 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
327  return data_types.at(utility::tolower(name));
328 
329 #ifndef ARM_COMPUTE_EXCEPTIONS_DISABLED
330  }
331  catch(const std::out_of_range &)
332  {
333  ARM_COMPUTE_ERROR_VAR("Invalid data type name: %s", name.c_str());
334  }
335 #endif /* ARM_COMPUTE_EXCEPTIONS_DISABLED */
336 }
337 
338 std::string lower_string(const std::string &val)
339 {
340  std::string res = val;
341  std::transform(res.begin(), res.end(), res.begin(), ::tolower);
342  return res;
343 }
344 
345 std::string upper_string(const std::string &val)
346 {
347  std::string res = val;
348  std::transform(res.begin(), res.end(), res.begin(), ::toupper);
349  return res;
350 }
351 
353  const DimensionRoundingType &rounding_type)
354 {
355  const auto &strides = conv_info.stride();
356  ARM_COMPUTE_ERROR_ON_MSG((strides.first < 1 || strides.second < 1), "Stride values should be greater than or equal to 1.");
357 
358  const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
359  const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
360  const unsigned int in_width = input_shape[width_idx];
361  const unsigned int in_height = input_shape[height_idx];
362  const unsigned int kernel_width = weights_shape[width_idx];
363  const unsigned int kernel_height = weights_shape[height_idx];
364 
365  // Calculate output dimensions
366  const auto is_ceil = static_cast<unsigned int>(rounding_type == DimensionRoundingType::CEIL);
367  const unsigned int out_width = ((in_width - is_ceil) + strides.first - 1) / strides.first + is_ceil;
368  const unsigned int out_height = ((in_height - is_ceil) + strides.second - 1) / strides.second + is_ceil;
369 
370  // Calculate effective weights sizes
371  const int real_weight_width = (kernel_width - 1) * dilation.x() + 1;
372  const int real_weight_height = (kernel_height - 1) * dilation.y() + 1;
373 
374  // Calculate total pad
375  const int pad_width = std::max(0, static_cast<int>((out_width - 1) * strides.first + real_weight_width - in_width));
376  const int pad_height = std::max(0, static_cast<int>((out_height - 1) * strides.second + real_weight_height - in_height));
377 
378  // Calculate individual paddings
379  const unsigned int pad_left = pad_width / 2;
380  const unsigned int pad_top = pad_height / 2;
381  const unsigned int pad_right = pad_width - pad_left;
382  const unsigned int pad_bottom = pad_height - pad_top;
383 
384  PadStrideInfo same_info(strides.first, strides.second, pad_left, pad_right, pad_top, pad_bottom, rounding_type);
385 
386  // Check for correctness of predicted output shape against the one calculated using the generated info
387  const auto out_dims = scaled_dimensions(in_width, in_height, kernel_width, kernel_height, same_info, dilation);
388  ARM_COMPUTE_ERROR_ON(out_dims.first != out_width || out_dims.second != out_height);
389  ARM_COMPUTE_UNUSED(out_dims);
390 
391  return same_info;
392 }
393 
394 std::pair<unsigned int, unsigned int> deconvolution_output_dimensions(unsigned int in_width, unsigned int in_height,
395  unsigned int kernel_width, unsigned int kernel_height,
396  const PadStrideInfo &pad_stride_info)
397 {
398  const unsigned int pad_left = pad_stride_info.pad_left();
399  const unsigned int pad_top = pad_stride_info.pad_top();
400  const unsigned int pad_right = pad_stride_info.pad_right();
401  const unsigned int pad_bottom = pad_stride_info.pad_bottom();
402  const unsigned int stride_x = pad_stride_info.stride().first;
403  const unsigned int stride_y = pad_stride_info.stride().second;
404 
405  ARM_COMPUTE_ERROR_ON(in_width < 1 || in_height < 1);
406  ARM_COMPUTE_ERROR_ON(((in_width - 1) * stride_x + kernel_width) < (pad_left + pad_right));
407  ARM_COMPUTE_ERROR_ON(((in_height - 1) * stride_y + kernel_height) < (pad_top + pad_bottom));
408  const int w = stride_x * (in_width - 1) + kernel_width - (pad_left + pad_right);
409  const int h = stride_y * (in_height - 1) + kernel_height - (pad_top + pad_bottom);
410 
411  return std::make_pair<unsigned int, unsigned int>(w, h);
412 }
413 
414 std::pair<unsigned int, unsigned int> scaled_dimensions(int width, int height,
415  int kernel_width, int kernel_height,
416  const PadStrideInfo &pad_stride_info,
417  const Size2D &dilation)
418 {
419  const int dilation_x = dilation.x();
420  const int dilation_y = dilation.y();
421  const int pad_left = pad_stride_info.pad_left();
422  const int pad_top = pad_stride_info.pad_top();
423  const int pad_right = pad_stride_info.pad_right();
424  const int pad_bottom = pad_stride_info.pad_bottom();
425  const int stride_x = pad_stride_info.stride().first;
426  const int stride_y = pad_stride_info.stride().second;
427  int w = 0;
428  int h = 0;
429  switch(pad_stride_info.round())
430  {
432  w = static_cast<int>(std::floor((static_cast<float>(width + pad_left + pad_right - (dilation_x * (kernel_width - 1) + 1)) / stride_x) + 1));
433  h = static_cast<int>(std::floor((static_cast<float>(height + pad_top + pad_bottom - (dilation_y * (kernel_height - 1) + 1)) / stride_y) + 1));
434  break;
436  w = static_cast<int>(std::ceil((static_cast<float>(width + pad_left + pad_right - (dilation_x * (kernel_width - 1) + 1)) / stride_x) + 1));
437  h = static_cast<int>(std::ceil((static_cast<float>(height + pad_top + pad_bottom - (dilation_y * (kernel_height - 1) + 1)) / stride_y) + 1));
438  break;
439  default:
440  ARM_COMPUTE_ERROR("Unsupported rounding type");
441  }
442 
443  w = std::max(1, w);
444  h = std::max(1, h);
445  return std::make_pair(static_cast<unsigned int>(w), static_cast<unsigned int>(h));
446 }
447 
448 std::pair<int, int> scaled_dimensions_signed(int width, int height,
449  int kernel_width, int kernel_height,
450  const PadStrideInfo &pad_stride_info)
451 {
452  const int pad_left = pad_stride_info.pad_left();
453  const int pad_top = pad_stride_info.pad_top();
454  const int pad_right = pad_stride_info.pad_right();
455  const int pad_bottom = pad_stride_info.pad_bottom();
456  const int stride_x = pad_stride_info.stride().first;
457  const int stride_y = pad_stride_info.stride().second;
458  int w = 0;
459  int h = 0;
460  switch(pad_stride_info.round())
461  {
463  w = static_cast<int>(std::floor((static_cast<float>(width + pad_left + pad_right - kernel_width) / stride_x) + 1));
464  h = static_cast<int>(std::floor((static_cast<float>(height + pad_top + pad_bottom - kernel_height) / stride_y) + 1));
465  break;
467  w = static_cast<int>(std::ceil((static_cast<float>(width + pad_left + pad_right - kernel_width) / stride_x) + 1));
468  h = static_cast<int>(std::ceil((static_cast<float>(height + pad_top + pad_bottom - kernel_height) / stride_y) + 1));
469  break;
470  default:
471  ARM_COMPUTE_ERROR("Unsupported rounding type");
472  }
473 
474  return std::make_pair(static_cast<int>(w), static_cast<int>(h));
475 }
476 
478 {
479  const bool is_min_max = (op == ReductionOperation::MAX || op == ReductionOperation::MIN);
480  const bool is_quantized_type = is_data_type_quantized(dt);
481  const bool is_first_dim = (axis == 0);
482 
483  return !is_first_dim || is_min_max || is_quantized_type;
484 }
485 
487 {
488  // Note: Output quantization info for softmax should always have
489  // * Softmax with QASYMM8: scale = 1/256, offset = 0
490  // * Softmax with QASYMM8_SIGNED: scale = 1/256, offset = -128
491  // * LogSoftmax with QASYMM8: scale = 1/256, offset = 0
492  // * LogSoftmax with QASYMM8_SIGNED: scale = 16/256, offset = 127
494  {
495  if(is_log)
496  {
497  return QuantizationInfo(16.f / 256, 127);
498  }
499  else
500  {
501  return QuantizationInfo(1.f / 256, -128);
502  }
503  }
504  return QuantizationInfo(1.f / 256, 0);
505 }
506 
508 {
509  const bool is_qasymm8_signed = is_data_type_quantized_asymmetric_signed(data_type);
510  const auto a = act_info.a();
511  const auto b = act_info.b();
512  const int a_int = is_qasymm8_signed ? quantize_qasymm8_signed(a, oq_info) : quantize_qasymm8(a, oq_info);
513  const int b_int = is_qasymm8_signed ? quantize_qasymm8_signed(b, oq_info) : quantize_qasymm8(b, oq_info);
514  const auto type_max_value = std::get<1>(get_min_max(data_type)).get<int32_t>();
515 
516  const int32_t min_activation = act_info.activation() != ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU ? oq_info.offset : b_int;
517  const int32_t max_activation = act_info.activation() == ActivationLayerInfo::ActivationFunction::RELU ? type_max_value : a_int;
518 
519  return std::make_pair(min_activation, max_activation);
520 }
521 
522 std::unordered_map<const ITensorInfo *, PaddingSize> get_padding_info(std::initializer_list<const ITensor *> tensors)
523 {
524  std::unordered_map<const ITensorInfo *, PaddingSize> res;
525 
526  for(const ITensor *tensor : tensors)
527  {
528  if(tensor)
529  {
530  res.insert({ tensor->info(), tensor->info()->padding() });
531  }
532  }
533 
534  return res;
535 }
536 
537 std::unordered_map<const ITensorInfo *, PaddingSize> get_padding_info(std::initializer_list<const ITensorInfo *> infos)
538 {
539  std::unordered_map<const ITensorInfo *, PaddingSize> res;
540 
541  for(const ITensorInfo *info : infos)
542  {
543  if(info)
544  {
545  res.insert({ info, info->padding() });
546  }
547  }
548 
549  return res;
550 }
551 
552 bool has_padding_changed(const std::unordered_map<const ITensorInfo *, PaddingSize> &padding_map)
553 {
554  return std::find_if(padding_map.begin(), padding_map.end(), [](const std::pair<const ITensorInfo *, PaddingSize> &padding_info)
555  {
556  return (padding_info.first->padding() != padding_info.second);
557  })
558  != padding_map.end();
559 }
560 
561 #ifdef ARM_COMPUTE_ASSERTS_ENABLED
562 void print_consecutive_elements(std::ostream &s, DataType dt, const uint8_t *ptr, unsigned int n, int stream_width, const std::string &element_delim)
563 {
564  switch(dt)
565  {
566  case DataType::U8:
567  case DataType::QASYMM8:
568  print_consecutive_elements_impl<uint8_t>(s, ptr, n, stream_width, element_delim);
569  break;
570  case DataType::S8:
571  case DataType::QSYMM8:
574  print_consecutive_elements_impl<int8_t>(s, reinterpret_cast<const int8_t *>(ptr), n, stream_width, element_delim);
575  break;
576  case DataType::U16:
577  case DataType::QASYMM16:
578  print_consecutive_elements_impl<uint16_t>(s, reinterpret_cast<const uint16_t *>(ptr), n, stream_width, element_delim);
579  break;
580  case DataType::S16:
581  case DataType::QSYMM16:
582  print_consecutive_elements_impl<int16_t>(s, reinterpret_cast<const int16_t *>(ptr), n, stream_width, element_delim);
583  break;
584  case DataType::U32:
585  print_consecutive_elements_impl<uint32_t>(s, reinterpret_cast<const uint32_t *>(ptr), n, stream_width, element_delim);
586  break;
587  case DataType::S32:
588  print_consecutive_elements_impl<int32_t>(s, reinterpret_cast<const int32_t *>(ptr), n, stream_width, element_delim);
589  break;
590  case DataType::BFLOAT16:
591  print_consecutive_elements_impl<bfloat16>(s, reinterpret_cast<const bfloat16 *>(ptr), n, stream_width, element_delim);
592  break;
593  case DataType::F16:
594  print_consecutive_elements_impl<half>(s, reinterpret_cast<const half *>(ptr), n, stream_width, element_delim);
595  break;
596  case DataType::F32:
597  print_consecutive_elements_impl<float>(s, reinterpret_cast<const float *>(ptr), n, stream_width, element_delim);
598  break;
599  default:
600  ARM_COMPUTE_ERROR("Undefined element size for given data type");
601  }
602 }
603 
604 int max_consecutive_elements_display_width(std::ostream &s, DataType dt, const uint8_t *ptr, unsigned int n)
605 {
606  switch(dt)
607  {
608  case DataType::U8:
609  case DataType::QASYMM8:
610  return max_consecutive_elements_display_width_impl<uint8_t>(s, ptr, n);
611  case DataType::S8:
612  case DataType::QSYMM8:
615  return max_consecutive_elements_display_width_impl<int8_t>(s, reinterpret_cast<const int8_t *>(ptr), n);
616  case DataType::U16:
617  case DataType::QASYMM16:
618  return max_consecutive_elements_display_width_impl<uint16_t>(s, reinterpret_cast<const uint16_t *>(ptr), n);
619  case DataType::S16:
620  case DataType::QSYMM16:
621  return max_consecutive_elements_display_width_impl<int16_t>(s, reinterpret_cast<const int16_t *>(ptr), n);
622  case DataType::U32:
623  return max_consecutive_elements_display_width_impl<uint32_t>(s, reinterpret_cast<const uint32_t *>(ptr), n);
624  case DataType::S32:
625  return max_consecutive_elements_display_width_impl<int32_t>(s, reinterpret_cast<const int32_t *>(ptr), n);
626  case DataType::BFLOAT16:
627  return max_consecutive_elements_display_width_impl<bfloat16>(s, reinterpret_cast<const bfloat16 *>(ptr), n);
628  case DataType::F16:
629  return max_consecutive_elements_display_width_impl<half>(s, reinterpret_cast<const half *>(ptr), n);
630  case DataType::F32:
631  return max_consecutive_elements_display_width_impl<float>(s, reinterpret_cast<const float *>(ptr), n);
632  default:
633  ARM_COMPUTE_ERROR("Undefined element size for given data type");
634  }
635  return 0;
636 }
637 #endif /* ARM_COMPUTE_ASSERTS_ENABLED */
638 
639 } // namespace arm_compute
BorderMode
Methods available to handle borders.
Definition: Types.h:261
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Definition: Utils.h:996
bool needs_serialized_reduction(ReductionOperation op, DataType dt, unsigned int axis)
Check if the given reduction operation should be handled in a serial way.
Definition: Utils.cpp:477
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
A single plane of 32-bit macro pixel of U0, Y0, V0, Y1 byte.
InterpolationPolicy
Interpolation method.
Definition: Types.h:398
SimpleTensor< float > w
Definition: DFT.cpp:156
Second channel (used by formats with unknown channel types).
Shape of a tensor.
Definition: TensorShape.h:39
Quantize using a fixed point multiplication.
DimensionRoundingType round() const
Get the rounding type.
Definition: Types.h:751
quantized, symmetric fixed-point 16-bit number
ReductionOperation
Available reduction operations.
Definition: Types.h:463
SimpleTensor< float > b
Definition: DFT.cpp:157
const std::string & string_from_channel(Channel channel)
Convert a channel identity into a string.
Definition: Utils.cpp:102
uint8_t quantize_qasymm8(float value, const INFO_TYPE &qinfo, RoundingPolicy rounding_policy=RoundingPolicy::TO_NEAREST_UP)
Quantize a value given an unsigned 8-bit asymmetric quantization scheme.
std::pair< unsigned int, unsigned int > deconvolution_output_dimensions(unsigned int in_width, unsigned int in_height, unsigned int kernel_width, unsigned int kernel_height, const PadStrideInfo &pad_stride_info)
Returns expected width and height of the deconvolution&#39;s output tensor.
Definition: Utils.cpp:394
Brain floating point representation class.
Definition: Bfloat16.h:81
Cr/V/Value channel.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
1 channel, 1 U8 per channel
float a() const
Get the alpha value.
Definition: Types.h:1549
void get(uint8_t &v) const
Interpret the pixel value as a U8.
Definition: PixelValue.h:244
half_float::half half
16-bit floating point type
Definition: Types.h:48
1 channel, 1 F32 per channel
DimensionRoundingType
Dimension rounding type when down-scaling on CNNs.
Definition: Types.h:537
Unknown channel format.
Output values are defined by bilinear interpolation between the pixels.
#define ARM_COMPUTE_ERROR_VAR(msg,...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:346
std::stringstream ss(mlgo_str)
std::string string_from_pixel_value(const PixelValue &value, const DataType data_type)
Convert a PixelValue to a string, represented through the specific data type.
Definition: Utils.cpp:260
#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
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
A 2 plane YUV format of Luma (Y) and interleaved UV data at 4:2:0 sampling.
QuantizationInfo get_softmax_output_quantization_info(DataType input_type, bool is_log)
Returns output quantization information for softmax layer.
Definition: Utils.cpp:486
Quantization info when assuming per layer quantization.
quantized, asymmetric fixed-point 16-bit number
1 channel, 1 U16 per channel
size_t x() const
Semantic accessor for width as x.
Definition: Size2D.h:75
unsigned int pad_top() const
Get the top padding.
Definition: Types.h:740
Output values are defined to match the source pixel whose center is nearest to the sample position...
const std::string & string_from_gemmlowp_output_stage(GEMMLowpOutputStageType output_stage)
Translates a given GEMMLowp output stage to a string.
Definition: Utils.cpp:247
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:338
Activation Layer Information class.
Definition: Types.h:1509
decltype(strategy::transforms) typedef type
Interface for CPU tensor.
Definition: ITensor.h:36
A 2 plane YUV format of Luma (Y) and interleaved VU data at 4:2:0 sampling.
Copyright (c) 2017-2021 Arm Limited.
ActivationFunction
Available activation functions.
Definition: Types.h:1513
1 channel, 1 F16 per channel
std::pair< unsigned int, unsigned int > scaled_dimensions(int width, int height, int kernel_width, int kernel_height, const PadStrideInfo &pad_stride_info, const Size2D &dilation=Size2D(1U, 1U))
Returns expected width and height of output scaled tensor depending on dimensions rounding mode...
Definition: Utils.cpp:414
const std::string & string_from_norm_type(NormType type)
Translates a given normalization type to a string.
Definition: Utils.cpp:211
const std::string & string_from_border_mode(BorderMode border_mode)
Translates a given border mode policy to a string.
Definition: Utils.cpp:199
1 channel, 1 S32 per channel
std::pair< int, int > scaled_dimensions_signed(int width, int height, int kernel_width, int kernel_height, const PadStrideInfo &pad_stride_info)
Returns calculated width and height of output scaled tensor depending on dimensions rounding mode...
Definition: Utils.cpp:448
16-bit brain floating-point number
signed 64-bit number
3 channels, 1 U8 per channel
const DataType data_type
Definition: Im2Col.cpp:150
std::string tolower(std::string string)
Convert string to lower case.
Definition: Utility.h:205
Quantization information.
std::string upper_string(const std::string &val)
Raise a given string to upper case.
Definition: Utils.cpp:345
const auto input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
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
std::string read_file(const std::string &filename, bool binary)
Load an entire file in memory.
Definition: Utils.cpp:38
Third channel (used by formats with unknown channel types).
1 channel, 1 U32 per channel
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
Definition: Utils.h:1090
Normalization applied within the same map in 1D region.
Channel
Available channels.
Definition: Types.h:446
Format
Image colour formats.
Definition: Types.h:56
std::pair< int32_t, int32_t > get_quantized_activation_min_max(ActivationLayerInfo act_info, DataType data_type, UniformQuantizationInfo oq_info)
Returns a pair of minimum and maximum values for a quantized activation.
Definition: Utils.cpp:507
int8_t quantize_qasymm8_signed(float value, const INFO_TYPE &qinfo, RoundingPolicy rounding_policy=RoundingPolicy::TO_NEAREST_UP)
Quantize a value given a signed 8-bit asymmetric quantization scheme.
quantized, asymmetric fixed-point 8-bit number unsigned
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
Definition: Types.h:704
const std::string & string_from_interpolation_policy(InterpolationPolicy policy)
Translates a given interpolation policy to a string.
Definition: Utils.cpp:187
Pooling Layer Information struct.
Definition: Types.h:1173
bool is_data_type_quantized_asymmetric_signed(DataType dt)
Check if a given data type is of asymmetric quantized signed type.
Definition: Utils.h:1037
A 3 plane of 8 bit 4:4:4 sampled Y, U, V planes.
Fourth channel (used by formats with unknown channel types).
unsigned int pad_right() const
Get the right padding.
Definition: Types.h:735
Quantize using a floating point multiplication.
Padding and stride information class.
Definition: Types.h:656
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
const char * name
GEMMLowpOutputStageType
GEMMLowp output stage type.
Definition: Types.h:1913
Quantize using an integer multiplication.
1 channel, 1 S16 per channel
Output values are determined by averaging the source pixels whose areas fall under the area of the de...
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:552
quantized, symmetric fixed-point 8-bit number
Num samples, channels, height, width.
size_t y() const
Semantic accessor for height as y.
Definition: Size2D.h:84
quantized, symmetric per channel fixed-point 8-bit number
A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes.
4 channels, 1 U8 per channel
PoolingType
Available pooling types.
Definition: Types.h:544
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
const std::string & string_from_data_layout(DataLayout dl)
Convert a data layout identity into a string.
Definition: Utils.cpp:123
PadStrideInfo pad_stride_info
Definition: Types.h:1261
Borders are left undefined.
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:193
Pixels outside the image are assumed to have the same value as the closest image pixel.
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
Num samples, height, width, channels.
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:537
2 channel, 1 U8 per channel
bool is_pool_region_entirely_outside_input(const PoolingLayerInfo &info)
Check if the pool region is entirely outside the input tensor.
Definition: Utils.cpp:235
ActivationFunction activation() const
Get the type of activation function.
Definition: Types.h:1544
float b() const
Get the beta value.
Definition: Types.h:1554
quantized, asymmetric fixed-point 8-bit number signed
64-bit floating-point number
DataType data_type_from_name(const std::string &name)
Convert a string to DataType.
Definition: Utils.cpp:313
unsigned int pad_bottom() const
Get the bottom padding.
Definition: Types.h:745
A single plane of 32-bit macro pixel of Y0, U0, Y1, V0 bytes.
unsigned 64-bit number
DataType
Available data types.
Definition: Types.h:79
unsigned int pad_left() const
Get the left padding.
Definition: Types.h:730
DataLayout
[DataLayout enum definition]
Definition: Types.h:113
const std::string & string_from_pooling_type(PoolingType type)
Translates a given pooling type to a string.
Definition: Utils.cpp:223
NormType
The normalization type used for the normalization layer.
Definition: Types.h:511
signed 8-bit number
Normalization applied cross maps.
std::tuple< PixelValue, PixelValue > get_min_max(DataType dt)
Compute the mininum and maximum values a data type can take.
Definition: Utils.h:564
Normalization applied within the same map in 2D region.
PadStrideInfo calculate_same_pad(TensorShape input_shape, TensorShape weights_shape, PadStrideInfo conv_info, DataLayout data_layout=DataLayout::NCHW, const Size2D &dilation=Size2D(1u, 1u), const DimensionRoundingType &rounding_type=DimensionRoundingType::FLOOR)
Calculate padding requirements in case of SAME padding.
Definition: Utils.cpp:352
const std::string & string_from_format(Format format)
Convert a tensor format into a string.
Definition: Utils.cpp:76