| AIfES 2 2.0.0

aimath_q7.h
Go to the documentation of this file.
1
87 #ifndef AIMATH_Q7
88 #define AIMATH_Q7
89
90 #include "core/aifes_math.h"
91 #include "basic/base/aimath/aimath_basic.h"
92
99 #define AITENSOR_2D_Q7(shape, params, data) {aiq7, 2, shape, params, data}
100
112 #define Q7_TO_FLOAT(Q, S, Z) ((float) ((int16_t)(Q) - (int16_t)(Z)) / (float) (1 << (S)))
113
124 #define FLOAT_TO_Q7(F, S, Z) ((int8_t) ((int16_t)((F) * (1 << (S)) + ((F) >= 0 ? 0.5f : -0.5f)) + (int16_t)(Z)))
125
141 #define AISCALAR_Q7(F, S, Z) {FLOAT_TO_Q7(F, S, Z), S, Z}
142
143 typedef struct aimath_q7_params aimath_q7_params_t;
144 typedef struct aiscalar_q7 aiscalar_q7_t;
145
148 struct aimath_q7_params {
149 uint16_t shift;
150 int8_t zero_point;
151 };
152
155 struct aiscalar_q7 {
156 int8_t value;
157 uint16_t shift;
158 int8_t zero_point;
159 };
160
171 void aimath_q7_print_aitensor(const aitensor_t *tensor);
172
183 void aimath_q7_print_aiscalar(const void *scalar);
184
194 void aimath_q7_calc_q_params_from_f32(float min_value, float max_value, aimath_q7_params_t *q_params);
195
204 void aimath_q7_quantize_tensor_from_f32(const aitensor_t *tensor_f32, aitensor_t *tensor_q7);
205
210 extern const aimath_dtype_t *aiq7;
211
212 #endif // AIMATH_Q7
aifes_math.h
AIfES 2 math interface.
aimath_basic.h
Basic data-type independent math operations.
aimath_q7_quantize_tensor_from_f32
void aimath_q7_quantize_tensor_from_f32(const aitensor_t *tensor_f32, aitensor_t *tensor_q7)
Converts a float f32 tensor into a quantized q7 tensor.
aiq7
const aimath_dtype_t * aiq7
The Q7 data-type indicator.
aimath_q7_print_aiscalar
void aimath_q7_print_aiscalar(const void *scalar)
Printing a Q7 scalar to console.
aimath_q7_calc_q_params_from_f32
void aimath_q7_calc_q_params_from_f32(float min_value, float max_value, aimath_q7_params_t *q_params)
Calculates the aimath_q7_params parameters.
aimath_q7_print_aitensor
void aimath_q7_print_aitensor(const aitensor_t *tensor)
Printing a Q7 tensor to console.
aimath_dtype
Indicator for the used datatype.
Definition: aifes_math.h:44
aimath_q7_params
Parameters used for the quantized Q7 values, used as property of a tensor.
Definition: aimath_q7.h:148
aimath_q7_params::zero_point
int8_t zero_point
The zero point of the quantization.
Definition: aimath_q7.h:150
aimath_q7_params::shift
uint16_t shift
The scaling factor of the quantization (The total scale is calculated with )
Definition: aimath_q7.h:149
aiscalar_q7
Single quantized Q7 value/scalar.
Definition: aimath_q7.h:155
aiscalar_q7::zero_point
int8_t zero_point
The zero point of the quantization.
Definition: aimath_q7.h:158
aiscalar_q7::shift
uint16_t shift
The scaling factor of the quantization (The total scale is calculated with )
Definition: aimath_q7.h:157
aiscalar_q7::value
int8_t value
Quantized value .
Definition: aimath_q7.h:156
aitensor
A tensor in AIfES.
Definition: aifes_math.h:89