COMPMID-3069: Fix QASYMM8_SIGNED RELUs in NEActivationLayerKernel
authorMichele Di Giorgio <michele.digiorgio@arm.com>
Mon, 20 Apr 2020 16:39:33 +0000 (17:39 +0100)
committerMichele Di Giorgio <michele.digiorgio@arm.com>
Tue, 21 Apr 2020 13:49:49 +0000 (13:49 +0000)
Wrong boundaries were used for clamping the output when data type was QASYMM8_SIGNED.

Change-Id: Ie93bf64643fce95be2b4a5a63ef2d1dc83bbdd97
Signed-off-by: Michele Di Giorgio <michele.digiorgio@arm.com>
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/3064
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>

src/core/NEON/kernels/NEActivationLayerKernel.cpp

index 5251209463a3c7709b6280b21ce044c03896b8a3..a1652447f419087362adb0d3e1cbf42a362ee46a 100644 (file)
@@ -533,17 +533,17 @@ typename std::enable_if<std::is_same<T, qasymm8_t>::value, void>::type NEActivat
             if(act == ActivationFunction::RELU)
             {
                 tmp = std::max(const_0, in);
-                tmp = std::max<int32_t>(0, std::min<int32_t>(tmp * s + o, 255));
+                tmp = utility::clamp<qasymm8_t>(tmp * s + o);
             }
             else if(act == ActivationFunction::BOUNDED_RELU)
             {
                 tmp = std::min(a, std::max(const_0, in));
-                tmp = std::max<int32_t>(0, std::min<int32_t>(tmp * s + o, 255));
+                tmp = utility::clamp<qasymm8_t>(tmp * s + o);
             }
             else if(act == ActivationFunction::LU_BOUNDED_RELU)
             {
                 tmp = std::min(a, std::max(b, in));
-                tmp = std::max<int32_t>(0, std::min<int32_t>(tmp * s + o, 255));
+                tmp = utility::clamp<qasymm8_t>(tmp * s + o);
             }
             else if(act == ActivationFunction::LOGISTIC)
             {
@@ -710,17 +710,17 @@ typename std::enable_if<std::is_same<T, qasymm8_signed_t>::value, void>::type NE
             if(act == ActivationFunction::RELU)
             {
                 tmp = std::max(const_0, in);
-                tmp = std::max<int32_t>(0, std::min<int32_t>(tmp * s + o, 255));
+                tmp = utility::clamp<qasymm8_signed_t>(tmp * s + o);
             }
             else if(act == ActivationFunction::BOUNDED_RELU)
             {
                 tmp = std::min(a, std::max(const_0, in));
-                tmp = std::max<int32_t>(0, std::min<int32_t>(tmp * s + o, 255));
+                tmp = utility::clamp<qasymm8_signed_t>(tmp * s + o);
             }
             else if(act == ActivationFunction::LU_BOUNDED_RELU)
             {
                 tmp = std::min(a, std::max(b, in));
-                tmp = std::max<int32_t>(0, std::min<int32_t>(tmp * s + o, 255));
+                tmp = utility::clamp<qasymm8_signed_t>(tmp * s + o);
             }
             else if(act == ActivationFunction::LOGISTIC)
             {