Compute Library
 20.08
arm_compute::quantization Namespace Reference

Functions

Status calculate_quantized_multiplier (float multiplier, int32_t *quant_multiplier, int32_t *shift, bool ignore_epsilon=false)
 Calculate quantized representation of multiplier. More...
 
Status calculate_quantized_multiplier_less_than_one (float multiplier, int32_t *quant_multiplier, int32_t *right_shift, bool ignore_epsilon=false)
 Calculate quantized representation of multiplier with value less than one. More...
 
Status calculate_quantized_multiplier_greater_than_one (float multiplier, int32_t *quantized_multiplier, int32_t *left_shift)
 Calculate quantized representation of multiplier having value greater than one. More...
 
Status calculate_quantized_multipliers (const QuantizationInfo &iq_info, const QuantizationInfo &wq_info, const QuantizationInfo &oq_info, GEMMLowpOutputStageInfo &stage_info)
 Calculate quantized representation of per-channel multipliers. More...
 
std::pair< int, int > get_min_max_values_from_quantized_data_type (DataType data_type)
 Get minimum and maximum values for the input quantized data type. More...
 
void compute_quantized_multipliers_and_shifts (const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *output, unsigned int idx_ofms, int32_t *output_multipliers_ptr, int32_t *output_shifts_ptr)
 Compute quantized per-channel multipliers and shifts. More...
 
int32_t rounding_divide_by_pow2 (int32_t x, int exponent)
 Round to the nearest division by a power-of-two using exponent, copied from NEMath. More...
 
int32_t saturating_rounding_doubling_highmul (int32_t a, int32_t b)
 Compute multiplication of two integers. More...
 
int32_t multiply_by_quantized_multiplier (int32_t input, int32_t qmul, int32_t shift)
 Compute the value multiplied by given quantized multiplier and shift. More...
 
int32_t saturating_rounding_multiply_by_pow2 (int32_t exponent, int32_t v)
 Compute the value multiplied the power-of-two. More...
 
void get_invsqrt_quantized_multiplier_exp (int32_t input, int32_t reverse_shift, int32_t &output_inv_sqrt, int32_t &output_shift)
 Compute quantized multiplier and shift for the inverse square root of input. More...
 

Variables

constexpr int64_t fixed_point_one_Q0 = (1LL << 31)
 
constexpr float epsilon = 0.00001f
 

Function Documentation

◆ calculate_quantized_multiplier()

Status calculate_quantized_multiplier ( float  multiplier,
int32_t *  quant_multiplier,
int32_t *  shift,
bool  ignore_epsilon = false 
)

Calculate quantized representation of multiplier.

Parameters
[in]multiplierReal multiplier.
[out]quant_multiplierInteger multiplier.
[out]shiftbit shift. A negative value indicates a left shift, while a positive value indicates a right shift
[in]ignore_epsilonWhen true, ignore pre-defined epsilon value. Defaults to false
Returns
a status

Definition at line 39 of file AsymmHelpers.cpp.

40 {
41  if(multiplier >= 1.f)
42  {
43  Status status = calculate_quantized_multiplier_greater_than_one(multiplier, quant_multiplier, shift);
44  *shift *= -1;
45  return status;
46  }
47  else
48  {
49  return calculate_quantized_multiplier_less_than_one(multiplier, quant_multiplier, shift, ignore_epsilon);
50  }
51 }
Status calculate_quantized_multiplier_greater_than_one(float multiplier, int32_t *quantized_multiplier, int32_t *left_shift)
Calculate quantized representation of multiplier having value greater than one.
Status calculate_quantized_multiplier_less_than_one(float multiplier, int32_t *quant_multiplier, int32_t *right_shift, bool ignore_epsilon=false)
Calculate quantized representation of multiplier with value less than one.

References calculate_quantized_multiplier_greater_than_one(), calculate_quantized_multiplier_less_than_one(), and arm_compute::test::validation::shift.

Referenced by calculate_quantized_multipliers(), compute_quantized_multipliers_and_shifts(), NEQLSTMLayerNormalizationKernel::configure(), CLQLSTMLayerNormalizationKernel::configure(), NEDepthwiseConvolutionLayerNativeKernel::configure(), CLDepthwiseConvolutionLayer3x3NCHWKernel::configure(), CLDepthwiseConvolutionLayer3x3NHWCKernel::configure(), CLDepthwiseConvolutionLayerNativeKernel::configure(), CLDirectConvolutionLayerKernel::configure(), NELSTMLayerQuantized::configure(), NEQLSTMLayer::configure(), CLLSTMLayerQuantized::configure(), CLQLSTMLayer::configure(), arm_compute::test::validation::reference::qlstm_layer_normalization(), NELSTMLayerQuantized::validate(), CLLSTMLayerQuantized::validate(), NEQLSTMLayer::validate(), and CLQLSTMLayer::validate().

◆ calculate_quantized_multiplier_greater_than_one()

Status calculate_quantized_multiplier_greater_than_one ( float  multiplier,
int32_t *  quantized_multiplier,
int32_t *  left_shift 
)

Calculate quantized representation of multiplier having value greater than one.

Parameters
[in]multiplierReal multiplier.
[out]quantized_multiplierInteger multiplier.
[out]left_shiftLeft bit shift.
Returns
a status

Definition at line 95 of file AsymmHelpers.cpp.

98 {
99  ARM_COMPUTE_RETURN_ERROR_ON(quantized_multiplier == nullptr);
100  ARM_COMPUTE_RETURN_ERROR_ON(left_shift == nullptr);
101  ARM_COMPUTE_RETURN_ERROR_ON(multiplier < 1.f);
102 
103  int shift_exp = 0;
104  const double q = std::frexp(multiplier, &shift_exp);
105  *left_shift = shift_exp;
106  auto q_fixed = static_cast<int64_t>(support::cpp11::round(q * fixed_point_one_Q0));
108  if(q_fixed == fixed_point_one_Q0)
109  {
110  q_fixed /= 2;
111  ++*left_shift;
112  }
113  ARM_COMPUTE_RETURN_ERROR_ON(*left_shift < 0);
114  ARM_COMPUTE_RETURN_ERROR_ON(q_fixed > std::numeric_limits<int32_t>::max());
115  *quantized_multiplier = static_cast<int32_t>(q_fixed);
116 
117  return Status{};
118 }
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
int round(float x, RoundingPolicy rounding_policy)
Return a rounded value of x.
Definition: Rounding.cpp:35
constexpr int64_t fixed_point_one_Q0

References ARM_COMPUTE_RETURN_ERROR_ON, fixed_point_one_Q0, and arm_compute::support::cpp11::round().

Referenced by calculate_quantized_multiplier().

◆ calculate_quantized_multiplier_less_than_one()

Status calculate_quantized_multiplier_less_than_one ( float  multiplier,
int32_t *  quant_multiplier,
int32_t *  right_shift,
bool  ignore_epsilon = false 
)

Calculate quantized representation of multiplier with value less than one.

Parameters
[in]multiplierReal multiplier.
[out]quant_multiplierInteger multiplier.
[out]right_shiftRight bit shift.
[in]ignore_epsilonWhen true, ignore pre-defined epsilon value. Defaults to false
Returns
a status

Definition at line 53 of file AsymmHelpers.cpp.

57 {
58  const float internal_epsilon = ignore_epsilon ? 0.0f : epsilon;
59 
60  ARM_COMPUTE_RETURN_ERROR_ON(quant_multiplier == nullptr);
61  ARM_COMPUTE_RETURN_ERROR_ON(right_shift == nullptr);
62  ARM_COMPUTE_RETURN_ERROR_ON(multiplier < -internal_epsilon);
63  ARM_COMPUTE_RETURN_ERROR_ON(multiplier > 1.0f + internal_epsilon);
64  if(std::fabs(0.0f - multiplier) < internal_epsilon)
65  {
66  *quant_multiplier = 0;
67  *right_shift = 0;
68  return Status{};
69  }
70 
71  int shift_exp = 0;
72  const double q = std::frexp(multiplier, &shift_exp);
73  *right_shift = -1 * shift_exp;
74  auto q_fixed = static_cast<int64_t>(support::cpp11::round(q * fixed_point_one_Q0));
76  if(q_fixed == fixed_point_one_Q0)
77  {
78  q_fixed /= 2;
79  --*right_shift;
80  }
81 
82  if(ignore_epsilon && *right_shift > 31)
83  {
84  *right_shift = 0;
85  q_fixed = 0;
86  }
87 
88  ARM_COMPUTE_RETURN_ERROR_ON(*right_shift < 0);
89  ARM_COMPUTE_RETURN_ERROR_ON(q_fixed > std::numeric_limits<int32_t>::max());
90  *quant_multiplier = static_cast<int32_t>(q_fixed);
91 
92  return Status{};
93 }
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
int round(float x, RoundingPolicy rounding_policy)
Return a rounded value of x.
Definition: Rounding.cpp:35
constexpr int64_t fixed_point_one_Q0

