From a2b89ca5407532257a959ad1852f29187e1be4ac Mon Sep 17 00:00:00 2001 From: Pablo Palmier Date: Thu, 5 Oct 2017 15:01:34 +0100 Subject: IVGCVSW-631 Neon support for Softmax beta parameter (F32 only) Change-Id: Ibf6f038b39f1a4e557f5d04feb08e3d5ef54e223 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/112019 Tested-by: BSG Visual Compute Jenkins server to access repositories on http://mpd-gerrit.cambridge.arm.com Reviewed-by: Anthony Barbier Reviewed-by: Georgios Pinitas --- tests/validation/reference/SoftmaxLayer.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'tests/validation/reference/SoftmaxLayer.cpp') diff --git a/tests/validation/reference/SoftmaxLayer.cpp b/tests/validation/reference/SoftmaxLayer.cpp index 8e8cc1bd25..90b9b1f7e2 100644 --- a/tests/validation/reference/SoftmaxLayer.cpp +++ b/tests/validation/reference/SoftmaxLayer.cpp @@ -35,7 +35,7 @@ namespace validation namespace reference { template ::value, int>::type> -SimpleTensor softmax_layer(const SimpleTensor &src) +SimpleTensor softmax_layer(const SimpleTensor &src, float beta) { // Create reference SimpleTensor dst{ src.shape(), src.data_type(), 1, src.fixed_point_position() }; @@ -54,9 +54,9 @@ SimpleTensor softmax_layer(const SimpleTensor &src) // Regularize T sum(0.f); - std::transform(src_row_ptr, src_row_ptr + cols, dst_row_ptr, [&sum, max](T val) + std::transform(src_row_ptr, src_row_ptr + cols, dst_row_ptr, [&sum, max, beta](T val) { - const T res(std::exp(val - max)); + const T res(std::exp((val - max) * beta)); sum += res; return res; }); @@ -72,8 +72,10 @@ SimpleTensor softmax_layer(const SimpleTensor &src) } template ::value, int>::type> -SimpleTensor softmax_layer(const SimpleTensor &src) +SimpleTensor softmax_layer(const SimpleTensor &src, float beta) { + ARM_COMPUTE_UNUSED(beta); + using namespace fixed_point_arithmetic; // Create reference @@ -113,21 +115,21 @@ SimpleTensor softmax_layer(const SimpleTensor &src) } template <> -SimpleTensor softmax_layer(const SimpleTensor &src) +SimpleTensor softmax_layer(const SimpleTensor &src, float beta) { // Note: Output quantization info should always have scale = 1/256 and offset = 0 const QuantizationInfo output_quantization_info = QuantizationInfo(1.f / 256, 0); SimpleTensor src_tmp = convert_from_asymmetric(src); - SimpleTensor dst_tmp = softmax_layer(src_tmp); + SimpleTensor dst_tmp = softmax_layer(src_tmp, beta); SimpleTensor dst = convert_to_asymmetric(dst_tmp, output_quantization_info); return dst; } -template SimpleTensor softmax_layer(const SimpleTensor &src); -template SimpleTensor softmax_layer(const SimpleTensor &src); -template SimpleTensor softmax_layer(const SimpleTensor &src); -template SimpleTensor softmax_layer(const SimpleTensor &src); +template SimpleTensor softmax_layer(const SimpleTensor &src, float beta); +template SimpleTensor softmax_layer(const SimpleTensor &src, float beta); +template SimpleTensor softmax_layer(const SimpleTensor &src, float beta); +template SimpleTensor softmax_layer(const SimpleTensor &src, float beta); } // namespace reference } // namespace validation } // namespace test -- cgit v1.2.1