From a83af7b388a1ac721c6a85b0e80ac2950687dfad Mon Sep 17 00:00:00 2001 From: Jan Eilers Date: Wed, 18 Mar 2020 15:58:11 +0000 Subject: [PATCH] IVGCVSW-4446 Add HardSwish EndToEnd tests * adds convert from armnn HardSwish to Acl HardSwish * adds EndToEnd tests for Ref, Cl and Neon Signed-off-by: Jan Eilers Change-Id: If997dad783ff45d7f061254e7e30bb69d4d4d564 --- src/backends/aclCommon/ArmComputeUtils.hpp | 1 + .../test/ActivationEndToEndTestImpl.hpp | 33 +++++++++++++++++++++- src/backends/cl/test/ClEndToEndTests.cpp | 26 +++++++++++++++++ src/backends/neon/test/NeonEndToEndTests.cpp | 21 ++++++++++++++ src/backends/reference/test/RefEndToEndTests.cpp | 31 ++++++++++++++++++++ 5 files changed, 111 insertions(+), 1 deletion(-) diff --git a/src/backends/aclCommon/ArmComputeUtils.hpp b/src/backends/aclCommon/ArmComputeUtils.hpp index 01a5445..c3cfb5c 100644 --- a/src/backends/aclCommon/ArmComputeUtils.hpp +++ b/src/backends/aclCommon/ArmComputeUtils.hpp @@ -66,6 +66,7 @@ ConvertActivationFunctionToAclActivationFunction(ActivationFunction armnnFunctio case ActivationFunction::Square: return AclActivationFunction::SQUARE; case ActivationFunction::TanH: return AclActivationFunction::TANH; case ActivationFunction::Elu: return AclActivationFunction::ELU; + case ActivationFunction::HardSwish: return AclActivationFunction::HARD_SWISH; default: throw InvalidArgumentException("Unsupported activation function"); } } diff --git a/src/backends/backendsCommon/test/ActivationEndToEndTestImpl.hpp b/src/backends/backendsCommon/test/ActivationEndToEndTestImpl.hpp index 23884b0..1b735be 100644 --- a/src/backends/backendsCommon/test/ActivationEndToEndTestImpl.hpp +++ b/src/backends/backendsCommon/test/ActivationEndToEndTestImpl.hpp @@ -32,6 +32,8 @@ float GetActivationTolerance(const armnn::ActivationFunction& activationFunction // The following values are taken from ArmComputeLibrary/tests/validation/CL/ActivationLayer.cpp case ActivationFunction::Elu: return (dataType == DataType::Float16 ? 0.01f : 0.00001f); + case ActivationFunction::HardSwish: + return (dataType == DataType::Float16 ? 0.01f : defaultTolerance); default: return defaultTolerance; } @@ -123,7 +125,7 @@ void EluEndToEndTest(const std::vector& backends) 1.0f, 2.0f, 3.0f, 4.0f }; std::vector floatExpectedOutputData{ -0.86466471676f, -0.63212055882f, -0.0f, 0.0f, - 1.0f , 2.0f, 3.0f, 4.0f }; + 1.0f , 2.0f , 3.0f, 4.0f }; float qScale = 1.0f; int32_t qOffset = 0; @@ -140,4 +142,33 @@ void EluEndToEndTest(const std::vector& backends) descriptor); } +/** Executes an end to end test for HardSwish activation with specific input and expected-output data + * + * @tparam ArmnnType The armnn data type for the input and expected-output data + * @param backends The backends on which to run the test + */ +template> +void HardSwishEndToEndTest(const std::vector& backends) +{ + std::vector floatInputData{ -2.0f, -1.0f, -0.5f, 0.0f, + 1.0f, 2.0f, 3.0f, 4.0f }; + + std::vector floatExpectedOutputData{ -0.33333333333f, -0.33333333333f, -0.208333f, 0.0f, + 0.66666666667f, 1.66666666667f, 3.0f , 4.0f }; + + float qScale = 1.0f; + int32_t qOffset = 0; + armnn::TensorInfo inputInfo({ 2, 2, 2, 1 }, ArmnnType, qScale, qOffset); + armnn::TensorInfo outputInfo({ 2, 2, 2, 1 }, ArmnnType, qScale, qOffset); + + armnn::ActivationDescriptor descriptor(ActivationFunction::HardSwish, 1.0); + + ActivationEndToEndImpl(backends, + floatInputData, + floatExpectedOutputData, + inputInfo, + outputInfo, + descriptor); +} + } // anonymous namespace \ No newline at end of file diff --git a/src/backends/cl/test/ClEndToEndTests.cpp b/src/backends/cl/test/ClEndToEndTests.cpp index 8b4fbbb..5a9cf39 100644 --- a/src/backends/cl/test/ClEndToEndTests.cpp +++ b/src/backends/cl/test/ClEndToEndTests.cpp @@ -182,6 +182,32 @@ BOOST_AUTO_TEST_CASE(ClGreaterBroadcastEndToEndUint8Test) expectedOutput); } +// HardSwish +BOOST_AUTO_TEST_CASE(ClHardSwishEndToEndTestFloat32) +{ + HardSwishEndToEndTest(defaultBackends); +} + +BOOST_AUTO_TEST_CASE(ClHardSwishEndToEndTestFloat16) +{ + HardSwishEndToEndTest(defaultBackends); +} + +BOOST_AUTO_TEST_CASE(ClHardSwishEndToEndTestQAsymmS8) +{ + HardSwishEndToEndTest(defaultBackends); +} + +BOOST_AUTO_TEST_CASE(ClHardSwishEndToEndTestQAsymmU8) +{ + HardSwishEndToEndTest(defaultBackends); +} + +BOOST_AUTO_TEST_CASE(ClHardSwishEndToEndTestQSymmS16) +{ + HardSwishEndToEndTest(defaultBackends); +} + // InstanceNormalization BOOST_AUTO_TEST_CASE(ClInstanceNormalizationNhwcEndToEndTest1) { diff --git a/src/backends/neon/test/NeonEndToEndTests.cpp b/src/backends/neon/test/NeonEndToEndTests.cpp index b2c43e1..487aaeb 100644 --- a/src/backends/neon/test/NeonEndToEndTests.cpp +++ b/src/backends/neon/test/NeonEndToEndTests.cpp @@ -218,6 +218,27 @@ BOOST_AUTO_TEST_CASE(NeonEluEndToEndTestFloat16) EluEndToEndTest(defaultBackends); } +// HardSwish +BOOST_AUTO_TEST_CASE(NeonHardSwishEndToEndTestFloat32) +{ + HardSwishEndToEndTest(defaultBackends); +} + +BOOST_AUTO_TEST_CASE(NeonHardSwishEndToEndTestFloat16) +{ + HardSwishEndToEndTest(defaultBackends); +} + +BOOST_AUTO_TEST_CASE(NeonHardSwishEndToEndTestQAsymmS8) +{ + HardSwishEndToEndTest(defaultBackends); +} + +BOOST_AUTO_TEST_CASE(NeonHardSwishEndToEndTestQAsymmU8) +{ + HardSwishEndToEndTest(defaultBackends); +} + BOOST_AUTO_TEST_CASE(NeonPreluEndToEndFloat32Test) { PreluEndToEndNegativeTest(defaultBackends); diff --git a/src/backends/reference/test/RefEndToEndTests.cpp b/src/backends/reference/test/RefEndToEndTests.cpp index 83f947c..9c10a68 100644 --- a/src/backends/reference/test/RefEndToEndTests.cpp +++ b/src/backends/reference/test/RefEndToEndTests.cpp @@ -837,6 +837,37 @@ BOOST_AUTO_TEST_CASE(RefDetectionPostProcessFastNmsUint8Test) 1.0f, 1, 0.01f, 0, 0.5f, 0); } +// HardSwish +BOOST_AUTO_TEST_CASE(RefHardSwishEndToEndTestFloat32) +{ + HardSwishEndToEndTest(defaultBackends); +} + +BOOST_AUTO_TEST_CASE(RefHardSwishEndToEndTestFloat16) +{ + HardSwishEndToEndTest(defaultBackends); +} + +BOOST_AUTO_TEST_CASE(RefHardSwishEndToEndTestBFloat16) +{ +HardSwishEndToEndTest(defaultBackends); +} + +BOOST_AUTO_TEST_CASE(RefHardSwishEndToEndTestQAsymmS8) +{ + HardSwishEndToEndTest(defaultBackends); +} + +BOOST_AUTO_TEST_CASE(RefHardSwishEndToEndTestQAsymmU8) +{ + HardSwishEndToEndTest(defaultBackends); +} + +BOOST_AUTO_TEST_CASE(RefHardSwishEndToEndTestQSymmS16) +{ + HardSwishEndToEndTest(defaultBackends); +} + // LogSoftmax BOOST_AUTO_TEST_CASE(RefLogSoftmaxEndToEndTest) { -- 2.7.4