From 3ec3077b4eaedcc0c20ab5774bdbe365da541445 Mon Sep 17 00:00:00 2001 From: Mike Kelly Date: Wed, 8 Mar 2023 13:47:17 +0000 Subject: 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 Signed-off-by: Mike Kelly Change-Id: I7cbb96b60eb01f0e2b57b0541016d48a08b86c75 --- src/armnnTestUtils/CreateWorkload.hpp | 39 +++++++++++++++++++++++++++++++++-- src/armnnTestUtils/MockBackend.cpp | 3 ++- 2 files changed, 39 insertions(+), 3 deletions(-) (limited to 'src/armnnTestUtils') diff --git a/src/armnnTestUtils/CreateWorkload.hpp b/src/armnnTestUtils/CreateWorkload.hpp index 0846d21388..691adbff9d 100644 --- a/src/armnnTestUtils/CreateWorkload.hpp +++ b/src/armnnTestUtils/CreateWorkload.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017,2021-2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #pragma once @@ -125,7 +125,41 @@ std::unique_ptr CreateElementwiseWorkloadTest(armnn::IWorkloadFact // Makes the workload and checks it. auto workload = MakeAndCheckWorkload(*layer, factory); - DescriptorType queueDescriptor = workload->GetData(); + auto queueDescriptor = workload->GetData(); + CHECK(queueDescriptor.m_Inputs.size() == 2); + CHECK(queueDescriptor.m_Outputs.size() == 1); + + // Returns so we can do extra, backend-specific tests. + return workload; +} + +template +std::unique_ptr CreateElementwiseBinaryWorkloadTest(armnn::IWorkloadFactory & factory, + armnn::Graph & graph, + armnn::BinaryOperation binaryOperation) +{ + // Creates the layer we're testing. + ElementwiseBinaryDescriptor descriptor(binaryOperation); + //ElementwiseBinaryDescriptor descriptor = ElementwiseBinaryDescriptor(binaryOperation); + + Layer* const layer = graph.AddLayer(descriptor, "layer"); + + // Creates extra layers. + Layer* const input1 = graph.AddLayer(1, "input1"); + Layer* const input2 = graph.AddLayer(2, "input2"); + Layer* const output = graph.AddLayer(0, "output"); + + // Connects up. + armnn::TensorInfo tensorInfo({2, 3}, DataType); + Connect(input1, layer, tensorInfo, 0, 0); + Connect(input2, layer, tensorInfo, 0, 1); + Connect(layer, output, tensorInfo); + CreateTensorHandles(graph, factory); + + // Makes the workload and checks it. + auto workload = MakeAndCheckWorkload(*layer, factory); + + auto queueDescriptor = workload->GetData(); CHECK(queueDescriptor.m_Inputs.size() == 2); CHECK(queueDescriptor.m_Outputs.size() == 1); @@ -191,6 +225,7 @@ std::unique_ptr CreateSubtractionWithBlobWorkloadTest(armnn::IWork return workload; } + template diff --git a/src/armnnTestUtils/MockBackend.cpp b/src/armnnTestUtils/MockBackend.cpp index 5dfe9a3b8b..7441d0c487 100644 --- a/src/armnnTestUtils/MockBackend.cpp +++ b/src/armnnTestUtils/MockBackend.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -69,6 +69,7 @@ bool IsLayerSupported(const armnn::Layer* layer) case armnn::LayerType::Constant: case armnn::LayerType::Addition: case armnn::LayerType::Convolution2d: + case armnn::LayerType::ElementwiseBinary: // Layer supported return true; default: -- cgit v1.2.1