Compute Library
 21.08
arm_compute::test Namespace Reference

Namespaces

 benchmark
 
 colorconvert_helper
 
 convolution_3d
 
 detail
 
 framework
 
 traits
 
 validation
 

Data Structures

class  Accessor
 Accessor implementation for Tensor objects. More...
 
class  ArrayAccessor
 ArrayAccessor implementation for Array objects. More...
 
class  AssetsLibrary
 Factory class to create and fill tensors. More...
 
class  CLAccessor
 Accessor implementation for CLTensor objects. More...
 
class  CLArrayAccessor
 Accessor implementation for CLArray objects. More...
 
class  CLSynthetizeFunction
 This template synthetizes an ICLSimpleFunction which runs the given kernel K. More...
 
class  CLSynthetizeFunctionInitOutputWithZeroAndWithZeroConstantBorder
 As above but this also initializes to zero the input tensor. More...
 
class  CLSynthetizeFunctionWithZeroConstantBorder
 As above but this also setups a Zero border on the input tensor of the specified bordersize. More...
 
class  CLSynthetizeOperator
 This template synthetizes a simple IOperator which runs the given kernel K. More...
 
class  CLSynthetizeOperatorInitOutputWithZeroAndWithZeroConstantBorder
 As above but this also initializes to zero the input tensor. More...
 
class  ClSynthetizeOperatorWithBorder
 As above but this also setups a Zero border on the input tensor of the kernel's bordersize. More...
 
struct  common_promoted_signed_type
 Find the signed promoted common type. More...
 
struct  common_promoted_unsigned_type
 Find the unsigned promoted common type. More...
 
class  ContextSchedulerUser
 
struct  ContextType
 
struct  ContextType< Tensor >
 
class  IAccessor
 Common interface to provide information and access to tensor like structures. More...
 
class  IArrayAccessor
 Common interface to provide information and access to array like structures. More...
 
class  NESynthetizeFunction
 This template synthetizes an INESimpleFunction which runs the given kernel K. More...
 
class  NESynthetizeFunctionWithZeroConstantBorder
 As above but this also setups a Zero border on the input tensor of the specified bordersize. More...
 
class  NESynthetizeFunctionWithZeroConstantKernelBorder
 As above but this also setups a Zero border on the input tensor of the kernel's bordersize. More...
 
class  PaddingCalculator
 Calculate required padding. More...
 
class  ParametersLibrary
 Class that contains all the global parameters used by the tests. More...
 
class  RawTensor
 Subclass of SimpleTensor using uint8_t as value type. More...
 
class  SimpleTensor
 Simple tensor object that stores elements in a consecutive chunk of memory. More...
 
class  SimpleTensorAccessor
 Accessor implementation for SimpleTensor objects. More...
 
class  TensorCache
 Stores RawTensor categorised by the image they are created from including name, format and channel. More...
 

Functions

template<typename O , typename F , typename... As>
void apply (O *obj, F &&func, const std::tuple< As... > &args)
 
template<typename T , typename std::enable_if< std::is_same< typename T::value_type, std::string >::value, int >::type = 0>
std::string join (T first, T last, const std::string &separator)
 Helper function to concatenate multiple strings. More...
 
template<typename T , typename UnaryOp >
std::string join (T &&first, T &&last, const std::string &separator, UnaryOp &&op)
 Helper function to concatenate multiple values. More...
 
template<typename T , typename std::enable_if< std::is_arithmetic< typename T::value_type >::value, int >::type = 0>
std::string join (T &&first, T &&last, const std::string &separator)
 Helper function to concatenate multiple values. More...
 
std::string tolower (std::string string)
 Convert string to lower case. More...
 
template<typename T , typename std::enable_if< std::is_arithmetic< T >::value, int >::type = 0>
std::string arithmetic_to_string (T val, int decimal_places=0)
 Create a string with the arithmetic value in full precision. More...
 
void sleep_in_seconds (float seconds)
 Makes the calling thread to sleep for a specified number of seconds. More...
 
template<typename D , typename T , typename... Ts>
void fill_tensors (D &&dist, std::initializer_list< int > seeds, T &&tensor, Ts &&... other_tensors)
 
template<typename T1 , typename T2 >
SimpleTensor< T1 > copy_tensor (const SimpleTensor< T2 > &tensor)
 
template<typename T1 , typename T2 , typename std::enable_if< std::is_same< T1, T2 >::value, int >::type = 0>
SimpleTensor< T1 > copy_tensor (const SimpleTensor< half > &tensor)
 
template<typename U >
void swap (SimpleTensor< U > &tensor1, SimpleTensor< U > &tensor2)
 
template<typename T , typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
round_half_up (T value)
 Round floating-point value with half value rounding to positive infinity. More...
 
template<typename T , typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
round_half_even (T value, T epsilon=std::numeric_limits< T >::epsilon())
 Round floating-point value with half value rounding to nearest even. More...
 
Format get_format_for_channel (Channel channel)
 Look up the format corresponding to a channel. More...
 
Format get_channel_format (Channel channel)
 Return the format of a channel. More...
 
template<typename F , typename T >
foldl (F &&, const T &value)
 Base case of foldl. More...
 
template<typename F , typename T , typename U >
auto foldl (F &&func, T &&value1, U &&value2) -> decltype(func(value1, value2))
 Base case of foldl. More...
 
template<typename F , typename I , typename T , typename... Vs>
foldl (F &&func, I &&initial, T &&value, Vs &&... values)
 Fold left. More...
 
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. More...
 