References ARM_COMPUTE_RETURN_ERROR_ON, epsilon, fixed_point_one_Q0, and arm_compute::support::cpp11::round().

Referenced by calculate_quantized_multiplier(), and main().

◆ calculate_quantized_multipliers()

arm_compute::Status calculate_quantized_multipliers ( const QuantizationInfo iq_info,
const QuantizationInfo wq_info,
const QuantizationInfo oq_info,
GEMMLowpOutputStageInfo stage_info 
)

Calculate quantized representation of per-channel multipliers.

Parameters
[in]iq_infoInput quantization info.
[in]wq_infoWeights quantization info.
[in]oq_infoOutput quantization info.
[in,out]stage_infoGemmLowp output stage info
Returns
a status

Definition at line 120 of file AsymmHelpers.cpp.

124 {
125  ARM_COMPUTE_RETURN_ERROR_ON(iq_info.scale().empty());
126  ARM_COMPUTE_RETURN_ERROR_ON(wq_info.scale().empty());
127  ARM_COMPUTE_RETURN_ERROR_ON(oq_info.scale().empty());
128 
129  const unsigned int size = wq_info.scale().size();
130 
131  auto &quant_multipliers = stage_info.gemmlowp_multipliers;
132  auto &quant_shifts = stage_info.gemmlowp_shifts;
133  quant_multipliers.resize(size);
134  quant_shifts.resize(size);
135 
136  const auto &w_scales = wq_info.scale();
137  const float i_scale = iq_info.scale().at(0);
138  const float o_scale = oq_info.scale().at(0);
139 
140  for(unsigned int i = 0; i < size; ++i)
141  {
142  const float multiplier = i_scale * w_scales[i] / o_scale;
143  int32_t quant_multiplier = 0;
144  int32_t quant_shift = 0;
145  ARM_COMPUTE_RETURN_ON_ERROR(calculate_quantized_multiplier(multiplier, &quant_multiplier, &quant_shift));
146  quant_multipliers[i] = quant_multiplier;
147  quant_shifts[i] = quant_shift;
148  }
149 
150  // Legacy part
151  stage_info.gemmlowp_shift = quant_shifts[0];
152  stage_info.gemmlowp_multiplier = quant_multipliers[0];
153 
154  return Status{};
155 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
Status calculate_quantized_multiplier(float multiplier, int32_t *quant_multiplier, int32_t *shift, bool ignore_epsilon=false)
Calculate quantized representation of multiplier.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296

References ARM_COMPUTE_RETURN_ERROR_ON, ARM_COMPUTE_RETURN_ON_ERROR, calculate_quantized_multiplier(), GEMMLowpOutputStageInfo::gemmlowp_multiplier, GEMMLowpOutputStageInfo::gemmlowp_multipliers, GEMMLowpOutputStageInfo::gemmlowp_shift, GEMMLowpOutputStageInfo::gemmlowp_shifts, and QuantizationInfo::scale().

◆ compute_quantized_multipliers_and_shifts()

void compute_quantized_multipliers_and_shifts ( const ITensorInfo input,
const ITensorInfo weights,
const ITensorInfo output,
unsigned int  idx_ofms,
int32_t *  output_multipliers_ptr,
int32_t *  output_shifts_ptr 
)

Compute quantized per-channel multipliers and shifts.

As many multipliers and shifts as output channels are computed. If weights are not quantized per-channel, multipliers and shifts will end up being the same for each channel.

Parameters
[in]inputInput tensor info.
[in]weightsWeights tensor info.
[in]outputOutput tensor info.
[in]idx_ofmsDimension index to get OFMs from the weights tensor.
[out]output_multipliers_ptrPointer to the buffer where to store per-channel multipliers.
[out]output_shifts_ptrPointer to the buffer where to store per-channel shifts.
Returns
min and max values for the quantized data type

Definition at line 185 of file AsymmHelpers.cpp.

191 {
192  const unsigned int num_filters = is_data_type_quantized_per_channel(weights->data_type()) ? weights->dimension(idx_ofms) : 1;
193 
194  const UniformQuantizationInfo iq_info = input->quantization_info().uniform();
195  const QuantizationInfo wq_info = weights->quantization_info();
196  const UniformQuantizationInfo oq_info = output->quantization_info().uniform();
197 
198  for(unsigned int i = 0; i < num_filters; ++i)
199  {
200  int32_t output_multiplier = 0;
201  int32_t output_shift = 0;
202  const float multiplier = iq_info.scale * wq_info.scale()[i] / oq_info.scale;
203  calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift);
204 
205  output_multipliers_ptr[i] = output_multiplier;
206  output_shifts_ptr[i] = output_shift;
207  }
208 }
Status calculate_quantized_multiplier(float multiplier, int32_t *quant_multiplier, int32_t *shift, bool ignore_epsilon=false)
Calculate quantized representation of multiplier.
bool is_data_type_quantized_per_channel(DataType dt)
Check if a given data type is of per channel type.
Definition: Utils.h:1198

