ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::backend::cpu::ops::QuantizeLayer Class Reference

#include <QuantizeLayer.h>

Collaboration diagram for onert::backend::cpu::ops::QuantizeLayer:

Public Member Functions

 QuantizeLayer ()
 
void configure (const IPortableTensor *input, IPortableTensor *output)
 
void run () override
 
- Public Member Functions inherited from onert::exec::IFunction
virtual ~IFunction ()=default
 
virtual void prepare ()
 

Detailed Description

Definition at line 32 of file QuantizeLayer.h.

Constructor & Destructor Documentation

◆ QuantizeLayer()

onert::backend::cpu::ops::QuantizeLayer::QuantizeLayer ( )
inline

Definition at line 35 of file QuantizeLayer.h.

35 : _input(nullptr), _output(nullptr), _output_multiplier(0), _output_shift(0)
36 {
37 // DO NOTHING
38 }

Member Function Documentation

◆ configure()

void onert::backend::cpu::ops::QuantizeLayer::configure ( const IPortableTensor input,
IPortableTensor output 
)

Definition at line 42 of file QuantizeLayer.cc.

43{
44 assert(input != nullptr);
45 assert(output != nullptr);
46
47 _input = input;
48 _output = output;
49
50 if ((_input->data_type() == OperandType::FLOAT32))
51 {
52 // DO NOTHING
53 }
54 else if (((input->data_type() == OperandType::QUANT_UINT8_ASYMM) &&
55 (output->data_type() == OperandType::QUANT_INT8_ASYMM)) ||
56 ((input->data_type() == OperandType::QUANT_INT8_ASYMM) &&
57 (output->data_type() == OperandType::QUANT_UINT8_ASYMM)))
58 {
59 const double effective_output_scale =
60 static_cast<double>(input->data_scale()) / static_cast<double>(output->data_scale());
61 QuantizeMultiplier(effective_output_scale, &_output_multiplier, &_output_shift);
62 }
63 else
64 {
65 throw std::runtime_error{"Quantize: Unsupported data type"};
66 }
67}
ir::DataType data_type() const override final
void QuantizeMultiplier(double double_multiplier, int32_t *quantized_multiplier, int *shift)

References onert::backend::IPortableTensor::data_type(), and onert::backend::cpu::ops::QuantizeMultiplier().

◆ run()

void onert::backend::cpu::ops::QuantizeLayer::run ( )
overridevirtual

Implements onert::exec::IFunction.

Definition at line 69 of file QuantizeLayer.cc.

70{
71 if ((_input->data_type() == OperandType::FLOAT32))
72 {
73 affineQuantize<float, uint8_t>(_input, _output);
74 }
75 else if ((_input->data_type() == OperandType::QUANT_UINT8_ASYMM) &&
76 (_output->data_type() == OperandType::QUANT_INT8_ASYMM))
77 {
79 getBuffer<uint8_t>(_input), MatchingFlatSize(getShape(_input), getShape(_output)),
80 _output_multiplier, _output_shift, _input->data_zero_point(), _output->data_zero_point(),
81 getBuffer<int8_t>(_output));
82 }
83 else if ((_input->data_type() == OperandType::QUANT_INT8_ASYMM) &&
84 (_output->data_type() == OperandType::QUANT_UINT8_ASYMM))
85 {
87 getBuffer<int8_t>(_input), MatchingFlatSize(getShape(_input), getShape(_output)),
88 _output_multiplier, _output_shift, _input->data_zero_point(), _output->data_zero_point(),
89 getBuffer<uint8_t>(_output));
90 }
91 else
92 {
93 throw std::runtime_error{"Quantize: Unsupported data type"};
94 }
95}
int MatchingFlatSize(const Dims< N > &dims, const Dims< N > &check_dims_0)
Definition Dims.h:108
int32_t data_zero_point() const override final
void Requantize< int8_t, uint8_t >(const int8_t *input_data, int32_t size, int32_t effective_scale_multiplier, int32_t effective_scale_shift, int32_t input_zeropoint, int32_t output_zeropoint, uint8_t *output_data)
Definition Quantize.h:379
void Requantize< uint8_t, int8_t >(const uint8_t *input_data, int32_t size, int32_t effective_scale_multiplier, int32_t effective_scale_shift, int32_t input_zeropoint, int32_t output_zeropoint, int8_t *output_data)
Definition Quantize.h:311
nnfw::cker::Shape getShape(const IPortableTensor *tensor)

References onert::backend::IPortableTensor::data_type(), onert::backend::IPortableTensor::data_zero_point(), onert::backend::cpu::ops::getShape(), MatchingFlatSize(), nnfw::cker::Requantize< int8_t, uint8_t >(), and nnfw::cker::Requantize< uint8_t, int8_t >().

Referenced by package.infer.session::inference().


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