template<typename T >
void store_value_with_data_type (void *ptr, T value, DataType data_type)
 Write the value after casting the pointer according to data_type. More...
 
template<typename U , typename T >
saturate_cast (T val)
 Saturate a value of type T against the numeric limits of type U. More...
 
Coordinates index2coord (const TensorShape &shape, int index)
 Convert a linear index into n-dimensional coordinates. More...
 
int coord2index (const TensorShape &shape, const Coordinates &coord)
 Linearise the given coordinate. More...
 
bool is_in_valid_region (const ValidRegion &valid_region, Coordinates coord)
 Check if a coordinate is within a valid region. More...
 
template<typename T >
create_tensor (const TensorInfo &info, IRuntimeContext *ctx=nullptr)
 Create and initialize a tensor of the given type. More...
 
template<typename T >
create_tensor (const TensorShape &shape, DataType data_type, int num_channels=1, QuantizationInfo quantization_info=QuantizationInfo(), DataLayout data_layout=DataLayout::NCHW, IRuntimeContext *ctx=nullptr)
 Create and initialize a tensor of the given type. More...
 
template<typename T >
create_tensor (const TensorShape &shape, Format format, IRuntimeContext *ctx=nullptr)
 Create and initialize a tensor of the given type. More...
 
template<typename T , typename = typename std::enable_if<std::is_floating_point<T>::value>::type>
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. More...
 
template<typename T , typename ArrayAccessor_T >
void fill_array (ArrayAccessor_T &&array, const std::vector< T > &v)
 
std::string get_typestring (DataType data_type)
 Obtain numpy type string from DataType. More...
 
template<typename TensorType >
void sync_if_necessary ()
 Sync if necessary. More...
 
template<typename TensorType >
void sync_tensor_if_necessary (TensorType &tensor)
 Sync tensor if necessary. More...
 
ITensorInfo::TensorDimsState construct_dims_state (int32_t value)
 Construct and return object for dimensions' state filled with the given value. More...
 
ITensorInfo::TensorDimsState construct_dynamic_dims_state ()
 Construct and return object for dimensions' state filled with the value for dynamic state. More...
 
ITensorInfo::TensorDimsState construct_static_dims_state ()
 Construct and return object for dimensions' state filled with the value for non-dynamic state. More...
 
template<typename TensorType >
void set_tensor_dynamic (TensorType &t)
 Set the dimension states of the given tensor to dynamic. More...
 
template<typename TensorType >
void set_tensor_static (TensorType &t)
 Set the dimension states of the given tensor to state. More...
 

Variables

std::unique_ptr< ParametersLibraryparameters
 
std::unique_ptr< AssetsLibrarylibrary
 
std::unique_ptr< AssetsLibraryfixed_library
 

Function Documentation

◆ apply()

void arm_compute::test::apply ( O *  obj,
F &&  func,
const std::tuple< As... > &  args 
)

Definition at line 79 of file Utils.h.

References arm_compute::test::framework::apply_impl(), and type.

80 {
81  detail::apply_impl(obj, std::forward<F>(func), args, detail::sequence_t<sizeof...(As)>());
82 }
void apply_impl(O *obj, F &&func, const std::tuple< As... > &args, detail::sequence< S... >)
Definition: Utils.h:72

◆ arithmetic_to_string()

std::string arm_compute::test::arithmetic_to_string ( val,
int  decimal_places = 0 
)
inline

Create a string with the arithmetic value in full precision.

Parameters
valArithmetic value
decimal_placesHow many decimal places to show
Returns
String with the arithmetic value.

Definition at line 164 of file Utils.h.

References arm_compute::test::framework::sleep_in_seconds(), and arm_compute::test::validation::ss().

Referenced by PrettyPrinter::print_measurements().

165 {
166  std::stringstream ss;
167  ss << std::fixed;
168  ss.precision((decimal_places) ? decimal_places : std::numeric_limits<T>::digits10 + 1);
169  ss << val;
170  return ss.str();
171 }
std::stringstream ss(mlgo_str)

◆ construct_dims_state()

ITensorInfo::TensorDimsState arm_compute::test::construct_dims_state ( int32_t  value)
inline

Construct and return object for dimensions' state filled with the given value.

Parameters
[in]valueThe value to fill
Returns
Constructed class

Definition at line 585 of file Utils.h.

References arm_compute::test::validation::fill().

Referenced by construct_dynamic_dims_state(), and construct_static_dims_state().

586 {
587  auto states = ITensorInfo::TensorDimsState{};
588  std::fill(states.begin(), states.end(), value);
589  return states;
590 }
library fill(src, distribution, 0)

◆ construct_dynamic_dims_state()

ITensorInfo::TensorDimsState arm_compute::test::construct_dynamic_dims_state ( )
inline

Construct and return object for dimensions' state filled with the value for dynamic state.

Returns
Constructed class filled with the value for dynamic state

Definition at line 596 of file Utils.h.

References construct_dims_state(), and ITensorInfo::get_dynamic_state_value().

Referenced by set_tensor_dynamic().

597 {
598  return construct_dims_state(ITensorInfo::get_dynamic_state_value());
599 }
ITensorInfo::TensorDimsState construct_dims_state(int32_t value)
Construct and return object for dimensions&#39; state filled with the given value.
Definition: Utils.h:585

◆ construct_static_dims_state()

