ArmNN
 22.08
EthosnRefQuantizedMultiplierSmallerThanOne 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 <EthosnRefConvImpl.hpp>

Public Member Functions

 EthosnRefQuantizedMultiplierSmallerThanOne (float multiplier)
 Constructs a EthosnRefQuantizedMultiplierSmallerThanOne 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 MultiplyByEthosnRefQuantizedMultiplierSmallerThanOne(). More...
 
int64_t operator* (int64_t rhs) const
 

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 25 of file EthosnRefConvImpl.hpp.

Constructor & Destructor Documentation

◆ EthosnRefQuantizedMultiplierSmallerThanOne()

Constructs a EthosnRefQuantizedMultiplierSmallerThanOne 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 EthosnRefConvImpl.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>(std::round(q * (1ll << 16)));
29  ARMNN_ASSERT(qFixed <= (1ll << 16));
30  if (qFixed == (1ll << 16))
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*() [1/2]

int32_t operator* ( int32_t  rhs) const

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

Definition at line 48 of file EthosnRefConvImpl.cpp.

References SATURATE_VAL_S_32S.

49 {
50  // Align with the implementation in NPU model
51  // See function WinogradFinalTransform::postscale_uint8 in winograd_final_transform.cpp
52  int64_t a_64(rhs);
53  int64_t b_64(m_Multiplier);
54  int64_t ab_64 = a_64 * b_64;
55 
56  ab_64 = ab_64 >> 15;
57  int32_t roundBit = (ab_64 >> m_RightShift) & 0x1;
58  int64_t resultShifted = (ab_64 >> (m_RightShift + 1)) + roundBit;
59 
60  return SATURATE_VAL_S_32S(9, resultShifted);
61 }
#define SATURATE_VAL_S_32S(WIDTH, VAL)

◆ operator*() [2/2]

int64_t operator* ( int64_t  rhs) const

Definition at line 63 of file EthosnRefConvImpl.cpp.

References SATURATE_VAL_S_32S.

64 {
65  // Align with the implementation in NPU model
66  // See function WinogradFinalTransform::postscale_uint8 in winograd_final_transform.cpp
67  int64_t a_64(rhs);
68  int64_t b_64(m_Multiplier);
69  int64_t ab_64 = a_64 * b_64;
70 
71  ab_64 = ab_64 >> 15;
72  int32_t roundBit = (ab_64 >> m_RightShift) & 0x1;
73  int64_t resultShifted = (ab_64 >> (m_RightShift + 1)) + roundBit;
74 
75  return SATURATE_VAL_S_32S(16, resultShifted);
76 }
#define SATURATE_VAL_S_32S(WIDTH, VAL)

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