36 template<
typename IType>
44 virtual void Reset(
void*) = 0;
46 virtual IType Get()
const = 0;
48 virtual std::vector<float>
50 bool isDepthwise =
false) = 0;
53 template<
typename IType>
61 virtual void Reset(
void*) = 0;
63 virtual void Set(IType right) = 0;
65 virtual IType Get()
const = 0;
68 template<
typename T,
typename Base>
73 : m_Iterator(data), m_Start(data)
78 m_Iterator =
reinterpret_cast<T*
>(data);
92 m_Iterator += increment;
99 m_Iterator -= increment;
106 m_Iterator = m_Start + index;
124 float Get()
const override 129 const bool isDepthwise)
override 134 std::vector<float> decodedTensor;
135 decodedTensor.reserve(size);
137 for (uint32_t i = 0; i < size; ++i)
143 return decodedTensor;
149 const int32_t m_Offset;
161 float Get()
const override 166 const bool isDepthwise)
override 171 std::vector<float> decodedTensor;
172 decodedTensor.reserve(size);
174 for (uint32_t i = 0; i < size; ++i)
180 return decodedTensor;
185 const int32_t m_Offset;
198 float Get()
const override 203 const bool isDepthwise)
override 208 std::vector<float> decodedTensor;
209 decodedTensor.reserve(size);
211 for (uint32_t i = 0; i < size; ++i)
217 return decodedTensor;
222 const int32_t m_Offset;
235 float Get()
const override 240 const bool isDepthwise)
override 245 std::vector<float> decodedTensor;
246 decodedTensor.reserve(size);
248 for (uint32_t i = 0; i < size; ++i)
254 return decodedTensor;
259 const int32_t m_Offset;
272 float Get()
const override 279 const bool isDepthwise)
override 284 std::vector<float> decodedTensor;
285 decodedTensor.reserve(size);
287 for (uint32_t i = 0; i < size; ++i)
293 decodedTensor.emplace_back(val);
296 return decodedTensor;
310 float Get()
const override 317 const bool isDepthwise)
override 322 std::vector<float> decodedTensor;
323 decodedTensor.reserve(size);
325 for (uint32_t i = 0; i < size; ++i)
330 decodedTensor.emplace_back(val);
333 return decodedTensor;
348 float Get()
const override 353 const bool isDepthwise)
override 357 std::vector<float> decodedTensor;
359 decodedTensor.reserve(size);
360 decodedTensor.assign(m_Start, m_Start + size);
362 return decodedTensor;
375 float Get()
const override 377 return static_cast<float>(*m_Iterator) * m_Scale;
380 const bool isDepthwise)
override 385 std::vector<float> decodedTensor;
386 decodedTensor.reserve(size);
388 for (uint32_t i = 0; i < size; ++i)
391 decodedTensor.emplace_back(static_cast<float>(*m_Iterator) * m_Scale);
394 return decodedTensor;
411 float Get()
const override 413 return static_cast<float>(*m_Iterator);
416 const bool isDepthwise)
override 421 std::vector<float> decodedTensor;
422 decodedTensor.reserve(size);
424 for (uint32_t i = 0; i < size; ++i)
427 decodedTensor.emplace_back(static_cast<float>(*m_Iterator));
430 return decodedTensor;
443 int32_t
Get()
const override 448 const bool isDepthwise)
override 453 std::vector<float> decodedTensor;
454 decodedTensor.reserve(size);
456 for (uint32_t i = 0; i < size; ++i)
459 decodedTensor.emplace_back(static_cast<float>(*m_Iterator));
462 return decodedTensor;
475 float Get()
const override 480 const bool isDepthwise)
override 485 std::vector<float> decodedTensor;
486 decodedTensor.reserve(size);
488 for (uint32_t i = 0; i < size; ++i)
491 decodedTensor.emplace_back(*m_Iterator);
494 return decodedTensor;
513 const bool isDepthwise)
override 518 std::vector<float> decodedTensor;
519 decodedTensor.reserve(size);
521 for (uint32_t i = 0; i < size; ++i)
524 decodedTensor.emplace_back(*m_Iterator);
527 return decodedTensor;
540 void Set(
float right)
override 542 *m_Iterator = armnn::Quantize<uint8_t>(right, m_Scale, m_Offset);
545 float Get()
const override 552 const int32_t m_Offset;
564 void Set(
float right)
override 566 *m_Iterator = armnn::Quantize<int8_t>(right, m_Scale, m_Offset);
569 float Get()
const override 576 const int32_t m_Offset;
588 void Set(
float right)
override 590 *m_Iterator = armnn::Quantize<int8_t>(right, m_Scale, m_Offset);
593 float Get()
const override 600 const int32_t m_Offset;
612 void Set(
float right)
override 614 *m_Iterator = armnn::Quantize<int16_t>(right, m_Scale, m_Offset);
617 float Get()
const override 624 const int32_t m_Offset;
636 void Set(
float right)
override 641 float Get()
const override 658 void Set(
float right)
override 663 float Get()
const override 680 void Set(
float right)
override 685 float Get()
const override 700 void Set(
float right)
override 702 *m_Iterator =
static_cast<int32_t
>(right);
705 float Get()
const override 707 return static_cast<float>(*m_Iterator);
720 void Set(int32_t right)
override 725 int32_t
Get()
const override 740 void Set(
bool right)
override 753 template<
typename T,
typename Base>
758 unsigned int axisFactor = 0,
759 unsigned int axisDimensionality=0)
763 m_AxisDimensionality(axisDimensionality),
764 m_AxisFactor(axisFactor),
770 const unsigned int axis = 0)
776 m_AxisDimensionality = tensorShape[axis];
782 m_Iterator =
reinterpret_cast<T*
>(data);
783 m_Start = m_Iterator;
797 m_Index += increment;
804 m_Index -= decrement;
813 m_Iterator = m_Start + index;
814 if (index < m_AxisFactor)
820 m_AxisIndex = (index / m_AxisFactor) % m_AxisDimensionality;
828 SetIndexOnMem(index);
845 :
PerAxisIterator(data, tensorInfo.GetShape(), tensorInfo.GetQuantizationDim().value()),
846 m_Scales(tensorInfo.GetQuantizationScales())
849 float Get()
const override 857 return m_Scales[m_AxisIndex];
861 bool isDepthwise)
override 866 std::vector<float> decodedTensor;
867 decodedTensor.reserve(size);
869 for (uint32_t i = 0; i < size; ++i)
874 return decodedTensor;
878 std::vector<float> m_Scales;
889 *m_Iterator = armnn::Quantize<int8_t>(right, m_Scale[m_AxisIndex], 0);
900 return m_Scale[m_AxisIndex];
904 std::vector<float> m_Scale;
911 :
PerAxisIterator(data, tensorInfo.GetShape(), tensorInfo.GetQuantizationDim().value()),
912 m_Scales(tensorInfo.GetQuantizationScales())
915 float Get()
const override 923 return m_Scales[m_AxisIndex];
927 bool isDepthwise)
override 931 const uint32_t stepSize = isDepthwise ?
932 tensorShape[2] * tensorShape[3] : tensorShape.
GetNumElements() / tensorShape[0];
934 const uint32_t stepNum = size / stepSize;
936 std::vector<float> decodedTensor;
937 decodedTensor.reserve(size);
942 for (uint32_t step = 0; step < stepNum; ++step)
945 for (uint32_t i = 0; i < stepSize; ++i)
947 unsigned int index = step * stepSize + i;
952 return decodedTensor;
956 std::vector<float> m_Scales;
unsigned int GetNumElements() const
Function that calculates the tensor elements by multiplying all dimension size which are Specified...
PerAxisIterator & operator++() override
Float32Decoder(const float *data)
void Set(float right) override
ScaledInt32Decoder(const float scale)
void Set(int32_t right) override
BFloat16Decoder(const BFloat16 *data)
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const bool isDepthwise) override
unsigned int m_AxisFactor
virtual BaseIterator & operator-=(const unsigned int increment)=0
PerAxisIterator for per-axis quantization.
float Get() const override
PerAxisIterator(T *data=nullptr, const armnn::TensorShape &tensorShape=TensorShape(), const unsigned int axis=0)
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const bool isDepthwise) override
PerAxisIterator & operator[](const unsigned int index) override
QSymmS8Decoder(const float scale, const int32_t offset)
float Get() const override
QSymm16Encoder(const float scale, const int32_t offset)
static void ConvertBFloat16ToFloat32(const void *srcBFloat16Buffer, size_t numElements, float *dstFloat32Buffer)
void Reset(void *data) override
Int32ToInt32tEncoder(int32_t *data)
void Set(float right) override
ScaledInt32Decoder(const int32_t *data, const float scale)
int32_t Get() const override
QSymm16Decoder(const int16_t *data, const float scale, const int32_t offset)
BooleanDecoderBool(const uint8_t *data)
void Set(bool right) override
std::vector< float > DecodeTensor(const TensorShape &tensorShape, bool isDepthwise) override
QSymm8PerAxisDecoder(const int8_t *data, const armnn::TensorInfo &tensorInfo)
float Get() const override
QSymmS8Encoder(int8_t *data, const float scale, const int32_t offset)
float Get() const override
BFloat16Encoder(armnn::BFloat16 *data)
void Set(float right) override
QSymmS8Decoder(const int8_t *data, const float scale, const int32_t offset)
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const bool isDepthwise) override
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
float Get() const override
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const bool isDepthwise) override
void Set(float right) override
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const bool isDepthwise) override
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const bool isDepthwise) override
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const bool isDepthwise) override
float Get() const override
float Get() const override
QASymmS8Decoder(const int8_t *data, const float scale, const int32_t offset)
float Get() const override
unsigned int m_AxisDimensionality
Int32Decoder(const int32_t *data)
float Get() const override
virtual BaseIterator & operator[](const unsigned int index)=0
TypedIterator & operator[](const unsigned int index) override
QASymmS8Decoder(const float scale, const int32_t offset)
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const bool isDepthwise) override
QASymm8Encoder(const float scale, const int32_t offset)
static void ConvertFloat32To16(const float *srcFloat32Buffer, size_t numElements, void *dstFloat16Buffer)
Converts a buffer of FP32 values to FP16, and stores in the given dstFloat16Buffer.
float Get() const override
QSymmS8Encoder(const float scale, const int32_t offset)
ScaledInt32PerAxisDecoder(const int32_t *data, const armnn::TensorInfo tensorInfo)
Int32Encoder(int32_t *data)
void Set(float right) override
void Reset(void *data) override
virtual BaseIterator & operator++()=0
#define ARMNN_ASSERT(COND)
float Get() const override
QASymm8Encoder(uint8_t *data, const float scale, const int32_t offset)
float Get() const override
static void ConvertFloat16To32(const void *srcFloat16Buffer, size_t numElements, float *dstFloat32Buffer)
int32_t Get() const override
BooleanEncoder(uint8_t *data)
float Get() const override
bool Get() const override
PerAxisIterator(T *data=nullptr, unsigned int axisFactor=0, unsigned int axisDimensionality=0)
float Get() const override
float Get() const override
Float16Encoder(Half *data)
QSymm8PerAxisEncoder(int8_t *data, const std::vector< float > &scale, unsigned int axisFactor)
QASymm8Decoder(const float scale, const int32_t offset)
Int32ToInt32tDecoder(const int32_t *data)
TypedIterator & operator++() override
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const bool isDepthwise) override
Float16Decoder(const Half *data)
float Get() const override
float Get() const override
QASymmS8Encoder(const float scale, const int32_t offset)
PerAxisIterator & operator-=(const unsigned int decrement) override
virtual BaseIterator & operator+=(const unsigned int increment)=0
static void ConvertFloat32ToBFloat16(const float *srcFloat32Buffer, size_t numElements, void *dstBFloat16Buffer)
void Set(float right) override
QSymm16Decoder(const float scale, const int32_t offset)
Float32Encoder(float *data)
float Get() const override
QASymm8Decoder(const uint8_t *data, const float scale, const int32_t offset)
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const bool isDepthwise) override
TypedIterator & operator+=(const unsigned int increment) override
PerAxisIterator & SetIndexOnMem(const unsigned int index)
float Get() const override
QSymm16Encoder(int16_t *data, const float scale, const int32_t offset)
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const bool isDepthwise) override
unsigned int GetNumElementsAfter(const armnn::TensorShape &shape, unsigned int axis)
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const bool isDepthwise) override
PerAxisIterator & operator+=(const unsigned int increment) override
void Set(float right) override
std::vector< float > DecodeTensor(const TensorShape &tensorShape, bool isDepthwise) override
QASymmS8Encoder(int8_t *data, const float scale, const int32_t offset)
BooleanDecoder(const uint8_t *data)
TypedIterator & operator-=(const unsigned int increment) override
TypedIterator(T *data=nullptr)
void Set(float right) override
bool Get() const override
float Get() const override