ITensorInfo::TensorDimsState arm_compute::test::construct_static_dims_state ( )
inline

Construct and return object for dimensions' state filled with the value for non-dynamic state.

Returns
Constructed class filled with the value for non-dynamic state

Definition at line 605 of file Utils.h.

References construct_dims_state(), and ITensorInfo::get_static_state_value().

Referenced by set_tensor_static().

606 {
607  return construct_dims_state(ITensorInfo::get_static_state_value());
608 }
ITensorInfo::TensorDimsState construct_dims_state(int32_t value)
Construct and return object for dimensions&#39; state filled with the given value.
Definition: Utils.h:585

◆ coord2index()

int arm_compute::test::coord2index ( const TensorShape shape,
const Coordinates coord 
)
inline

Linearise the given coordinate.

Transforms the given coordinate into a linear offset in terms of elements.

Parameters
[in]shapeShape of the n-dimensional tensor.
[in]coordThe to be converted coordinate.
Returns
Linear offset to the element.

Definition at line 387 of file Utils.h.

References ARM_COMPUTE_ERROR_ON_MSG, Dimensions< T >::num_dimensions(), and TensorShape::total_size().

Referenced by arm_compute::test::validation::apply_2d_spatial_filter(), arm_compute::test::validation::reference::col2im(), DATA_TEST_CASE(), arm_compute::test::validation::reference::instance_normalization(), arm_compute::test::validation::reference::logical_binary_op(), RawTensor::operator()(), SimpleTensor< uint8_t >::operator()(), arm_compute::test::validation::reference::pad_layer(), arm_compute::test::validation::reference::pooling_layer_internal(), arm_compute::test::validation::reference::remap(), arm_compute::test::validation::reference::reverse(), arm_compute::test::validation::reference::scale_core(), arm_compute::test::validation::tensor_elem_at(), arm_compute::test::validation::reference::tile(), arm_compute::test::validation::reference::transpose(), and arm_compute::test::validation::reference::weights_reshape().

388 {
389  ARM_COMPUTE_ERROR_ON_MSG(shape.total_size() == 0, "Cannot get index from empty shape");
390  ARM_COMPUTE_ERROR_ON_MSG(coord.num_dimensions() == 0, "Cannot get index of empty coordinate");
391 
392  int index = 0;
393  int dim_size = 1;
394 
395  for(unsigned int i = 0; i < coord.num_dimensions(); ++i)
396  {
397  index += coord[i] * dim_size;
398  dim_size *= shape[i];
399  }
400 
401  return index;
402 }
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456

◆ copy_tensor() [1/2]

SimpleTensor<T1> arm_compute::test::copy_tensor ( const SimpleTensor< T2 > &  tensor)

Definition at line 223 of file SimpleTensor.h.

References SimpleTensor< T >::data(), SimpleTensor< T >::data_layout(), SimpleTensor< T >::data_type(), SimpleTensor< T >::num_channels(), SimpleTensor< T >::quantization_info(), SimpleTensor< T >::shape(), and type.

Referenced by copy_tensor().

224 {
225  SimpleTensor<T1> st(tensor.shape(), tensor.data_type(),
226  tensor.num_channels(),
227  tensor.quantization_info(),
228  tensor.data_layout());
229  for(size_t n = 0; n < size_t(st.num_elements()); n++)
230  {
231  st.data()[n] = static_cast<T1>(tensor.data()[n]);
232  }
233  return st;
234 }

◆ copy_tensor() [2/2]

SimpleTensor< T1 > copy_tensor ( const SimpleTensor< half > &  tensor)

Definition at line 237 of file SimpleTensor.h.

References copy_tensor(), SimpleTensor< T >::data(), SimpleTensor< T >::data_layout(), SimpleTensor< T >::data_type(), SimpleTensor< T >::num_channels(), SimpleTensor< T >::quantization_info(), SimpleTensor< T >::shape(), and type.

238 {
239  SimpleTensor<T1> st(tensor.shape(), tensor.data_type(),
240  tensor.num_channels(),
241  tensor.quantization_info(),
242  tensor.data_layout());
243  memcpy((void *)st.data(), (const void *)tensor.data(), size_t(st.num_elements() * sizeof(T1)));
244  return st;
245 }

◆ create_tensor() [1/3]

T arm_compute::test::create_tensor ( const TensorInfo info,
IRuntimeContext ctx = nullptr 
)
inline

Create and initialize a tensor of the given type.

Parameters
[in]infoTensor information to be used to create the tensor
[in]ctx(Optional) Pointer to the runtime context.
Returns
Initialized tensor of given type.

Definition at line 426 of file Utils.h.

Referenced by IContext::is_valid().

427 {
428  T tensor(ctx);
429  tensor.allocator()->init(info);
430  return tensor;
431 }
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

◆ create_tensor() [2/3]

T arm_compute::test::create_tensor ( const TensorShape shape,
DataType  data_type,
int  num_channels = 1,
QuantizationInfo  quantization_info = QuantizationInfo(),
DataLayout  data_layout = DataLayout::NCHW,
IRuntimeContext ctx = nullptr 
)
inline

Create and initialize a tensor of the given type.

Parameters
[in]shapeTensor shape.
[in]data_typeData type.
[in]num_channels(Optional) Number of channels.
[in]quantization_info(Optional) Quantization info for asymmetric quantized types.
[in]data_layout(Optional) Data layout. Default is NCHW.
[in]ctx(Optional) Pointer to the runtime context.
Returns
Initialized tensor of given type.

