ArmNN
 22.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 16 of file ConvImpl.cpp.

References ARMNN_ASSERT.

17 {
18  ARMNN_ASSERT(multiplier >= 0.0f && multiplier < 1.0f);
19  if (multiplier == 0.0f)
20  {
21  m_Multiplier = 0;
22  m_RightShift = 0;
23  }
24  else
25  {
26  const double q = std::frexp(multiplier, &m_RightShift);
27  m_RightShift = -m_RightShift;
28  int64_t qFixed = static_cast<int64_t>(::round(q * (1ll << 31)));
29  ARMNN_ASSERT(qFixed <= (1ll << 31));
30  if (qFixed == (1ll << 31))
31  {
32  qFixed /= 2;
33  --m_RightShift;
34  }
35  ARMNN_ASSERT(m_RightShift >= 0);
36  ARMNN_ASSERT(qFixed <= std::numeric_limits<int32_t>::max());
37  m_Multiplier = static_cast<int32_t>(qFixed);
38  }
39 }
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

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 41 of file ConvImpl.cpp.

References ARMNN_ASSERT.

42 {
43  int32_t x = SaturatingRoundingDoublingHighMul(rhs, m_Multiplier);
44  return RoundingDivideByPOT(x, m_RightShift);
45 }

The documentation for this struct was generated from the following files: