From 8d5dd867c32fc31f635fdc58783c29a38a99ebb7 Mon Sep 17 00:00:00 2001 From: Michele Di Giorgio Date: Fri, 13 Sep 2019 12:23:46 +0100 Subject: COMPMID-2659: Activation.SQRT Failure on NEON When one of the inputs is zero in a NEON vector our computation of square root returns -nan. This patch adds a small epsilon to the input to avoid this issue. Change-Id: I0357001fd2ff0f868acfaae66b47b6962dbb0144 Signed-off-by: Michele Di Giorgio Reviewed-on: https://review.mlplatform.org/c/1921 Reviewed-by: Pablo Marquez Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins --- src/core/NEON/kernels/NEActivationLayerKernel.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/NEON/kernels/NEActivationLayerKernel.cpp b/src/core/NEON/kernels/NEActivationLayerKernel.cpp index 242382c206..6f722e0457 100644 --- a/src/core/NEON/kernels/NEActivationLayerKernel.cpp +++ b/src/core/NEON/kernels/NEActivationLayerKernel.cpp @@ -228,6 +228,7 @@ NEActivationLayerKernel::activation(const Window &window) Iterator input(_input, win_collapsed); Iterator output(_output, win_collapsed); + const auto epsilon = wrapper::vdup_n(static_cast(1e-24), ExactTagType{}); const auto const_1 = wrapper::vdup_n(static_cast(1.f), ExactTagType{}); const auto const_0 = wrapper::vdup_n(static_cast(0.f), ExactTagType{}); const auto va = wrapper::vdup_n(static_cast(_act_info.a()), ExactTagType{}); @@ -277,7 +278,7 @@ NEActivationLayerKernel::activation(const Window &window) tmp = wrapper::vbsl(wrapper::vcge(vin, const_0), vin, wrapper::vmul(va, wrapper::vsub(wrapper::vexpq(vin), const_1))); break; case ActivationFunction::SQRT: - tmp = wrapper::vinv(wrapper::vinvsqrt(vin)); + tmp = wrapper::vinv(wrapper::vinvsqrt(vin + epsilon)); break; case ActivationFunction::SQUARE: tmp = wrapper::vmul(vin, vin); -- cgit v1.2.1