Definition at line 445 of file Utils.h.

References arm_compute::test::validation::data_layout, arm_compute::test::validation::info, TensorInfo::set_data_layout(), and TensorInfo::set_quantization_info().

447 {
448  T tensor(ctx);
449  TensorInfo info(shape, num_channels, data_type);
450  info.set_quantization_info(quantization_info);
451  info.set_data_layout(data_layout);
452 
453  return create_tensor<T>(info, ctx);
454 }
const DataLayout data_layout
Definition: Im2Col.cpp:151
const DataType data_type
Definition: Im2Col.cpp:150
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

◆ create_tensor() [3/3]

T arm_compute::test::create_tensor ( const TensorShape shape,
Format  format,
IRuntimeContext ctx = nullptr 
)
inline

Create and initialize a tensor of the given type.

Parameters
[in]shapeTensor shape.
[in]formatFormat type.
[in]ctx(Optional) Pointer to the runtime context.
Returns
Initialized tensor of given type.

Definition at line 465 of file Utils.h.

References arm_compute::test::validation::info, and type.

466 {
467  TensorInfo info(shape, format);
468 
469  return create_tensor<T>(info, ctx);
470 }
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

◆ fill_array()

void arm_compute::test::fill_array ( ArrayAccessor_T &&  array,
const std::vector< T > &  v 
)
inline

Definition at line 497 of file Utils.h.

498 {
499  array.resize(v.size());
500  std::memcpy(array.buffer(), v.data(), v.size() * sizeof(T));
501 }

◆ fill_tensors()

void arm_compute::test::fill_tensors ( D &&  dist,
std::initializer_list< int >  seeds,
T &&  tensor,
Ts &&...  other_tensors 
)

Definition at line 45 of file Helper.h.

References ARM_COMPUTE_ERROR_ON, and library.

46 {
47  const std::array < T, 1 + sizeof...(Ts) > tensors{ { std::forward<T>(tensor), std::forward<Ts>(other_tensors)... } };
48  std::vector<int> vs(seeds);
49  ARM_COMPUTE_ERROR_ON(vs.size() != tensors.size());
50  int k = 0;
51  for(auto tp : tensors)
52  {
53  library->fill(Accessor(*tp), std::forward<D>(dist), vs[k++]);
54  }
55 }
#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
std::unique_ptr< AssetsLibrary > library
Definition: main.cpp:76

◆ foldl() [1/3]

T arm_compute::test::foldl ( F &&  ,
const T &  value 
)
inline

Base case of foldl.

Returns
value.

Definition at line 181 of file Utils.h.

Referenced by foldl().

182 {
183  return value;
184 }

◆ foldl() [2/3]

auto arm_compute::test::foldl ( F &&  func,
T &&  value1,
U &&  value2 
) -> decltype(func(value1, value2))
inline

Base case of foldl.

Returns
func(value1, value2).

Definition at line 191 of file Utils.h.

192 {
193  return func(value1, value2);
194 }

◆ foldl() [3/3]

I arm_compute::test::foldl ( F &&  func,
I &&  initial,
T &&  value,
Vs &&...  values 
)
inline

Fold left.

Parameters
[in]funcBinary function to be called.
[in]initialInitial value.
[in]valueArgument passed to the function.
[in]valuesRemaining arguments.

Definition at line 204 of file Utils.h.

References foldl().

205 {
206  return foldl(std::forward<F>(func), func(std::forward<I>(initial), std::forward<T>(value)), std::forward<Vs>(values)...);
207 }
I foldl(F &&func, I &&initial, T &&value, Vs &&... values)
Fold left.
Definition: Utils.h:204

◆ generate_random_real()

std::vector<T> arm_compute::test::generate_random_real ( unsigned int  num_values,
min,
max,
std::random_device::result_type  seed 
)
inline

Create a vector with a uniform distribution of floating point values across the specified range.

Parameters
[in]num_valuesThe number of values to be created.
[in]minThe minimum value in distribution (inclusive).
[in]maxThe maximum value in distribution (inclusive).
[in]seedThe random seed to be used.
Returns
A vector that contains the requested number of random floating point values

Definition at line 482 of file Utils.h.

483 {
484  std::vector<T> v(num_values);
485  std::mt19937 gen(seed);
486  std::uniform_real_distribution<T> dist(min, max);
487 
488  for(unsigned int i = 0; i < num_values; ++i)
489  {
490  v.at(i) = dist(gen);
491  }
492 
493  return v;
494 }

◆ get_channel_format()

Format arm_compute::test::get_channel_format ( Channel  channel)
inline

Return the format of a channel.

Parameters
[in]channelChannel type.
Returns
Format of the given channel.

Definition at line 163 of file Utils.h.

References arm_compute::B, arm_compute::G, arm_compute::R, and arm_compute::U8.

Referenced by AssetsLibrary::fill().

164 {
165  switch(channel)
166  {
167  case Channel::R:
168  case Channel::G:
169  case Channel::B:
170  return Format::U8;
171  default:
172  throw std::runtime_error("Unsupported channel");
173  }
174 }

◆ get_format_for_channel()

Format arm_compute::test::get_format_for_channel ( Channel  channel)
inline

Look up the format corresponding to a channel.

Parameters
[in]channelChannel type.
Returns
Format that contains the given channel.

Definition at line 144 of file Utils.h.

References arm_compute::B, arm_compute::G, arm_compute::R, and arm_compute::RGB888.

