aboutsummaryrefslogtreecommitdiff
path: root/src/core/utils/quantization/AsymmHelpers.cpp
diff options
context:
space:
mode:
authorSang-Hoon Park <sang-hoon.park@arm.com>2020-04-18 01:40:57 +0100
committerSang-Hoon Park <sang-hoon.park@arm.com>2020-04-20 14:53:23 +0000
commit30b46a660629ccd5bf715f63b90d6d7655416e2c (patch)
tree9d30cb7d4950d4f21d0033c9d88c842c587f5a51 /src/core/utils/quantization/AsymmHelpers.cpp
parenteb65f6da695ac0d3e495817145cceb1c4de4f048 (diff)
downloadComputeLibrary-30b46a660629ccd5bf715f63b90d6d7655416e2c.tar.gz
COMPMID-3241: Fix hidden scale in NEQLSTMLayer
- Fix wrong data types in LSTMParams - Add logic to ignore epsilon for quantization multiplier computation - Ignore epsilon for hidden gate scale computation Change-Id: Ia0b2f523b1c2ad325f3523439a8eea051d81958c Signed-off-by: Sang-Hoon Park <sang-hoon.park@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/3058 Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'src/core/utils/quantization/AsymmHelpers.cpp')
-rw-r--r--src/core/utils/quantization/AsymmHelpers.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/core/utils/quantization/AsymmHelpers.cpp b/src/core/utils/quantization/AsymmHelpers.cpp
index f923518ca4..8e0e92c7ab 100644
--- a/src/core/utils/quantization/AsymmHelpers.cpp
+++ b/src/core/utils/quantization/AsymmHelpers.cpp
@@ -36,7 +36,7 @@ namespace quantization
constexpr int64_t fixed_point_one_Q0 = (1LL << 31);
constexpr float epsilon = 0.00001f;
-Status calculate_quantized_multiplier(float multiplier, int32_t *quant_multiplier, int32_t *shift)
+Status calculate_quantized_multiplier(float multiplier, int32_t *quant_multiplier, int32_t *shift, bool ignore_epsilon)
{
if(multiplier >= 1.f)
{
@@ -46,19 +46,22 @@ Status calculate_quantized_multiplier(float multiplier, int32_t *quant_multiplie
}
else
{
- return calculate_quantized_multiplier_less_than_one(multiplier, quant_multiplier, shift);
+ return calculate_quantized_multiplier_less_than_one(multiplier, quant_multiplier, shift, ignore_epsilon);
}
}
Status calculate_quantized_multiplier_less_than_one(float multiplier,
int32_t *quant_multiplier,
- int32_t *right_shift)
+ int32_t *right_shift,
+ bool ignore_epsilon)
{
+ const float internal_epsilon = ignore_epsilon ? 0.0f : epsilon;
+
ARM_COMPUTE_RETURN_ERROR_ON(quant_multiplier == nullptr);
ARM_COMPUTE_RETURN_ERROR_ON(right_shift == nullptr);
- ARM_COMPUTE_RETURN_ERROR_ON(multiplier < -epsilon);
- ARM_COMPUTE_RETURN_ERROR_ON(multiplier > 1.0f + epsilon);
- if(std::fabs(0.0f - multiplier) < epsilon)
+ ARM_COMPUTE_RETURN_ERROR_ON(multiplier < -internal_epsilon);
+ ARM_COMPUTE_RETURN_ERROR_ON(multiplier > 1.0f + internal_epsilon);
+ if(std::fabs(0.0f - multiplier) < internal_epsilon)
{
*quant_multiplier = 0;
*right_shift = 0;
@@ -75,6 +78,13 @@ Status calculate_quantized_multiplier_less_than_one(float multiplier,
q_fixed /= 2;
--*right_shift;
}
+
+ if(ignore_epsilon && *right_shift > 31)
+ {
+ *right_shift = 0;
+ q_fixed = 0;
+ }
+
ARM_COMPUTE_RETURN_ERROR_ON(*right_shift < 0);
ARM_COMPUTE_RETURN_ERROR_ON(q_fixed > std::numeric_limits<int32_t>::max());
*quant_multiplier = static_cast<int32_t>(q_fixed);