ArmNN
 24.08
QuantizedMultiplierSmallerThanOne Struct Reference

Performs multiplication of an integer with a multiplier which is less than one, using quantized integer arithmetic which is consistent with AndroidNN's CPU executor. More...

#include <ConvImpl.hpp>

Public Member Functions

 QuantizedMultiplierSmallerThanOne (float multiplier)
 Constructs a QuantizedMultiplierSmallerThanOne which will multiply by the given multiplier. More...
 
int32_t operator* (int32_t rhs) const
 The implementation of this function is adapted from Android NN's MultiplyByQuantizedMultiplierSmallerThanOne(). More...
 

Detailed Description

Performs multiplication of an integer with a multiplier which is less than one, using quantized integer arithmetic which is consistent with AndroidNN's CPU executor.

Definition at line 26 of file ConvImpl.hpp.

Constructor & Destructor Documentation

◆ QuantizedMultiplierSmallerThanOne()

QuantizedMultiplierSmallerThanOne ( float  multiplier)

Constructs a QuantizedMultiplierSmallerThanOne which will multiply by the given multiplier.

This stores the appropriate integer quantities (derived from the given multiplier) for later use. The implementation of this function is adapted from Android NN's QuantizeMultiplierSmallerThanOne().

Definition at line 14 of file ConvImpl.cpp.

15 {
16  ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(multiplier >= 0.0f && multiplier < 1.0f,
17  "QuantizedMultiplierSmallerThanOne: multiplier must be between 0.0f and 1.0f.");
18  if (multiplier == 0.0f)
19  {
20  m_Multiplier = 0;
21  m_RightShift = 0;
22  }
23  else
24  {
25  const double q = std::frexp(multiplier, &m_RightShift);
26  m_RightShift = -m_RightShift;
27  int64_t qFixed = static_cast<int64_t>(::round(q * (1ll << 31)));
28  if (qFixed == (1ll << 31))
29  {
30  qFixed /= 2;
31  --m_RightShift;
32  }
33  m_Multiplier = static_cast<int32_t>(qFixed);
34  }
35 }

References ARMNN_THROW_INVALIDARG_MSG_IF_FALSE.

Member Function Documentation

◆ operator*()

int32_t operator* ( int32_t  rhs) const

The implementation of this function is adapted from Android NN's MultiplyByQuantizedMultiplierSmallerThanOne().

Definition at line 37 of file ConvImpl.cpp.

38 {
39  int32_t x = SaturatingRoundingDoublingHighMul(rhs, m_Multiplier);
40  return RoundingDivideByPOT(x, m_RightShift);
41 }

The documentation for this struct was generated from the following files:
ARMNN_THROW_INVALIDARG_MSG_IF_FALSE
#define ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(_cond, _str)
Definition: Exceptions.hpp:210