Referenced by AssetsLibrary::fill(), and AssetsLibrary::get().

145 {
146  switch(channel)
147  {
148  case Channel::R:
149  case Channel::G:
150  case Channel::B:
151  return Format::RGB888;
152  default:
153  throw std::runtime_error("Unsupported channel");
154  }
155 }

◆ get_typestring()

std::string arm_compute::test::get_typestring ( DataType  data_type)
inline

Obtain numpy type string from DataType.

Parameters
[in]data_typeData type.
Returns
numpy type string.

Definition at line 509 of file Utils.h.

References ARM_COMPUTE_ERROR, arm_compute::F32, arm_compute::F64, arm_compute::S16, arm_compute::S32, arm_compute::S64, arm_compute::S8, arm_compute::SIZET, arm_compute::support::cpp11::to_string(), arm_compute::U16, arm_compute::U32, arm_compute::U64, and arm_compute::U8.

510 {
511  // Check endianness
512  const unsigned int i = 1;
513  const char *c = reinterpret_cast<const char *>(&i);
514  std::string endianness;
515  if(*c == 1)
516  {
517  endianness = std::string("<");
518  }
519  else
520  {
521  endianness = std::string(">");
522  }
523  const std::string no_endianness("|");
524 
525  switch(data_type)
526  {
527  case DataType::U8:
528  return no_endianness + "u" + support::cpp11::to_string(sizeof(uint8_t));
529  case DataType::S8:
530  return no_endianness + "i" + support::cpp11::to_string(sizeof(int8_t));
531  case DataType::U16:
532  return endianness + "u" + support::cpp11::to_string(sizeof(uint16_t));
533  case DataType::S16:
534  return endianness + "i" + support::cpp11::to_string(sizeof(int16_t));
535  case DataType::U32:
536  return endianness + "u" + support::cpp11::to_string(sizeof(uint32_t));
537  case DataType::S32:
538  return endianness + "i" + support::cpp11::to_string(sizeof(int32_t));
539  case DataType::U64:
540  return endianness + "u" + support::cpp11::to_string(sizeof(uint64_t));
541  case DataType::S64:
542  return endianness + "i" + support::cpp11::to_string(sizeof(int64_t));
543  case DataType::F32:
544  return endianness + "f" + support::cpp11::to_string(sizeof(float));
545  case DataType::F64:
546  return endianness + "f" + support::cpp11::to_string(sizeof(double));
547  case DataType::SIZET:
548  return endianness + "u" + support::cpp11::to_string(sizeof(size_t));
549  default:
550  ARM_COMPUTE_ERROR("NOT SUPPORTED!");
551  }
552 }
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
std::string to_string(const GEMMConfigNative &config)
Definition: Utils.cpp:156
const DataType data_type
Definition: Im2Col.cpp:150

◆ index2coord()

Coordinates arm_compute::test::index2coord ( const TensorShape shape,
int  index 
)
inline

Convert a linear index into n-dimensional coordinates.

Parameters
[in]shapeShape of the n-dimensional tensor.
[in]indexLinear index specifying the i-th element.
Returns
n-dimensional coordinates.

Definition at line 358 of file Utils.h.

References ARM_COMPUTE_ERROR_ON_MSG, Dimensions< T >::num_dimensions(), TensorShape::set(), and TensorShape::total_size().

Referenced by DATA_TEST_CASE(), arm_compute::test::validation::reference::erode(), AssetsLibrary::fill(), AssetsLibrary::fill_boxes(), arm_compute::test::validation::reference::non_maxima_suppression(), arm_compute::test::validation::reference::pad_layer(), arm_compute::test::validation::reference::permute(), arm_compute::test::validation::reference::remap(), arm_compute::test::validation::reference::reverse(), arm_compute::test::validation::reference::scale_core(), arm_compute::test::validation::reference::tile(), arm_compute::test::validation::reference::transpose(), arm_compute::test::validation::transpose(), arm_compute::test::validation::validate(), and arm_compute::test::validation::validate_wrap().

359 {
360  int num_elements = shape.total_size();
361 
362  ARM_COMPUTE_ERROR_ON_MSG(index < 0 || index >= num_elements, "Index has to be in [0, num_elements]");
363  ARM_COMPUTE_ERROR_ON_MSG(num_elements == 0, "Cannot create coordinate from empty shape");
364 
365  Coordinates coord{ 0 };
366 
367  for(int d = shape.num_dimensions() - 1; d >= 0; --d)
368  {
369  num_elements /= shape[d];
370  coord.set(d, index / num_elements);
371  index %= num_elements;
372  }
373 
374  return coord;
375 }
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456

◆ is_in_valid_region()

bool arm_compute::test::is_in_valid_region ( const ValidRegion valid_region,
Coordinates  coord 
)
inline

Check if a coordinate is within a valid region.

Definition at line 405 of file Utils.h.

References ValidRegion::end(), Dimensions< int >::num_max_dimensions, and ValidRegion::start().

Referenced by arm_compute::test::validation::reference::non_maxima_suppression(), arm_compute::test::validation::validate(), and arm_compute::test::validation::validate_wrap().

406 {
407  for(size_t d = 0; d < Coordinates::num_max_dimensions; ++d)
408  {
409  if(coord[d] < valid_region.start(d) || coord[d] >= valid_region.end(d))
410  {
411  return false;
412  }
413  }
414 
415  return true;
416 }
const ValidRegion valid_region
Definition: Scale.cpp:223
int start(unsigned int d) const
Return the start of the valid region for the given dimension d.
Definition: Types.h:225
int end(unsigned int d) const
Return the end of the valid region for the given dimension d.
Definition: Types.h:231

