23.11
|
Go to the documentation of this file.
24 #ifndef ARM_COMPUTE_TEST_UTILS_H
25 #define ARM_COMPUTE_TEST_UTILS_H
48 #include <type_traits>
68 template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>
::type>
71 return std::floor(value + 0.5f);
81 template <typename T, typename = typename std::enable_if<std::is_floating_point<T>::value>
::type>
84 T positive_value = std::abs(value);
86 std::modf(positive_value, &ipart);
88 if(std::abs(positive_value - (ipart + 0.5f)) <
epsilon)
91 if(std::fmod(ipart, 2.f) <
epsilon)
126 template <
typename T>
129 template <
typename T>
132 template <
typename T>
154 throw std::runtime_error(
"Unsupported channel");
173 throw std::runtime_error(
"Unsupported channel");
181 template <
typename F,
typename T>
182 inline T
foldl(F &&,
const T &value)
191 template <
typename F,
typename T,
typename U>
192 inline auto foldl(F &&func, T &&value1, U &&value2) -> decltype(func(value1, value2))
194 return func(value1, value2);
204 template <
typename F,
typename I,
typename T,
typename... Vs>
205 inline I
foldl(F &&func, I &&initial, T &&value, Vs &&... values)
207 return foldl(std::forward<F>(func), func(std::forward<I>(initial), std::forward<T>(value)), std::forward<Vs>(values)...);
230 anchor.
set(0, border_size.left);
231 anchor.
set(1, border_size.top);
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));
236 shape.set(0, valid_shape_x);
237 shape.set(1, valid_shape_y);
251 template <
typename T>
258 *
reinterpret_cast<uint8_t *
>(ptr) = value;
264 *
reinterpret_cast<int8_t *
>(ptr) = value;
268 *
reinterpret_cast<uint16_t *
>(ptr) = value;
272 *
reinterpret_cast<int16_t *
>(ptr) = value;
275 *
reinterpret_cast<uint32_t *
>(ptr) = value;
278 *
reinterpret_cast<int32_t *
>(ptr) = value;
281 *
reinterpret_cast<uint64_t *
>(ptr) = value;
284 *
reinterpret_cast<int64_t *
>(ptr) = value;
290 *
reinterpret_cast<half *
>(ptr) = value;
293 *
reinterpret_cast<float *
>(ptr) = value;
296 *
reinterpret_cast<double *
>(ptr) = value;
299 *
reinterpret_cast<size_t *
>(ptr) = value;
312 template <
typename U,
typename T>
315 if(val >
static_cast<T
>(std::numeric_limits<U>::max()))
317 val =
static_cast<T
>(std::numeric_limits<U>::max());
328 template <
typename... T>
341 template <
typename... T>
361 int num_elements =
shape.total_size();
368 for(
int d =
shape.num_dimensions() - 1; d >= 0; --d)
370 num_elements /=
shape[d];
371 coord.set(d, index / num_elements);
372 index %= num_elements;
398 index += coord[i] * dim_size;
399 dim_size *=
shape[i];
426 template <
typename T>
445 template <
typename T>
451 info.set_quantization_info(quantization_info);
454 return create_tensor<T>(
info, ctx);
465 template <
typename T>
470 return create_tensor<T>(
info, ctx);
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)
485 std::vector<T> v(num_values);
486 std::mt19937 gen(seed);
487 std::uniform_real_distribution<T> dist(min, max);
489 for(
unsigned int i = 0; i < num_values; ++i)
497 template <
typename T,
typename ArrayAccessor_T>
498 inline void fill_array(ArrayAccessor_T &&array,
const std::vector<T> &v)
500 array.resize(v.size());
501 std::memcpy(array.buffer(), v.data(), v.size() *
sizeof(T));
513 const unsigned int i = 1;
514 const char *c =
reinterpret_cast<const char *
>(&i);
515 std::string endianness;
518 endianness = std::string(
"<");
522 endianness = std::string(
">");
524 const std::string no_endianness(
"|");
557 template <
typename TensorType>
560 #ifdef ARM_COMPUTE_CL
574 template <
typename TensorType>
589 std::fill(states.begin(), states.end(), value);
616 template <
typename TensorType>
627 template <
typename TensorType>
636 const Size2D info_stride(
info.stride().first,
info.stride().second);
@ NCHW
Num samples, channels, height, width.
std::string to_string(T &&value)
Convert integer and float values to string.
@ QSYMM8_PER_CHANNEL
quantized, symmetric per channel fixed-point 8-bit number
@ QASYMM16
quantized, asymmetric fixed-point 16-bit number
bool opencl_is_available()
Check if OpenCL is available.
static constexpr int32_t get_dynamic_state_value()
Get the value representing dynamic dimension state.
@ RGB888
3 channels, 1 U8 per channel
Conv2dAttributes & pad(const Padding2D &pad)
Set padding.
@ U64
unsigned 64-bit number
ITensorInfo::TensorDimsState construct_dims_state(int32_t value)
Construct and return object for dimensions' state filled with the given value.
decltype(strategy::transforms) typedef type
@ BFLOAT16
16-bit brain floating-point number
Quantization information.
void set(size_t dimension, T value, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
DataLayout
[DataLayout enum definition]
experimental::dynamic_fusion::Conv2dAttributes convert_pad_stride_info_to_conv_attr(const PadStrideInfo &info, const Size2D &dialation)
@ F64
64-bit floating-point number
static constexpr int32_t get_static_state_value()
Get the value representing static dimension state.
Container for 2D border size.
ITensorInfo::TensorDimsState construct_dynamic_dims_state()
Construct and return object for dimensions' state filled with the value for dynamic state.
@ QASYMM8
quantized, asymmetric fixed-point 8-bit number unsigned
@ U16
unsigned 16-bit number
int coord2index(const TensorShape &shape, const Coordinates &coord)
Linearise the given coordinate.
T round(T value)
Round floating-point value with half value rounding away from zero.
void sync()
Blocks until all commands in the associated command queue have finished.
@ QSYMM8
quantized, symmetric fixed-point 8-bit number
typename std::conditional< std::is_integral< T >::value, std::make_signed< T >, std::common_type< T > >::type make_signed_conditional_t
void set_tensor_static(TensorType &t)
Set the dimension states of the given tensor to state.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Class for specifying the size of an image or rectangle.
typename std::conditional< std::is_integral< T >::value, std::make_unsigned< T >, std::common_type< T > >::type make_unsigned_conditional_t
Basic implementation of the OpenCL tensor interface.
bool is_in_valid_region(const ValidRegion &valid_region, Coordinates coord)
Check if a coordinate is within a valid region.
void fill(U &&tensor, int seed, AssetsLibrary *library)
Brain floating point representation class.
void sync_tensor_if_necessary(TensorType &tensor)
Sync tensor if necessary.
constexpr auto data_layout
@ QSYMM16
quantized, symmetric fixed-point 16-bit number
ITensorInfo::TensorDimsState construct_static_dims_state()
Construct and return object for dimensions' state filled with the value for non-dynamic state.
const ValidRegion valid_region
Attributes are backend-agnostic parameters (in addition to the input/output tensors) of an operator.
Conv2dAttributes & stride(const Size2D &stride)
Set stride.
half_float::half half
16-bit floating point type
void sync_if_necessary()
Sync if necessary.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
@ U32
unsigned 32-bit number
Coordinates index2coord(const TensorShape &shape, int index)
Convert a linear index into n-dimensional coordinates.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
@ U8
unsigned 8-bit number
void set_tensor_dynamic(TensorType &t)
Set the dimension states of the given tensor to dynamic.
T round_half_up(T value)
Round floating-point value with half value rounding to positive infinity.
@ S16
signed 16-bit number
Container for valid region of a window.
@ QASYMM8_SIGNED
quantized, asymmetric fixed-point 8-bit number signed
T foldl(F &&, const T &value)
Base case of foldl.
arm_compute::bfloat16 bfloat16
Interface to enqueue OpenCL kernels and get/set the OpenCL CommandQueue and ICLTuner.
int start(unsigned int d) const
Return the start of the valid region for the given dimension d.
Wrapper to configure the Khronos OpenCL C++ header.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
CLTensor * tensor
Pointer to the auxiliary tensor.
Basic pool of threads to execute CPP/Neon code on several cores in parallel.
void store_value_with_data_type(void *ptr, T value, DataType data_type)
Write the value after casting the pointer according to data_type.
@ U8
1 channel, 1 U8 per channel
static CLScheduler & get()
Access the scheduler singleton.
Format
Image colour formats.
Channel
Available channels.
std::vector< int > TensorDimsState
Store the tensor's metadata.
Conv2dAttributes & dilation(const Size2D &dilation)
Set dilation.
TensorShape shape
Shape of the valid region.
@ S64
signed 64-bit number
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.
Copyright (c) 2017-2023 Arm Limited.
T round_half_even(T value, T epsilon=std::numeric_limits< T >::epsilon())
Round floating-point value with half value rounding to nearest even.
@ F16
16-bit floating-point number
std::string get_typestring(DataType data_type)
Obtain numpy type string from DataType.
T copysign(T x, T y)
Composes a floating point value with the magnitude of x and the sign of y.
Format get_format_for_channel(Channel channel)
Look up the format corresponding to a channel.
@ S32
signed 32-bit number
int end(unsigned int d) const
Return the end of the valid region for the given dimension d.
Format get_channel_format(Channel channel)
Return the format of a channel.
@ F32
32-bit floating-point number
Padding and stride information class.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
T create_tensor(const TensorInfo &info, IRuntimeContext *ctx=nullptr)
Create and initialize a tensor of the given type.
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
T saturate_cast(T val)
Saturate a value of type T against the numeric limits of type U.
typename promote< T >::type promote_t
Get promoted type.
void fill_array(ArrayAccessor_T &&array, const std::vector< T > &v)
DataType
Available data types.
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Coordinates anchor
Anchor for the start of the 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.