References calculate_quantized_multiplier(), arm_compute::test::validation::input, arm_compute::is_data_type_quantized_per_channel(), ITensorInfo::quantization_info(), UniformQuantizationInfo::scale, QuantizationInfo::scale(), QuantizationInfo::uniform(), and arm_compute::test::validation::weights.

Referenced by CLGEMMConvolutionLayer::configure(), and CLGEMMConvolutionLayer::validate().

◆ get_invsqrt_quantized_multiplier_exp()

void get_invsqrt_quantized_multiplier_exp ( int32_t  input,
int32_t  reverse_shift,
int32_t &  output_inv_sqrt,
int32_t &  output_shift 
)

Compute quantized multiplier and shift for the inverse square root of input.

Using 3-bit fixed point and 5 iteration of Newton-Raphson method.

Parameters
[in]inputInput to use
[in]reverse_shift-1 to reverse the shift direction
[out]output_inv_sqrtQuantized multiplier for inverse square root
[out]output_shiftShift for inverse square root

Definition at line 262 of file AsymmHelpers.cpp.

263 {
265 
266  if(input <= 1)
267  {
268  // dealing the inputs (0 and 1) separately to avoid overflow
269  output_inv_sqrt = std::numeric_limits<std::int32_t>::max();
270  output_shift = 0;
271  return;
272  }
273 
274  // prepare input for fixed point operation and compute shift value
275  output_shift = 11;
276  while(input >= (1 << 29))
277  {
278  input /= 4;
279  ++output_shift;
280  }
281 
282  const uint32_t max_left_shift_bits = __builtin_clz(static_cast<uint32_t>(input)) - 1;
283  const uint32_t max_left_shift_bits_pairs = max_left_shift_bits / 2;
284  const uint32_t left_shift_bit_pairs = max_left_shift_bits_pairs - 1;
285  output_shift -= left_shift_bit_pairs;
286  input <<= 2 * left_shift_bit_pairs;
287 
288  // Calculation in fixed point domain with 3 integer bits.
289  using FixedPointRawType = int32_t;
290  constexpr uint32_t fixedpoint_position = 3;
291  constexpr uint32_t fixedpoint_int_position = sizeof(FixedPointRawType) * 8 - 1 - fixedpoint_position;
292  using FixedPoint3 = FixedPointRawType;
293  using FixedPoint0 = FixedPointRawType;
294 
295  // fixed point representation of input divided by 2 and 1.5 for Newton-Raphson iteration
296  const FixedPoint3 fixedpoint_input = (input >> 1);
297  const FixedPoint3 fixedpoint_half_input = rounding_divide_by_pow2(fixedpoint_input, 1);
298  const FixedPoint3 fixedpoint_half_three = (0x1 << fixedpoint_int_position) + (0x1 << (fixedpoint_int_position - 1));
299 
300  // initial guess (1) in fixed point representation
301  FixedPoint3 x = 0x1 << fixedpoint_int_position;
302 
303  // multiplication of two fixed point numbers, defined for readability
304  auto fixed_point_mul = [](FixedPointRawType a, FixedPointRawType b) -> FixedPointRawType
305  {
307  };
308 
309  // rescaling of fixed point to have dst_bit integer bits, defined for readability
310  auto fixed_point_rescale = [](FixedPointRawType a, uint32_t src_bit, uint32_t dst_bit) -> FixedPointRawType
311  {
312  const uint32_t exponent = src_bit - dst_bit;
313  return saturating_rounding_multiply_by_pow2(exponent, a);
314  };
315 
316  // 5 iterations of Newton-Raphson method for inverse square root - 1.5 * x_n = input/2 * (x_n)^3
317  constexpr int32_t num_iteration = 5;
318  for(int32_t i = 0; i < num_iteration; ++i)
319  {
320  const auto x3 = fixed_point_rescale(fixed_point_mul(fixed_point_mul(x, x), x), 9, fixedpoint_position);
321  x = fixed_point_rescale(fixed_point_mul(fixedpoint_half_three, x) - fixed_point_mul(fixedpoint_half_input, x3), 6, fixedpoint_position);
322  }
323 
324  // fixed point representation of sqrt(1/2)
325  const FixedPoint0 fixedpoint_half_sqrt_2 = 1518500250;
326  x = fixed_point_mul(fixedpoint_half_sqrt_2, x);
327  output_inv_sqrt = x;
328  if(output_shift < 0)
329  {
330  output_inv_sqrt <<= -output_shift;
331  output_shift = 0;
332  }
333  // convert right shift to left shift
334  output_shift *= reverse_shift;
335 }
SimpleTensor< float > b
Definition: DFT.cpp:157
#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
int32_t saturating_rounding_doubling_highmul(int32_t a, int32_t b)
Compute multiplication of two integers.
int32x4_t rounding_divide_by_pow2(int32x4_t x, int32x4_t exponent)
Round to the nearest division by a power-of-two using exponent.
Definition: NEMath.inl:301
int32_t saturating_rounding_multiply_by_pow2(int32_t exponent, int32_t v)
Compute the value multiplied the power-of-two.

