diff options
author | John Mcloughlin <john.mcloughlin@arm.com> | 2023-05-15 17:03:49 +0100 |
---|---|---|
committer | John Mcloughlin <john.mcloughlin@arm.com> | 2023-05-17 12:29:54 +0100 |
commit | 0ec008761ab26110dcb108d544be4040a14fd403 (patch) | |
tree | 87bbc145ff2a4ea3221440b0fbd7c91a5b8a7c91 /src/backends/reference | |
parent | 499ebd917d8399f0a9d4d7e6e40a0ec321a4bab4 (diff) | |
download | armnn-0ec008761ab26110dcb108d544be4040a14fd403.tar.gz |
IVGCVSW-7400 POW IVGCVSW-7278 SQUARED_DIFFERENCE.
* Added 2 new operators as ElementWiseBinary ops
* Ref End to End and unit tests
* Serialize and Deserialize tests
* Delegate and Opaque Delegate tests
* TfLite Parser tests
Signed-off-by: John Mcloughlin <john.mcloughlin@arm.com>
Change-Id: I537158127f602f0c41ca0402aa31655cd3bd4281
Diffstat (limited to 'src/backends/reference')
6 files changed, 134 insertions, 1 deletions
diff --git a/src/backends/reference/test/RefEndToEndTests.cpp b/src/backends/reference/test/RefEndToEndTests.cpp index 95004c4dc2..4bb3f2947a 100644 --- a/src/backends/reference/test/RefEndToEndTests.cpp +++ b/src/backends/reference/test/RefEndToEndTests.cpp @@ -1602,6 +1602,22 @@ TEST_CASE("RefMinimumEndToEndTestUint8") { ElementwiseBinarySimpleEndToEnd<armnn::DataType::QAsymmU8>(defaultBackends, BinaryOperation::Minimum); } +TEST_CASE("RefPowerEndToEndTestFloat32") +{ + ElementwiseBinarySimpleEndToEnd<armnn::DataType::Float32>(defaultBackends, BinaryOperation::Power); +} +TEST_CASE("RefPowerEndToEndTestUint8") +{ + ElementwiseBinarySimpleEndToEnd<armnn::DataType::QAsymmU8>(defaultBackends, BinaryOperation::Power); +} +TEST_CASE("RefSquaredDifferenceEndToEndTestFloat32") +{ + ElementwiseBinarySimpleEndToEnd<armnn::DataType::Float32>(defaultBackends, BinaryOperation::SqDiff); +} +TEST_CASE("RefSquaredDifferenceEndToEndTestUint8") +{ + ElementwiseBinarySimpleEndToEnd<armnn::DataType::QAsymmU8>(defaultBackends, BinaryOperation::SqDiff); +} #endif } diff --git a/src/backends/reference/test/RefLayerTests.cpp b/src/backends/reference/test/RefLayerTests.cpp index 0e228dbea9..8b89743870 100644 --- a/src/backends/reference/test/RefLayerTests.cpp +++ b/src/backends/reference/test/RefLayerTests.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2022, 2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -1003,6 +1003,48 @@ ARMNN_AUTO_TEST_CASE_WITH_THF(MultiplicationBroadcast1ElementInt32, Multiplicati ARMNN_AUTO_TEST_CASE_WITH_THF(MultiplicationBroadcast1DVectorInt32, MultiplicationBroadcast1DVectorInt32Test) ARMNN_AUTO_TEST_CASE_WITH_THF(Multiplication5d, Multiplication5dTest) +// SquaredDifference +ARMNN_AUTO_TEST_CASE_WITH_THF(SimpleSquaredDifference, SquaredDifferenceTest) +ARMNN_AUTO_TEST_CASE_WITH_THF(SquaredDiffBroadcast1Element, SquaredDiffBroadcast1ElementTest) +ARMNN_AUTO_TEST_CASE_WITH_THF(SquaredDiffBroadcast, SquaredDiffBroadcastTest) + +ARMNN_AUTO_TEST_CASE_WITH_THF(SquaredDifferenceFloat16, SquaredDifferenceFloat16Test) +ARMNN_AUTO_TEST_CASE_WITH_THF(SquaredDiffBroadcast1ElementFloat16, SquaredDiffBroadcast1ElementFloat16Test) +ARMNN_AUTO_TEST_CASE_WITH_THF(SquaredDiffBroadcastFloat16, SquaredDiffBroadcastFloat16Test) + +ARMNN_AUTO_TEST_CASE_WITH_THF(SquaredDifferenceUint8, SquaredDifferenceUint8Test) +ARMNN_AUTO_TEST_CASE_WITH_THF(SquaredDiffBroadcastUint8, SquaredDiffBroadcastUint8Test) +ARMNN_AUTO_TEST_CASE_WITH_THF(SquaredDiffBroadcast1ElementUint8, SquaredDiffBroadcast1ElementUint8Test) + +ARMNN_AUTO_TEST_CASE_WITH_THF(SquaredDifferenceInt16, SquaredDifferenceInt16Test) +ARMNN_AUTO_TEST_CASE_WITH_THF(SquaredDiffBroadcastInt16, SquaredDiffBroadcastInt16Test) +ARMNN_AUTO_TEST_CASE_WITH_THF(SquaredDiffBroadcast1ElementInt16, SquaredDiffBroadcast1ElementInt16Test) + +ARMNN_AUTO_TEST_CASE_WITH_THF(SquaredDifferenceInt32, SquaredDifferenceInt32Test) +ARMNN_AUTO_TEST_CASE_WITH_THF(SquaredDiffBroadcastInt32, SquaredDiffBroadcastInt32Test) +ARMNN_AUTO_TEST_CASE_WITH_THF(SquaredDiffBroadcast1ElementInt32, SquaredDiffBroadcast1ElementInt32Test) + +// Power +ARMNN_AUTO_TEST_CASE_WITH_THF(SimplePower, PowerTest) +ARMNN_AUTO_TEST_CASE_WITH_THF(PowerBroadcast1Element, PowerBroadcast1ElementTest) +ARMNN_AUTO_TEST_CASE_WITH_THF(PowerBroadcast, PowerBroadcastTest) + +ARMNN_AUTO_TEST_CASE_WITH_THF(PowerFloat16, PowerFloat16Test) +ARMNN_AUTO_TEST_CASE_WITH_THF(PowerBroadcast1ElementFloat16, PowerBroadcast1ElementFloat16Test) +ARMNN_AUTO_TEST_CASE_WITH_THF(PowerBroadcastFloat16, PowerBroadcastFloat16Test) + +ARMNN_AUTO_TEST_CASE_WITH_THF(PowerUint8, PowerUint8Test) +ARMNN_AUTO_TEST_CASE_WITH_THF(PowerBroadcastUint8, PowerBroadcastUint8Test) +ARMNN_AUTO_TEST_CASE_WITH_THF(PowerBroadcast1ElementUint8, PowerBroadcast1ElementUint8Test) + +ARMNN_AUTO_TEST_CASE_WITH_THF(PowerInt16, PowerInt16Test) +ARMNN_AUTO_TEST_CASE_WITH_THF(PowerBroadcastInt16, PowerBroadcastInt16Test) +ARMNN_AUTO_TEST_CASE_WITH_THF(PowerBroadcast1ElementInt16, PowerBroadcast1ElementInt16Test) + +ARMNN_AUTO_TEST_CASE_WITH_THF(PowerInt32, PowerInt32Test) +ARMNN_AUTO_TEST_CASE_WITH_THF(PowerBroadcastInt32, PowerBroadcastInt32Test) +ARMNN_AUTO_TEST_CASE_WITH_THF(PowerBroadcast1ElementInt32, PowerBroadcast1ElementInt32Test) + // Batch Mat Mul ARMNN_AUTO_TEST_CASE_WITH_THF(BatchMatMul2DSimpleFloat32, BatchMatMul2DSimpleTest<DataType::Float32>); ARMNN_AUTO_TEST_CASE_WITH_THF(BatchMatMul2DSimpleFloat16, BatchMatMul2DSimpleTest<DataType::Float16>); diff --git a/src/backends/reference/workloads/ElementwiseFunction.cpp b/src/backends/reference/workloads/ElementwiseFunction.cpp index c5b0ad1f24..4044f06ac4 100644 --- a/src/backends/reference/workloads/ElementwiseFunction.cpp +++ b/src/backends/reference/workloads/ElementwiseFunction.cpp @@ -14,6 +14,8 @@ #include "Rsqrt.hpp" #include "Sin.hpp" #include "Sqrt.hpp" +#include "Power.hpp" +#include "SquaredDifference.hpp" namespace armnn @@ -67,6 +69,8 @@ template struct armnn::ElementwiseBinaryFunction<std::multiplies<float>>; template struct armnn::ElementwiseBinaryFunction<std::divides<float>>; template struct armnn::ElementwiseBinaryFunction<armnn::maximum<float>>; template struct armnn::ElementwiseBinaryFunction<armnn::minimum<float>>; +template struct armnn::ElementwiseBinaryFunction<armnn::power<float>>; +template struct armnn::ElementwiseBinaryFunction<armnn::squaredDifference<float>>; template struct armnn::ElementwiseBinaryFunction<std::plus<int32_t>>; template struct armnn::ElementwiseBinaryFunction<std::minus<int32_t>>; @@ -74,6 +78,8 @@ template struct armnn::ElementwiseBinaryFunction<std::multiplies<int32_t>>; template struct armnn::ElementwiseBinaryFunction<std::divides<int32_t>>; template struct armnn::ElementwiseBinaryFunction<armnn::maximum<int32_t>>; template struct armnn::ElementwiseBinaryFunction<armnn::minimum<int32_t>>; +template struct armnn::ElementwiseBinaryFunction<armnn::power<int32_t>>; +template struct armnn::ElementwiseBinaryFunction<armnn::squaredDifference<int32_t>>; // Comparison template struct armnn::ElementwiseBinaryFunction<std::equal_to<float>>; diff --git a/src/backends/reference/workloads/Power.hpp b/src/backends/reference/workloads/Power.hpp new file mode 100644 index 0000000000..744328e8bf --- /dev/null +++ b/src/backends/reference/workloads/Power.hpp @@ -0,0 +1,27 @@ +// +// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include <iostream> + +namespace armnn +{ + +template<typename T> +struct power +{ + typedef T result_type; + typedef T first_argument_type; + + T + operator()(const T& input1, const T& input2) const + { + T power = armnn::numeric_cast<T>(std::pow(static_cast<float>(input1), static_cast<float>(input2))); + return power; + } +}; + +} //namespace armnn diff --git a/src/backends/reference/workloads/RefElementwiseBinaryWorkload.cpp b/src/backends/reference/workloads/RefElementwiseBinaryWorkload.cpp index 5dc77f8496..e71cdd4e3c 100644 --- a/src/backends/reference/workloads/RefElementwiseBinaryWorkload.cpp +++ b/src/backends/reference/workloads/RefElementwiseBinaryWorkload.cpp @@ -11,6 +11,8 @@ #include "RefWorkloadUtils.hpp" #include "Maximum.hpp" #include "Minimum.hpp" +#include "SquaredDifference.hpp" +#include "Power.hpp" #include <Profiling.hpp> @@ -44,6 +46,8 @@ void ExecuteFunction(std::vector<ITensorHandle*> inputs, using MinimumFunction = ElementwiseBinaryFunction<armnn::minimum<DataType>>; using MulFunction = ElementwiseBinaryFunction<std::multiplies<DataType>>; using SubFunction = ElementwiseBinaryFunction<std::minus<DataType>>; + using SqDiffFunction = ElementwiseBinaryFunction<armnn::squaredDifference<DataType>>; + using PowerFunction = ElementwiseBinaryFunction<armnn::power<DataType>>; switch (operation) { @@ -77,6 +81,16 @@ void ExecuteFunction(std::vector<ITensorHandle*> inputs, SubFunction(inShape0, inShape1, outShape, *input0, *input1, *output); break; } + case BinaryOperation::SqDiff: + { + SqDiffFunction(inShape0, inShape1, outShape, *input0, *input1, *output); + break; + } + case BinaryOperation::Power: + { + PowerFunction(inShape0, inShape1, outShape, *input0, *input1, *output); + break; + } default: { throw InvalidArgumentException(std::string("Unsupported binary operation ") + diff --git a/src/backends/reference/workloads/SquaredDifference.hpp b/src/backends/reference/workloads/SquaredDifference.hpp new file mode 100644 index 0000000000..c15b379a4d --- /dev/null +++ b/src/backends/reference/workloads/SquaredDifference.hpp @@ -0,0 +1,28 @@ +// +// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include <cmath> + +namespace armnn +{ + +template<typename T> +struct squaredDifference +{ + typedef T result_type; + typedef T first_argument_type; + + T + operator()(const T& input1, const T& input2) const + { + float diff = std::minus<>{}(static_cast<float>(input1),static_cast<float>(input2)); + T squaredDiff = armnn::numeric_cast<T>(std::pow(static_cast<float>(diff), 2)); + return squaredDiff; + } +}; + +} //namespace armnn |