ONE - On-device Neural Engine
|
#include "helpers.h"
Go to the source code of this file.
Macros | |
#define | CONVERT_DOWN_RTE_STR(x, type) (convert_##type##_rte((x))) |
#define | CONVERT_DOWN_RTE(x, type) CONVERT_DOWN_RTE_STR(x, type) |
#define | QUANTIZE_IMPL(type, size) |
#define | DEQUANTIZE_IMPL(type, size) |
#define | ASYMM_ROUNDING_DIVIDE_BY_POW2_IMPL(size) |
#define | ASYMM_MULT_IMPL(size) |
#define | ASYMM_EXP_ON_INTERVAL_BETWEEN_NEGATIVE_ONE_QUARTER_AND_0_EXCL_IMPL(size) |
#define | ASYMM_SELECT_USING_MASK_IMPL(size) |
#define | ASYMM_MASK_IF_ZERO_IMPL(size) |
#define | ASYMM_MASK_IF_NON_ZERO_IMPL(size) |
#define | EXP_BARREL_SHIFTER_IMPL(size) |
#define | ASYMM_EXP_ON_NEGATIVE_VALUES_IMPL(size) |
#define | ASYMM_SATURATING_ROUNDING_MULT_BY_POW2_IMPL(size) |
#define | ASYMM_ROUNDING_HALF_SUM_IMPL(size) |
#define | ASYMM_ONE_OVER_ONE_PLUS_X_FOR_X_IN_0_1_IMPL(size) |
#define | ASYMM_RESCALE_IMPL(size) |
#define | QUANTIZE_STR(input, offset, scale, type, size) quantize_##type##size(input, offset, scale) |
#define | QUANTIZE(input, offset, scale, type, size) QUANTIZE_STR(input, offset, scale, type, size) |
#define | DEQUANTIZE_STR(input, offset, scale, type, size) dequantize_##type##size(input, offset, scale) |
#define | DEQUANTIZE(input, offset, scale, type, size) DEQUANTIZE_STR(input, offset, scale, type, size) |
#define | ASYMM_ROUNDING_DIVIDE_BY_POW2(x, exponent, size) asymm_rounding_divide_by_POW2_##size(x, exponent) |
#define | ASYMM_MULT(a, b, size) asymm_mult##size(a, b) |
#define | ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE(x, quantized_multiplier, left_shift, size) ASYMM_MULT(x *((VEC_DATA_TYPE(int, size))(1) << (-left_shift)), quantized_multiplier, size) |
#define | ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE(x, quantized_multiplier, right_shift, size) ASYMM_ROUNDING_DIVIDE_BY_POW2(ASYMM_MULT(x, quantized_multiplier, size), right_shift, size) |
#define | ASYMM_EXP_ON_INTERVAL_BETWEEN_NEGATIVE_ONE_QUARTER_AND_0_EXCL(a, size) asymm_exp_on_interval_between_negative_one_quarter_and_0_excl##size(a) |
#define | ASYMM_SELECT_USING_MASK(if_mask, then_val, else_val, size) asymm_select_using_mask##size(if_mask, then_val, else_val) |
#define | ASYMM_MASK_IF_ZERO(a, size) asymm_mask_if_zero##size(a) |
#define | ASYMM_MASK_IF_NON_ZERO(a, size) asymm_mask_if_non_zero##size(a) |
#define | EXP_BARREL_SHIFTER(result, exponent, fp_multiplier, k_integer_bits, k_fractional_bits, remainder, size) |
#define | ASYMM_EXP_ON_NEGATIVE_VALUES(a, k_integer_bits, size) asymm_exp_on_negative_values##size(a, k_integer_bits) |
#define | ASYMM_ONE_OVER_ONE_PLUS_X_FOR_X_IN_0_1(a, size) asymm_one_over_one_plus_x_for_x_in_0_1##size(a) |
#define | ASYMM_SATURATING_ROUNDING_MULT_BY_POW2(x, exponent, size) asymm_saturating_rounding_mult_by_pow2##size(x, exponent) |
#define | ASYMM_ROUNDING_HALF_SUM(a, b, size) asymm_rounding_half_sum##size(a, b) |
#define | ASYMM_RESCALE(value, src_integer_bits, dst_integer_bits, size) asymm_rescale##size(value, src_integer_bits, dst_integer_bits) |
#define | MULTIPLY_BY_QUANTIZED_MULTIPLIER_IMPL(size) |
#define | MULTIPLY_BY_QUANTIZED_MULTIPLIER(input, qmul, shift, size) multiply_by_quantized_multiplier##size(input, qmul, shift) |
Functions | |
uchar | quantize_qasymm8 (float input, float offset, float scale) |
float | dequantize_qasymm8 (uchar input, float offset, float scale) |
float | dequantize_qasymm8_signed (char input, float offset, float scale) |
#define ASYMM_EXP_ON_INTERVAL_BETWEEN_NEGATIVE_ONE_QUARTER_AND_0_EXCL | ( | a, | |
size | |||
) | asymm_exp_on_interval_between_negative_one_quarter_and_0_excl##size(a) |
Definition at line 445 of file helpers_asymm.h.
#define ASYMM_EXP_ON_INTERVAL_BETWEEN_NEGATIVE_ONE_QUARTER_AND_0_EXCL_IMPL | ( | size | ) |
Calculates for x in [-1/4, 0).
[in] | size | Size of vector. |
Definition at line 189 of file helpers_asymm.h.
#define ASYMM_EXP_ON_NEGATIVE_VALUES | ( | a, | |
k_integer_bits, | |||
size | |||
) | asymm_exp_on_negative_values##size(a, k_integer_bits) |
Definition at line 455 of file helpers_asymm.h.
#define ASYMM_EXP_ON_NEGATIVE_VALUES_IMPL | ( | size | ) |
Calculates for x < 0.
[in] | size | Size of vector. |
Definition at line 286 of file helpers_asymm.h.
Definition at line 450 of file helpers_asymm.h.
#define ASYMM_MASK_IF_NON_ZERO_IMPL | ( | size | ) |
For each element of input vector, the corresponding bits of the result item are set if the input item is non-zero.
[in] | size | Size of vector. |
a
is non zero. Definition at line 256 of file helpers_asymm.h.
Definition at line 449 of file helpers_asymm.h.
#define ASYMM_MASK_IF_ZERO_IMPL | ( | size | ) |
For each element of input vector, the corresponding bits of the result item are set if the input item is zero.
[in] | size | Size of vector. |
a
is zero. Definition at line 241 of file helpers_asymm.h.
Definition at line 440 of file helpers_asymm.h.
#define ASYMM_MULT_BY_QUANT_MULTIPLIER_GREATER_THAN_ONE | ( | x, | |
quantized_multiplier, | |||
left_shift, | |||
size | |||
) | ASYMM_MULT(x *((VEC_DATA_TYPE(int, size))(1) << (-left_shift)), quantized_multiplier, size) |
Definition at line 441 of file helpers_asymm.h.
#define ASYMM_MULT_BY_QUANT_MULTIPLIER_LESS_THAN_ONE | ( | x, | |
quantized_multiplier, | |||
right_shift, | |||
size | |||
) | ASYMM_ROUNDING_DIVIDE_BY_POW2(ASYMM_MULT(x, quantized_multiplier, size), right_shift, size) |
Definition at line 443 of file helpers_asymm.h.
#define ASYMM_MULT_IMPL | ( | size | ) |
Product of two numbers, interpreting them as fixed-point values in the interval [-1, 1), rounding to the nearest value, and saturating -1 * -1 to the maximum value.
[in] | size | Size of vector. |
Definition at line 155 of file helpers_asymm.h.
#define ASYMM_ONE_OVER_ONE_PLUS_X_FOR_X_IN_0_1 | ( | a, | |
size | |||
) | asymm_one_over_one_plus_x_for_x_in_0_1##size(a) |
Definition at line 457 of file helpers_asymm.h.
#define ASYMM_ONE_OVER_ONE_PLUS_X_FOR_X_IN_0_1_IMPL | ( | size | ) |
Calculates for x in (0, 1).
[in] | size | Size of vector. |
Definition at line 391 of file helpers_asymm.h.
#define ASYMM_RESCALE | ( | value, | |
src_integer_bits, | |||
dst_integer_bits, | |||
size | |||
) | asymm_rescale##size(value, src_integer_bits, dst_integer_bits) |
Definition at line 462 of file helpers_asymm.h.
#define ASYMM_RESCALE_IMPL | ( | size | ) |
Considering the integer value as fixed-point, change the number of integer bits and update value accordingly.
[in] | size | Size of vector. |
Definition at line 423 of file helpers_asymm.h.
#define ASYMM_ROUNDING_DIVIDE_BY_POW2 | ( | x, | |
exponent, | |||
size | |||
) | asymm_rounding_divide_by_POW2_##size(x, exponent) |
Definition at line 438 of file helpers_asymm.h.
#define ASYMM_ROUNDING_DIVIDE_BY_POW2_IMPL | ( | size | ) |
Correctly-rounded-to-nearest division by a power-of-two.
[in] | size | Size of vector. |
Definition at line 135 of file helpers_asymm.h.
Definition at line 461 of file helpers_asymm.h.
#define ASYMM_ROUNDING_HALF_SUM_IMPL | ( | size | ) |
Calculates (a+b)/2, rounded to the nearest integer. Equivalent to VRHADD in the ARM NEON instruction set.
[in] | size | Size of vector. |
Definition at line 368 of file helpers_asymm.h.
#define ASYMM_SATURATING_ROUNDING_MULT_BY_POW2 | ( | x, | |
exponent, | |||
size | |||
) | asymm_saturating_rounding_mult_by_pow2##size(x, exponent) |
Definition at line 459 of file helpers_asymm.h.
#define ASYMM_SATURATING_ROUNDING_MULT_BY_POW2_IMPL | ( | size | ) |
Calculates the product of a integer value by a power of two, with either a positive exponent (equivalent to an arithmetic left shift, saturating) or a negative exponent (equivalent to an arithmetic right shift, rounding to nearest).
[in] | size | Size of vector. |
Definition at line 338 of file helpers_asymm.h.
#define ASYMM_SELECT_USING_MASK | ( | if_mask, | |
then_val, | |||
else_val, | |||
size | |||
) | asymm_select_using_mask##size(if_mask, then_val, else_val) |
Definition at line 447 of file helpers_asymm.h.
#define ASYMM_SELECT_USING_MASK_IMPL | ( | size | ) |
Each bit of the result is set to the corresponding bit of either then_val or else_val depending on whether the corresponding bit of if_mask is set. Equivalent to the VBSL instruction in ARM NEON.
[in] | size | Size of vector. |
then_val
or from else_val
depending on corresponding bit in if_mask
is set or not. Definition at line 226 of file helpers_asymm.h.
#define CONVERT_DOWN_RTE | ( | x, | |
type | |||
) | CONVERT_DOWN_RTE_STR(x, type) |
Definition at line 53 of file helpers_asymm.h.
#define CONVERT_DOWN_RTE_STR | ( | x, | |
type | |||
) | (convert_##type##_rte((x))) |
Convert the given vector with round to nearest even rounding mode
[in] | x | The target to be converted |
[in] | type | The target type |
Definition at line 52 of file helpers_asymm.h.
#define DEQUANTIZE | ( | input, | |
offset, | |||
scale, | |||
type, | |||
size | |||
) | DEQUANTIZE_STR(input, offset, scale, type, size) |
Definition at line 435 of file helpers_asymm.h.
#define DEQUANTIZE_IMPL | ( | type, | |
size | |||
) |
Dequantize a vector of values to floating-point
[in] | type | Input data type. |
[in] | size | Size of vector. |
Definition at line 122 of file helpers_asymm.h.
#define DEQUANTIZE_STR | ( | input, | |
offset, | |||
scale, | |||
type, | |||
size | |||
) | dequantize_##type##size(input, offset, scale) |
Definition at line 433 of file helpers_asymm.h.
#define EXP_BARREL_SHIFTER | ( | result, | |
exponent, | |||
fp_multiplier, | |||
k_integer_bits, | |||
k_fractional_bits, | |||
remainder, | |||
size | |||
) |
Definition at line 451 of file helpers_asymm.h.
#define EXP_BARREL_SHIFTER_IMPL | ( | size | ) |
Definition at line 264 of file helpers_asymm.h.
#define MULTIPLY_BY_QUANTIZED_MULTIPLIER | ( | input, | |
qmul, | |||
shift, | |||
size | |||
) | multiply_by_quantized_multiplier##size(input, qmul, shift) |
Definition at line 474 of file helpers_asymm.h.
#define MULTIPLY_BY_QUANTIZED_MULTIPLIER_IMPL | ( | size | ) |
Definition at line 465 of file helpers_asymm.h.
#define QUANTIZE | ( | input, | |
offset, | |||
scale, | |||
type, | |||
size | |||
) | QUANTIZE_STR(input, offset, scale, type, size) |
Definition at line 432 of file helpers_asymm.h.
#define QUANTIZE_IMPL | ( | type, | |
size | |||
) |
Quantize a vector of values from floating-point
[in] | type | Output data type. |
[in] | size | Size of vector. |
Definition at line 103 of file helpers_asymm.h.
#define QUANTIZE_STR | ( | input, | |
offset, | |||
scale, | |||
type, | |||
size | |||
) | quantize_##type##size(input, offset, scale) |
Definition at line 431 of file helpers_asymm.h.
|
inline |
Dequantize a scalar value from 8-bit asymmetric to floating-point
[in] | input | Input value to quantize |
[in] | offset | Quantization offset |
[in] | scale | Quantization scale |
Definition at line 78 of file helpers_asymm.h.
References offset().
|
inline |
Dequantize a scalar value from signed 8-bit asymmetric to floating-point
[in] | input | Input value to quantize |
[in] | offset | Quantization offset |
[in] | scale | Quantization scale |
Definition at line 91 of file helpers_asymm.h.
References offset().
|
inline |
Quantize a floating-point scalar value to 8-bit asymmetric
[in] | input | Input value to quantize |
[in] | offset | Quantization offset |
[in] | scale | Quantization scale |
Definition at line 63 of file helpers_asymm.h.
References CONVERT_DOWN_RTE, CONVERT_SAT, and offset().