Prefer the standard integral types over custom type-aliases.
PiperOrigin-RevId: 323036134 Change-Id: Id035d66f9e37485eb059cfa5756440c4f72871d1
This commit is contained in:
parent
435d9b7858
commit
1d4a43b0bf
@ -209,6 +209,14 @@ config_setting(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
config_setting(
|
||||||
|
name = "tf_lite_static_memory",
|
||||||
|
values = {
|
||||||
|
"copt": "-DTF_LITE_STATIC_MEMORY",
|
||||||
|
"cpu": "k8",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "common",
|
name = "common",
|
||||||
srcs = [],
|
srcs = [],
|
||||||
@ -455,16 +463,12 @@ cc_library(
|
|||||||
"reference/integer_ops/add.h",
|
"reference/integer_ops/add.h",
|
||||||
"reference/integer_ops/conv.h",
|
"reference/integer_ops/conv.h",
|
||||||
"reference/integer_ops/depthwise_conv.h",
|
"reference/integer_ops/depthwise_conv.h",
|
||||||
"reference/integer_ops/dequantize.h",
|
|
||||||
"reference/integer_ops/fully_connected.h",
|
"reference/integer_ops/fully_connected.h",
|
||||||
"reference/integer_ops/l2normalization.h",
|
"reference/integer_ops/l2normalization.h",
|
||||||
"reference/integer_ops/log_softmax.h",
|
|
||||||
"reference/integer_ops/logistic.h",
|
"reference/integer_ops/logistic.h",
|
||||||
"reference/integer_ops/mean.h",
|
|
||||||
"reference/integer_ops/mul.h",
|
"reference/integer_ops/mul.h",
|
||||||
"reference/integer_ops/pooling.h",
|
"reference/integer_ops/pooling.h",
|
||||||
"reference/integer_ops/tanh.h",
|
"reference/integer_ops/tanh.h",
|
||||||
"reference/integer_ops/transpose_conv.h",
|
|
||||||
"reference/l2normalization.h",
|
"reference/l2normalization.h",
|
||||||
"reference/logistic.h",
|
"reference/logistic.h",
|
||||||
"reference/maximum_minimum.h",
|
"reference/maximum_minimum.h",
|
||||||
@ -477,17 +481,25 @@ cc_library(
|
|||||||
"reference/process_broadcast_shapes.h",
|
"reference/process_broadcast_shapes.h",
|
||||||
"reference/quantize.h",
|
"reference/quantize.h",
|
||||||
"reference/reduce.h",
|
"reference/reduce.h",
|
||||||
"reference/reference_ops.h",
|
|
||||||
"reference/requantize.h",
|
"reference/requantize.h",
|
||||||
"reference/resize_nearest_neighbor.h",
|
"reference/resize_nearest_neighbor.h",
|
||||||
"reference/round.h",
|
"reference/round.h",
|
||||||
"reference/softmax.h",
|
"reference/softmax.h",
|
||||||
"reference/sparse_ops/fully_connected.h",
|
|
||||||
"reference/strided_slice.h",
|
"reference/strided_slice.h",
|
||||||
"reference/sub.h",
|
"reference/sub.h",
|
||||||
"reference/svdf.h",
|
"reference/svdf.h",
|
||||||
"reference/tanh.h",
|
"reference/tanh.h",
|
||||||
],
|
] + select({
|
||||||
|
":tf_lite_static_memory": [],
|
||||||
|
"//conditions:default": [
|
||||||
|
"reference/integer_ops/dequantize.h",
|
||||||
|
"reference/integer_ops/log_softmax.h",
|
||||||
|
"reference/integer_ops/mean.h",
|
||||||
|
"reference/integer_ops/transpose_conv.h",
|
||||||
|
"reference/reference_ops.h",
|
||||||
|
"reference/sparse_ops/fully_connected.h",
|
||||||
|
],
|
||||||
|
}),
|
||||||
build_for_embedded = True,
|
build_for_embedded = True,
|
||||||
copts = tflite_copts(),
|
copts = tflite_copts(),
|
||||||
select_deps = {
|
select_deps = {
|
||||||
@ -787,7 +799,12 @@ cc_library(
|
|||||||
":freebsd": [
|
":freebsd": [
|
||||||
":sse_tensor_utils",
|
":sse_tensor_utils",
|
||||||
],
|
],
|
||||||
":windows": [":sse_tensor_utils"],
|
":windows": [
|
||||||
|
":sse_tensor_utils",
|
||||||
|
],
|
||||||
|
":tf_lite_static_memory": [
|
||||||
|
":portable_tensor_utils",
|
||||||
|
],
|
||||||
"//conditions:default": [
|
"//conditions:default": [
|
||||||
":portable_tensor_utils",
|
":portable_tensor_utils",
|
||||||
],
|
],
|
||||||
|
@ -138,23 +138,24 @@ inline void BiasAndClamp(float clamp_min, float clamp_max, int bias_size,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int32 MultiplyByQuantizedMultiplierSmallerThanOneExp(
|
inline int32_t MultiplyByQuantizedMultiplierSmallerThanOneExp(
|
||||||
int32 x, int32 quantized_multiplier, int left_shift) {
|
int32_t x, int32_t quantized_multiplier, int left_shift) {
|
||||||
using gemmlowp::RoundingDivideByPOT;
|
using gemmlowp::RoundingDivideByPOT;
|
||||||
using gemmlowp::SaturatingRoundingDoublingHighMul;
|
using gemmlowp::SaturatingRoundingDoublingHighMul;
|
||||||
return RoundingDivideByPOT(
|
return RoundingDivideByPOT(
|
||||||
SaturatingRoundingDoublingHighMul(x, quantized_multiplier), -left_shift);
|
SaturatingRoundingDoublingHighMul(x, quantized_multiplier), -left_shift);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int32 MultiplyByQuantizedMultiplierGreaterThanOne(
|
inline int32_t MultiplyByQuantizedMultiplierGreaterThanOne(
|
||||||
int32 x, int32 quantized_multiplier, int left_shift) {
|
int32_t x, int32_t quantized_multiplier, int left_shift) {
|
||||||
using gemmlowp::SaturatingRoundingDoublingHighMul;
|
using gemmlowp::SaturatingRoundingDoublingHighMul;
|
||||||
return SaturatingRoundingDoublingHighMul(x * (1 << left_shift),
|
return SaturatingRoundingDoublingHighMul(x * (1 << left_shift),
|
||||||
quantized_multiplier);
|
quantized_multiplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int32 MultiplyByQuantizedMultiplier(int32 x, int32 quantized_multiplier,
|
inline int32_t MultiplyByQuantizedMultiplier(int32_t x,
|
||||||
int shift) {
|
int32_t quantized_multiplier,
|
||||||
|
int shift) {
|
||||||
using gemmlowp::RoundingDivideByPOT;
|
using gemmlowp::RoundingDivideByPOT;
|
||||||
using gemmlowp::SaturatingRoundingDoublingHighMul;
|
using gemmlowp::SaturatingRoundingDoublingHighMul;
|
||||||
int left_shift = shift > 0 ? shift : 0;
|
int left_shift = shift > 0 ? shift : 0;
|
||||||
@ -164,16 +165,16 @@ inline int32 MultiplyByQuantizedMultiplier(int32 x, int32 quantized_multiplier,
|
|||||||
right_shift);
|
right_shift);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int32 MultiplyByQuantizedMultiplier(int64_t x,
|
inline int32_t MultiplyByQuantizedMultiplier(int64_t x,
|
||||||
int32 quantized_multiplier,
|
int32_t quantized_multiplier,
|
||||||
int shift) {
|
int shift) {
|
||||||
// Inputs:
|
// Inputs:
|
||||||
// - quantized_multiplier has fixed point at bit 31
|
// - quantized_multiplier has fixed point at bit 31
|
||||||
// - shift is -31 to +7 (negative for right shift)
|
// - shift is -31 to +7 (negative for right shift)
|
||||||
//
|
//
|
||||||
// Assumptions: The following input ranges are assumed
|
// Assumptions: The following input ranges are assumed
|
||||||
// - quantize_scale>=0 (the usual range is (1<<30) to (1>>31)-1)
|
// - quantize_scale>=0 (the usual range is (1<<30) to (1>>31)-1)
|
||||||
// - scaling is chosen so final scaled result fits in int32
|
// - scaling is chosen so final scaled result fits in int32_t
|
||||||
// - input x is in the range -(1<<47) <= x < (1<<47)
|
// - input x is in the range -(1<<47) <= x < (1<<47)
|
||||||
assert(quantized_multiplier >= 0);
|
assert(quantized_multiplier >= 0);
|
||||||
assert(shift >= -31 && shift < 8);
|
assert(shift >= -31 && shift < 8);
|
||||||
@ -218,9 +219,9 @@ inline int CountLeadingSignBits(T integer_input) {
|
|||||||
using U = typename std::make_unsigned<T>::type;
|
using U = typename std::make_unsigned<T>::type;
|
||||||
return integer_input >= 0
|
return integer_input >= 0
|
||||||
? CountLeadingZeros(static_cast<U>(integer_input)) - 1
|
? CountLeadingZeros(static_cast<U>(integer_input)) - 1
|
||||||
: integer_input != std::numeric_limits<T>::min()
|
: integer_input != std::numeric_limits<T>::min()
|
||||||
? CountLeadingZeros(2 * static_cast<U>(-integer_input) - 1)
|
? CountLeadingZeros(2 * static_cast<U>(-integer_input) - 1)
|
||||||
: 0;
|
: 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +263,7 @@ inline void gen_lut(const std::function<double(double)>& func, double min,
|
|||||||
std::min(std::max(TfLiteRound(func(max) * 32768.0), -32768.0), 32767.0);
|
std::min(std::max(TfLiteRound(func(max) * 32768.0), -32768.0), 32767.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// int16 func table lookup, e.g., lookup exp() and 1/(1+x) used in softmax
|
// int16_t func table lookup, e.g., lookup exp() and 1/(1+x) used in softmax
|
||||||
inline int16_t generic_int16_table_lookup(int16_t value, const int16_t* lut) {
|
inline int16_t generic_int16_table_lookup(int16_t value, const int16_t* lut) {
|
||||||
// 512 base value, lut[513] only for calculate slope
|
// 512 base value, lut[513] only for calculate slope
|
||||||
uint16_t index = static_cast<uint16_t>(256 + (value >> 7));
|
uint16_t index = static_cast<uint16_t>(256 + (value >> 7));
|
||||||
@ -413,21 +414,21 @@ SaturatingRoundingMultiplyByPOTParam(
|
|||||||
SaturatingRoundingMultiplyByPOTParam(a.raw(), exponent));
|
SaturatingRoundingMultiplyByPOTParam(a.raw(), exponent));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert int32 multiplier to int16 with rounding.
|
// Convert int32_t multiplier to int16_t with rounding.
|
||||||
inline void DownScaleInt32ToInt16Multiplier(int32_t multiplier_int32,
|
inline void DownScaleInt32ToInt16Multiplier(int32_t multiplier_int32_t,
|
||||||
int16_t* multiplier_int16) {
|
int16_t* multiplier_int16_t) {
|
||||||
TFLITE_DCHECK_GE(multiplier_int32, 0);
|
TFLITE_DCHECK_GE(multiplier_int32_t, 0);
|
||||||
static constexpr int32_t kRoundingOffset = 1 << 15;
|
static constexpr int32_t kRoundingOffset = 1 << 15;
|
||||||
if (multiplier_int32 >=
|
if (multiplier_int32_t >=
|
||||||
std::numeric_limits<int32_t>::max() - kRoundingOffset) {
|
std::numeric_limits<int32_t>::max() - kRoundingOffset) {
|
||||||
*multiplier_int16 = std::numeric_limits<int16_t>::max();
|
*multiplier_int16_t = std::numeric_limits<int16_t>::max();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const int32_t result = (multiplier_int32 + kRoundingOffset) >> 16;
|
const int32_t result = (multiplier_int32_t + kRoundingOffset) >> 16;
|
||||||
TFLITE_DCHECK_LE(result << 16, multiplier_int32 + kRoundingOffset);
|
TFLITE_DCHECK_LE(result << 16, multiplier_int32_t + kRoundingOffset);
|
||||||
TFLITE_DCHECK_GT(result << 16, multiplier_int32 - kRoundingOffset);
|
TFLITE_DCHECK_GT(result << 16, multiplier_int32_t - kRoundingOffset);
|
||||||
*multiplier_int16 = result;
|
*multiplier_int16_t = result;
|
||||||
TFLITE_DCHECK_EQ(*multiplier_int16, result);
|
TFLITE_DCHECK_EQ(*multiplier_int16_t, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Minimum output bits to accommodate log of maximum input range. It actually
|
// Minimum output bits to accommodate log of maximum input range. It actually
|
||||||
@ -438,15 +439,13 @@ inline void DownScaleInt32ToInt16Multiplier(int32_t multiplier_int32,
|
|||||||
// ceil(log(abs( log(2.^(0:127))+1 ))/log(2)); ...
|
// ceil(log(abs( log(2.^(0:127))+1 ))/log(2)); ...
|
||||||
// ceil(log(abs( log(2.^(0:127))+1 ))/log(2))]
|
// ceil(log(abs( log(2.^(0:127))+1 ))/log(2))]
|
||||||
constexpr int min_log_x_output_bits(int input_bits) {
|
constexpr int min_log_x_output_bits(int input_bits) {
|
||||||
return input_bits > 90
|
return input_bits > 90 ? 7
|
||||||
? 7
|
: input_bits > 44 ? 6
|
||||||
: input_bits > 44
|
: input_bits > 21 ? 5
|
||||||
? 6
|
: input_bits > 10 ? 4
|
||||||
: input_bits > 21
|
: input_bits > 4 ? 3
|
||||||
? 5
|
: input_bits > 1 ? 2
|
||||||
: input_bits > 10
|
: 1;
|
||||||
? 4
|
|
||||||
: input_bits > 4 ? 3 : input_bits > 1 ? 2 : 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Although currently the name of this function says that it cannot handle
|
// Although currently the name of this function says that it cannot handle
|
||||||
@ -454,17 +453,17 @@ constexpr int min_log_x_output_bits(int input_bits) {
|
|||||||
// x_max is the largest representable input. In other words, the output range
|
// x_max is the largest representable input. In other words, the output range
|
||||||
// is symmetric.
|
// is symmetric.
|
||||||
template <int OutputIntegerBits, int InputIntegerBits>
|
template <int OutputIntegerBits, int InputIntegerBits>
|
||||||
inline gemmlowp::FixedPoint<int32, OutputIntegerBits>
|
inline gemmlowp::FixedPoint<int32_t, OutputIntegerBits>
|
||||||
log_x_for_x_greater_than_or_equal_to_1_impl(
|
log_x_for_x_greater_than_or_equal_to_1_impl(
|
||||||
gemmlowp::FixedPoint<int32, InputIntegerBits> input_val) {
|
gemmlowp::FixedPoint<int32_t, InputIntegerBits> input_val) {
|
||||||
// assert(__builtin_clz(0u) >= std::numeric_limits<uint32>::digits - 1);
|
// assert(__builtin_clz(0u) >= std::numeric_limits<uint32_t>::digits - 1);
|
||||||
// assert(__builtin_clz(0u) <= std::numeric_limits<uint32>::digits);
|
// assert(__builtin_clz(0u) <= std::numeric_limits<uint32_t>::digits);
|
||||||
using FixedPoint0 = gemmlowp::FixedPoint<int32, 0>;
|
using FixedPoint0 = gemmlowp::FixedPoint<int32_t, 0>;
|
||||||
// The reason for accumulating the result with an extra bit of headroom is
|
// The reason for accumulating the result with an extra bit of headroom is
|
||||||
// that z_pow_2_adj * log_2 might be saturated, and adding num_scaled *
|
// that z_pow_2_adj * log_2 might be saturated, and adding num_scaled *
|
||||||
// recip_denom will otherwise introduce an error.
|
// recip_denom will otherwise introduce an error.
|
||||||
static constexpr int kAccumIntegerBits = OutputIntegerBits + 1;
|
static constexpr int kAccumIntegerBits = OutputIntegerBits + 1;
|
||||||
using FixedPointAccum = gemmlowp::FixedPoint<int32, kAccumIntegerBits>;
|
using FixedPointAccum = gemmlowp::FixedPoint<int32_t, kAccumIntegerBits>;
|
||||||
|
|
||||||
const FixedPoint0 log_2 = GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(
|
const FixedPoint0 log_2 = GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(
|
||||||
FixedPoint0, 1488522236, std::log(2.0));
|
FixedPoint0, 1488522236, std::log(2.0));
|
||||||
@ -492,10 +491,10 @@ log_x_for_x_greater_than_or_equal_to_1_impl(
|
|||||||
// required shift "ourselves" instead of using, say, Rescale.
|
// required shift "ourselves" instead of using, say, Rescale.
|
||||||
FixedPoint0 z_a = FixedPoint0::FromRaw(input_val.raw());
|
FixedPoint0 z_a = FixedPoint0::FromRaw(input_val.raw());
|
||||||
// z_a_pow_2 = input_integer_bits - z_a_headroom;
|
// z_a_pow_2 = input_integer_bits - z_a_headroom;
|
||||||
int z_a_headroom_plus_1 = CountLeadingZeros(static_cast<uint32>(z_a.raw()));
|
int z_a_headroom_plus_1 = CountLeadingZeros(static_cast<uint32_t>(z_a.raw()));
|
||||||
FixedPoint0 r_a_tmp =
|
FixedPoint0 r_a_tmp =
|
||||||
SaturatingRoundingMultiplyByPOTParam(z_a, (z_a_headroom_plus_1 - 1));
|
SaturatingRoundingMultiplyByPOTParam(z_a, (z_a_headroom_plus_1 - 1));
|
||||||
const int32 r_a_raw =
|
const int32_t r_a_raw =
|
||||||
SaturatingRoundingMultiplyByPOTParam((r_a_tmp * sqrt_half).raw(), 1);
|
SaturatingRoundingMultiplyByPOTParam((r_a_tmp * sqrt_half).raw(), 1);
|
||||||
// z_pow_2_adj = max(z_pow_2_a - 0.75, z_pow_2_b - 0.25);
|
// z_pow_2_adj = max(z_pow_2_a - 0.75, z_pow_2_b - 0.25);
|
||||||
// z_pow_2_adj = max(InputIntegerBits - z_a_headroom_plus_1 + 0.25,
|
// z_pow_2_adj = max(InputIntegerBits - z_a_headroom_plus_1 + 0.25,
|
||||||
@ -507,8 +506,8 @@ log_x_for_x_greater_than_or_equal_to_1_impl(
|
|||||||
|
|
||||||
// z_b is treated like z_a, but premultiplying by sqrt(0.5).
|
// z_b is treated like z_a, but premultiplying by sqrt(0.5).
|
||||||
FixedPoint0 z_b = z_a * sqrt_half;
|
FixedPoint0 z_b = z_a * sqrt_half;
|
||||||
int z_b_headroom = CountLeadingZeros(static_cast<uint32>(z_b.raw())) - 1;
|
int z_b_headroom = CountLeadingZeros(static_cast<uint32_t>(z_b.raw())) - 1;
|
||||||
const int32 r_b_raw =
|
const int32_t r_b_raw =
|
||||||
SaturatingRoundingMultiplyByPOTParam(z_a.raw(), z_b_headroom);
|
SaturatingRoundingMultiplyByPOTParam(z_a.raw(), z_b_headroom);
|
||||||
const FixedPointAccum z_b_pow_2_adj = SaturatingSub(
|
const FixedPointAccum z_b_pow_2_adj = SaturatingSub(
|
||||||
FixedPointAccum::FromRaw(SaturatingRoundingMultiplyByPOTParam(
|
FixedPointAccum::FromRaw(SaturatingRoundingMultiplyByPOTParam(
|
||||||
@ -536,9 +535,9 @@ log_x_for_x_greater_than_or_equal_to_1_impl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <int OutputIntegerBits, int InputIntegerBits>
|
template <int OutputIntegerBits, int InputIntegerBits>
|
||||||
inline gemmlowp::FixedPoint<int32, OutputIntegerBits>
|
inline gemmlowp::FixedPoint<int32_t, OutputIntegerBits>
|
||||||
log_x_for_x_greater_than_or_equal_to_1(
|
log_x_for_x_greater_than_or_equal_to_1(
|
||||||
gemmlowp::FixedPoint<int32, InputIntegerBits> input_val) {
|
gemmlowp::FixedPoint<int32_t, InputIntegerBits> input_val) {
|
||||||
static_assert(
|
static_assert(
|
||||||
OutputIntegerBits >= min_log_x_output_bits(InputIntegerBits),
|
OutputIntegerBits >= min_log_x_output_bits(InputIntegerBits),
|
||||||
"Output integer bits must be sufficient to accommodate logs of inputs.");
|
"Output integer bits must be sufficient to accommodate logs of inputs.");
|
||||||
@ -547,25 +546,25 @@ log_x_for_x_greater_than_or_equal_to_1(
|
|||||||
input_val);
|
input_val);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int32 GetReciprocal(int32 x, int x_integer_digits,
|
inline int32_t GetReciprocal(int32_t x, int x_integer_digits,
|
||||||
int* num_bits_over_unit) {
|
int* num_bits_over_unit) {
|
||||||
int headroom_plus_one = CountLeadingZeros(static_cast<uint32>(x));
|
int headroom_plus_one = CountLeadingZeros(static_cast<uint32_t>(x));
|
||||||
// This is the number of bits to the left of the binary point above 1.0.
|
// This is the number of bits to the left of the binary point above 1.0.
|
||||||
// Consider x=1.25. In that case shifted_scale=0.8 and
|
// Consider x=1.25. In that case shifted_scale=0.8 and
|
||||||
// no later adjustment will be needed.
|
// no later adjustment will be needed.
|
||||||
*num_bits_over_unit = x_integer_digits - headroom_plus_one;
|
*num_bits_over_unit = x_integer_digits - headroom_plus_one;
|
||||||
const int32 shifted_sum_minus_one =
|
const int32_t shifted_sum_minus_one =
|
||||||
static_cast<int32>((static_cast<uint32>(x) << headroom_plus_one) -
|
static_cast<int32_t>((static_cast<uint32_t>(x) << headroom_plus_one) -
|
||||||
(static_cast<uint32>(1) << 31));
|
(static_cast<uint32_t>(1) << 31));
|
||||||
|
|
||||||
gemmlowp::FixedPoint<int32, 0> shifted_scale =
|
gemmlowp::FixedPoint<int32_t, 0> shifted_scale =
|
||||||
gemmlowp::one_over_one_plus_x_for_x_in_0_1(
|
gemmlowp::one_over_one_plus_x_for_x_in_0_1(
|
||||||
gemmlowp::FixedPoint<int32, 0>::FromRaw(shifted_sum_minus_one));
|
gemmlowp::FixedPoint<int32_t, 0>::FromRaw(shifted_sum_minus_one));
|
||||||
return shifted_scale.raw();
|
return shifted_scale.raw();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void GetInvSqrtQuantizedMultiplierExp(int32 input, int reverse_shift,
|
inline void GetInvSqrtQuantizedMultiplierExp(int32_t input, int reverse_shift,
|
||||||
int32* output_inv_sqrt,
|
int32_t* output_inv_sqrt,
|
||||||
int* output_shift) {
|
int* output_shift) {
|
||||||
TFLITE_DCHECK_GE(input, 0);
|
TFLITE_DCHECK_GE(input, 0);
|
||||||
if (input <= 1) {
|
if (input <= 1) {
|
||||||
@ -585,7 +584,7 @@ inline void GetInvSqrtQuantizedMultiplierExp(int32 input, int reverse_shift,
|
|||||||
++*output_shift;
|
++*output_shift;
|
||||||
}
|
}
|
||||||
const unsigned max_left_shift_bits =
|
const unsigned max_left_shift_bits =
|
||||||
CountLeadingZeros(static_cast<uint32>(input)) - 1;
|
CountLeadingZeros(static_cast<uint32_t>(input)) - 1;
|
||||||
const unsigned max_left_shift_bit_pairs = max_left_shift_bits / 2;
|
const unsigned max_left_shift_bit_pairs = max_left_shift_bits / 2;
|
||||||
const unsigned left_shift_bit_pairs = max_left_shift_bit_pairs - 1;
|
const unsigned left_shift_bit_pairs = max_left_shift_bit_pairs - 1;
|
||||||
*output_shift -= left_shift_bit_pairs;
|
*output_shift -= left_shift_bit_pairs;
|
||||||
@ -597,8 +596,8 @@ inline void GetInvSqrtQuantizedMultiplierExp(int32 input, int reverse_shift,
|
|||||||
using gemmlowp::SaturatingRoundingMultiplyByPOT;
|
using gemmlowp::SaturatingRoundingMultiplyByPOT;
|
||||||
// Using 3 integer bits gives us enough room for the internal arithmetic in
|
// Using 3 integer bits gives us enough room for the internal arithmetic in
|
||||||
// this Newton-Raphson iteration.
|
// this Newton-Raphson iteration.
|
||||||
using F3 = FixedPoint<int32, 3>;
|
using F3 = FixedPoint<int32_t, 3>;
|
||||||
using F0 = FixedPoint<int32, 0>;
|
using F0 = FixedPoint<int32_t, 0>;
|
||||||
const F3 fixedpoint_input = F3::FromRaw(input >> 1);
|
const F3 fixedpoint_input = F3::FromRaw(input >> 1);
|
||||||
const F3 fixedpoint_half_input =
|
const F3 fixedpoint_half_input =
|
||||||
SaturatingRoundingMultiplyByPOT<-1>(fixedpoint_input);
|
SaturatingRoundingMultiplyByPOT<-1>(fixedpoint_input);
|
||||||
|
@ -76,13 +76,15 @@ limitations under the License.
|
|||||||
#define TFLITE_CHECK_LT(x, y) ((x) < (y)) ? (void)0 : TFLITE_ABORT
|
#define TFLITE_CHECK_LT(x, y) ((x) < (y)) ? (void)0 : TFLITE_ABORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO(ahentz): Clean up.
|
#ifndef TF_LITE_STATIC_MEMORY
|
||||||
|
// TODO(b/162019032): Consider removing these type-aliases.
|
||||||
using int8 = std::int8_t;
|
using int8 = std::int8_t;
|
||||||
using uint8 = std::uint8_t;
|
using uint8 = std::uint8_t;
|
||||||
using int16 = std::int16_t;
|
using int16 = std::int16_t;
|
||||||
using uint16 = std::uint16_t;
|
using uint16 = std::uint16_t;
|
||||||
using int32 = std::int32_t;
|
using int32 = std::int32_t;
|
||||||
using uint32 = std::uint32_t;
|
using uint32 = std::uint32_t;
|
||||||
|
#endif // !defined(TF_LITE_STATIC_MEMORY)
|
||||||
|
|
||||||
// TFLITE_DEPRECATED()
|
// TFLITE_DEPRECATED()
|
||||||
//
|
//
|
||||||
|
@ -342,13 +342,13 @@ void NudgeQuantizationRange(const float min, const float max,
|
|||||||
const float quant_max_float = static_cast<float>(quant_max);
|
const float quant_max_float = static_cast<float>(quant_max);
|
||||||
*nudged_scale = (max - min) / (quant_max_float - quant_min_float);
|
*nudged_scale = (max - min) / (quant_max_float - quant_min_float);
|
||||||
const float zero_point_from_min = quant_min_float - min / *nudged_scale;
|
const float zero_point_from_min = quant_min_float - min / *nudged_scale;
|
||||||
uint16 nudged_zero_point;
|
uint16_t nudged_zero_point;
|
||||||
if (zero_point_from_min < quant_min_float) {
|
if (zero_point_from_min < quant_min_float) {
|
||||||
nudged_zero_point = static_cast<uint16>(quant_min);
|
nudged_zero_point = static_cast<uint16_t>(quant_min);
|
||||||
} else if (zero_point_from_min > quant_max_float) {
|
} else if (zero_point_from_min > quant_max_float) {
|
||||||
nudged_zero_point = static_cast<uint16>(quant_max);
|
nudged_zero_point = static_cast<uint16_t>(quant_max);
|
||||||
} else {
|
} else {
|
||||||
nudged_zero_point = static_cast<uint16>(TfLiteRound(zero_point_from_min));
|
nudged_zero_point = static_cast<uint16_t>(TfLiteRound(zero_point_from_min));
|
||||||
}
|
}
|
||||||
*nudged_min = (quant_min_float - nudged_zero_point) * (*nudged_scale);
|
*nudged_min = (quant_min_float - nudged_zero_point) * (*nudged_scale);
|
||||||
*nudged_max = (quant_max_float - nudged_zero_point) * (*nudged_scale);
|
*nudged_max = (quant_max_float - nudged_zero_point) * (*nudged_scale);
|
||||||
|
@ -76,12 +76,12 @@ class VectorOfTensors {
|
|||||||
|
|
||||||
// A list of quantized tensors in a format that can be used by kernels like
|
// A list of quantized tensors in a format that can be used by kernels like
|
||||||
// split and concatenation.
|
// split and concatenation.
|
||||||
class VectorOfQuantizedTensors : public VectorOfTensors<uint8> {
|
class VectorOfQuantizedTensors : public VectorOfTensors<uint8_t> {
|
||||||
public:
|
public:
|
||||||
// Build with the tensors in 'tensor_list'.
|
// Build with the tensors in 'tensor_list'.
|
||||||
VectorOfQuantizedTensors(const TfLiteContext& context,
|
VectorOfQuantizedTensors(const TfLiteContext& context,
|
||||||
const TfLiteIntArray& tensor_list)
|
const TfLiteIntArray& tensor_list)
|
||||||
: VectorOfTensors<uint8>(context, tensor_list) {
|
: VectorOfTensors<uint8_t>(context, tensor_list) {
|
||||||
for (int i = 0; i < tensor_list.size; ++i) {
|
for (int i = 0; i < tensor_list.size; ++i) {
|
||||||
TfLiteTensor* t = &context.tensors[tensor_list.data[i]];
|
TfLiteTensor* t = &context.tensors[tensor_list.data[i]];
|
||||||
zero_point_.push_back(t->params.zero_point);
|
zero_point_.push_back(t->params.zero_point);
|
||||||
@ -90,10 +90,10 @@ class VectorOfQuantizedTensors : public VectorOfTensors<uint8> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const float* scale() const { return scale_.data(); }
|
const float* scale() const { return scale_.data(); }
|
||||||
const int32* zero_point() const { return zero_point_.data(); }
|
const int32_t* zero_point() const { return zero_point_.data(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<int32> zero_point_;
|
std::vector<int32_t> zero_point_;
|
||||||
std::vector<float> scale_;
|
std::vector<float> scale_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@ limitations under the License.
|
|||||||
|
|
||||||
#include "tensorflow/lite/kernels/internal/optimized/neon_check.h"
|
#include "tensorflow/lite/kernels/internal/optimized/neon_check.h"
|
||||||
|
|
||||||
#if defined(__SSSE3__)
|
#if defined(__SSSE3__) && !defined(TF_LITE_STATIC_MEMORY)
|
||||||
#include "tensorflow/lite/kernels/internal/optimized/sse_tensor_utils.h"
|
#include "tensorflow/lite/kernels/internal/optimized/sse_tensor_utils.h"
|
||||||
#elif defined(USE_NEON)
|
#elif defined(USE_NEON) && !defined(TF_LITE_STATIC_MEMORY)
|
||||||
#include "tensorflow/lite/kernels/internal/optimized/neon_tensor_utils.h"
|
#include "tensorflow/lite/kernels/internal/optimized/neon_tensor_utils.h"
|
||||||
#else
|
#else
|
||||||
#include "tensorflow/lite/kernels/internal/reference/portable_tensor_utils.h"
|
#include "tensorflow/lite/kernels/internal/reference/portable_tensor_utils.h"
|
||||||
|
@ -24,24 +24,29 @@ limitations under the License.
|
|||||||
|
|
||||||
namespace tflite {
|
namespace tflite {
|
||||||
|
|
||||||
enum class FusedActivationFunctionType : uint8 { kNone, kRelu6, kRelu1, kRelu };
|
enum class FusedActivationFunctionType : uint8_t {
|
||||||
enum class PaddingType : uint8 { kNone, kSame, kValid };
|
kNone,
|
||||||
|
kRelu6,
|
||||||
|
kRelu1,
|
||||||
|
kRelu
|
||||||
|
};
|
||||||
|
enum class PaddingType : uint8_t { kNone, kSame, kValid };
|
||||||
|
|
||||||
struct PaddingValues {
|
struct PaddingValues {
|
||||||
int16 width;
|
int16_t width;
|
||||||
int16 height;
|
int16_t height;
|
||||||
// offset is used for calculating "remaining" padding, for example, `width`
|
// offset is used for calculating "remaining" padding, for example, `width`
|
||||||
// is 1 and `width_offset` is 1, so padding_left is 1 while padding_right is
|
// is 1 and `width_offset` is 1, so padding_left is 1 while padding_right is
|
||||||
// 1 + 1 = 2.
|
// 1 + 1 = 2.
|
||||||
int16 width_offset;
|
int16_t width_offset;
|
||||||
// Same as width_offset except it's over the height dimension.
|
// Same as width_offset except it's over the height dimension.
|
||||||
int16 height_offset;
|
int16_t height_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This enumeration allows for non-default formats for the weights array
|
// This enumeration allows for non-default formats for the weights array
|
||||||
// of a fully-connected operator, allowing the use of special optimized
|
// of a fully-connected operator, allowing the use of special optimized
|
||||||
// runtime paths.
|
// runtime paths.
|
||||||
enum class FullyConnectedWeightsFormat : uint8 {
|
enum class FullyConnectedWeightsFormat : uint8_t {
|
||||||
// Default format (flat 2D layout, the inner contiguous dimension
|
// Default format (flat 2D layout, the inner contiguous dimension
|
||||||
// is input_depth, the outer non-contiguous dimension is output_depth)
|
// is input_depth, the outer non-contiguous dimension is output_depth)
|
||||||
kDefault,
|
kDefault,
|
||||||
@ -88,11 +93,11 @@ enum class FullyConnectedWeightsFormat : uint8 {
|
|||||||
// maximize arithmetic throughput.
|
// maximize arithmetic throughput.
|
||||||
//
|
//
|
||||||
// Finally, the 'Int8' part in the name refers to the fact that this
|
// Finally, the 'Int8' part in the name refers to the fact that this
|
||||||
// weights format has each weights value encoded as a signed int8 value,
|
// weights format has each weights value encoded as a signed int8_t value,
|
||||||
// even if the data type of the weights buffer is uint8. This is intended
|
// even if the data type of the weights buffer is uint8_t. This is intended
|
||||||
// to save runtime kernels the effort to have to XOR the top bit of these
|
// to save runtime kernels the effort to have to XOR the top bit of these
|
||||||
// bytes before using them in signed arithmetic, see this file for more
|
// bytes before using them in signed arithmetic, see this file for more
|
||||||
// explanations on the 'signed int8 trick' in matrix multiplication kernels:
|
// explanations on the 'signed int8_t trick' in matrix multiplication kernels:
|
||||||
//
|
//
|
||||||
// tensorflow/lite/toco/graph_transformations/ensure_uint8_weights_safe_for_fast_int8_kernels.cc
|
// tensorflow/lite/toco/graph_transformations/ensure_uint8_weights_safe_for_fast_int8_kernels.cc
|
||||||
//
|
//
|
||||||
@ -111,7 +116,7 @@ enum class FullyConnectedWeightsFormat : uint8 {
|
|||||||
// the real 0 value, and scale designates the difference between the real values
|
// the real 0 value, and scale designates the difference between the real values
|
||||||
// corresponding to consecutive quantized values differing by 1.
|
// corresponding to consecutive quantized values differing by 1.
|
||||||
struct QuantizationParams {
|
struct QuantizationParams {
|
||||||
int32 zero_point = 0;
|
int32_t zero_point = 0;
|
||||||
double scale = 0.0;
|
double scale = 0.0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -141,19 +146,19 @@ class RuntimeShape {
|
|||||||
#ifdef TF_LITE_STATIC_MEMORY
|
#ifdef TF_LITE_STATIC_MEMORY
|
||||||
TFLITE_CHECK(false && "No shape resizing supported on this platform");
|
TFLITE_CHECK(false && "No shape resizing supported on this platform");
|
||||||
#else // TF_LITE_STATIC_MEMORY
|
#else // TF_LITE_STATIC_MEMORY
|
||||||
dims_pointer_ = new int32[dimensions_count];
|
dims_pointer_ = new int32_t[dimensions_count];
|
||||||
#endif // TF_LITE_STATIC_MEMORY
|
#endif // TF_LITE_STATIC_MEMORY
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RuntimeShape(int shape_size, int32 value) : size_(0) {
|
RuntimeShape(int shape_size, int32_t value) : size_(0) {
|
||||||
Resize(shape_size);
|
Resize(shape_size);
|
||||||
for (int i = 0; i < shape_size; ++i) {
|
for (int i = 0; i < shape_size; ++i) {
|
||||||
SetDim(i, value);
|
SetDim(i, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RuntimeShape(int dimensions_count, const int32* dims_data) : size_(0) {
|
RuntimeShape(int dimensions_count, const int32_t* dims_data) : size_(0) {
|
||||||
ReplaceWith(dimensions_count, dims_data);
|
ReplaceWith(dimensions_count, dims_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,14 +170,15 @@ class RuntimeShape {
|
|||||||
// rolls out.
|
// rolls out.
|
||||||
RuntimeShape(RuntimeShape const& other) : size_(other.DimensionsCount()) {
|
RuntimeShape(RuntimeShape const& other) : size_(other.DimensionsCount()) {
|
||||||
if (size_ > kMaxSmallSize) {
|
if (size_ > kMaxSmallSize) {
|
||||||
dims_pointer_ = new int32[size_];
|
dims_pointer_ = new int32_t[size_];
|
||||||
}
|
}
|
||||||
std::memcpy(DimsData(), other.DimsData(), sizeof(int32) * size_);
|
std::memcpy(DimsData(), other.DimsData(), sizeof(int32_t) * size_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const RuntimeShape& comp) const {
|
bool operator==(const RuntimeShape& comp) const {
|
||||||
return this->size_ == comp.size_ &&
|
return this->size_ == comp.size_ &&
|
||||||
std::memcmp(DimsData(), comp.DimsData(), size_ * sizeof(int32)) == 0;
|
std::memcmp(DimsData(), comp.DimsData(), size_ * sizeof(int32_t)) ==
|
||||||
|
0;
|
||||||
}
|
}
|
||||||
|
|
||||||
~RuntimeShape() {
|
~RuntimeShape() {
|
||||||
@ -185,13 +191,13 @@ class RuntimeShape {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int32 DimensionsCount() const { return size_; }
|
inline int32_t DimensionsCount() const { return size_; }
|
||||||
inline int32 Dims(int i) const {
|
inline int32_t Dims(int i) const {
|
||||||
TFLITE_DCHECK_GE(i, 0);
|
TFLITE_DCHECK_GE(i, 0);
|
||||||
TFLITE_DCHECK_LT(i, size_);
|
TFLITE_DCHECK_LT(i, size_);
|
||||||
return size_ > kMaxSmallSize ? dims_pointer_[i] : dims_[i];
|
return size_ > kMaxSmallSize ? dims_pointer_[i] : dims_[i];
|
||||||
}
|
}
|
||||||
inline void SetDim(int i, int32 val) {
|
inline void SetDim(int i, int32_t val) {
|
||||||
TFLITE_DCHECK_GE(i, 0);
|
TFLITE_DCHECK_GE(i, 0);
|
||||||
TFLITE_DCHECK_LT(i, size_);
|
TFLITE_DCHECK_LT(i, size_);
|
||||||
if (size_ > kMaxSmallSize) {
|
if (size_ > kMaxSmallSize) {
|
||||||
@ -201,14 +207,14 @@ class RuntimeShape {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int32* DimsData() {
|
inline int32_t* DimsData() {
|
||||||
return size_ > kMaxSmallSize ? dims_pointer_ : dims_;
|
return size_ > kMaxSmallSize ? dims_pointer_ : dims_;
|
||||||
}
|
}
|
||||||
inline const int32* DimsData() const {
|
inline const int32_t* DimsData() const {
|
||||||
return size_ > kMaxSmallSize ? dims_pointer_ : dims_;
|
return size_ > kMaxSmallSize ? dims_pointer_ : dims_;
|
||||||
}
|
}
|
||||||
// The caller must ensure that the shape is no bigger than 5-D.
|
// The caller must ensure that the shape is no bigger than 5-D.
|
||||||
inline const int32* DimsDataUpTo5D() const { return dims_; }
|
inline const int32_t* DimsDataUpTo5D() const { return dims_; }
|
||||||
|
|
||||||
inline void Resize(int dimensions_count) {
|
inline void Resize(int dimensions_count) {
|
||||||
if (size_ > kMaxSmallSize) {
|
if (size_ > kMaxSmallSize) {
|
||||||
@ -223,15 +229,15 @@ class RuntimeShape {
|
|||||||
#ifdef TF_LITE_STATIC_MEMORY
|
#ifdef TF_LITE_STATIC_MEMORY
|
||||||
TFLITE_CHECK(false && "No shape resizing supported on this platform");
|
TFLITE_CHECK(false && "No shape resizing supported on this platform");
|
||||||
#else // TF_LITE_STATIC_MEMORY
|
#else // TF_LITE_STATIC_MEMORY
|
||||||
dims_pointer_ = new int32[dimensions_count];
|
dims_pointer_ = new int32_t[dimensions_count];
|
||||||
#endif // TF_LITE_STATIC_MEMORY
|
#endif // TF_LITE_STATIC_MEMORY
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void ReplaceWith(int dimensions_count, const int32* dims_data) {
|
inline void ReplaceWith(int dimensions_count, const int32_t* dims_data) {
|
||||||
Resize(dimensions_count);
|
Resize(dimensions_count);
|
||||||
int32* dst_dims = DimsData();
|
int32_t* dst_dims = DimsData();
|
||||||
std::memcpy(dst_dims, dims_data, dimensions_count * sizeof(int32));
|
std::memcpy(dst_dims, dims_data, dimensions_count * sizeof(int32_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -239,7 +245,7 @@ class RuntimeShape {
|
|||||||
const int dimensions_count =
|
const int dimensions_count =
|
||||||
std::distance(src_iterable.begin(), src_iterable.end());
|
std::distance(src_iterable.begin(), src_iterable.end());
|
||||||
Resize(dimensions_count);
|
Resize(dimensions_count);
|
||||||
int32* data = DimsData();
|
int32_t* data = DimsData();
|
||||||
for (auto it : src_iterable) {
|
for (auto it : src_iterable) {
|
||||||
*data = it;
|
*data = it;
|
||||||
++data;
|
++data;
|
||||||
@ -288,13 +294,13 @@ class RuntimeShape {
|
|||||||
SetDim(i, pad_value);
|
SetDim(i, pad_value);
|
||||||
}
|
}
|
||||||
std::memcpy(DimsData() + size_increase, shape.DimsData(),
|
std::memcpy(DimsData() + size_increase, shape.DimsData(),
|
||||||
sizeof(int32) * shape.DimensionsCount());
|
sizeof(int32_t) * shape.DimensionsCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 size_;
|
int32_t size_;
|
||||||
union {
|
union {
|
||||||
int32 dims_[kMaxSmallSize];
|
int32_t dims_[kMaxSmallSize];
|
||||||
int32* dims_pointer_;
|
int32_t* dims_pointer_;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -713,7 +719,7 @@ void ComputeStrides(Dims<N>* dims) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class BroadcastableOpCategory : uint8 {
|
enum class BroadcastableOpCategory : uint8_t {
|
||||||
kNone,
|
kNone,
|
||||||
kNonBroadcast, // Matching input shapes.
|
kNonBroadcast, // Matching input shapes.
|
||||||
kFirstInputBroadcastsFast, // Fivefold nested loops.
|
kFirstInputBroadcastsFast, // Fivefold nested loops.
|
||||||
@ -729,21 +735,21 @@ static_assert(sizeof(MinMax) == 8, "");
|
|||||||
|
|
||||||
struct ActivationParams {
|
struct ActivationParams {
|
||||||
FusedActivationFunctionType activation_type;
|
FusedActivationFunctionType activation_type;
|
||||||
// uint8, etc, activation params.
|
// uint8_t, etc, activation params.
|
||||||
int32 quantized_activation_min;
|
int32_t quantized_activation_min;
|
||||||
int32 quantized_activation_max;
|
int32_t quantized_activation_max;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ReluParams : public ActivationParams {
|
struct ReluParams : public ActivationParams {
|
||||||
int32 input_offset;
|
int32_t input_offset;
|
||||||
int32 output_offset;
|
int32_t output_offset;
|
||||||
int32 output_multiplier;
|
int32_t output_multiplier;
|
||||||
int output_shift;
|
int output_shift;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Styles of resizing op usages. For example, kImageStyle can be used with a Pad
|
// Styles of resizing op usages. For example, kImageStyle can be used with a Pad
|
||||||
// op for pattern-specific optimization.
|
// op for pattern-specific optimization.
|
||||||
enum class ResizingCategory : uint8 {
|
enum class ResizingCategory : uint8_t {
|
||||||
kNone,
|
kNone,
|
||||||
kImageStyle, // 4D, operating on inner dimensions, say {0, a, b, 0}.
|
kImageStyle, // 4D, operating on inner dimensions, say {0, a, b, 0}.
|
||||||
kGenericResize,
|
kGenericResize,
|
||||||
@ -753,27 +759,27 @@ enum class ResizingCategory : uint8 {
|
|||||||
struct ArithmeticParams {
|
struct ArithmeticParams {
|
||||||
// Shape dependent / common to data / op types.
|
// Shape dependent / common to data / op types.
|
||||||
BroadcastableOpCategory broadcast_category;
|
BroadcastableOpCategory broadcast_category;
|
||||||
// uint8 inference params.
|
// uint8_t inference params.
|
||||||
int32 input1_offset;
|
int32_t input1_offset;
|
||||||
int32 input2_offset;
|
int32_t input2_offset;
|
||||||
int32 output_offset;
|
int32_t output_offset;
|
||||||
int32 output_multiplier;
|
int32_t output_multiplier;
|
||||||
int output_shift;
|
int output_shift;
|
||||||
// Add / Sub, not Mul, uint8 inference params.
|
// Add / Sub, not Mul, uint8_t inference params.
|
||||||
int left_shift;
|
int left_shift;
|
||||||
int32 input1_multiplier;
|
int32_t input1_multiplier;
|
||||||
int input1_shift;
|
int input1_shift;
|
||||||
int32 input2_multiplier;
|
int32_t input2_multiplier;
|
||||||
int input2_shift;
|
int input2_shift;
|
||||||
|
|
||||||
// TODO(b/158622529): Union the following activation params.
|
// TODO(b/158622529): Union the following activation params.
|
||||||
// uint8, etc, activation params.
|
// uint8_t, etc, activation params.
|
||||||
int32 quantized_activation_min;
|
int32_t quantized_activation_min;
|
||||||
int32 quantized_activation_max;
|
int32_t quantized_activation_max;
|
||||||
// float activation params.
|
// float activation params.
|
||||||
float float_activation_min;
|
float float_activation_min;
|
||||||
float float_activation_max;
|
float float_activation_max;
|
||||||
// int64 activation params.
|
// int64_t activation params.
|
||||||
int64_t int64_activation_min;
|
int64_t int64_activation_min;
|
||||||
int64_t int64_activation_max;
|
int64_t int64_activation_max;
|
||||||
|
|
||||||
@ -790,22 +796,22 @@ struct ArithmeticParams {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ConcatenationParams {
|
struct ConcatenationParams {
|
||||||
int8 axis;
|
int8_t axis;
|
||||||
const int32* input_zeropoint;
|
const int32_t* input_zeropoint;
|
||||||
const float* input_scale;
|
const float* input_scale;
|
||||||
uint16 inputs_count;
|
uint16_t inputs_count;
|
||||||
int32 output_zeropoint;
|
int32_t output_zeropoint;
|
||||||
float output_scale;
|
float output_scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ComparisonParams {
|
struct ComparisonParams {
|
||||||
// uint8 inference params.
|
// uint8_t inference params.
|
||||||
int left_shift;
|
int left_shift;
|
||||||
int32 input1_offset;
|
int32_t input1_offset;
|
||||||
int32 input1_multiplier;
|
int32_t input1_multiplier;
|
||||||
int input1_shift;
|
int input1_shift;
|
||||||
int32 input2_offset;
|
int32_t input2_offset;
|
||||||
int32 input2_multiplier;
|
int32_t input2_multiplier;
|
||||||
int input2_shift;
|
int input2_shift;
|
||||||
// Shape dependent / common to inference types.
|
// Shape dependent / common to inference types.
|
||||||
bool is_broadcast;
|
bool is_broadcast;
|
||||||
@ -815,81 +821,81 @@ struct ConvParams {
|
|||||||
PaddingType padding_type;
|
PaddingType padding_type;
|
||||||
PaddingValues padding_values;
|
PaddingValues padding_values;
|
||||||
// TODO(starka): This was just "stride", so check that width+height is OK.
|
// TODO(starka): This was just "stride", so check that width+height is OK.
|
||||||
int16 stride_width;
|
int16_t stride_width;
|
||||||
int16 stride_height;
|
int16_t stride_height;
|
||||||
int16 dilation_width_factor;
|
int16_t dilation_width_factor;
|
||||||
int16 dilation_height_factor;
|
int16_t dilation_height_factor;
|
||||||
// uint8 inference params.
|
// uint8_t inference params.
|
||||||
// TODO(b/65838351): Use smaller types if appropriate.
|
// TODO(b/65838351): Use smaller types if appropriate.
|
||||||
int32 input_offset;
|
int32_t input_offset;
|
||||||
int32 weights_offset;
|
int32_t weights_offset;
|
||||||
int32 output_offset;
|
int32_t output_offset;
|
||||||
int32 output_multiplier;
|
int32_t output_multiplier;
|
||||||
int output_shift;
|
int output_shift;
|
||||||
// uint8, etc, activation params.
|
// uint8_t, etc, activation params.
|
||||||
int32 quantized_activation_min;
|
int32_t quantized_activation_min;
|
||||||
int32 quantized_activation_max;
|
int32_t quantized_activation_max;
|
||||||
// float activation params.
|
// float activation params.
|
||||||
float float_activation_min;
|
float float_activation_min;
|
||||||
float float_activation_max;
|
float float_activation_max;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DepthToSpaceParams {
|
struct DepthToSpaceParams {
|
||||||
int32 block_size;
|
int32_t block_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DepthwiseParams {
|
struct DepthwiseParams {
|
||||||
PaddingType padding_type;
|
PaddingType padding_type;
|
||||||
PaddingValues padding_values;
|
PaddingValues padding_values;
|
||||||
int16 stride_width;
|
int16_t stride_width;
|
||||||
int16 stride_height;
|
int16_t stride_height;
|
||||||
int16 dilation_width_factor;
|
int16_t dilation_width_factor;
|
||||||
int16 dilation_height_factor;
|
int16_t dilation_height_factor;
|
||||||
int16 depth_multiplier;
|
int16_t depth_multiplier;
|
||||||
// uint8 inference params.
|
// uint8_t inference params.
|
||||||
// TODO(b/65838351): Use smaller types if appropriate.
|
// TODO(b/65838351): Use smaller types if appropriate.
|
||||||
int32 input_offset;
|
int32_t input_offset;
|
||||||
int32 weights_offset;
|
int32_t weights_offset;
|
||||||
int32 output_offset;
|
int32_t output_offset;
|
||||||
int32 output_multiplier;
|
int32_t output_multiplier;
|
||||||
int output_shift;
|
int output_shift;
|
||||||
// uint8, etc, activation params.
|
// uint8_t, etc, activation params.
|
||||||
int32 quantized_activation_min;
|
int32_t quantized_activation_min;
|
||||||
int32 quantized_activation_max;
|
int32_t quantized_activation_max;
|
||||||
// float activation params.
|
// float activation params.
|
||||||
float float_activation_min;
|
float float_activation_min;
|
||||||
float float_activation_max;
|
float float_activation_max;
|
||||||
const int32* output_multiplier_per_channel;
|
const int32_t* output_multiplier_per_channel;
|
||||||
const int32* output_shift_per_channel;
|
const int32_t* output_shift_per_channel;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DequantizationParams {
|
struct DequantizationParams {
|
||||||
double scale;
|
double scale;
|
||||||
int32 zero_point;
|
int32_t zero_point;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PerChannelDequantizationParams {
|
struct PerChannelDequantizationParams {
|
||||||
const float* scale;
|
const float* scale;
|
||||||
const int32* zero_point;
|
const int32_t* zero_point;
|
||||||
int32 quantized_dimension;
|
int32_t quantized_dimension;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FakeQuantParams {
|
struct FakeQuantParams {
|
||||||
MinMax minmax;
|
MinMax minmax;
|
||||||
int32 num_bits;
|
int32_t num_bits;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FullyConnectedParams {
|
struct FullyConnectedParams {
|
||||||
// uint8 inference params.
|
// uint8_t inference params.
|
||||||
// TODO(b/65838351): Use smaller types if appropriate.
|
// TODO(b/65838351): Use smaller types if appropriate.
|
||||||
int32 input_offset;
|
int32_t input_offset;
|
||||||
int32 weights_offset;
|
int32_t weights_offset;
|
||||||
int32 output_offset;
|
int32_t output_offset;
|
||||||
int32 output_multiplier;
|
int32_t output_multiplier;
|
||||||
int output_shift;
|
int output_shift;
|
||||||
// uint8, etc, activation params.
|
// uint8_t, etc, activation params.
|
||||||
int32 quantized_activation_min;
|
int32_t quantized_activation_min;
|
||||||
int32 quantized_activation_max;
|
int32_t quantized_activation_max;
|
||||||
// float activation params.
|
// float activation params.
|
||||||
float float_activation_min;
|
float float_activation_min;
|
||||||
float float_activation_max;
|
float float_activation_max;
|
||||||
@ -900,16 +906,16 @@ struct FullyConnectedParams {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct GatherParams {
|
struct GatherParams {
|
||||||
int16 axis;
|
int16_t axis;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct L2NormalizationParams {
|
struct L2NormalizationParams {
|
||||||
// uint8 inference params.
|
// uint8_t inference params.
|
||||||
int32 input_zero_point;
|
int32_t input_zero_point;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LocalResponseNormalizationParams {
|
struct LocalResponseNormalizationParams {
|
||||||
int32 range;
|
int32_t range;
|
||||||
double bias;
|
double bias;
|
||||||
double alpha;
|
double alpha;
|
||||||
double beta;
|
double beta;
|
||||||
@ -937,50 +943,50 @@ struct HardSwishParams {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct LogisticParams {
|
struct LogisticParams {
|
||||||
// uint8 inference params.
|
// uint8_t inference params.
|
||||||
int32 input_zero_point;
|
int32_t input_zero_point;
|
||||||
int32 input_range_radius;
|
int32_t input_range_radius;
|
||||||
int32 input_multiplier;
|
int32_t input_multiplier;
|
||||||
int input_left_shift;
|
int input_left_shift;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LstmCellParams {
|
struct LstmCellParams {
|
||||||
int32 weights_zero_point;
|
int32_t weights_zero_point;
|
||||||
int32 accum_multiplier;
|
int32_t accum_multiplier;
|
||||||
int accum_shift;
|
int accum_shift;
|
||||||
int state_integer_bits;
|
int state_integer_bits;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MeanParams {
|
struct MeanParams {
|
||||||
int8 axis_count;
|
int8_t axis_count;
|
||||||
int16 axis[4];
|
int16_t axis[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PackParams {
|
struct PackParams {
|
||||||
int8 axis;
|
int8_t axis;
|
||||||
const int32* input_zeropoint;
|
const int32_t* input_zeropoint;
|
||||||
const float* input_scale;
|
const float* input_scale;
|
||||||
uint16 inputs_count;
|
uint16_t inputs_count;
|
||||||
int32 output_zeropoint;
|
int32_t output_zeropoint;
|
||||||
float output_scale;
|
float output_scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PadParams {
|
struct PadParams {
|
||||||
int8 left_padding_count;
|
int8_t left_padding_count;
|
||||||
int32 left_padding[4];
|
int32_t left_padding[4];
|
||||||
int8 right_padding_count;
|
int8_t right_padding_count;
|
||||||
int32 right_padding[4];
|
int32_t right_padding[4];
|
||||||
ResizingCategory resizing_category;
|
ResizingCategory resizing_category;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PreluParams {
|
struct PreluParams {
|
||||||
int32 input_offset;
|
int32_t input_offset;
|
||||||
int32 alpha_offset;
|
int32_t alpha_offset;
|
||||||
int32 output_offset;
|
int32_t output_offset;
|
||||||
int32 output_multiplier_1;
|
int32_t output_multiplier_1;
|
||||||
int32 output_shift_1;
|
int32_t output_shift_1;
|
||||||
int32 output_multiplier_2;
|
int32_t output_multiplier_2;
|
||||||
int32 output_shift_2;
|
int32_t output_shift_2;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PoolParams {
|
struct PoolParams {
|
||||||
@ -991,17 +997,17 @@ struct PoolParams {
|
|||||||
int stride_width;
|
int stride_width;
|
||||||
int filter_height;
|
int filter_height;
|
||||||
int filter_width;
|
int filter_width;
|
||||||
// uint8, etc, activation params.
|
// uint8_t, etc, activation params.
|
||||||
int32 quantized_activation_min;
|
int32_t quantized_activation_min;
|
||||||
int32 quantized_activation_max;
|
int32_t quantized_activation_max;
|
||||||
// float activation params.
|
// float activation params.
|
||||||
float float_activation_min;
|
float float_activation_min;
|
||||||
float float_activation_max;
|
float float_activation_max;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ReshapeParams {
|
struct ReshapeParams {
|
||||||
int8 shape_count;
|
int8_t shape_count;
|
||||||
int32 shape[4];
|
int32_t shape[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ResizeBilinearParams {
|
struct ResizeBilinearParams {
|
||||||
@ -1018,22 +1024,22 @@ struct ResizeNearestNeighborParams {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct SliceParams {
|
struct SliceParams {
|
||||||
int8 begin_count;
|
int8_t begin_count;
|
||||||
int32 begin[4];
|
int32_t begin[4];
|
||||||
int8 size_count;
|
int8_t size_count;
|
||||||
int32 size[4];
|
int32_t size[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SoftmaxParams {
|
struct SoftmaxParams {
|
||||||
// beta is not really used (not a Tensorflow parameter) and not implemented
|
// beta is not really used (not a Tensorflow parameter) and not implemented
|
||||||
// for LogSoftmax.
|
// for LogSoftmax.
|
||||||
double beta;
|
double beta;
|
||||||
// uint8 inference params. Used even when beta defaults to 1.0.
|
// uint8_t inference params. Used even when beta defaults to 1.0.
|
||||||
int32 input_multiplier;
|
int32_t input_multiplier;
|
||||||
int32 input_left_shift;
|
int32_t input_left_shift;
|
||||||
// Reverse scaling is only used by LogSoftmax.
|
// Reverse scaling is only used by LogSoftmax.
|
||||||
int32 reverse_scaling_divisor;
|
int32_t reverse_scaling_divisor;
|
||||||
int32 reverse_scaling_right_shift;
|
int32_t reverse_scaling_right_shift;
|
||||||
int diff_min;
|
int diff_min;
|
||||||
int32_t zero_point;
|
int32_t zero_point;
|
||||||
float scale;
|
float scale;
|
||||||
@ -1045,66 +1051,66 @@ struct SoftmaxParams {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct SpaceToBatchParams {
|
struct SpaceToBatchParams {
|
||||||
// "Zero" padding for uint8 means padding with the output offset.
|
// "Zero" padding for uint8_t means padding with the output offset.
|
||||||
int32 output_offset;
|
int32_t output_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SpaceToDepthParams {
|
struct SpaceToDepthParams {
|
||||||
int32 block_size;
|
int32_t block_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SplitParams {
|
struct SplitParams {
|
||||||
// Graphs that split into, say, 2000 nodes are encountered. The indices in
|
// Graphs that split into, say, 2000 nodes are encountered. The indices in
|
||||||
// OperatorEdges are of type uint16.
|
// OperatorEdges are of type uint16_t.
|
||||||
uint16 num_split;
|
uint16_t num_split;
|
||||||
int16 axis;
|
int16_t axis;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SqueezeParams {
|
struct SqueezeParams {
|
||||||
int8 squeeze_dims_count;
|
int8_t squeeze_dims_count;
|
||||||
int32 squeeze_dims[4];
|
int32_t squeeze_dims[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StridedSliceParams {
|
struct StridedSliceParams {
|
||||||
int8 start_indices_count;
|
int8_t start_indices_count;
|
||||||
int32 start_indices[5];
|
int32_t start_indices[5];
|
||||||
int8 stop_indices_count;
|
int8_t stop_indices_count;
|
||||||
int32 stop_indices[5];
|
int32_t stop_indices[5];
|
||||||
int8 strides_count;
|
int8_t strides_count;
|
||||||
int32 strides[5];
|
int32_t strides[5];
|
||||||
|
|
||||||
int16 begin_mask;
|
int16_t begin_mask;
|
||||||
int16 ellipsis_mask;
|
int16_t ellipsis_mask;
|
||||||
int16 end_mask;
|
int16_t end_mask;
|
||||||
int16 new_axis_mask;
|
int16_t new_axis_mask;
|
||||||
int16 shrink_axis_mask;
|
int16_t shrink_axis_mask;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TanhParams {
|
struct TanhParams {
|
||||||
int32 input_zero_point;
|
int32_t input_zero_point;
|
||||||
int32 input_range_radius;
|
int32_t input_range_radius;
|
||||||
int32 input_multiplier;
|
int32_t input_multiplier;
|
||||||
int input_left_shift;
|
int input_left_shift;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TransposeParams {
|
struct TransposeParams {
|
||||||
int8 perm_count;
|
int8_t perm_count;
|
||||||
int32 perm[5];
|
int32_t perm[5];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UnpackParams {
|
struct UnpackParams {
|
||||||
uint16 num_split;
|
uint16_t num_split;
|
||||||
int16 axis;
|
int16_t axis;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LeakyReluParams {
|
struct LeakyReluParams {
|
||||||
float alpha;
|
float alpha;
|
||||||
int32 input_offset;
|
int32_t input_offset;
|
||||||
int32 output_offset;
|
int32_t output_offset;
|
||||||
int32 output_multiplier_alpha;
|
int32_t output_multiplier_alpha;
|
||||||
int32 output_shift_alpha;
|
int32_t output_shift_alpha;
|
||||||
int32 output_multiplier_identity;
|
int32_t output_multiplier_identity;
|
||||||
int32 output_shift_identity;
|
int32_t output_shift_identity;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename P>
|
template <typename P>
|
||||||
@ -1114,7 +1120,7 @@ inline void SetActivationParams(float min, float max, P* params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename P>
|
template <typename P>
|
||||||
inline void SetActivationParams(int32 min, int32 max, P* params) {
|
inline void SetActivationParams(int32_t min, int32_t max, P* params) {
|
||||||
params->quantized_activation_min = min;
|
params->quantized_activation_min = min;
|
||||||
params->quantized_activation_max = max;
|
params->quantized_activation_max = max;
|
||||||
}
|
}
|
||||||
@ -1126,7 +1132,7 @@ inline void SetActivationParams(int64_t min, int64_t max, P* params) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename P>
|
template <typename P>
|
||||||
inline void GetActivationParams(const P& params, int32* min, int32* max) {
|
inline void GetActivationParams(const P& params, int32_t* min, int32_t* max) {
|
||||||
*min = params.quantized_activation_min;
|
*min = params.quantized_activation_min;
|
||||||
*max = params.quantized_activation_max;
|
*max = params.quantized_activation_max;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user