24.02.1
|
Go to the documentation of this file.
44 #pragma omp parallel for
46 for(
int i = 0; i <
src.num_elements(); ++i)
60 #pragma omp parallel for
62 for(
int i = 0; i <
src.num_elements(); ++i)
76 #pragma omp parallel for
78 for(
int i = 0; i <
src.num_elements(); ++i)
92 #pragma omp parallel for
94 for(
int i = 0; i <
src.num_elements(); ++i)
108 #pragma omp parallel for
110 for(
int i = 0; i <
src.num_elements(); ++i)
118 SimpleTensor<uint16_t>
convert_to_asymmetric(
const SimpleTensor<float> &
src,
const QuantizationInfo &quantization_info)
121 const UniformQuantizationInfo &
qinfo = quantization_info.
uniform();
124 #pragma omp parallel for
126 for(
int i = 0; i <
src.num_elements(); ++i)
140 #pragma omp parallel for
142 for(
int i = 0; i <
src.num_elements(); ++i)
156 #pragma omp parallel for
158 for(
int i = 0; i <
src.num_elements(); ++i)
165 template <
typename T>
172 const int M = a.
shape()[1];
173 const int N =
b.shape()[0];
174 const int K =
b.shape()[1];
177 #pragma omp parallel for collapse(2)
179 for(
int y = 0; y <
M; ++y)
181 for(
int x = 0; x <
N; ++x)
184 for(
int k = 0; k <
K; ++k)
186 acc += a[y *
K + k] *
b[x + k *
N];
189 out[x + y *
N] = acc;
194 template <
typename T>
199 const int width = in.
shape()[0];
200 const int height = in.
shape()[1];
203 #pragma omp parallel for collapse(2)
205 for(
int y = 0; y < height; ++y)
207 for(
int x = 0; x < width; ++x)
209 const T val = in[x + y * width];
211 out[x * height + y] = val;
216 template <
typename T>
221 const int w_tile =
tile.shape()[0];
222 const int h_tile =
tile.shape()[1];
225 std::fill(
tile.data() + 0, (
tile.data() + (w_tile * h_tile)),
static_cast<T
>(0));
230 if(coord[d] < 0 || coord[d] >=
static_cast<int>(in.
shape()[d]))
243 auto in_ptr =
static_cast<const T *
>(in(start_coord));
244 auto roi_ptr =
static_cast<T *
>(
tile.data());
246 const int x_in_start = std::max(0, coord[0]);
247 const int y_in_start = std::max(0, coord[1]);
248 const int x_in_end = std::min(
static_cast<int>(in.
shape()[0]), coord[0] + w_tile);
249 const int y_in_end = std::min(
static_cast<int>(in.
shape()[1]), coord[1] + h_tile);
252 const int n = x_in_end - x_in_start;
255 const int x_tile_start = coord[0] > 0 ? 0 : std::abs(coord[0]);
256 const int y_tile_start = coord[1] > 0 ? 0 : std::abs(coord[1]);
259 in_ptr += x_in_start;
260 in_ptr += (y_in_start * in.
shape()[0]);
263 roi_ptr += x_tile_start;
264 roi_ptr += (y_tile_start *
tile.shape()[0]);
266 for(
int y = y_in_start; y < y_in_end; ++y)
271 in_ptr += in.
shape()[0];
272 roi_ptr +=
tile.shape()[0];
276 template <
typename T>
286 if(anchor[d] < 0 || ((anchor[d] +
shape[d]) > in.
shape()[d]))
293 auto in_ptr =
static_cast<T *
>(in(anchor[0] + anchor[1] * in.
shape()[0]));
295 const unsigned int n = in.
shape()[0];
297 for(
unsigned int y = 0; y <
shape[1]; ++y)
310 return std::pair<int, int> { min_bound, max_bound };
319 return std::pair<int, int> { min_bound, max_bound };
328 return std::pair<int, int> { min_bound, max_bound };
335 constexpr
unsigned int lower = 1
U;
336 constexpr
unsigned int upper = 16
U;
338 std::uniform_int_distribution<unsigned int>
distribution(lower, upper);
339 size_t seed_offset = 0;
345 std::mt19937 gen(
library->seed() + seed_offset++);
348 const unsigned int left = only_right_pad ? 0 :
distribution(gen);
435 const int32_t t_max =
static_cast<int32_t
>(
data_type ==
DataType::QASYMM8 ? std::numeric_limits<uint8_t>::max() : std::numeric_limits<int8_t>::max());
436 const int32_t t_min =
static_cast<int32_t
>(
data_type ==
DataType::QASYMM8 ? std::numeric_limits<uint8_t>::min() : std::numeric_limits<int8_t>::min());
527 const float mean_a_int = (t_max + t_min) / 2.f;
528 constexpr
float var_a_int = (256 * 256 - 1) / 12.f;
529 const float mean_b_int = mean_a_int;
530 constexpr
float var_b_int = var_a_int;
533 const float max_a = (t_max - a_offset) * a_scale;
534 const float min_a = (t_min - a_offset) * a_scale;
535 const float mean_a = (max_a + min_a) / 2;
536 const float var_a = (max_a - min_a) * (max_a - min_a) / 12;
539 const float max_b = (t_max - b_offset) * b_scale;
540 const float min_b = (t_min - b_offset) * b_scale;
541 const float mean_b = (max_b + min_b) / 2;
542 const float var_b = (max_b - min_b) * (max_b - min_b) / 12;
545 const float mean_m_int =
K * mean_a_int * mean_b_int;
546 const float var_m_int =
K * (var_a_int * var_b_int + mean_a_int * var_b_int + mean_b_int + var_a_int);
547 const float std_m_int = sqrt(var_m_int);
550 const float mean_d_int = bias_fraction * mean_m_int;
551 const float std_d_int = bias_fraction * std_m_int;
552 const float mean_d = a_scale * b_scale * mean_d_int;
553 const float std_d = a_scale * b_scale * std_d_int;
554 const float var_d = std_d * std_d;
557 const int32_t min_bias = mean_d_int - (num_sd * std_d_int);
558 const int32_t max_bias = mean_d_int + (num_sd * std_d_int);
561 const float mean_out =
K * mean_a * mean_b + mean_d;
562 const float var_out =
K * (var_a * var_b + var_a * mean_b * mean_b + var_b * mean_a * mean_a) + var_d;
563 const float std_out = sqrt(var_out);
566 const float scale_out = (2 * num_sd) * std_out / 255;
567 const int32_t offset_out =
static_cast<int32_t
>(t_min - (mean_out - (num_sd * std_out)) / scale_out);
571 return { c_q_info, min_bias, max_bias };
@ QASYMM16
quantized, asymmetric fixed-point 16-bit number
void zeros(SimpleTensor< T > &in, const Coordinates &anchor, const TensorShape &shape)
Fill with zeros the input tensor in the area defined by anchor and shape.
float dequantize_qasymm8(uint8_t value, const INFO_TYPE &qinfo)
Dequantize a value given an unsigned 8-bit asymmetric quantization scheme.
SimpleTensor< float > src
void matrix_multiply(const SimpleTensor< T > &a, const SimpleTensor< T > &b, SimpleTensor< T > &out)
Matrix multiply between 2 float simple tensors.
Quantization information.
void add_padding_x(std::initializer_list< ITensor * > tensors, const DataLayout &data_layout, bool only_right_pad)
Add random padding along the X axis (between 1 and 16 columns per side) to all the input tensors.
DataLayout
[DataLayout enum definition]
Helper struct to store the hints for.
@ NHWC
Num samples, height, width, channels.
int16_t quantize_qsymm16(float value, const UniformQuantizationInfo &qinfo, RoundingPolicy rounding_policy=RoundingPolicy::TO_NEAREST_UP)
Quantize a value given a 16-bit symmetric quantization scheme.
@ QASYMM8
quantized, asymmetric fixed-point 8-bit number unsigned
SimpleTensor< float > convert_from_symmetric(const SimpleTensor< int16_t > &src)
uint8_t quantize_qasymm8(float value, const INFO_TYPE &qinfo, RoundingPolicy rounding_policy=RoundingPolicy::TO_NEAREST_UP)
Quantize a value given an unsigned 8-bit asymmetric quantization scheme.
std::pair< int, int > get_symm_quantized_per_channel_bounds(const QuantizationInfo &quant_info, float min, float max, size_t channel_id)
Helper function to compute symmetric quantized min and max bounds.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
TensorShape shape() const override
Shape of the tensor.
SimpleTensor< float > convert_from_asymmetric(const SimpleTensor< uint8_t > &src)
Interface for CPU tensor.
QuantizationHint suggest_mac_dst_q_info_and_bias(const QuantizationInfo &a_q_info, const QuantizationInfo &b_q_info, int32_t K, DataType data_type, float bias_fraction, int num_sd)
For a multiply-accumulate (mac), given the Lhs/Rhs vector quantization informations and the dot produ...
std::pair< int, int > get_quantized_bounds(const QuantizationInfo &quant_info, float min, float max)
Helper function to compute quantized min and max bounds.
SimpleTensor< int16_t > convert_to_symmetric(const SimpleTensor< float > &src, const QuantizationInfo &quantization_info)
SimpleTensor< T > tile(const SimpleTensor< T > &src, const Multiples &multiples)
@ QSYMM16
quantized, symmetric fixed-point 16-bit number
SimpleTensor< uint8_t > convert_to_asymmetric(const SimpleTensor< float > &src, const QuantizationInfo &quantization_info)
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
int8_t quantize_qasymm8_signed(float value, const INFO_TYPE &qinfo, RoundingPolicy rounding_policy=RoundingPolicy::TO_NEAREST_UP)
Quantize a value given a signed 8-bit asymmetric quantization scheme.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
library fill(src, distribution, 0)
@ QASYMM8_SIGNED
quantized, asymmetric fixed-point 8-bit number signed
QuantizationHint suggest_matmul_dst_q_info_and_bias(const QuantizationInfo &lhs_q_info, const QuantizationInfo &rhs_q_info, int32_t m, int32_t n, int32_t k, DataType data_type, float bias_fraction)
For a matrix multiplication, given the Lhs/Rhs matrix quantization informations and the matrix multip...
std::pair< int, int > get_quantized_qasymm8_signed_bounds(const QuantizationInfo &quant_info, float min, float max)
Helper function to compute asymmetric quantized signed min and max bounds.
#define ARM_COMPUTE_ASSERT(cond)
SimpleTensor< T > copy(const SimpleTensor< T > &src, const TensorShape &output_shape)
float dequantize_qasymm16(uint16_t value, const UniformQuantizationInfo &qinfo)
Dequantize a value given a 16-bit asymmetric quantization scheme.
float dequantize_qsymm16(int16_t value, const UniformQuantizationInfo &qinfo)
Dequantize a value given a 16-bit symmetric quantization scheme.
UniformQuantizationInfo uniform() const
Return per layer quantization info.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
CLTensor * tensor
Pointer to the auxiliary tensor.
std::unique_ptr< AssetsLibrary > library
void transpose_matrix(const SimpleTensor< T > &in, SimpleTensor< T > &out)
Transpose matrix.
const DataLayout data_layout
Simple tensor object that stores elements in a consecutive chunk of memory.
BorderSize PaddingSize
Container for 2D padding size.
void get_tile(const SimpleTensor< T > &in, SimpleTensor< T > &tile, const Coordinates &coord)
Get a 2D tile from a tensor.
float dequantize_qasymm8_signed(int8_t value, const INFO_TYPE &qinfo)
Dequantize a value given a signed 8-bit asymmetric quantization scheme.
Copyright (c) 2017-2024 Arm Limited.
QuantizationHint suggest_conv_dst_q_info_and_bias(const QuantizationInfo &in_q_info, const QuantizationInfo &weight_q_info, int32_t height, int32_t width, int32_t channels, DataType data_type, float bias_fraction)
For 2d convolution, given the Lhs/Rhs matrix quantization informations and the convolution dimension,...
std::uniform_real_distribution< float > distribution(-5.f, 5.f)
uint16_t quantize_qasymm16(float value, const UniformQuantizationInfo &qinfo, RoundingPolicy rounding_policy=RoundingPolicy::TO_NEAREST_UP)
Quantize a value given a 16-bit asymmetric quantization scheme.
int8_t quantize_qsymm8_per_channel(float value, const QuantizationInfo &qinfo, size_t channel_id=0)
Quantize a value given a 8-bit symmetric per channel quantization scheme.
@ F32
32-bit floating-point number
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
DataType
Available data types.
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
const QuantizationInfo qinfo