References ARM_COMPUTE_ERROR_ON, arm_compute::test::validation::b, arm_compute::test::validation::input, rounding_divide_by_pow2(), saturating_rounding_doubling_highmul(), and saturating_rounding_multiply_by_pow2().

Referenced by arm_compute::test::validation::reference::qlstm_layer_normalization().

◆ get_min_max_values_from_quantized_data_type()

std::pair< int, int > get_min_max_values_from_quantized_data_type ( DataType  data_type)

Get minimum and maximum values for the input quantized data type.

Returns
min and max values for the quantized data type

Definition at line 157 of file AsymmHelpers.cpp.

158 {
159  int min_quant_val = 0;
160  int max_quant_val = 0;
161  switch(data_type)
162  {
163  case DataType::QASYMM8:
164  min_quant_val = std::numeric_limits<uint8_t>::min();
165  max_quant_val = std::numeric_limits<uint8_t>::max();
166  break;
167  case DataType::QSYMM8:
168  case DataType::QASYMM8_SIGNED:
169  min_quant_val = std::numeric_limits<int8_t>::min();
170  max_quant_val = std::numeric_limits<int8_t>::max();
171  break;
172  case DataType::QASYMM16:
173  min_quant_val = std::numeric_limits<uint16_t>::min();
174  max_quant_val = std::numeric_limits<uint16_t>::max();
175  break;
176  case DataType::QSYMM16:
177  min_quant_val = std::numeric_limits<int16_t>::min();
178  max_quant_val = std::numeric_limits<int16_t>::max();
179  break;
180  default:
181  ARM_COMPUTE_ERROR("Unsupported data type");
182  }
183  return std::make_pair(min_quant_val, max_quant_val);
184 }
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352

References ARM_COMPUTE_ERROR, arm_compute::test::validation::data_type, arm_compute::QASYMM16, arm_compute::QASYMM8, arm_compute::QASYMM8_SIGNED, arm_compute::QSYMM16, and arm_compute::QSYMM8.

Referenced by CLQLSTMLayerNormalizationKernel::configure(), CLQuantizationLayerKernel::configure(), CLGEMMLowpQuantizeDownInt32ScaleKernel::configure(), and arm_compute::validate_arguments().

◆ multiply_by_quantized_multiplier()

int32_t multiply_by_quantized_multiplier ( int32_t  input,
int32_t  qmul,
int32_t  shift 
)

Compute the value multiplied by given quantized multiplier and shift.

