24 #ifndef ARM_COMPUTE_UTILS_H 25 #define ARM_COMPUTE_UTILS_H 40 #include <type_traits> 41 #include <unordered_map> 57 template <
typename S,
typename T>
58 constexpr
auto DIV_CEIL(S val, T m) -> decltype((val + m - 1) / m)
60 return (val + m - 1) / m;
70 template <
typename S,
typename T>
71 inline auto ceil_to_multiple(S value, T divisor) -> decltype(((value + divisor - 1) / divisor) * divisor)
74 return DIV_CEIL(value, divisor) * divisor;
84 template <
typename S,
typename T>
88 return (value / divisor) * divisor;
98 std::string
read_file(
const std::string &filename,
bool binary);
133 return sizeof(size_t);
574 max =
PixelValue(static_cast<int32_t>(std::numeric_limits<uint8_t>::max()));
583 max =
PixelValue(static_cast<int32_t>(std::numeric_limits<int8_t>::max()));
590 max =
PixelValue(static_cast<int32_t>(std::numeric_limits<uint16_t>::max()));
597 max =
PixelValue(static_cast<int32_t>(std::numeric_limits<int16_t>::max()));
603 max =
PixelValue(std::numeric_limits<uint32_t>::max());
609 max =
PixelValue(std::numeric_limits<int32_t>::max());
621 max =
PixelValue(std::numeric_limits<half>::max());
627 max =
PixelValue(std::numeric_limits<float>::max());
633 return std::make_tuple(min, max);
678 output.
set(0, (output.x() + 1) & ~1
U);
684 output.
set(1, (output.y() + 1) & ~1
U);
708 output.
set(0, output.x() / 2
U);
714 output.
set(1, output.y() / 2
U);
727 template <
typename T>
730 const auto old_dim = utility::make_array<Dimensions<T>::num_max_dimensions>(dimensions.
begin(), dimensions.
end());
733 T dimension_val = old_dim[i];
734 dimensions.
set(perm[i], dimension_val);
763 unsigned int kernel_width,
unsigned int kernel_height,
778 int kernel_width,
int kernel_height,
793 int kernel_width,
int kernel_height,
917 std::unordered_map<const ITensorInfo *, PaddingSize>
get_padding_info(std::initializer_list<const ITensorInfo *> infos);
924 std::unordered_map<const ITensorInfo *, PaddingSize>
get_padding_info(std::initializer_list<const ITensor *> tensors);
931 bool has_padding_changed(
const std::unordered_map<const ITensorInfo *, PaddingSize> &padding_map);
1077 std::stringstream
ss;
1078 ss.precision(std::numeric_limits<float>::max_digits10);
1081 if(val != static_cast<int>(val))
1100 return size_t(std::ceil((end - start) / step));
1111 template <
typename T>
1118 const auto val_u8 =
static_cast<uint8_t
>(val);
1125 return ((
double)val >= min && (double)val <= max);
1129 const auto val_s8 =
static_cast<int8_t
>(val);
1134 const auto val_u16 =
static_cast<uint16_t
>(val);
1139 const auto val_s16 =
static_cast<int16_t
>(val);
1144 const auto val_u32 =
static_cast<uint32_t
>(val);
1149 const auto val_s32 =
static_cast<int32_t
>(val);
1175 if((vec_size >= dim0) && (dim0 == 3))
1180 while(vec_size > dim0)
1188 #ifdef ARM_COMPUTE_ASSERTS_ENABLED 1197 template <
typename T>
1198 void print_consecutive_elements_impl(std::ostream &s,
const T *ptr,
unsigned int n,
int stream_width = 0,
const std::string &element_delim =
" ")
1200 using print_type =
typename std::conditional<std::is_floating_point<T>::value, T,
int>
::type;
1201 std::ios stream_status(
nullptr);
1202 stream_status.copyfmt(s);
1204 for(
unsigned int i = 0; i < n; ++i)
1207 if(stream_width != 0)
1209 s.width(stream_width);
1215 s << std::right << static_cast<T>(ptr[i]) << element_delim;
1220 s << std::right << float(ptr[i]) << element_delim;
1224 s << std::right << static_cast<print_type>(ptr[i]) << element_delim;
1229 s.copyfmt(stream_status);
1240 template <
typename T>
1241 int max_consecutive_elements_display_width_impl(std::ostream &s,
const T *ptr,
unsigned int n)
1243 using print_type =
typename std::conditional<std::is_floating_point<T>::value, T,
int>
::type;
1246 for(
unsigned int i = 0; i < n; ++i)
1248 std::stringstream
ss;
1254 ss << static_cast<T>(ptr[i]);
1259 ss << float(ptr[i]);
1263 ss << static_cast<print_type>(ptr[i]);
1266 max_width = std::max<int>(max_width, ss.str().size());
1280 void print_consecutive_elements(std::ostream &s,
DataType dt,
const uint8_t *ptr,
unsigned int n,
int stream_width,
const std::string &element_delim =
" ");
1291 int max_consecutive_elements_display_width(std::ostream &s,
DataType dt,
const uint8_t *ptr,
unsigned int n);
BorderMode
Methods available to handle borders.
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
void set(size_t dimension, T value, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
bool needs_serialized_reduction(ReductionOperation op, DataType dt, unsigned int axis)
Check if the given reduction operation should be handled in a serial way.
Class describing the value of a pixel for any image format.
A single plane of 32-bit macro pixel of U0, Y0, V0, Y1 byte.
InterpolationPolicy
Interpolation method.
bool has_format_vertical_subsampling(Format format)
Return true if the given format has vertical subsampling.
quantized, symmetric fixed-point 16-bit number
int plane_idx_from_channel(Format format, Channel channel)
Return the plane index of a given channel given an input format.
TensorShape calculate_subsampled_shape(const TensorShape &shape, Format format, Channel channel=Channel::UNKNOWN)
Calculate subsampled shape for a given format and channel.
float dequantize_qasymm8(uint8_t value, const INFO_TYPE &qinfo)
Dequantize a value given an unsigned 8-bit asymmetric quantization scheme.
ReductionOperation
Available reduction operations.
void permute_strides(Dimensions< T > &dimensions, const PermutationVector &perm)
Permutes the given dimensions according the permutation vector.
size_t num_planes_from_format(Format format)
Return the number of planes for a given format.
const std::string & string_from_channel(Channel channel)
Convert a channel identity into a string.
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's output tensor.
Brain floating point representation class.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
1 channel, 1 U8 per channel
size_t element_size_from_data_type(DataType dt)
The size in bytes of the data type.
half_float::half half
16-bit floating point type
1 channel, 1 F32 per channel
DimensionRoundingType
Dimension rounding type when down-scaling on CNNs.
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.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
const DataLayout data_layout
size_t num_channels_from_format(Format format)
Return the number of channels for a given single-planar pixel format.
const std::string & string_from_activation_func(ActivationLayerInfo::ActivationFunction act)
Translates a given activation function to a string.
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.
quantized, asymmetric fixed-point 16-bit number
1 channel, 1 U16 per channel
const std::string & string_from_gemmlowp_output_stage(GEMMLowpOutputStageType output_stage)
Translates a given GEMMLowp output stage to a string.
std::string lower_string(const std::string &val)
Lower a given string.
bool is_data_type_quantized_symmetric(DataType dt)
Check if a given data type is of symmetric quantized type.
Activation Layer Information class.
decltype(strategy::transforms) typedef type
auto floor_to_multiple(S value, T divisor) -> decltype((value/divisor) *divisor)
Computes the largest number smaller or equal to value that is a multiple of divisor.
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.
1 channel, 1 F16 per channel
constexpr auto DIV_CEIL(S val, T m) -> decltype((val+m - 1)/m)
Calculate the rounded up quotient of val / m.
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...
const std::string & string_from_norm_type(NormType type)
Translates a given normalization type to a string.
const std::string & string_from_border_mode(BorderMode border_mode)
Translates a given border mode policy to a string.
static bfloat16 lowest()
Lowest representative value.
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...
16-bit brain floating-point number
3 channels, 1 U8 per channel
Quantization information.
TensorShape 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.
DataType get_promoted_data_type(DataType dt)
Return the promoted data type of a given data type.
std::string read_file(const std::string &filename, bool binary)
Load an entire file in memory.
1 channel, 1 U32 per channel
bool is_data_type_quantized_per_channel(DataType dt)
Check if a given data type is of per channel type.
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
bool check_value_range(T val, DataType dt, QuantizationInfo qinfo=QuantizationInfo())
Returns true if the value can be represented by the given data type.
Channel
Available channels.
Format
Image colour formats.
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.
auto ceil_to_multiple(S value, T divisor) -> decltype(((value+divisor - 1)/divisor) *divisor)
Computes the smallest number larger or equal to value that is a multiple of divisor.
quantized, asymmetric fixed-point 8-bit number unsigned
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
const std::string & string_from_interpolation_policy(InterpolationPolicy policy)
Translates a given interpolation policy to a string.
bool is_data_type_quantized_asymmetric_signed(DataType dt)
Check if a given data type is of asymmetric quantized signed type.
Dimensions with dimensionality.
A 3 plane of 8 bit 4:4:4 sampled Y, U, V planes.
size_t data_size_from_type(DataType data_type)
The size in bytes of the data type.
Padding and stride information class.
void end(TokenStream &in, bool &valid)
std::array< T, num_max_dimensions >::iterator begin()
Returns a read/write iterator that points to the first element in the dimension array.
GEMMLowpOutputStageType
GEMMLowp output stage type.
size_t num_of_elements_in_range(const float start, const float end, const float step)
Returns the number of elements required to go from start to end with the wanted step.
1 channel, 1 S16 per channel
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.
quantized, symmetric fixed-point 8-bit number
Num samples, channels, height, width.
TensorShape adjust_odd_shape(const TensorShape &shape, Format format)
Adjust tensor shape size if width or height are odd for a given multi-planar format.
DataType data_type_from_format(Format format)
Return the data type used by a given single-planar pixel format.
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
Strides of an item in bytes.
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.
std::array< T, num_max_dimensions >::iterator end()
Returns a read/write iterator that points one past the last element in the dimension array...
const std::string & string_from_data_layout(DataLayout dl)
Convert a data layout identity into a string.
size_t pixel_size_from_format(Format format)
The size in bytes of the pixel format.
Class for specifying the size of an image or rectangle.
const QuantizationInfo qinfo
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo *> infos)
Stores padding information before configuring a kernel.
2 channel, 1 U8 per channel
bool has_format_horizontal_subsampling(Format format)
Return true if the given format has horizontal subsampling.
unsigned int adjust_vec_size(unsigned int vec_size, size_t dim0)
Returns the adjusted vector size in case it is less than the input's first dimension, getting rounded down to its closest valid vector size.
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.
A single plane of 32-bit macro pixel of Y0, U0, Y1, V0 bytes.
DataType
Available data types.
static bfloat16 max()
Largest representative value.
DataLayout
[DataLayout enum definition]
const std::string & string_from_pooling_type(PoolingType type)
Translates a given pooling type to a string.
NormType
The normalization type used for the normalization layer.
std::tuple< PixelValue, PixelValue > get_min_max(DataType dt)
Compute the mininum and maximum values a data type can take.
TensorShape & set(size_t dimension, size_t value, bool apply_dim_correction=true, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
int channel_idx_from_format(Format format, Channel channel)
Return the channel index of a given channel given an input format.
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.
inline ::std::istream & operator>>(::std::istream &stream, DataType &data_type)
Input Stream operator for DataType.
const std::string & string_from_format(Format format)
Convert a tensor format into a string.