◆ join() [1/3]

std::string arm_compute::test::join ( first,
last,
const std::string &  separator 
)

Helper function to concatenate multiple strings.

Parameters
[in]firstIterator pointing to the first element to be concatenated.
[in]lastIterator pointing behind the last element to be concatenated.
[in]separatorString used to join the elements.
Returns
String containing all elements joined by separator.

Definition at line 93 of file Utils.h.

References arm_compute::test::validation::reference::accumulate().

Referenced by GEMMParam::__str__(), NativeGEMMConfig::__str__(), ReshapedOnlyRHSGEMMConfig::__str__(), ReshapedGEMMConfig::__str__(), Measurement::__str__(), Framework::init(), join(), JSONPrinter::print_measurements(), format_doxygen::process_comment(), and GEMMBenchmarkResultRecorder::summary().

94 {
95  return std::accumulate(std::next(first), last, *first, [&separator](const std::string & base, const std::string & suffix)
96  {
97  return base + separator + suffix;
98  });
99 }
SimpleTensor< T2 > accumulate(const SimpleTensor< T1 > &src, DataType output_data_type)
Definition: Accumulate.cpp:38

◆ join() [2/3]

std::string arm_compute::test::join ( T &&  first,
T &&  last,
const std::string &  separator,
UnaryOp &&  op 
)

Helper function to concatenate multiple values.

All values are converted to std::string using the provided operation before being joined.

The signature of op has to be equivalent to std::string op(const T::value_type &val).

Parameters
[in]firstIterator pointing to the first element to be concatenated.
[in]lastIterator pointing behind the last element to be concatenated.
[in]separatorString used to join the elements.
[in]opConversion function.
Returns
String containing all elements joined by separator.

Definition at line 117 of file Utils.h.

References arm_compute::test::validation::reference::accumulate().

118 {
119  return std::accumulate(std::next(first), last, op(*first), [&separator, &op](const std::string & base, const typename T::value_type & suffix)
120  {
121  return base + separator + op(suffix);
122  });
123 }
SimpleTensor< T2 > accumulate(const SimpleTensor< T1 > &src, DataType output_data_type)
Definition: Accumulate.cpp:38

◆ join() [3/3]

std::string arm_compute::test::join ( T &&  first,
T &&  last,
const std::string &  separator 
)

Helper function to concatenate multiple values.

All values are converted to std::string using std::to_string before being joined.

Parameters
[in]firstIterator pointing to the first element to be concatenated.
[in]lastIterator pointing behind the last element to be concatenated.
[in]separatorString used to join the elements.
Returns
String containing all elements joined by separator.

Definition at line 136 of file Utils.h.

References join(), and arm_compute::support::cpp11::to_string().

137 {
138  return join(std::forward<T>(first), std::forward<T>(last), separator, support::cpp11::to_string);
139 }
std::string to_string(const GEMMConfigNative &config)
Definition: Utils.cpp:156
std::string join(T &&first, T &&last, const std::string &separator)
Helper function to concatenate multiple values.
Definition: Utils.h:136

◆ round_half_even()

T arm_compute::test::round_half_even ( value,
epsilon = std::numeric_limits<T>::epsilon() 
)
inline

Round floating-point value with half value rounding to nearest even.

Parameters
[in]valuefloating-point value to be rounded.
[in]epsilonprecision.
Returns
Floating-point value of rounded value.

Definition at line 81 of file Utils.h.

References arm_compute::support::cpp11::copysign(), arm_compute::quantization::epsilon, and arm_compute::support::cpp11::round().

Referenced by DATA_TEST_CASE().

82 {
83  T positive_value = std::abs(value);
84  T ipart = 0;
85  std::modf(positive_value, &ipart);
86  // If 'value' is exactly halfway between two integers
87  if(std::abs(positive_value - (ipart + 0.5f)) < epsilon)
88  {
89  // If 'ipart' is even then return 'ipart'
90  if(std::fmod(ipart, 2.f) < epsilon)
91  {
92  return support::cpp11::copysign(ipart, value);
93  }
94  // Else return the nearest even integer
95  return support::cpp11::copysign(std::ceil(ipart + 0.5f), value);
96  }
97  // Otherwise use the usual round to closest
98  return support::cpp11::copysign(support::cpp11::round(positive_value), value);
99 }
T copysign(T x, T y)
Composes a floating point value with the magnitude of x and the sign of y.
int round(float x, RoundingPolicy rounding_policy)
Return a rounded value of x.
Definition: Rounding.cpp:35

◆ round_half_up()

T arm_compute::test::round_half_up ( value)
inline

Round floating-point value with half value rounding to positive infinity.

Parameters
[in]valuefloating-point value to be rounded.
Returns
Floating-point value of rounded value.

Definition at line 68 of file Utils.h.

References type.

Referenced by DATA_TEST_CASE().

69 {
70  return std::floor(value + 0.5f);
71 }

◆ saturate_cast()

T arm_compute::test::saturate_cast ( val)

Saturate a value of type T against the numeric limits of type U.

Parameters
[in]valValue to be saturated.
Returns
saturated value.

Definition at line 312 of file Utils.h.

References arm_compute::support::cpp11::lowest().