Parameters
[in]inputTarget value to multiply.
[in]qmulQuantized multipler
[in]shiftLeft bit shift
Returns
The multiplied value

Definition at line 229 of file AsymmHelpers.cpp.

230 {
231  const auto left_shift = shift > 0 ? shift : 0;
232  const auto right_shift = shift > 0 ? 0 : -shift;
233  return rounding_divide_by_pow2(saturating_rounding_doubling_highmul(input * (1 << left_shift), qmul), right_shift);
234 }
int32_t saturating_rounding_doubling_highmul(int32_t a, int32_t b)
Compute multiplication of two integers.
int32x4_t rounding_divide_by_pow2(int32x4_t x, int32x4_t exponent)
Round to the nearest division by a power-of-two using exponent.
Definition: NEMath.inl:301

References arm_compute::test::validation::input, rounding_divide_by_pow2(), saturating_rounding_doubling_highmul(), and arm_compute::test::validation::shift.

Referenced by arm_compute::test::validation::reference::qlstm_layer_normalization().

◆ rounding_divide_by_pow2()

int32_t rounding_divide_by_pow2 ( int32_t  x,
int  exponent 
)
inline

Round to the nearest division by a power-of-two using exponent, copied from NEMath.

Note
This function calculates the following expression: (x + 2^n -1 ) / 2^n where n = exponent
Parameters
[in]xElement to divide.
[in]exponentInteger value used to round to nearest division by a power-of-two
Returns
the nearest division by a power-of-two using exponent

Definition at line 222 of file AsymmHelpers.cpp.

223 {
224  const int32_t mask = (1 << exponent) - 1;
225  const int32_t threshold = (mask >> 1) + (x < 0 ? 1 : 0);
226  return (x >> exponent) + ((x & mask) > threshold ? 1 : 0);
227 }
SimpleTensor< T > threshold(const SimpleTensor< T > &src, T threshold, T false_value, T true_value, ThresholdType type, T upper)
Definition: Threshold.cpp:35

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

Referenced by get_invsqrt_quantized_multiplier_exp(), multiply_by_quantized_multiplier(), and saturating_rounding_multiply_by_pow2().

◆ saturating_rounding_doubling_highmul()

int32_t saturating_rounding_doubling_highmul ( int32_t  a,
int32_t  b 
)

Compute multiplication of two integers.

Parameters
[in]aOne integer to multiply
[in]bAnother integer to multiply
Returns
The multiplied value

Definition at line 210 of file AsymmHelpers.cpp.

211 {
212  bool overflow = a == b && a == std::numeric_limits<int32_t>::min();
213  int64_t a_64(a);
214  int64_t b_64(b);
215  int64_t ab_64 = a_64 * b_64;
216  bool is_positive_or_zero = a == 0 || b == 0 || (std::signbit(a) == std::signbit(b));
217  int32_t nudge = is_positive_or_zero ? (1 << 30) : (1 - (1 << 30));
218  int32_t ab_x2_high32 = static_cast<int32_t>((ab_64 + nudge) / (1ll << 31));
219  return overflow ? std::numeric_limits<int32_t>::max() : ab_x2_high32;
220 }
SimpleTensor< float > b
Definition: DFT.cpp:157

References arm_compute::test::validation::b.

Referenced by get_invsqrt_quantized_multiplier_exp(), and multiply_by_quantized_multiplier().

◆ saturating_rounding_multiply_by_pow2()

int32_t saturating_rounding_multiply_by_pow2 ( int32_t  exponent,
int32_t  v 
)

Compute the value multiplied the power-of-two.

Parameters
[in]exponentExponent used to calculate power-of-two
[in]vTarget value to multiply
Returns
The multiplied value

Definition at line 236 of file AsymmHelpers.cpp.

237 {
238  if(exponent == 0)
239  {
240  return v;
241  }
242  else if(exponent < 0)
243  {
244  return rounding_divide_by_pow2(v, -exponent);
245  }
246  else
247  {
248  constexpr auto min = std::numeric_limits<int32_t>::min();
249  constexpr auto max = std::numeric_limits<int32_t>::max();
250  const auto width = sizeof(int32_t) * 8;
251 
252  const int32_t threshold = ((1 << (width - 1 - exponent)) - 1);
253  bool pos_mask = v > threshold;
254  bool neg_mask = v < -threshold;
255  int32_t result = v << exponent;
256  result = pos_mask ? max : result;
257  result = neg_mask ? min : result;
258  return result;
259  }
260 }
int32x4_t rounding_divide_by_pow2(int32x4_t x, int32x4_t exponent)
Round to the nearest division by a power-of-two using exponent.
Definition: NEMath.inl:301
SimpleTensor< T > threshold(const SimpleTensor< T > &src, T threshold, T false_value, T true_value, ThresholdType type, T upper)
Definition: Threshold.cpp:35

