aboutsummaryrefslogtreecommitdiff
path: root/delegate
diff options
context:
space:
mode:
authorJohn Mcloughlin <john.mcloughlin@arm.com>2023-05-15 17:03:49 +0100
committerJohn Mcloughlin <john.mcloughlin@arm.com>2023-05-17 12:29:54 +0100
commit0ec008761ab26110dcb108d544be4040a14fd403 (patch)
tree87bbc145ff2a4ea3221440b0fbd7c91a5b8a7c91 /delegate
parent499ebd917d8399f0a9d4d7e6e40a0ec321a4bab4 (diff)
downloadarmnn-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 'delegate')
-rw-r--r--delegate/CMakeLists.txt2
-rw-r--r--delegate/classic/src/ElementwiseBinary.hpp70
-rw-r--r--delegate/classic/src/armnn_delegate.cpp12
-rw-r--r--delegate/opaque/src/ElementwiseBinary.hpp70
-rw-r--r--delegate/opaque/src/armnn_delegate.cpp12
-rw-r--r--delegate/test/ElementwiseBinaryTest.cpp56
-rw-r--r--delegate/test/ElementwiseBinaryTestHelper.hpp12
7 files changed, 234 insertions, 0 deletions
diff --git a/delegate/CMakeLists.txt b/delegate/CMakeLists.txt
index 055ffce1c3..272c9a5a73 100644
--- a/delegate/CMakeLists.txt
+++ b/delegate/CMakeLists.txt
@@ -280,6 +280,8 @@ if(BUILD_UNIT_TESTS)
test/Convolution3dTest.cpp
test/ConvolutionTestHelper.hpp
test/DepthwiseConvolution2dTest.cpp
+ test/ElementwiseBinaryTest.cpp
+ test/ElementwiseBinaryTestHelper.hpp
test/ElementwiseUnaryTestHelper.hpp
test/ElementwiseUnaryTest.cpp
test/ExpandDimsTest.cpp
diff --git a/delegate/classic/src/ElementwiseBinary.hpp b/delegate/classic/src/ElementwiseBinary.hpp
index dbbf47941a..8055a6958c 100644
--- a/delegate/classic/src/ElementwiseBinary.hpp
+++ b/delegate/classic/src/ElementwiseBinary.hpp
@@ -174,6 +174,56 @@ TfLiteStatus ValidateMulOperator(DelegateData& delegateData,
return isSupported ? kTfLiteOk : kTfLiteError;
}
+TfLiteStatus ValidatePowerOperator(DelegateData& delegateData,
+ TfLiteContext* tfLiteContext,
+ const armnn::TensorInfo& inputInfo1,
+ const armnn::TensorInfo& inputInfo2,
+ const armnn::TensorInfo& outputInfo)
+{
+ bool isSupported = false;
+ auto validateFunc = [&](const armnn::TensorInfo& outputTensorInfo, bool& isSupported)
+ {
+ FORWARD_LAYER_SUPPORT_FUNC("POWER",
+ tfLiteContext,
+ IsElementwiseBinarySupported,
+ delegateData.m_Backends,
+ isSupported,
+ armnn::BackendId(),
+ inputInfo1,
+ inputInfo2,
+ outputTensorInfo,
+ armnn::BinaryOperation::Power);
+ };
+
+ validateFunc(outputInfo, isSupported);
+ return isSupported ? kTfLiteOk : kTfLiteError;
+}
+
+TfLiteStatus ValidateSquaredDifferenceOperator(DelegateData& delegateData,
+ TfLiteContext* tfLiteContext,
+ const armnn::TensorInfo& inputInfo1,
+ const armnn::TensorInfo& inputInfo2,
+ const armnn::TensorInfo& outputInfo)
+{
+ bool isSupported = false;
+ auto validateFunc = [&](const armnn::TensorInfo& outputTensorInfo, bool& isSupported)
+ {
+ FORWARD_LAYER_SUPPORT_FUNC("SQUAREDDIFFERENCE",
+ tfLiteContext,
+ IsElementwiseBinarySupported,
+ delegateData.m_Backends,
+ isSupported,
+ armnn::BackendId(),
+ inputInfo1,
+ inputInfo2,
+ outputTensorInfo,
+ armnn::BinaryOperation::SqDiff);
+ };
+
+ validateFunc(outputInfo, isSupported);
+ return isSupported ? kTfLiteOk : kTfLiteError;
+}
+
TfLiteStatus ValidateSubOperator(DelegateData& delegateData,
TfLiteContext* tfLiteContext,
const armnn::TensorInfo& inputInfo1,
@@ -322,6 +372,18 @@ TfLiteStatus VisitElementwiseBinaryOperator(DelegateData& delegateData,
inputTensorInfo0,
inputTensorInfo1,
outputTensorInfo);
+ case kTfLiteBuiltinPow:
+ return ValidatePowerOperator(delegateData,
+ tfLiteContext,
+ inputTensorInfo0,
+ inputTensorInfo1,
+ outputTensorInfo);
+ case kTfLiteBuiltinSquaredDifference:
+ return ValidateSquaredDifferenceOperator(delegateData,
+ tfLiteContext,
+ inputTensorInfo0,
+ inputTensorInfo1,
+ outputTensorInfo);
case kTfLiteBuiltinSub:
return ValidateSubOperator(delegateData,
tfLiteContext,
@@ -364,6 +426,14 @@ TfLiteStatus VisitElementwiseBinaryOperator(DelegateData& delegateData,
elementwiseBinaryLayer = delegateData.m_Network->AddElementwiseBinaryLayer(
armnn::BinaryOperation::Mul);
break;
+ case kTfLiteBuiltinPow:
+ elementwiseBinaryLayer = delegateData.m_Network->AddElementwiseBinaryLayer(
+ armnn::BinaryOperation::Power);
+ break;
+ case kTfLiteBuiltinSquaredDifference:
+ elementwiseBinaryLayer = delegateData.m_Network->AddElementwiseBinaryLayer(
+ armnn::BinaryOperation::SqDiff);
+ break;
case kTfLiteBuiltinSub:
elementwiseBinaryLayer = delegateData.m_Network->AddElementwiseBinaryLayer(
armnn::BinaryOperation::Sub);
diff --git a/delegate/classic/src/armnn_delegate.cpp b/delegate/classic/src/armnn_delegate.cpp
index 9b4a7d3b86..e597d13fb2 100644
--- a/delegate/classic/src/armnn_delegate.cpp
+++ b/delegate/classic/src/armnn_delegate.cpp
@@ -871,6 +871,12 @@ TfLiteStatus ArmnnSubgraph::VisitNode(DelegateData& delegateData,
tfLiteNode,
nodeIndex,
kTfLiteBuiltinPadv2);
+ case kTfLiteBuiltinPow:
+ return VisitElementwiseBinaryOperator(delegateData,
+ tfLiteContext,
+ tfLiteNode,
+ nodeIndex,
+ kTfLiteBuiltinPow);
case kTfLiteBuiltinPrelu:
return VisitPreluOperator(delegateData,
tfLiteContext,
@@ -979,6 +985,12 @@ TfLiteStatus ArmnnSubgraph::VisitNode(DelegateData& delegateData,
tfLiteNode,
nodeIndex,
armnn::UnaryOperation::Sqrt);
+ case kTfLiteBuiltinSquaredDifference:
+ return VisitElementwiseBinaryOperator(delegateData,
+ tfLiteContext,
+ tfLiteNode,
+ nodeIndex,
+ kTfLiteBuiltinSquaredDifference);
case kTfLiteBuiltinSqueeze:
return VisitSqueezeOperator(delegateData,
tfLiteContext,
diff --git a/delegate/opaque/src/ElementwiseBinary.hpp b/delegate/opaque/src/ElementwiseBinary.hpp
index d6a0947b96..8448609695 100644
--- a/delegate/opaque/src/ElementwiseBinary.hpp
+++ b/delegate/opaque/src/ElementwiseBinary.hpp
@@ -167,6 +167,56 @@ TfLiteStatus ValidateMulOperator(DelegateData& delegateData,
return isSupported ? kTfLiteOk : kTfLiteError;
}
+TfLiteStatus ValidatePowerOperator(DelegateData& delegateData,
+ TfLiteOpaqueContext* tfLiteContext,
+ const armnn::TensorInfo& inputInfo1,
+ const armnn::TensorInfo& inputInfo2,
+ const armnn::TensorInfo& outputInfo)
+{
+ bool isSupported = false;
+ auto validateFunc = [&](const armnn::TensorInfo& outputTensorInfo, bool& isSupported)
+ {
+ FORWARD_LAYER_OPAQUE_SUPPORT_FUNC("POWER",
+ tfLiteContext,
+ IsElementwiseBinarySupported,
+ delegateData.m_Backends,
+ isSupported,
+ armnn::BackendId(),
+ inputInfo1,
+ inputInfo2,
+ outputTensorInfo,
+ armnn::BinaryOperation::Power);
+ };
+
+ validateFunc(outputInfo, isSupported);
+ return isSupported ? kTfLiteOk : kTfLiteError;
+}
+
+TfLiteStatus ValidateSquaredDifferenceOperator(DelegateData& delegateData,
+ TfLiteOpaqueContext* tfLiteContext,
+ const armnn::TensorInfo& inputInfo1,
+ const armnn::TensorInfo& inputInfo2,
+ const armnn::TensorInfo& outputInfo)
+{
+ bool isSupported = false;
+ auto validateFunc = [&](const armnn::TensorInfo& outputTensorInfo, bool& isSupported)
+ {
+ FORWARD_LAYER_OPAQUE_SUPPORT_FUNC("SQUAREDDIFFERENCE",
+ tfLiteContext,
+ IsElementwiseBinarySupported,
+ delegateData.m_Backends,
+ isSupported,
+ armnn::BackendId(),
+ inputInfo1,
+ inputInfo2,
+ outputTensorInfo,
+ armnn::BinaryOperation::SqDiff);
+ };
+
+ validateFunc(outputInfo, isSupported);
+ return isSupported ? kTfLiteOk : kTfLiteError;
+}
+
TfLiteStatus ValidateSubOperator(DelegateData& delegateData,
TfLiteOpaqueContext* tfLiteContext,
const armnn::TensorInfo& inputInfo1,
@@ -336,6 +386,18 @@ TfLiteStatus VisitElementwiseBinaryOperator(DelegateData& delegateData,
inputTensorInfo0,
inputTensorInfo1,
outputTensorInfo);
+ case kTfLiteBuiltinPow:
+ return ValidatePowerOperator(delegateData,
+ tfLiteContext,
+ inputTensorInfo0,
+ inputTensorInfo1,
+ outputTensorInfo);
+ case kTfLiteBuiltinSquaredDifference:
+ return ValidateSquaredDifferenceOperator(delegateData,
+ tfLiteContext,
+ inputTensorInfo0,
+ inputTensorInfo1,
+ outputTensorInfo);
case kTfLiteBuiltinSub:
return ValidateSubOperator(delegateData,
tfLiteContext,
@@ -378,6 +440,14 @@ TfLiteStatus VisitElementwiseBinaryOperator(DelegateData& delegateData,
elementwiseBinaryLayer = delegateData.m_Network->AddElementwiseBinaryLayer(
armnn::BinaryOperation::Mul);
break;
+ case kTfLiteBuiltinPow:
+ elementwiseBinaryLayer = delegateData.m_Network->AddElementwiseBinaryLayer(
+ armnn::BinaryOperation::Power);
+ break;
+ case kTfLiteBuiltinSquaredDifference:
+ elementwiseBinaryLayer = delegateData.m_Network->AddElementwiseBinaryLayer(
+ armnn::BinaryOperation::SqDiff);
+ break;
case kTfLiteBuiltinSub:
elementwiseBinaryLayer = delegateData.m_Network->AddElementwiseBinaryLayer(
armnn::BinaryOperation::Sub);
diff --git a/delegate/opaque/src/armnn_delegate.cpp b/delegate/opaque/src/armnn_delegate.cpp
index 1c9f2d973e..45aff85346 100644
--- a/delegate/opaque/src/armnn_delegate.cpp
+++ b/delegate/opaque/src/armnn_delegate.cpp
@@ -966,6 +966,12 @@ TfLiteStatus ArmnnSubgraph::VisitNode(DelegateData& delegateData,
tfLiteNode,
nodeIndex,
kTfLiteBuiltinPadv2);
+ case kTfLiteBuiltinPow:
+ return VisitElementwiseBinaryOperator(delegateData,
+ tfLiteContext,
+ tfLiteNode,
+ nodeIndex,
+ kTfLiteBuiltinPow);
case kTfLiteBuiltinPrelu:
return VisitPreluOperator(delegateData,
tfLiteContext,
@@ -1088,6 +1094,12 @@ TfLiteStatus ArmnnSubgraph::VisitNode(DelegateData& delegateData,
tfLiteNode,
nodeIndex,
kTfLiteBuiltinSplitV);
+ case kTfLiteBuiltinSquaredDifference:
+ return VisitElementwiseBinaryOperator(delegateData,
+ tfLiteContext,
+ tfLiteNode,
+ nodeIndex,
+ kTfLiteBuiltinSquaredDifference);
case kTfLiteBuiltinSub:
return VisitElementwiseBinaryOperator(delegateData,
tfLiteContext,
diff --git a/delegate/test/ElementwiseBinaryTest.cpp b/delegate/test/ElementwiseBinaryTest.cpp
index effed03e5e..2f22e7d1b1 100644
--- a/delegate/test/ElementwiseBinaryTest.cpp
+++ b/delegate/test/ElementwiseBinaryTest.cpp
@@ -699,6 +699,50 @@ void SubFP32Test(std::vector<armnn::BackendId>& backends)
expectedOutputValues);
}
+void PowerFP32Test(std::vector<armnn::BackendId>& backends)
+{
+ std::vector<int32_t> input0Shape { 1, 1, 2, 2 };
+ std::vector<int32_t> input1Shape { 1, 1, 2, 2 };
+ std::vector<int32_t> expectedOutputShape { 1, 1, 2, 2 };
+
+ std::vector<float> input0Values = { 1, 3, 3, -7 };
+ std::vector<float> input1Values = { 1, 1, 0, 2 };
+ std::vector<float> expectedOutputValues = { 1, 3, 1, 49 };
+
+ ElementwiseBinaryTest<float>(tflite::BuiltinOperator_POW,
+ tflite::ActivationFunctionType_NONE,
+ ::tflite::TensorType_FLOAT32,
+ backends,
+ input0Shape,
+ input1Shape,
+ expectedOutputShape,
+ input0Values,
+ input1Values,
+ expectedOutputValues);
+}
+
+void SqDiffFP32Test(std::vector<armnn::BackendId>& backends)
+{
+ std::vector<int32_t> input0Shape { 1, 1, 2, 2 };
+ std::vector<int32_t> input1Shape { 1, 1, 2, 2 };
+ std::vector<int32_t> expectedOutputShape { 1, 1, 2, 2 };
+
+ std::vector<float> input0Values = { 1, 3, 3, -7 };
+ std::vector<float> input1Values = { 1, -1, 0, -2 };
+ std::vector<float> expectedOutputValues = { 0, 16, 9, 25 };
+
+ ElementwiseBinaryTest<float>(tflite::BuiltinOperator_SQUARED_DIFFERENCE,
+ tflite::ActivationFunctionType_NONE,
+ ::tflite::TensorType_FLOAT32,
+ backends,
+ input0Shape,
+ input1Shape,
+ expectedOutputShape,
+ input0Values,
+ input1Values,
+ expectedOutputValues);
+}
+
void SubBroadcastTest(std::vector<armnn::BackendId>& backends)
{
std::vector<int32_t> input0Shape { 1, 1, 2, 2 };
@@ -1131,6 +1175,18 @@ TEST_CASE ("SUB_UINT8_CpuRef_Test")
SubUint8Test(backends);
}
+TEST_CASE ("SqDiffFP32_CpuRef_Test")
+{
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
+ SqDiffFP32Test(backends);
+}
+
+TEST_CASE ("PowerFP32_CpuRef_Test")
+{
+ std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
+ PowerFP32Test(backends);
+}
+
} // TEST_SUITE("ElementwiseBinary_CpuRefTests")
} // namespace armnnDelegate
diff --git a/delegate/test/ElementwiseBinaryTestHelper.hpp b/delegate/test/ElementwiseBinaryTestHelper.hpp
index fa9cbb881e..fc7549161c 100644
--- a/delegate/test/ElementwiseBinaryTestHelper.hpp
+++ b/delegate/test/ElementwiseBinaryTestHelper.hpp
@@ -124,6 +124,18 @@ std::vector<char> CreateElementwiseBinaryTfLiteModel(tflite::BuiltinOperator bin
operatorBuiltinOptions = CreateSubOptions(flatBufferBuilder, activationType).Union();
break;
}
+ case BuiltinOperator_POW:
+ {
+ operatorBuiltinOptionsType = BuiltinOptions_PowOptions;
+ operatorBuiltinOptions = CreatePowOptions(flatBufferBuilder).Union();
+ break;
+ }
+ case BuiltinOperator_SQUARED_DIFFERENCE:
+ {
+ operatorBuiltinOptionsType = BuiltinOptions_SquaredDifferenceOptions;
+ operatorBuiltinOptions = CreateSquaredDifferenceOptions(flatBufferBuilder).Union();
+ break;
+ }
case BuiltinOperator_FLOOR_DIV:
{
operatorBuiltinOptionsType = tflite::BuiltinOptions_FloorDivOptions;