Referenced by arm_compute::test::validation::reference::absolute_difference(), arm_compute::test::validation::reference::accumulate(), and arm_compute::test::validation::reference::accumulate_squared().

313 {
314  if(val > static_cast<T>(std::numeric_limits<U>::max()))
315  {
316  val = static_cast<T>(std::numeric_limits<U>::max());
317  }
318  if(val < static_cast<T>(std::numeric_limits<U>::lowest()))
319  {
320  val = static_cast<T>(std::numeric_limits<U>::lowest());
321  }
322  return val;
323 }

◆ set_tensor_dynamic()

void arm_compute::test::set_tensor_dynamic ( TensorType t)

Set the dimension states of the given tensor to dynamic.

Parameters
[in]tThe tensor to set to dynamic state

Definition at line 616 of file Utils.h.

References construct_dynamic_dims_state().

617 {
618  t.info()->set_tensor_dims_state(construct_dynamic_dims_state());
619 }
ITensorInfo::TensorDimsState construct_dynamic_dims_state()
Construct and return object for dimensions&#39; state filled with the value for dynamic state...
Definition: Utils.h:596

◆ set_tensor_static()

void arm_compute::test::set_tensor_static ( TensorType t)

Set the dimension states of the given tensor to state.

Parameters
[in]tThe tensor to set to static state

Definition at line 627 of file Utils.h.

References construct_static_dims_state().

628 {
629  t.info()->set_tensor_dims_state(construct_static_dims_state());
630 }
ITensorInfo::TensorDimsState construct_static_dims_state()
Construct and return object for dimensions&#39; state filled with the value for non-dynamic state...
Definition: Utils.h:605

◆ shape_to_valid_region()

ValidRegion arm_compute::test::shape_to_valid_region ( const TensorShape a_shape,
bool  border_undefined = false,
BorderSize  border_size = BorderSize(0) 
)
inline

Create a valid region based on tensor shape, border mode and border size.

Parameters
[in]a_shapeShape used as size of the valid region.
[in]border_undefined(Optional) Boolean indicating if the border mode is undefined.
[in]border_size(Optional) Border size used to specify the region to exclude.
Returns
A valid region starting at (0, 0, ...) with size of shape if border_undefined is false; otherwise return A valid region starting at (border_size.left, border_size.top, ...) with reduced size of shape.

Definition at line 218 of file Utils.h.

References ValidRegion::anchor, ARM_COMPUTE_ERROR_ON, Dimensions< T >::num_dimensions(), Dimensions< T >::set(), TensorShape::set(), arm_compute::test::validation::shape, ValidRegion::shape, arm_compute::test::validation::valid_region, Dimensions< T >::x(), and Dimensions< T >::y().

Referenced by arm_compute::test::validation::reference::non_maxima_suppression(), arm_compute::test::validation::validate(), and arm_compute::test::validation::validate_wrap().

219 {
220  ValidRegion valid_region{ Coordinates(), a_shape };
221 
222  Coordinates &anchor = valid_region.anchor;
223  TensorShape &shape = valid_region.shape;
224 
225  if(border_undefined)
226  {
227  ARM_COMPUTE_ERROR_ON(shape.num_dimensions() < 2);
228 
229  anchor.set(0, border_size.left);
230  anchor.set(1, border_size.top);
231 
232  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));
233  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));
234 
235  shape.set(0, valid_shape_x);
236  shape.set(1, valid_shape_y);
237  }
238 
239  return valid_region;
240 }
TensorShape shape
Shape of the valid region.
Definition: Types.h:252
#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 ValidRegion valid_region
Definition: Scale.cpp:223
Coordinates anchor
Anchor for the start of the valid region.
Definition: Types.h:251

◆ sleep_in_seconds()

void arm_compute::test::sleep_in_seconds ( float  seconds)

Makes the calling thread to sleep for a specified number of seconds.

Parameters
[in]secondsAmount of seconds to sleep. Will return immediately if less or equal to zero.

Definition at line 38 of file Utils.cpp.

Referenced by arithmetic_to_string(), and Framework::run().

39 {
40  // Early return on non-positive input
41  if(seconds <= 0.f)
42  {
43  return;
44  }
45 
46 #ifndef NO_MULTI_THREADING
47  const int64_t us = static_cast<int64_t>(seconds * 1e6);
48  std::this_thread::sleep_for(std::chrono::microseconds(us));
49 #endif /* NO_MULTI_THREADING */
50 }

◆ store_value_with_data_type()

void arm_compute::test::store_value_with_data_type ( void *  ptr,
value,
DataType  data_type 
)

Write the value after casting the pointer according to data_type.

Warning
The type of the value must match the specified data type.
Parameters
[out]ptrPointer to memory where the value will be written.
[in]valueValue that will be written.
[in]data_typeData type that will be written.

Definition at line 251 of file Utils.h.

References ARM_COMPUTE_ERROR, arm_compute::BFLOAT16, arm_compute::F16, arm_compute::F32, arm_compute::F64, arm_compute::QASYMM16, arm_compute::QASYMM8, arm_compute::QASYMM8_SIGNED, arm_compute::QSYMM16, arm_compute::QSYMM8, arm_compute::QSYMM8_PER_CHANNEL, arm_compute::S16, arm_compute::S32, arm_compute::S64, arm_compute::S8, arm_compute::SIZET, arm_compute::U16, arm_compute::U32, arm_compute::U64, and arm_compute::U8.

