AIfES 2
2.0.0
|
Definition of the Q7 (aiq7) data-type. More...
Go to the source code of this file.
Data Structures | |
struct | aimath_q7_params |
Parameters used for the quantized Q7 values, used as property of a tensor. More... | |
struct | aiscalar_q7 |
Single quantized Q7 value/scalar. More... | |
Typedefs | |
typedef struct aimath_q7_params | aimath_q7_params_t |
typedef struct aiscalar_q7 | aiscalar_q7_t |
Functions | |
void | aimath_q7_print_aitensor (const aitensor_t *tensor) |
Printing a Q7 tensor to console. More... | |
void | aimath_q7_print_aiscalar (const void *scalar) |
Printing a Q7 scalar to console. More... | |
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. More... | |
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. More... | |
Variables | |
const aimath_dtype_t * | aiq7 |
The Q7 data-type indicator. More... | |
Definition of the Q7 (aiq7) data-type.
The Q7 (aiq7) data-type stores data as quantized 8 bit integer values. In addition a scaling factor (shift) and a zero point (zero_point) is needed to fully define the value.
The Q7 quantization is an asymmetric 8 bit integer quantization that allows integer-only calculations on real values. A real value \( r \) is represented by an integer value \( q \), the scaling factor / shift \( s \) and the zero point \( z \) according to the following formula:
\[ r = 2^{-s} * (q - z) \]
To get the quantized value \( q \) out of a real value you have to calculate
\[ q = round(\frac{x}{2^{-s}} + z) \]
Example: Create a Q7 tensor
The tensor
\[ \left( \begin{array}{rrr} 0 & 1 & 2 \\ 3 & 4 & 5 \end{array}\right) \]
can be created with In C:
In C, C++ and on Arduino:
Example: Create a Q7 scalar
Either create it with the helper macro
or manually with
Example: Print a Q7 tensor to the console
Example: Print a Q7 scalar to the console
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.
Given a minimum and a maximum value, this function calculates the scaling shift and zero shift parameters for aimath_q7_params
min_value | Minimum value of a given range |
max_value | Maximum value of a given range |
*q_params | Pointer to write the results aimath_q7_params::zero_point and aimath_q7_params::shift into |
void aimath_q7_print_aiscalar | ( | const void * | scalar | ) |
Printing a Q7 scalar to console.
For users the function
is prefered.
*scalar | The scalar (type: aiscalar_q7_t) to print. |
void aimath_q7_print_aitensor | ( | const aitensor_t * | tensor | ) |
Printing a Q7 tensor to console.
For users the function
is prefered.
*tensor | The tensor to print. |
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.
Converts a float f32 tensor into a quantized q7 tensor by applying the aimath_q7_params_t given in the quantized q7 tensor
*tensor_f32 | Float f32 tensor to convert from |
*tensor_q7 | quantized q7 tensor to convert to, included aimath_q7_params must be set beforehand |
|
extern |
The Q7 data-type indicator.
Use this variable to configure some element with the Q7 data-type,