aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPablo Marquez Tello <pablo.tello@arm.com>2022-09-26 17:22:42 +0100
committerPablo Marquez Tello <pablo.tello@arm.com>2022-09-28 11:08:11 +0000
commitff81de5a9a0f6b9331c3b112cc2aed552f0482a9 (patch)
treea85005958a5ff6f9aef338bf4bbbcf2e2041a6d4
parentd6b8a71714361881a249a6f6ed67125f290f4a83 (diff)
downloadComputeLibrary-ff81de5a9a0f6b9331c3b112cc2aed552f0482a9.tar.gz
Fix overflow in NEActivationLayer for FP16 type
* Resolves MLCE-924 Change-Id: I3cc3d30893c2ee0865eacafdc1d9ba3d5b876d32 Signed-off-by: Pablo Marquez Tello <pablo.tello@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/8326 Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Viet-Hoa Do <viet-hoa.do@arm.com> Benchmark: Arm Jenkins <bsgcomp@arm.com>
-rw-r--r--src/core/NEON/NEMath.inl14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/core/NEON/NEMath.inl b/src/core/NEON/NEMath.inl
index 1b0b894153..1755974d2d 100644
--- a/src/core/NEON/NEMath.inl
+++ b/src/core/NEON/NEMath.inl
@@ -520,16 +520,14 @@ inline float16x8_t vinvq_f16(float16x8_t x)
inline float16x8_t vtanhq_f16(float16x8_t val)
{
- const float16x8_t CONST_1 = vdupq_n_f16(1.f);
- const float16x8_t CONST_2 = vdupq_n_f16(2.f);
const float16x8_t CONST_MIN_TANH = vdupq_n_f16(-10.f);
const float16x8_t CONST_MAX_TANH = vdupq_n_f16(10.f);
-
- const float16x8_t x = vminq_f16(vmaxq_f16(val, CONST_MIN_TANH), CONST_MAX_TANH);
- const float16x8_t exp2x = vexpq_f16(vmulq_f16(CONST_2, x));
- const float16x8_t num = vsubq_f16(exp2x, CONST_1);
- const float16x8_t den = vaddq_f16(exp2x, CONST_1);
- const float16x8_t tanh = vmulq_f16(num, vinvq_f16(den));
+ const float16x8_t x = vminq_f16(vmaxq_f16(val, CONST_MIN_TANH), CONST_MAX_TANH);
+ const auto expx = vexpq_f16(x);
+ const auto expmx = vinvq_f16(expx);
+ const auto ab = vsubq_f16(expx, expmx);
+ const auto cd = vaddq_f16(expx, expmx);
+ const float16x8_t tanh = vdivq_f16(ab, cd);
return tanh;
}