Compute Library
 23.11
Utils.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2023 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifndef ARM_COMPUTE_TEST_UTILS_H
25 #define ARM_COMPUTE_TEST_UTILS_H
26 
28 #include "arm_compute/core/Error.h"
32 #include "arm_compute/core/Types.h"
33 #include "support/StringSupport.h"
35 
36 #ifdef ARM_COMPUTE_CL
39 #endif /* ARM_COMPUTE_CL */
40 
41 #include <cmath>
42 #include <cstddef>
43 #include <limits>
44 #include <memory>
45 #include <random>
46 #include <sstream>
47 #include <string>
48 #include <type_traits>
49 #include <vector>
50 
54 
55 namespace arm_compute
56 {
57 #ifdef ARM_COMPUTE_CL
58 class CLTensor;
59 #endif /* ARM_COMPUTE_CL */
60 namespace test
61 {
62 /** Round floating-point value with half value rounding to positive infinity.
63  *
64  * @param[in] value floating-point value to be rounded.
65  *
66  * @return Floating-point value of rounded @p value.
67  */
68 template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
69 inline T round_half_up(T value)
70 {
71  return std::floor(value + 0.5f);
72 }
73 
74 /** Round floating-point value with half value rounding to nearest even.
75  *
76  * @param[in] value floating-point value to be rounded.
77  * @param[in] epsilon precision.
78  *
79  * @return Floating-point value of rounded @p value.
80  */
81 template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
83 {
84  T positive_value = std::abs(value);
85  T ipart = 0;
86  std::modf(positive_value, &ipart);
87  // If 'value' is exactly halfway between two integers
88  if(std::abs(positive_value - (ipart + 0.5f)) < epsilon)
89  {
90  // If 'ipart' is even then return 'ipart'
91  if(std::fmod(ipart, 2.f) < epsilon)
92  {
93  return support::cpp11::copysign(ipart, value);
94  }
95  // Else return the nearest even integer
96  return support::cpp11::copysign(std::ceil(ipart + 0.5f), value);
97  }
98  // Otherwise use the usual round to closest
99  return support::cpp11::copysign(support::cpp11::round(positive_value), value);
100 }
101 
102 namespace traits
103 {
104 // *INDENT-OFF*
105 // clang-format off
106 /** Promote a type */
107 template <typename T> struct promote { };
108 /** Promote uint8_t to uint16_t */
109 template <> struct promote<uint8_t> { using type = uint16_t; /**< Promoted type */ };
110 /** Promote int8_t to int16_t */
111 template <> struct promote<int8_t> { using type = int16_t; /**< Promoted type */ };
112 /** Promote uint16_t to uint32_t */
113 template <> struct promote<uint16_t> { using type = uint32_t; /**< Promoted type */ };
114 /** Promote int16_t to int32_t */
115 template <> struct promote<int16_t> { using type = int32_t; /**< Promoted type */ };
116 /** Promote uint32_t to uint64_t */
117 template <> struct promote<uint32_t> { using type = uint64_t; /**< Promoted type */ };
118 /** Promote int32_t to int64_t */
119 template <> struct promote<int32_t> { using type = int64_t; /**< Promoted type */ };
120 /** Promote float to float */
121 template <> struct promote<float> { using type = float; /**< Promoted type */ };
122 /** Promote half to half */
123 template <> struct promote<half> { using type = half; /**< Promoted type */ };
124 
125 /** Get promoted type */
126 template <typename T>
127 using promote_t = typename promote<T>::type;
128 
129 template <typename T>
130 using make_signed_conditional_t = typename std::conditional<std::is_integral<T>::value, std::make_signed<T>, std::common_type<T>>::type;
131 
132 template <typename T>
133 using make_unsigned_conditional_t = typename std::conditional<std::is_integral<T>::value, std::make_unsigned<T>, std::common_type<T>>::type;
134 
135 // clang-format on
136 // *INDENT-ON*
137 } // namespace traits
138 
139 /** Look up the format corresponding to a channel.
140  *
141  * @param[in] channel Channel type.
142  *
143  * @return Format that contains the given channel.
144  */
146 {
147  switch(channel)
148  {
149  case Channel::R:
150  case Channel::G:
151  case Channel::B:
152  return Format::RGB888;
153  default:
154  throw std::runtime_error("Unsupported channel");
155  }
156 }
157 
158 /** Return the format of a channel.
159  *
160  * @param[in] channel Channel type.
161  *
162  * @return Format of the given channel.
163  */
165 {
166  switch(channel)
167  {
168  case Channel::R:
169  case Channel::G:
170  case Channel::B:
171  return Format::U8;
172  default:
173  throw std::runtime_error("Unsupported channel");
174  }
175 }
176 
177 /** Base case of foldl.
178  *
179  * @return value.
180  */
181 template <typename F, typename T>
182 inline T foldl(F &&, const T &value)
183 {
184  return value;
185 }
186 
187 /** Base case of foldl.
188  *
189  * @return func(value1, value2).
190  */
191 template <typename F, typename T, typename U>
192 inline auto foldl(F &&func, T &&value1, U &&value2) -> decltype(func(value1, value2))
193 {
194  return func(value1, value2);
195 }
196 
197 /** Fold left.
198  *
199  * @param[in] func Binary function to be called.
200  * @param[in] initial Initial value.
201  * @param[in] value Argument passed to the function.
202  * @param[in] values Remaining arguments.
203  */
204 template <typename F, typename I, typename T, typename... Vs>
205 inline I foldl(F &&func, I &&initial, T &&value, Vs &&... values)
206 {
207  return foldl(std::forward<F>(func), func(std::forward<I>(initial), std::forward<T>(value)), std::forward<Vs>(values)...);
208 }
209 
210 /** Create a valid region based on tensor shape, border mode and border size
211  *
212  * @param[in] a_shape Shape used as size of the valid region.
213  * @param[in] border_undefined (Optional) Boolean indicating if the border mode is undefined.
214  * @param[in] border_size (Optional) Border size used to specify the region to exclude.
215  *
216  * @return A valid region starting at (0, 0, ...) with size of @p shape if @p border_undefined is false; otherwise
217  * return A valid region starting at (@p border_size.left, @p border_size.top, ...) with reduced size of @p shape.
218  */
219 inline ValidRegion shape_to_valid_region(const TensorShape &a_shape, bool border_undefined = false, BorderSize border_size = BorderSize(0))
220 {
221  ValidRegion valid_region{ Coordinates(), a_shape };
222 
223  Coordinates &anchor = valid_region.anchor;
225 
226  if(border_undefined)
227  {
228  ARM_COMPUTE_ERROR_ON(shape.num_dimensions() < 2);
229 
230  anchor.set(0, border_size.left);
231  anchor.set(1, border_size.top);
232 
233  const int valid_shape_x = std::max(0, static_cast<int>(shape.x()) - static_cast<int>(border_size.left) - static_cast<int>(border_size.right));
234  const int valid_shape_y = std::max(0, static_cast<int>(shape.y()) - static_cast<int>(border_size.top) - static_cast<int>(border_size.bottom));
235 
236  shape.set(0, valid_shape_x);
237  shape.set(1, valid_shape_y);
238  }
239 
240  return valid_region;
241 }
242 
243 /** Write the value after casting the pointer according to @p data_type.
244  *
245  * @warning The type of the value must match the specified data type.
246  *
247  * @param[out] ptr Pointer to memory where the @p value will be written.
248  * @param[in] value Value that will be written.
249  * @param[in] data_type Data type that will be written.
250  */
251 template <typename T>
253 {
254  switch(data_type)
255  {
256  case DataType::U8:
257  case DataType::QASYMM8:
258  *reinterpret_cast<uint8_t *>(ptr) = value;
259  break;
260  case DataType::S8:
262  case DataType::QSYMM8:
264  *reinterpret_cast<int8_t *>(ptr) = value;
265  break;
266  case DataType::U16:
267  case DataType::QASYMM16:
268  *reinterpret_cast<uint16_t *>(ptr) = value;
269  break;
270  case DataType::S16:
271  case DataType::QSYMM16:
272  *reinterpret_cast<int16_t *>(ptr) = value;
273  break;
274  case DataType::U32:
275  *reinterpret_cast<uint32_t *>(ptr) = value;
276  break;
277  case DataType::S32:
278  *reinterpret_cast<int32_t *>(ptr) = value;
279  break;
280  case DataType::U64:
281  *reinterpret_cast<uint64_t *>(ptr) = value;
282  break;
283  case DataType::S64:
284  *reinterpret_cast<int64_t *>(ptr) = value;
285  break;
286  case DataType::BFLOAT16:
287  *reinterpret_cast<bfloat16 *>(ptr) = bfloat16(value);
288  break;
289  case DataType::F16:
290  *reinterpret_cast<half *>(ptr) = value;
291  break;
292  case DataType::F32:
293  *reinterpret_cast<float *>(ptr) = value;
294  break;
295  case DataType::F64:
296  *reinterpret_cast<double *>(ptr) = value;
297  break;
298  case DataType::SIZET:
299  *reinterpret_cast<size_t *>(ptr) = value;
300  break;
301  default:
302  ARM_COMPUTE_ERROR("NOT SUPPORTED!");
303  }
304 }
305 
306 /** Saturate a value of type T against the numeric limits of type U.
307  *
308  * @param[in] val Value to be saturated.
309  *
310  * @return saturated value.
311  */
312 template <typename U, typename T>
314 {
315  if(val > static_cast<T>(std::numeric_limits<U>::max()))
316  {
317  val = static_cast<T>(std::numeric_limits<U>::max());
318  }
319  if(val < static_cast<T>(std::numeric_limits<U>::lowest()))
320  {
321  val = static_cast<T>(std::numeric_limits<U>::lowest());
322  }
323  return val;
324 }
325 
326 /** Find the signed promoted common type.
327  */
328 template <typename... T>
330 {
331  /** Common type */
332  using common_type = typename std::common_type<T...>::type;
333  /** Promoted type */
335  /** Intermediate type */
337 };
338 
339 /** Find the unsigned promoted common type.
340  */
341 template <typename... T>
343 {
344  /** Common type */
345  using common_type = typename std::common_type<T...>::type;
346  /** Promoted type */
348  /** Intermediate type */
350 };
351 
352 /** Convert a linear index into n-dimensional coordinates.
353  *
354  * @param[in] shape Shape of the n-dimensional tensor.
355  * @param[in] index Linear index specifying the i-th element.
356  *
357  * @return n-dimensional coordinates.
358  */
359 inline Coordinates index2coord(const TensorShape &shape, int index)
360 {
361  int num_elements = shape.total_size();
362 
363  ARM_COMPUTE_ERROR_ON_MSG(index < 0 || index >= num_elements, "Index has to be in [0, num_elements]");
364  ARM_COMPUTE_ERROR_ON_MSG(num_elements == 0, "Cannot create coordinate from empty shape");
365 
366  Coordinates coord{ 0 };
367 
368  for(int d = shape.num_dimensions() - 1; d >= 0; --d)
369  {
370  num_elements /= shape[d];
371  coord.set(d, index / num_elements);
372  index %= num_elements;
373  }
374 
375  return coord;
376 }
377 
378 /** Linearise the given coordinate.
379  *
380  * Transforms the given coordinate into a linear offset in terms of
381  * elements.
382  *
383  * @param[in] shape Shape of the n-dimensional tensor.
384  * @param[in] coord The to be converted coordinate.
385  *
386  * @return Linear offset to the element.
387  */
388 inline int coord2index(const TensorShape &shape, const Coordinates &coord)
389 {
390  ARM_COMPUTE_ERROR_ON_MSG(shape.total_size() == 0, "Cannot get index from empty shape");
391  ARM_COMPUTE_ERROR_ON_MSG(coord.num_dimensions() == 0, "Cannot get index of empty coordinate");
392 
393  int index = 0;
394  int dim_size = 1;
395 
396  for(unsigned int i = 0; i < coord.num_dimensions(); ++i)
397  {
398  index += coord[i] * dim_size;
399  dim_size *= shape[i];
400  }
401 
402  return index;
403 }
404 
405 /** Check if a coordinate is within a valid region */
407 {
408  for(size_t d = 0; d < Coordinates::num_max_dimensions; ++d)
409  {
410  if(coord[d] < valid_region.start(d) || coord[d] >= valid_region.end(d))
411  {
412  return false;
413  }
414  }
415 
416  return true;
417 }
418 
419 /** Create and initialize a tensor of the given type.
420  *
421  * @param[in] info Tensor information to be used to create the tensor
422  * @param[in] ctx (Optional) Pointer to the runtime context.
423  *
424  * @return Initialized tensor of given type.
425  */
426 template <typename T>
427 inline T create_tensor(const TensorInfo &info, IRuntimeContext *ctx = nullptr)
428 {
429  T tensor(ctx);
430  tensor.allocator()->init(info);
431  return tensor;
432 }
433 
434 /** Create and initialize a tensor of the given type.
435  *
436  * @param[in] shape Tensor shape.
437  * @param[in] data_type Data type.
438  * @param[in] num_channels (Optional) Number of channels.
439  * @param[in] quantization_info (Optional) Quantization info for asymmetric quantized types.
440  * @param[in] data_layout (Optional) Data layout. Default is NCHW.
441  * @param[in] ctx (Optional) Pointer to the runtime context.
442  *
443  * @return Initialized tensor of given type.
444  */
445 template <typename T>
446 inline T create_tensor(const TensorShape &shape, DataType data_type, int num_channels = 1,
448 {
449  T tensor(ctx);
450  TensorInfo info(shape, num_channels, data_type);
451  info.set_quantization_info(quantization_info);
452  info.set_data_layout(data_layout);
453 
454  return create_tensor<T>(info, ctx);
455 }
456 
457 /** Create and initialize a tensor of the given type.
458  *
459  * @param[in] shape Tensor shape.
460  * @param[in] format Format type.
461  * @param[in] ctx (Optional) Pointer to the runtime context.
462  *
463  * @return Initialized tensor of given type.
464  */
465 template <typename T>
466 inline T create_tensor(const TensorShape &shape, Format format, IRuntimeContext *ctx = nullptr)
467 {
468  TensorInfo info(shape, format);
469 
470  return create_tensor<T>(info, ctx);
471 }
472 
473 /** Create a vector with a uniform distribution of floating point values across the specified range.
474  *
475  * @param[in] num_values The number of values to be created.
476  * @param[in] min The minimum value in distribution (inclusive).
477  * @param[in] max The maximum value in distribution (inclusive).
478  * @param[in] seed The random seed to be used.
479  *
480  * @return A vector that contains the requested number of random floating point values
481  */
482 template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
483 inline std::vector<T> generate_random_real(unsigned int num_values, T min, T max, std::random_device::result_type seed)
484 {
485  std::vector<T> v(num_values);
486  std::mt19937 gen(seed);
487  std::uniform_real_distribution<T> dist(min, max);
488 
489  for(unsigned int i = 0; i < num_values; ++i)
490  {
491  v.at(i) = dist(gen);
492  }
493 
494  return v;
495 }
496 
497 template <typename T, typename ArrayAccessor_T>
498 inline void fill_array(ArrayAccessor_T &&array, const std::vector<T> &v)
499 {
500  array.resize(v.size());
501  std::memcpy(array.buffer(), v.data(), v.size() * sizeof(T));
502 }
503 
504 /** Obtain numpy type string from DataType.
505  *
506  * @param[in] data_type Data type.
507  *
508  * @return numpy type string.
509  */
510 inline std::string get_typestring(DataType data_type)
511 {
512  // Check endianness
513  const unsigned int i = 1;
514  const char *c = reinterpret_cast<const char *>(&i);
515  std::string endianness;
516  if(*c == 1)
517  {
518  endianness = std::string("<");
519  }
520  else
521  {
522  endianness = std::string(">");
523  }
524  const std::string no_endianness("|");
525 
526  switch(data_type)
527  {
528  case DataType::U8:
529  return no_endianness + "u" + support::cpp11::to_string(sizeof(uint8_t));
530  case DataType::S8:
531  return no_endianness + "i" + support::cpp11::to_string(sizeof(int8_t));
532  case DataType::U16:
533  return endianness + "u" + support::cpp11::to_string(sizeof(uint16_t));
534  case DataType::S16:
535  return endianness + "i" + support::cpp11::to_string(sizeof(int16_t));
536  case DataType::U32:
537  return endianness + "u" + support::cpp11::to_string(sizeof(uint32_t));
538  case DataType::S32:
539  return endianness + "i" + support::cpp11::to_string(sizeof(int32_t));
540  case DataType::U64:
541  return endianness + "u" + support::cpp11::to_string(sizeof(uint64_t));
542  case DataType::S64:
543  return endianness + "i" + support::cpp11::to_string(sizeof(int64_t));
544  case DataType::F32:
545  return endianness + "f" + support::cpp11::to_string(sizeof(float));
546  case DataType::F64:
547  return endianness + "f" + support::cpp11::to_string(sizeof(double));
548  case DataType::SIZET:
549  return endianness + "u" + support::cpp11::to_string(sizeof(size_t));
550  default:
551  ARM_COMPUTE_ERROR("NOT SUPPORTED!");
552  }
553 }
554 
555 /** Sync if necessary.
556  */
557 template <typename TensorType>
558 inline void sync_if_necessary()
559 {
560 #ifdef ARM_COMPUTE_CL
561  if(opencl_is_available() && std::is_same<typename std::decay<TensorType>::type, arm_compute::CLTensor>::value)
562  {
564  }
565 #endif /* ARM_COMPUTE_CL */
566 }
567 
568 /** Sync tensor if necessary.
569  *
570  * @note: If the destination tensor not being used on OpenGL ES, GPU will optimize out the operation.
571  *
572  * @param[in] tensor Tensor to be sync.
573  */
574 template <typename TensorType>
576 {
578 }
579 
580 /** Construct and return object for dimensions' state filled with the given value
581  *
582  * @param[in] value The value to fill
583  *
584  * @return Constructed class
585  */
587 {
588  auto states = ITensorInfo::TensorDimsState{};
589  std::fill(states.begin(), states.end(), value);
590  return states;
591 }
592 
593 /** Construct and return object for dimensions' state filled with the value for dynamic state
594  *
595  * @return Constructed class filled with the value for dynamic state
596  */
598 {
600 }
601 
602 /** Construct and return object for dimensions' state filled with the value for non-dynamic state
603  *
604  * @return Constructed class filled with the value for non-dynamic state
605  */
607 {
609 }
610 
611 /** Set the dimension states of the given tensor to dynamic
612  *
613  * @param[in] t The tensor to set to dynamic state
614  *
615  */
616 template <typename TensorType>
618 {
619  t.info()->set_tensor_dims_state(construct_dynamic_dims_state());
620 }
621 
622 /** Set the dimension states of the given tensor to state
623  *
624  * @param[in] t The tensor to set to static state
625  *
626  */
627 template <typename TensorType>
629 {
630  t.info()->set_tensor_dims_state(construct_static_dims_state());
631 }
632 
634 {
635  const Padding2D info_pad(info.pad_left(), info.pad_right(), info.pad_top(), info.pad_bottom());
636  const Size2D info_stride(info.stride().first, info.stride().second);
637  return arm_compute::experimental::dynamic_fusion::Conv2dAttributes().pad(info_pad).stride(info_stride).dilation(dialation);
638 }
639 
640 } // namespace test
641 } // namespace arm_compute
642 #endif /* ARM_COMPUTE_TEST_UTILS_H */
arm_compute::DataLayout::NCHW
@ NCHW
Num samples, channels, height, width.
arm_compute::support::cpp11::to_string
std::string to_string(T &&value)
Convert integer and float values to string.
Definition: StringSupport.h:168
arm_compute::DataType::QSYMM8_PER_CHANNEL
@ QSYMM8_PER_CHANNEL
quantized, symmetric per channel fixed-point 8-bit number
arm_compute::DataType::QASYMM16
@ QASYMM16
quantized, asymmetric fixed-point 16-bit number
arm_compute::test::traits::promote
Promote a type.
Definition: Utils.h:107
arm_compute::opencl_is_available
bool opencl_is_available()
Check if OpenCL is available.
Definition: OpenCL.cpp:208
StringSupport.h
arm_compute::ITensorInfo::get_dynamic_state_value
static constexpr int32_t get_dynamic_state_value()
Get the value representing dynamic dimension state.
Definition: ITensorInfo.h:58
arm_compute::Format::RGB888
@ RGB888
3 channels, 1 U8 per channel
arm_compute::experimental::dynamic_fusion::Conv2dAttributes::pad
Conv2dAttributes & pad(const Padding2D &pad)
Set padding.
Definition: Conv2dAttributes.cpp:33
arm_compute::test::traits::promote< uint16_t >::type
uint32_t type
Promoted type.
Definition: Utils.h:113
arm_compute::DataType::U64
@ U64
unsigned 64-bit number
arm_compute::test::construct_dims_state
ITensorInfo::TensorDimsState construct_dims_state(int32_t value)
Construct and return object for dimensions' state filled with the given value.
Definition: Utils.h:586
type
decltype(strategy::transforms) typedef type
Definition: gemm_interleaved.hpp:261
arm_compute::DataType::BFLOAT16
@ BFLOAT16
16-bit brain floating-point number
arm_compute::test::common_promoted_signed_type::intermediate_type
typename traits::make_signed_conditional_t< promoted_type >::type intermediate_type
Intermediate type.
Definition: Utils.h:336
arm_compute::QuantizationInfo
Quantization information.
Definition: QuantizationInfo.h:67
arm_compute::Dimensions::set
void set(size_t dimension, T value, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
Definition: Dimensions.h:75
arm_compute::DataLayout
DataLayout
[DataLayout enum definition]
Definition: CoreTypes.h:110
arm_compute::test::convert_pad_stride_info_to_conv_attr
experimental::dynamic_fusion::Conv2dAttributes convert_pad_stride_info_to_conv_attr(const PadStrideInfo &info, const Size2D &dialation)
Definition: Utils.h:633
arm_compute::DataType::F64
@ F64
64-bit floating-point number
arm_compute::test::traits::promote< float >::type
float type
Promoted type.
Definition: Utils.h:121
arm_compute::ITensorInfo::get_static_state_value
static constexpr int32_t get_static_state_value()
Get the value representing static dimension state.
Definition: ITensorInfo.h:67
arm_compute::BorderSize
Container for 2D border size.
Definition: Types.h:239
arm_compute::test::traits::promote< uint32_t >::type
uint64_t type
Promoted type.
Definition: Utils.h:117
arm_compute::test::construct_dynamic_dims_state
ITensorInfo::TensorDimsState construct_dynamic_dims_state()
Construct and return object for dimensions' state filled with the value for dynamic state.
Definition: Utils.h:597
arm_compute::test::common_promoted_unsigned_type::intermediate_type
typename traits::make_unsigned_conditional_t< promoted_type >::type intermediate_type
Intermediate type.
Definition: Utils.h:349
arm_compute::DataType::QASYMM8
@ QASYMM8
quantized, asymmetric fixed-point 8-bit number unsigned
arm_compute::DataType::U16
@ U16
unsigned 16-bit number
arm_compute::test::coord2index
int coord2index(const TensorShape &shape, const Coordinates &coord)
Linearise the given coordinate.
Definition: Utils.h:388
arm_compute::TensorShape
Shape of a tensor.
Definition: TensorShape.h:39
arm_compute::support::cpp11::round
T round(T value)
Round floating-point value with half value rounding away from zero.
Definition: ToolchainSupport.h:185
arm_compute::support::cpp11::lowest
T lowest()
Definition: ToolchainSupport.h:279
arm_compute::CLScheduler::sync
void sync()
Blocks until all commands in the associated command queue have finished.
Definition: CLScheduler.cpp:71
arm_compute::DataType::QSYMM8
@ QSYMM8
quantized, symmetric fixed-point 8-bit number
Types.h
RuntimeContext.h
arm_compute::test::traits::make_signed_conditional_t
typename std::conditional< std::is_integral< T >::value, std::make_signed< T >, std::common_type< T > >::type make_signed_conditional_t
Definition: Utils.h:130
arm_compute::test::set_tensor_static
void set_tensor_static(TensorType &t)
Set the dimension states of the given tensor to state.
Definition: Utils.h:628
ARM_COMPUTE_ERROR
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:354
arm_compute::Size2D
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
arm_compute::TensorType
TensorType
Memory type.
Definition: Types.h:38
arm_compute::test::traits::promote< uint8_t >::type
uint16_t type
Promoted type.
Definition: Utils.h:109
TensorInfo.h
arm_compute::test::traits::promote< int32_t >::type
int64_t type
Promoted type.
Definition: Utils.h:119
arm_compute::test::traits::make_unsigned_conditional_t
typename std::conditional< std::is_integral< T >::value, std::make_unsigned< T >, std::common_type< T > >::type make_unsigned_conditional_t
Definition: Utils.h:133
arm_compute::CLTensor
Basic implementation of the OpenCL tensor interface.
Definition: CLTensor.h:41
arm_compute::test::is_in_valid_region
bool is_in_valid_region(const ValidRegion &valid_region, Coordinates coord)
Check if a coordinate is within a valid region.
Definition: Utils.h:406
arm_compute::test::validation::utils::fill
void fill(U &&tensor, int seed, AssetsLibrary *library)
Definition: Utils.h:56
arm_compute::bfloat16
Brain floating point representation class.
Definition: Bfloat16.h:80
Error.h
arm_compute::test::sync_tensor_if_necessary
void sync_tensor_if_necessary(TensorType &tensor)
Sync tensor if necessary.
Definition: Utils.h:575
arm_compute::Channel::G
@ G
Green channel.
arm_compute::DataType::S8
@ S8
signed 8-bit number
arm_compute::cpu::data_layout
constexpr auto data_layout
Definition: impl.h:36
arm_compute::DataType::QSYMM16
@ QSYMM16
quantized, symmetric fixed-point 16-bit number
arm_compute::test::common_promoted_unsigned_type
Find the unsigned promoted common type.
Definition: Utils.h:342
arm_compute::test::construct_static_dims_state
ITensorInfo::TensorDimsState construct_static_dims_state()
Construct and return object for dimensions' state filled with the value for non-dynamic state.
Definition: Utils.h:606
arm_compute::test::validation::valid_region
const ValidRegion valid_region
Definition: Scale.cpp:214
arm_compute::experimental::dynamic_fusion::Conv2dAttributes
Attributes are backend-agnostic parameters (in addition to the input/output tensors) of an operator.
Definition: Conv2dAttributes.h:42
arm_compute::test::common_promoted_signed_type::promoted_type
traits::promote_t< common_type > promoted_type
Promoted type.
Definition: Utils.h:334
arm_compute::experimental::dynamic_fusion::Conv2dAttributes::stride
Conv2dAttributes & stride(const Size2D &stride)
Set stride.
Definition: Conv2dAttributes.cpp:42
arm_compute::half
half_float::half half
16-bit floating point type
Definition: CoreTypes.h:36
arm_compute::test::sync_if_necessary
void sync_if_necessary()
Sync if necessary.
Definition: Utils.h:558
arm_compute::test::validation::shape
shape
Definition: DFT.cpp:115
ARM_COMPUTE_ERROR_ON
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
arm_compute::DataType::U32
@ U32
unsigned 32-bit number
Coordinates.h
arm_compute::test::index2coord
Coordinates index2coord(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
Definition: Utils.h:359
arm_compute::test::common_promoted_signed_type
Find the signed promoted common type.
Definition: Utils.h:329
arm_compute::Channel::B
@ B
Blue channel.
ARM_COMPUTE_ERROR_ON_MSG
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
arm_compute::test::common_promoted_unsigned_type::promoted_type
traits::promote_t< common_type > promoted_type
Promoted type.
Definition: Utils.h:347
arm_compute::DataType::U8
@ U8
unsigned 8-bit number
arm_compute::test::set_tensor_dynamic
void set_tensor_dynamic(TensorType &t)
Set the dimension states of the given tensor to dynamic.
Definition: Utils.h:617
arm_compute::test::round_half_up
T round_half_up(T value)
Round floating-point value with half value rounding to positive infinity.
Definition: Utils.h:69
arm_compute::DataType::S16
@ S16
signed 16-bit number
arm_compute::ValidRegion
Container for valid region of a window.
Definition: Types.h:143
arm_compute::DataType::QASYMM8_SIGNED
@ QASYMM8_SIGNED
quantized, asymmetric fixed-point 8-bit number signed
arm_compute::test::foldl
T foldl(F &&, const T &value)
Base case of foldl.
Definition: Utils.h:182
arm_compute::test::traits::promote< int16_t >::type
int32_t type
Promoted type.
Definition: Utils.h:115
arm_gemm::bfloat16
arm_compute::bfloat16 bfloat16
Definition: bfloat.hpp:30
CLScheduler.h
Interface to enqueue OpenCL kernels and get/set the OpenCL CommandQueue and ICLTuner.
arm_compute::ValidRegion::start
int start(unsigned int d) const
Return the start of the valid region for the given dimension d.
Definition: Types.h:187
OpenCL.h
Wrapper to configure the Khronos OpenCL C++ header.
arm_compute::test::common_promoted_signed_type::common_type
typename std::common_type< T... >::type common_type
Common type.
Definition: Utils.h:332
arm_compute::test::traits::promote< half >::type
half type
Promoted type.
Definition: Utils.h:123
ARM_COMPUTE_UNUSED
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:151
Size2D.h
arm_compute::Coordinates
Coordinates of an item.
Definition: Coordinates.h:37
tensor
CLTensor * tensor
Pointer to the auxiliary tensor.
Definition: ClWorkloadRuntime.cpp:67
CPPScheduler.h
Basic pool of threads to execute CPP/Neon code on several cores in parallel.
arm_compute::PadStrideInfo
Definition: CoreTypes.h:139
arm_compute::test::store_value_with_data_type
void store_value_with_data_type(void *ptr, T value, DataType data_type)
Write the value after casting the pointer according to data_type.
Definition: Utils.h:252
arm_compute::Format::U8
@ U8
1 channel, 1 U8 per channel
arm_compute::CLScheduler::get
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:112
arm_compute::Format
Format
Image colour formats.
Definition: CoreTypes.h:58
arm_compute::Channel
Channel
Available channels.
Definition: CoreTypes.h:41
arm_compute::test::validation::data_type
data_type
Definition: Cast.cpp:222
arm_compute::IRuntimeContext
Context interface.
Definition: IRuntimeContext.h:34
arm_compute::test::traits::promote< int8_t >::type
int16_t type
Promoted type.
Definition: Utils.h:111
arm_compute::ITensorInfo::TensorDimsState
std::vector< int > TensorDimsState
Definition: ITensorInfo.h:47
arm_compute::TensorInfo
Store the tensor's metadata.
Definition: TensorInfo.h:41
arm_compute::experimental::dynamic_fusion::Conv2dAttributes::dilation
Conv2dAttributes & dilation(const Size2D &dilation)
Set dilation.
Definition: Conv2dAttributes.cpp:51
arm_compute::ValidRegion::shape
TensorShape shape
Shape of the valid region.
Definition: Types.h:223
arm_compute::DataType::S64
@ S64
signed 64-bit number
arm_compute::test::generate_random_real
std::vector< T > generate_random_real(unsigned int num_values, T min, T max, std::random_device::result_type seed)
Create a vector with a uniform distribution of floating point values across the specified range.
Definition: Utils.h:483
ToolchainSupport.h
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
arm_compute::test::round_half_even
T round_half_even(T value, T epsilon=std::numeric_limits< T >::epsilon())
Round floating-point value with half value rounding to nearest even.
Definition: Utils.h:82
arm_compute::DataType::F16
@ F16
16-bit floating-point number
arm_compute::test::get_typestring
std::string get_typestring(DataType data_type)
Obtain numpy type string from DataType.
Definition: Utils.h:510
arm_compute::support::cpp11::copysign
T copysign(T x, T y)
Composes a floating point value with the magnitude of x and the sign of y.
Definition: ToolchainSupport.h:232
arm_compute::DataType::SIZET
@ SIZET
size_t
arm_compute::Channel::R
@ R
Red channel.
arm_compute::test::get_format_for_channel
Format get_format_for_channel(Channel channel)
Look up the format corresponding to a channel.
Definition: Utils.h:145
arm_compute::DataType::S32
@ S32
signed 32-bit number
arm_compute::ValidRegion::end
int end(unsigned int d) const
Return the end of the valid region for the given dimension d.
Definition: Types.h:193
arm_compute::test::common_promoted_unsigned_type::common_type
typename std::common_type< T... >::type common_type
Common type.
Definition: Utils.h:345
TensorShape.h
arm_compute::test::get_channel_format
Format get_channel_format(Channel channel)
Return the format of a channel.
Definition: Utils.h:164
Conv2dAttributes.h
arm_compute::DataType::F32
@ F32
32-bit floating-point number
arm_compute::Padding2D
Padding and stride information class.
Definition: Types.h:609
arm_compute::test::validation::info
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
arm_compute::test::create_tensor
T create_tensor(const TensorInfo &info, IRuntimeContext *ctx=nullptr)
Create and initialize a tensor of the given type.
Definition: Utils.h:427
tf_frozen_model_extractor.t
t
Definition: tf_frozen_model_extractor.py:49
arm_compute::Dimensions::num_dimensions
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
Definition: Dimensions.h:142
arm_compute::test::saturate_cast
T saturate_cast(T val)
Saturate a value of type T against the numeric limits of type U.
Definition: Utils.h:313
arm_compute::test::traits::promote_t
typename promote< T >::type promote_t
Get promoted type.
Definition: Utils.h:127
arm_compute::test::fill_array
void fill_array(ArrayAccessor_T &&array, const std::vector< T > &v)
Definition: Utils.h:498
arm_compute::DataType
DataType
Available data types.
Definition: CoreTypes.h:83
arm_compute::Dimensions< int >::num_max_dimensions
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:46
arm_compute::ValidRegion::anchor
Coordinates anchor
Anchor for the start of the valid region.
Definition: Types.h:222
arm_compute::test::shape_to_valid_region
ValidRegion shape_to_valid_region(const TensorShape &a_shape, bool border_undefined=false, BorderSize border_size=BorderSize(0))
Create a valid region based on tensor shape, border mode and border size.
Definition: Utils.h:219
arm_compute::quantization::epsilon
constexpr float epsilon
Definition: AsymmHelpers.cpp:41