Referenced by AssetsLibrary::fill(), AssetsLibrary::fill_borders_with_garbage(), and AssetsLibrary::fill_boxes().

252 {
253  switch(data_type)
254  {
255  case DataType::U8:
256  case DataType::QASYMM8:
257  *reinterpret_cast<uint8_t *>(ptr) = value;
258  break;
259  case DataType::S8:
260  case DataType::QASYMM8_SIGNED:
261  case DataType::QSYMM8:
262  case DataType::QSYMM8_PER_CHANNEL:
263  *reinterpret_cast<int8_t *>(ptr) = value;
264  break;
265  case DataType::U16:
266  case DataType::QASYMM16:
267  *reinterpret_cast<uint16_t *>(ptr) = value;
268  break;
269  case DataType::S16:
270  case DataType::QSYMM16:
271  *reinterpret_cast<int16_t *>(ptr) = value;
272  break;
273  case DataType::U32:
274  *reinterpret_cast<uint32_t *>(ptr) = value;
275  break;
276  case DataType::S32:
277  *reinterpret_cast<int32_t *>(ptr) = value;
278  break;
279  case DataType::U64:
280  *reinterpret_cast<uint64_t *>(ptr) = value;
281  break;
282  case DataType::S64:
283  *reinterpret_cast<int64_t *>(ptr) = value;
284  break;
285  case DataType::BFLOAT16:
286  *reinterpret_cast<bfloat16 *>(ptr) = bfloat16(value);
287  break;
288  case DataType::F16:
289  *reinterpret_cast<half *>(ptr) = value;
290  break;
291  case DataType::F32:
292  *reinterpret_cast<float *>(ptr) = value;
293  break;
294  case DataType::F64:
295  *reinterpret_cast<double *>(ptr) = value;
296  break;
297  case DataType::SIZET:
298  *reinterpret_cast<size_t *>(ptr) = value;
299  break;
300  default:
301  ARM_COMPUTE_ERROR("NOT SUPPORTED!");
302  }
303 }
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
half_float::half half
16-bit floating point type
Definition: Types.h:46
arm_compute::bfloat16 bfloat16
Definition: bfloat.hpp:30
const DataType data_type
Definition: Im2Col.cpp:150

◆ swap()

void arm_compute::test::swap ( SimpleTensor< U > &  tensor1,
SimpleTensor< U > &  tensor2 
)
Parameters
[in,out]tensor1Tensor to be swapped.
[in,out]tensor2Tensor to be swapped.

Definition at line 442 of file SimpleTensor.h.

Referenced by SimpleTensor< uint8_t >::operator=().

443 {
444  // Use unqualified call to swap to enable ADL. But make std::swap available
445  // as backup.
446  using std::swap;
447  swap(tensor1._shape, tensor2._shape);
448  swap(tensor1._format, tensor2._format);
449  swap(tensor1._data_type, tensor2._data_type);
450  swap(tensor1._num_channels, tensor2._num_channels);
451  swap(tensor1._quantization_info, tensor2._quantization_info);
452  swap(tensor1._buffer, tensor2._buffer);
453 }
void swap(SimpleTensor< U > &tensor1, SimpleTensor< U > &tensor2)
Definition: SimpleTensor.h:442

◆ sync_if_necessary()

void arm_compute::test::sync_if_necessary ( )
inline

Sync if necessary.

Definition at line 557 of file Utils.h.

References CLScheduler::get(), arm_compute::opencl_is_available(), CLScheduler::sync(), and type.

558 {
559 #ifdef ARM_COMPUTE_CL
560  if(opencl_is_available() && std::is_same<typename std::decay<TensorType>::type, arm_compute::CLTensor>::value)
561  {
562  CLScheduler::get().sync();
563  }
564 #endif /* ARM_COMPUTE_CL */
565 }
decltype(strategy::transforms) typedef type
bool opencl_is_available()
Check if OpenCL is available.
Definition: OpenCL.cpp:154
Basic implementation of the OpenCL tensor interface.
Definition: CLTensor.h:41

◆ sync_tensor_if_necessary()

void arm_compute::test::sync_tensor_if_necessary ( TensorType tensor)
inline

Sync tensor if necessary.

Note
: If the destination tensor not being used on OpenGL ES, GPU will optimize out the operation.
Parameters
[in]tensorTensor to be sync.

Definition at line 574 of file Utils.h.

References ARM_COMPUTE_UNUSED.

575 {
576  ARM_COMPUTE_UNUSED(tensor);
577 }
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152

◆ tolower()

std::string arm_compute::test::tolower ( std::string  string)
inline

Convert string to lower case.

Parameters
[in]stringTo be converted string.
Returns
Lower case string.

Definition at line 147 of file Utils.h.

References arm_compute::mlgo::parser::end().

Referenced by arm_compute::test::framework::dataset_mode_from_name(), arm_compute::test::framework::instrument_type_from_name(), arm_compute::test::framework::log_format_from_name(), and arm_compute::test::framework::log_level_from_name().

148 {
149  std::transform(string.begin(), string.end(), string.begin(), [](unsigned char c)
150  {
151  return std::tolower(c);
152  });
153  return string;
154 }
std::string tolower(std::string string)
Convert string to lower case.
Definition: Utils.h:147
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290

Variable Documentation

◆ fixed_library

std::unique_ptr< AssetsLibrary > fixed_library

Definition at line 79 of file main.cpp.

Referenced by main(), and arm_compute::utils::run_example().

◆ library

◆ parameters