diff options
author | Mike Kelly <mike.kelly@arm.com> | 2023-03-08 13:47:17 +0000 |
---|---|---|
committer | Francis Murtagh <francis.murtagh@arm.com> | 2023-03-14 16:40:09 +0000 |
commit | 3ec3077b4eaedcc0c20ab5774bdbe365da541445 (patch) | |
tree | d601d2000897dec8691bf64cbddc9036f26b8034 /src/armnnSerializer/test | |
parent | a088cd00b3cce672d26cdcb4965fc2a86b48f339 (diff) | |
download | armnn-3ec3077b4eaedcc0c20ab5774bdbe365da541445.tar.gz |
IVGCVSW-3808 Add ElementwiseBinaryLayer
!android-nn-driver:9329
* Added ElementwiseBinaryLayer that can represent all ElementwiseBinary
operations including Add, Div, Sub, Maximum, Mul and Minimum.
* Updated Delegate to use ElementwiseBinaryLayer instead of the Add,
Div, Sub, Maximum, Mul and Minimum layers.
* Updated Deserializer to use ElementwiseBinaryLayer instead of the Add,
Div, Sub, Maximum, Mul and Minimum layers.
* Updated OnnxParser to use ElementwiseBinaryLayer instead of the Add
layer.
* Updated TfLiteParser to use ElementwiseBinaryLayer instead of the Add,
Div, Sub, Maximum, Mul and Minimum layers.
* Updated CL and Neon tests to use ElementwiseBinaryLayer.
* Updated CL and Neon Backend Specific Optimizations to accept
ElementBinaryLayers as well as Add, Div, Mul, Sub, Maximum and Minimum
layers.
Signed-off-by: Teresa Charlin <teresa.charlinreyes@arm.com>
Signed-off-by: Mike Kelly <mike.kelly@arm.com>
Change-Id: I7cbb96b60eb01f0e2b57b0541016d48a08b86c75
Diffstat (limited to 'src/armnnSerializer/test')
-rw-r--r-- | src/armnnSerializer/test/SerializerTests.cpp | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/armnnSerializer/test/SerializerTests.cpp b/src/armnnSerializer/test/SerializerTests.cpp index 3573a8195c..6ddc971f36 100644 --- a/src/armnnSerializer/test/SerializerTests.cpp +++ b/src/armnnSerializer/test/SerializerTests.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2020-2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -331,6 +331,7 @@ TEST_CASE("SerializeConstant") case armnn::LayerType::Input: break; case armnn::LayerType::Output: break; case armnn::LayerType::Addition: break; + case armnn::LayerType::ElementwiseBinary: break; default: { this->VerifyNameAndConnections(layer, name); @@ -972,6 +973,47 @@ TEST_CASE("SerializeDeserializeComparisonEqual") deserializedNetwork->ExecuteStrategy(verifier); } +void SerializeElementwiseBinaryTest(armnn::BinaryOperation binaryOperation) +{ + auto layerName = GetBinaryOperationAsCString(binaryOperation); + const armnn::TensorInfo tensorInfo({ 1, 5, 2, 3 }, armnn::DataType::Float32); + armnn::ElementwiseBinaryDescriptor descriptor(binaryOperation); + + armnn::INetworkPtr network = armnn::INetwork::Create(); + armnn::IConnectableLayer* const inputLayer0 = network->AddInputLayer(0); + armnn::IConnectableLayer* const inputLayer1 = network->AddInputLayer(1); + armnn::IConnectableLayer* const elementwiseBinaryLayer = network->AddElementwiseBinaryLayer(descriptor, + layerName); + armnn::IConnectableLayer* const outputLayer = network->AddOutputLayer(0); + + inputLayer0->GetOutputSlot(0).Connect(elementwiseBinaryLayer->GetInputSlot(0)); + inputLayer1->GetOutputSlot(0).Connect(elementwiseBinaryLayer->GetInputSlot(1)); + elementwiseBinaryLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); + + inputLayer0->GetOutputSlot(0).SetTensorInfo(tensorInfo); + inputLayer1->GetOutputSlot(0).SetTensorInfo(tensorInfo); + elementwiseBinaryLayer->GetOutputSlot(0).SetTensorInfo(tensorInfo); + + std::string serializedNetwork = SerializeNetwork(*network); + armnn::INetworkPtr deserializedNetwork = DeserializeNetwork(serializedNetwork); + CHECK(deserializedNetwork); + + LayerVerifierBaseWithDescriptor<armnn::ElementwiseBinaryDescriptor> + verifier(layerName, { tensorInfo, tensorInfo }, { tensorInfo }, descriptor); + deserializedNetwork->ExecuteStrategy(verifier); +} + +TEST_CASE("SerializeElementwiseBinary") +{ + using op = armnn::BinaryOperation; + std::initializer_list<op> allBinaryOperations = {op::Add, op::Div, op::Maximum, op::Minimum, op::Mul, op::Sub}; + + for (auto binaryOperation : allBinaryOperations) + { + SerializeElementwiseBinaryTest(binaryOperation); + } +} + void SerializeElementwiseUnaryTest(armnn::UnaryOperation unaryOperation) { auto layerName = GetUnaryOperationAsCString(unaryOperation); @@ -2883,6 +2925,7 @@ TEST_CASE("SerializeDeserializeNonLinearNetwork") CompareConstTensor(constants.at(0), m_LayerInput); break; } + case armnn::LayerType::ElementwiseBinary: break; default: { throw armnn::Exception("Unexpected layer type in test model"); |