References rounding_divide_by_pow2(), and arm_compute::test::validation::reference::threshold().

Referenced by get_invsqrt_quantized_multiplier_exp().

Variable Documentation

◆ epsilon

constexpr float epsilon = 0.00001f

Definition at line 37 of file AsymmHelpers.cpp.

Referenced by GraphBuilder::add_batch_normalization_node(), arm_compute::test::validation::reference::batch_normalization_layer(), calculate_quantized_multiplier_less_than_one(), CLMeanStdDevNormalizationLayer::configure(), NEMeanStdDevNormalizationLayer::configure(), CLInstanceNormalizationLayer::configure(), NEL2NormalizeLayer::configure(), CLMeanStdDevNormalizationKernel::configure(), GCBatchNormalizationLayer::configure(), NEInstanceNormalizationLayer::configure(), CLL2NormalizeLayerKernel::configure(), CLL2NormalizeLayer::configure(), CLBatchNormalizationLayer::configure(), NEBatchNormalizationLayer::configure(), GCBatchNormalizationLayerKernel::configure(), CLFuseBatchNormalizationKernel::configure(), CLBatchNormalizationLayerKernel::configure(), NEMeanStdDevNormalizationKernel::configure(), CLFuseBatchNormalization::configure(), NEFuseBatchNormalization::configure(), NEFuseBatchNormalizationKernel::configure(), NEBatchNormalizationLayerKernel::configure(), FusedDepthwiseConvolutionBatchNormalizationFunction< TargetInfo, FusedLayerTypes >::configure(), FusedConvolutionBatchNormalizationFunction< TargetInfo, FusedLayerTypes >::configure(), NEOpticalFlow::configure(), CLOpticalFlow::configure(), CLLKTrackerStage1Kernel::configure(), arm_compute::graph::backends::detail::create_batch_normalization_layer(), arm_compute::graph::backends::detail::create_fused_convolution_batch_normalization_layer(), arm_compute::graph::backends::detail::create_fused_depthwise_convolution_batch_normalization_layer(), AssetsLibrary::fill_boxes(), arm_compute::test::validation::reference::fuse_batch_normalization_conv_layer(), arm_compute::test::validation::reference::fuse_batch_normalization_dwc_layer(), arm_compute::graph::detail::fuse_convolution_with_batch_normalization(), arm_compute::graph::detail::fuse_depthwise_convolution_with_batch_normalization(), arm_compute::test::validation::reference::instance_normalization(), arm_compute::helpers::float_ops::is_one(), arm_compute::helpers::float_ops::is_zero(), arm_compute::test::validation::reference::l2_normalize(), l2_normalize_x(), l2_normalize_y(), l2_normalize_z(), lktracker_stage1(), compare< RelativeTolerance< U > >::operator bool(), RangedUniformDistribution< T >::RangedUniformDistribution(), NEMeanStdDevNormalizationLayer::validate(), CLMeanStdDevNormalizationLayer::validate(), NEL2NormalizeLayer::validate(), NEInstanceNormalizationLayer::validate(), NEMeanStdDevNormalizationKernel::validate(), CLInstanceNormalizationLayer::validate(), CLMeanStdDevNormalizationKernel::validate(), NEBatchNormalizationLayer::validate(), GCBatchNormalizationLayerKernel::validate(), CLL2NormalizeLayer::validate(), CLL2NormalizeLayerKernel::validate(), NEBatchNormalizationLayerKernel::validate(), NEFuseBatchNormalization::validate(), NEFuseBatchNormalizationKernel::validate(), CLBatchNormalizationLayer::validate(), CLBatchNormalizationLayerKernel::validate(), CLFuseBatchNormalizationKernel::validate(), and CLFuseBatchNormalization::validate().

◆ fixed_point_one_Q0

constexpr int64_t fixed_point_one_Q0 = (1LL << 31)