ONE - On-device Neural Engine
Loading...
Searching...
No Matches
luci_interpreter::kernels::Quantize Class Reference

#include <Quantize.h>

Collaboration diagram for luci_interpreter::kernels::Quantize:

Public Member Functions

 Quantize (const Tensor *input, Tensor *output)
 
const Tensorinput () const
 
Tensoroutput () const
 
void configure () override
 
void execute () const override
 
- Public Member Functions inherited from luci_interpreter::Kernel
virtual ~Kernel ()=default
 
const std::vector< const Tensor * > & getInputTensors () const
 
const std::vector< Tensor * > & getOutputTensors () const
 

Additional Inherited Members

- Protected Member Functions inherited from luci_interpreter::Kernel
 Kernel (std::vector< const Tensor * > inputs, std::vector< Tensor * > outputs)
 
- Protected Attributes inherited from luci_interpreter::Kernel
const std::vector< const Tensor * > _inputs
 
const std::vector< Tensor * > _outputs
 

Detailed Description

Definition at line 28 of file Quantize.h.

Constructor & Destructor Documentation

◆ Quantize()

luci_interpreter::kernels::Quantize::Quantize ( const Tensor input,
Tensor output 
)

Definition at line 64 of file Quantize.cpp.

64: Kernel({input}, {output}) {}
Kernel(std::vector< const Tensor * > inputs, std::vector< Tensor * > outputs)
Definition Kernel.h:31
const Tensor * input() const
Definition Quantize.h:33

References input().

Member Function Documentation

◆ configure()

void luci_interpreter::kernels::Quantize::configure ( )
overridevirtual

Implements luci_interpreter::Kernel.

Definition at line 66 of file Quantize.cpp.

67{
68
69 if (input()->element_type() == loco::DataType::S16)
70 LUCI_INTERPRETER_CHECK(input()->zero_point() == 0);
71
72 switch (input()->element_type())
73 {
74 case loco::DataType::FLOAT32:
75 {
76 LUCI_INTERPRETER_CHECK(output()->element_type() == loco::DataType::U8 ||
77 output()->element_type() == loco::DataType::S8 ||
78 output()->element_type() == loco::DataType::S16);
79 break;
80 }
81 case loco::DataType::S16:
82 case loco::DataType::S8:
83 case loco::DataType::U8:
84 {
85 LUCI_INTERPRETER_CHECK(output()->element_type() == loco::DataType::S8 ||
86 output()->element_type() == loco::DataType::U8 ||
87 output()->element_type() == loco::DataType::S16);
88 if (output()->element_type() == loco::DataType::S16)
89 {
90 LUCI_INTERPRETER_CHECK(output()->zero_point() == 0);
91 }
92 break;
93 }
94 default:
95 throw std::runtime_error("Unsupported type");
96 }
97
98 output()->resize(input()->shape());
99}
void resize(const Shape &new_shape)
Definition Tensor.cpp:56
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36

References input(), LUCI_INTERPRETER_CHECK, output(), and luci_interpreter::Tensor::resize().

◆ execute()

void luci_interpreter::kernels::Quantize::execute ( ) const
overridevirtual

Implements luci_interpreter::Kernel.

Definition at line 101 of file Quantize.cpp.

102{
103 switch (input()->element_type())
104 {
105 case loco::DataType::FLOAT32:
106 {
107 tflite::QuantizationParams op_params;
108 op_params.zero_point = output()->zero_point();
109 op_params.scale = output()->scale();
110 const auto input_data = getTensorData<float>(input());
111
112 switch (output()->element_type())
113 {
114 case loco::DataType::S8:
115 {
116 luci_interpreter_pal::Quantize(op_params, getTensorShape(input()), input_data,
117 getTensorShape(output()), getTensorData<int8_t>(output()));
118 break;
119 }
120 case loco::DataType::U8:
121 {
122 luci_interpreter_pal::Quantize(op_params, getTensorShape(input()), input_data,
124 getTensorData<uint8_t>(output()));
125 break;
126 }
127 case loco::DataType::S16:
128 {
129 luci_interpreter_pal::Quantize(op_params, getTensorShape(input()), input_data,
131 getTensorData<int16_t>(output()));
132 break;
133 }
134 default:
135 throw std::runtime_error("luci-intp Quantize(1) Unsupported type.");
136 }
137 break;
138 }
139 case loco::DataType::S16:
140 {
141 call_requantize<int16_t>(input(), output());
142 break;
143 }
144 case loco::DataType::S8:
145 {
146 call_requantize<int8_t>(input(), output());
147 break;
148 }
149 case loco::DataType::U8:
150 {
151 call_requantize<uint8_t>(input(), output());
152 break;
153 }
154 default:
155 throw std::runtime_error("luci-intp Quantize(2) Unsupported type.");
156 }
157}
float scale() const
Definition Tensor.h:109
int32_t zero_point() const
Definition Tensor.h:115
list input_data
Definition infer.py:29
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
Definition Utils.h:194

References luci_interpreter::kernels::getTensorShape(), input(), output(), luci_interpreter::Tensor::scale(), and luci_interpreter::Tensor::zero_point().

◆ input()

const Tensor * luci_interpreter::kernels::Quantize::input ( ) const
inline

Definition at line 33 of file Quantize.h.

33{ return _inputs[0]; }
const std::vector< const Tensor * > _inputs
Definition Kernel.h:52

References luci_interpreter::Kernel::_inputs.

Referenced by configure(), execute(), and Quantize().

◆ output()

Tensor * luci_interpreter::kernels::Quantize::output ( ) const
inline

Definition at line 34 of file Quantize.h.

34{ return _outputs[0]; }
const std::vector< Tensor * > _outputs
Definition Kernel.h:53

References luci_interpreter::Kernel::_outputs.

Referenced by configure(), and execute().


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