aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilos Puzovic <Milos.Puzovic@arm.com>2022-10-28 00:09:32 +0100
committerViet-Hoa Do <viet-hoa.do@arm.com>2022-11-01 11:08:33 +0000
commit199982fc01bcce10120cd6df03d11829a215c85c (patch)
tree5a8884fa7a216edf8c18b5cfeb8b1537935b5e80
parent4b5f6efef15efd79727a58c520c92c9e7a084256 (diff)
downloadComputeLibrary-199982fc01bcce10120cd6df03d11829a215c85c.tar.gz
Add threshold for floating-point SOFT_RELU activation
Added missing threshold for calculating SOFT_RELU when SVE and CL implementations are used. As a result removed from the testing bounds for input values that were set to be in the interval [-40, 40]. Resolves: COMPMID-5658 Signed-off-by: Milos Puzovic <Milos.Puzovic@arm.com> Change-Id: I3d14df60125e36e4eb85aeb222f4fb0cc5741521 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/8536 Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Viet-Hoa Do <viet-hoa.do@arm.com> Reviewed-by: Gunes Bayir <gunes.bayir@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Benchmark: Arm Jenkins <bsgcomp@arm.com>
-rw-r--r--src/core/CL/cl_kernels/activation_float_helpers.h2
-rw-r--r--src/cpu/kernels/activation/generic/sve/fp32.cpp13
-rw-r--r--tests/validation/Helpers.h6
-rw-r--r--tests/validation/reference/ActivationLayer.h2
4 files changed, 10 insertions, 13 deletions
diff --git a/src/core/CL/cl_kernels/activation_float_helpers.h b/src/core/CL/cl_kernels/activation_float_helpers.h
index 3f93c8d6fc..fe124bc032 100644
--- a/src/core/CL/cl_kernels/activation_float_helpers.h
+++ b/src/core/CL/cl_kernels/activation_float_helpers.h
@@ -52,7 +52,7 @@
#define lrelu_op(DATA_TYPE, VEC_SIZE, x, A_VAL, B_VAL) ((min(x, (DATA_TYPE)0.0) * (DATA_TYPE)A_VAL) + max(x, (DATA_TYPE)0.0))
// Soft RELU Activation
-#define srelu_op(DATA_TYPE, VEC_SIZE, x, A_VAL, B_VAL) (log((DATA_TYPE)1.0 + exp(x)))
+#define srelu_op(DATA_TYPE, VEC_SIZE, x, A_VAL, B_VAL) (select((log((DATA_TYPE)1.0 + exp(x))), x, (SELECT_VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE))isgreaterequal(x,(DATA_TYPE)16.63553047)))
// ELU Activation
#define elu_op(DATA_TYPE, VEC_SIZE, x, A_VAL, B_VAL) (select(((DATA_TYPE)A_VAL * (exp(x) - (DATA_TYPE)1.0)), x, (SELECT_VEC_DATA_TYPE(DATA_TYPE, VEC_SIZE))isgreaterequal(x, (DATA_TYPE)0.0)))
diff --git a/src/cpu/kernels/activation/generic/sve/fp32.cpp b/src/cpu/kernels/activation/generic/sve/fp32.cpp
index b5490063cf..8d5d627d70 100644
--- a/src/cpu/kernels/activation/generic/sve/fp32.cpp
+++ b/src/cpu/kernels/activation/generic/sve/fp32.cpp
@@ -48,11 +48,12 @@ void sve_fp32_activation(const ITensor *src, ITensor *dst, const ActivationLayer
Iterator input(src, win_collapsed);
Iterator output(dst, win_collapsed);
- const auto const_1 = svdup_n_f32(1.f);
- const auto const_0 = svdup_n_f32(0.f);
- const auto const_6 = svdup_n_f32(6.f);
- const auto const_3 = svdup_n_f32(3.f);
- const auto const_inv_6 = svdup_n_f32(0.166666667f);
+ const auto const_1 = svdup_n_f32(1.f);
+ const auto const_0 = svdup_n_f32(0.f);
+ const auto const_6 = svdup_n_f32(6.f);
+ const auto const_3 = svdup_n_f32(3.f);
+ const auto const_inv_6 = svdup_n_f32(0.166666667f);
+ const auto soft_relu_thresh = svdup_n_f32(16.63553047f);
const auto va = svdup_n_f32(act_info.a());
const auto vb = svdup_n_f32(act_info.b());
@@ -93,7 +94,7 @@ void sve_fp32_activation(const ITensor *src, ITensor *dst, const ActivationLayer
tmp = svadd_f32_z(pg, svmul_f32_z(pg, svmin_f32_z(pg, vin, const_0), va), svmax_f32_z(pg, vin, const_0));
break;
case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
- tmp = svlog_f32_z(pg, svadd_f32_z(pg, const_1, svexp_f32_z(pg, vin)));
+ tmp = svsel_f32(svcmpgt_f32(pg, vin, soft_relu_thresh), vin, svlog_f32_z(pg, svadd_f32_z(pg, const_1, svexp_f32_z(pg, vin))));
break;
case ActivationLayerInfo::ActivationFunction::ELU:
tmp = svsel_f32(svcmpgt_f32(pg, vin, const_0), vin, svmul_f32_z(pg, va, svsub_f32_z(pg, svexp_f32_z(pg, vin), const_1)));
diff --git a/tests/validation/Helpers.h b/tests/validation/Helpers.h
index a8804ad7e7..cbbdfbb6c4 100644
--- a/tests/validation/Helpers.h
+++ b/tests/validation/Helpers.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2021 Arm Limited.
+ * Copyright (c) 2017-2022 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -91,10 +91,6 @@ std::pair<T, T> get_activation_layer_test_bounds(ActivationLayerInfo::Activation
case DataType::F32:
switch(activation)
{
- case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
- // Reduce range as exponent overflows
- bounds = std::make_pair(-40.f, 40.f);
- break;
case ActivationLayerInfo::ActivationFunction::SQRT:
// Reduce range as sqrt should take a non-negative number
bounds = std::make_pair(0.f, 255.f);
diff --git a/tests/validation/reference/ActivationLayer.h b/tests/validation/reference/ActivationLayer.h
index 2bf96831a6..a813ba5037 100644
--- a/tests/validation/reference/ActivationLayer.h
+++ b/tests/validation/reference/ActivationLayer.h
@@ -64,7 +64,7 @@ inline T activate_float(T x, T a, T b, ActivationLayerInfo::ActivationFunction a
ret = (x > 0) ? x : a * x;
break;
case ActivationLayerInfo::ActivationFunction::SOFT_RELU:
- ret = std::log(static_cast<T>(1) + std::exp(x));
+ ret = std::log(static_cast<T>(1) + std::exp(static_cast<double>(x)));
break;
case ActivationLayerInfo::ActivationFunction::ELU:
ret = (x > 0) ? x : a * (std::exp(x) - static_cast<T>(1));