36 template<
typename IType>
44 virtual void Reset(
void*) = 0;
46 virtual IType Get()
const = 0;
48 virtual std::vector<float>
50 const unsigned int channelMultiplier = 1,
51 bool isDepthwise =
false) = 0;
54 template<
typename IType>
62 virtual void Reset(
void*) = 0;
64 virtual void Set(IType right) = 0;
66 virtual IType Get()
const = 0;
69 template<
typename T,
typename Base>
74 : m_Iterator(data), m_Start(data)
79 m_Iterator =
reinterpret_cast<T*
>(data);
93 m_Iterator += increment;
100 m_Iterator -= increment;
107 m_Iterator = m_Start + index;
115 m_Iterator = m_Start + index;
133 float Get()
const override 138 const unsigned int channelMultiplier,
139 const bool isDepthwise)
override 144 std::vector<float> decodedTensor;
145 decodedTensor.reserve(size);
147 for (uint32_t i = 0; i < size; ++i)
153 return decodedTensor;
159 const int32_t m_Offset;
171 float Get()
const override 176 const unsigned int channelMultiplier,
177 const bool isDepthwise)
override 182 std::vector<float> decodedTensor;
183 decodedTensor.reserve(size);
185 for (uint32_t i = 0; i < size; ++i)
191 return decodedTensor;
196 const int32_t m_Offset;
209 float Get()
const override 214 const unsigned int channelMultiplier,
215 const bool isDepthwise)
override 220 std::vector<float> decodedTensor;
221 decodedTensor.reserve(size);
223 for (uint32_t i = 0; i < size; ++i)
229 return decodedTensor;
234 const int32_t m_Offset;
247 float Get()
const override 252 const unsigned int channelMultiplier,
253 const bool isDepthwise)
override 258 std::vector<float> decodedTensor;
259 decodedTensor.reserve(size);
261 for (uint32_t i = 0; i < size; ++i)
267 return decodedTensor;
272 const int32_t m_Offset;
285 float Get()
const override 292 const unsigned int channelMultiplier,
293 const bool isDepthwise)
override 298 std::vector<float> decodedTensor;
299 decodedTensor.reserve(size);
301 for (uint32_t i = 0; i < size; ++i)
307 decodedTensor.emplace_back(val);
310 return decodedTensor;
324 float Get()
const override 331 const unsigned int channelMultiplier,
332 const bool isDepthwise)
override 337 std::vector<float> decodedTensor;
338 decodedTensor.reserve(size);
340 for (uint32_t i = 0; i < size; ++i)
345 decodedTensor.emplace_back(val);
348 return decodedTensor;
363 float Get()
const override 368 const unsigned int channelMultiplier,
369 const bool isDepthwise)
override 373 std::vector<float> decodedTensor;
375 decodedTensor.reserve(size);
376 decodedTensor.assign(m_Start, m_Start + size);
378 return decodedTensor;
391 float Get()
const override 393 return static_cast<float>(*m_Iterator) * m_Scale;
396 const unsigned int channelMultiplier,
397 const bool isDepthwise)
override 402 std::vector<float> decodedTensor;
403 decodedTensor.reserve(size);
405 for (uint32_t i = 0; i < size; ++i)
408 decodedTensor.emplace_back(static_cast<float>(*m_Iterator) * m_Scale);
411 return decodedTensor;
428 float Get()
const override 430 return static_cast<float>(*m_Iterator);
433 const unsigned int channelMultiplier,
434 const bool isDepthwise)
override 439 std::vector<float> decodedTensor;
440 decodedTensor.reserve(size);
442 for (uint32_t i = 0; i < size; ++i)
445 decodedTensor.emplace_back(static_cast<float>(*m_Iterator));
448 return decodedTensor;
461 int32_t
Get()
const override 466 const unsigned int channelMultiplier,
467 const bool isDepthwise)
override 472 std::vector<float> decodedTensor;
473 decodedTensor.reserve(size);
475 for (uint32_t i = 0; i < size; ++i)
478 decodedTensor.emplace_back(*m_Iterator);
481 return decodedTensor;
494 float Get()
const override 499 const unsigned int channelMultiplier,
500 const bool isDepthwise)
override 505 std::vector<float> decodedTensor;
506 decodedTensor.reserve(size);
508 for (uint32_t i = 0; i < size; ++i)
511 decodedTensor.emplace_back(*m_Iterator);
514 return decodedTensor;
533 const unsigned int channelMultiplier,
534 const bool isDepthwise)
override 539 std::vector<float> decodedTensor;
540 decodedTensor.reserve(size);
542 for (uint32_t i = 0; i < size; ++i)
545 decodedTensor.emplace_back(*m_Iterator);
548 return decodedTensor;
561 void Set(
float right)
override 563 *m_Iterator = armnn::Quantize<uint8_t>(right, m_Scale, m_Offset);
566 float Get()
const override 573 const int32_t m_Offset;
585 void Set(
float right)
override 587 *m_Iterator = armnn::Quantize<int8_t>(right, m_Scale, m_Offset);
590 float Get()
const override 597 const int32_t m_Offset;
609 void Set(
float right)
override 611 *m_Iterator = armnn::Quantize<int8_t>(right, m_Scale, m_Offset);
614 float Get()
const override 621 const int32_t m_Offset;
633 void Set(
float right)
override 635 *m_Iterator = armnn::Quantize<int16_t>(right, m_Scale, m_Offset);
638 float Get()
const override 645 const int32_t m_Offset;
657 void Set(
float right)
override 662 float Get()
const override 679 void Set(
float right)
override 684 float Get()
const override 701 void Set(
float right)
override 706 float Get()
const override 721 void Set(
float right)
override 723 *m_Iterator =
static_cast<int32_t
>(right);
726 float Get()
const override 728 return static_cast<float>(*m_Iterator);
741 void Set(int32_t right)
override 746 int32_t
Get()
const override 761 void Set(
bool right)
override 773 template<
typename T,
typename Base>
779 : m_Iterator(data), m_Start(data), m_AxisIndex(0), m_AxisFactor(axisFactor)
786 m_Iterator = m_Start + index;
787 m_AxisIndex = axisIndex;
793 m_Iterator =
reinterpret_cast<T*
>(data);
794 m_Start = m_Iterator;
802 m_AxisIndex =
static_cast<unsigned int>(*m_Iterator) % m_AxisFactor;
809 m_Iterator += increment;
810 m_AxisIndex =
static_cast<unsigned int>(*m_Iterator) % m_AxisFactor;
817 m_Iterator -= decrement;
818 m_AxisIndex =
static_cast<unsigned int>(*m_Iterator) % m_AxisFactor;
825 m_Iterator = m_Start + index;
826 m_AxisIndex =
static_cast<unsigned int>(*m_Iterator) % m_AxisFactor;
843 float Get()
const override 851 return m_Scales[m_AxisIndex];
855 const unsigned int channelMultiplier,
856 bool isDepthwise)
override 859 const uint32_t scaleSize =
static_cast<uint32_t
>(m_Scales.size());
861 const uint32_t stepSize = isDepthwise ?
862 tensorShape[2] * tensorShape[3] : tensorShape.
GetNumElements() / tensorShape[0];
864 const uint32_t stepNum = size / (stepSize * channelMultiplier);
867 std::vector<float> decodedTensor;
868 decodedTensor.reserve(size);
873 for (uint32_t mult = 0; mult < channelMultiplier; ++mult)
875 for (uint32_t step = 0; step < stepNum; ++step)
877 scale = (channelMultiplier * step + mult) % scaleSize;
878 for (uint32_t i = 0; i < stepSize; ++i)
880 unsigned int index = mult * stepSize * channelMultiplier +
887 return decodedTensor;
891 std::vector<float> m_Scales;
902 *m_Iterator = armnn::Quantize<int8_t>(right, m_Scale[m_AxisIndex], 0);
913 return m_Scale[m_AxisIndex];
917 std::vector<float> m_Scale;
926 float Get()
const override 934 return m_Scales[m_AxisIndex];
938 const unsigned int channelMultiplier,
939 bool isDepthwise)
override 942 const uint32_t scaleSize =
static_cast<uint32_t
>(m_Scales.size());
944 const uint32_t stepSize = isDepthwise ?
945 tensorShape[2] * tensorShape[3] : tensorShape.
GetNumElements() / tensorShape[0];
947 const uint32_t stepNum = size / (stepSize * channelMultiplier);
950 std::vector<float> decodedTensor;
951 decodedTensor.reserve(size);
956 for (uint32_t mult = 0; mult < channelMultiplier; ++mult)
958 for (uint32_t step = 0; step < stepNum; ++step)
960 scale = (channelMultiplier * step + mult) % scaleSize;
961 for (uint32_t i = 0; i < stepSize; ++i)
963 unsigned int index = mult * stepSize * channelMultiplier +
970 return decodedTensor;
974 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)
QSymm8PerAxisDecoder(const int8_t *data, const std::vector< float > &scale, unsigned int axisFactor)
void Set(float right) override
ScaledInt32Decoder(const float scale)
void Set(int32_t right) override
BFloat16Decoder(const BFloat16 *data)
PerAxisIterator(T *data=nullptr, unsigned int axisFactor=0)
unsigned int m_AxisFactor
virtual BaseIterator & operator-=(const unsigned int increment)=0
float Get() const 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
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const unsigned int channelMultiplier, const bool isDepthwise) override
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const unsigned int channelMultiplier, bool isDepthwise) 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)
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const unsigned int channelMultiplier, const bool isDepthwise) override
void Set(bool right) override
float Get() const override
QSymmS8Encoder(int8_t *data, const float scale, const int32_t offset)
ScaledInt32PerAxisDecoder(const int32_t *data, const std::vector< float > &scales, unsigned int axisFactor)
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)
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
float Get() const override
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const unsigned int channelMultiplier, const bool isDepthwise) override
void Set(float right) override
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const unsigned int channelMultiplier, bool isDepthwise) override
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const unsigned int channelMultiplier, 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
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)
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)
Int32Encoder(int32_t *data)
void Set(float right) override
void Reset(void *data) override
virtual BaseIterator & operator++()=0
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const unsigned int channelMultiplier, const bool isDepthwise) override
#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)
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const unsigned int channelMultiplier, const bool isDepthwise) override
float Get() const override
bool Get() const override
float Get() const override
float Get() const override
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const unsigned int channelMultiplier, const bool isDepthwise) 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 unsigned int channelMultiplier, const bool isDepthwise) override
Float16Decoder(const Half *data)
virtual BaseIterator & SetIndex(unsigned int index, unsigned int axisIndex=0)=0
float Get() const override
float Get() const override
PerAxisIterator & SetIndex(unsigned int index, unsigned int axisIndex) override
QASymmS8Encoder(const float scale, const int32_t offset)
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const unsigned int channelMultiplier, const bool isDepthwise) override
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)
TypedIterator & operator+=(const unsigned int increment) override
float Get() const override
QSymm16Encoder(int16_t *data, const float scale, const int32_t offset)
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const unsigned int channelMultiplier, const bool isDepthwise) override
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const unsigned int channelMultiplier, const bool isDepthwise) override
PerAxisIterator & operator+=(const unsigned int increment) override
void Set(float right) override
QASymmS8Encoder(int8_t *data, const float scale, const int32_t offset)
BooleanDecoder(const uint8_t *data)
TypedIterator & SetIndex(unsigned int index, unsigned int axisIndex=0) override
TypedIterator & operator-=(const unsigned int increment) override
TypedIterator(T *data=nullptr)
std::vector< float > DecodeTensor(const TensorShape &tensorShape, const unsigned int channelMultiplier, const bool isDepthwise) override
void Set(float right) override
bool Get() const override
float Get() const override