diff options
author | Nikhil Raj <nikhil.raj@arm.com> | 2022-12-05 11:24:35 +0000 |
---|---|---|
committer | Nikhil Raj Arm <nikhil.raj@arm.com> | 2022-12-23 10:28:30 +0000 |
commit | 9a33946fd0d5e14be6f957b5a985438fa69684d6 (patch) | |
tree | 07b93ffccc31c2183567fda3523d79a82510745b /src/backends/tosaCommon/operatorMappings | |
parent | 259adafd6840c612c2eb64653290cbe2cfa7cd8e (diff) | |
download | armnn-9a33946fd0d5e14be6f957b5a985438fa69684d6.tar.gz |
IVGCVSW-7172 Add ElementwiseBinary (Subtraction & Multiplication) support to TOSA Reference Backend
* Removed AdditionOperator and moved to new ElementwiseBinaryOperator.
Signed-off-by: Nikhil Raj <nikhil.raj@arm.com>
Signed-off-by: Matthew Sloyan <matthew.sloyan@arm.com>
Change-Id: I8ce20f7575d68334aadcd176827bca3db53d0052
Diffstat (limited to 'src/backends/tosaCommon/operatorMappings')
-rw-r--r-- | src/backends/tosaCommon/operatorMappings/AdditionOperator.hpp | 20 | ||||
-rw-r--r-- | src/backends/tosaCommon/operatorMappings/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/backends/tosaCommon/operatorMappings/ElementwiseBinaryOperator.cpp (renamed from src/backends/tosaCommon/operatorMappings/AdditionOperator.cpp) | 67 | ||||
-rw-r--r-- | src/backends/tosaCommon/operatorMappings/ElementwiseBinaryOperator.hpp | 20 | ||||
-rw-r--r-- | src/backends/tosaCommon/operatorMappings/TosaCommonOperators.hpp | 6 |
5 files changed, 74 insertions, 43 deletions
diff --git a/src/backends/tosaCommon/operatorMappings/AdditionOperator.hpp b/src/backends/tosaCommon/operatorMappings/AdditionOperator.hpp deleted file mode 100644 index 5eb7441531..0000000000 --- a/src/backends/tosaCommon/operatorMappings/AdditionOperator.hpp +++ /dev/null @@ -1,20 +0,0 @@ -// -// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. -// SPDX-License-Identifier: MIT -// - -#pragma once - -#include "TosaOperatorUtils.hpp" - -#include <Layer.hpp> - -#include <tosa_serialization_handler.h> - -using namespace armnn; -using namespace tosa; - -TosaSerializationBasicBlock* ConvertAdditionToTosaOperator(const Layer* layer, - const std::vector<const TensorInfo*>& inputs, - const std::vector<const TensorInfo*>& outputs); - diff --git a/src/backends/tosaCommon/operatorMappings/CMakeLists.txt b/src/backends/tosaCommon/operatorMappings/CMakeLists.txt index 2443dc0585..6e897aaa8c 100644 --- a/src/backends/tosaCommon/operatorMappings/CMakeLists.txt +++ b/src/backends/tosaCommon/operatorMappings/CMakeLists.txt @@ -4,8 +4,6 @@ # list(APPEND armnnTosaBackendOperators_sources - AdditionOperator.hpp - AdditionOperator.cpp AvgPool2DIgnoreValueOperator.hpp AvgPool2DIgnoreValueOperator.cpp ConcatOperator.hpp @@ -14,6 +12,8 @@ list(APPEND armnnTosaBackendOperators_sources ConstantOperator.cpp Conv2dOperator.hpp Conv2dOperator.cpp + ElementwiseBinaryOperator.hpp + ElementwiseBinaryOperator.cpp Pooling2DOperator.hpp Pooling2DOperator.cpp ReshapeOperator.hpp diff --git a/src/backends/tosaCommon/operatorMappings/AdditionOperator.cpp b/src/backends/tosaCommon/operatorMappings/ElementwiseBinaryOperator.cpp index 7014886d92..9909e66a7d 100644 --- a/src/backends/tosaCommon/operatorMappings/AdditionOperator.cpp +++ b/src/backends/tosaCommon/operatorMappings/ElementwiseBinaryOperator.cpp @@ -3,22 +3,23 @@ // SPDX-License-Identifier: MIT // -#include "AdditionOperator.hpp" +#include "ElementwiseBinaryOperator.hpp" -TosaSerializationBasicBlock* ConvertAdditionToTosaOperator(const Layer* layer, - const std::vector<const TensorInfo*>& inputs, - const std::vector<const TensorInfo*>& outputs) +TosaSerializationBasicBlock* ConvertElementwiseBinaryToTosaOperator(const Layer* layer, + const LayerType type, + const std::vector<const TensorInfo*>& inputs, + const std::vector<const TensorInfo*>& outputs) { std::string input0Name = std::string("input0_"); std::string input1Name = std::string("input1_"); std::string outputName = std::string("output0_"); - std::string blockName = std::string("Op_ADD_block_") + GetUniqueTosaMappingID(); + std::string blockName; // If a layer is present then the block will be used for execution, so input and output names need to be determined // using the previous and following layers so the graph is connected correctly. For validation this doesn't matter. if(layer != nullptr) { - // Get the layers connected to the input slots and determine unique tensors names. + // Get the layers connected to the input slots and determine unique tensor names. Layer& connectedLayer0 = layer->GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer(); input0Name = GenerateUniqueName(connectedLayer0, 0); @@ -29,15 +30,47 @@ TosaSerializationBasicBlock* ConvertAdditionToTosaOperator(const Layer* layer, outputName = GenerateUniqueOutputName(*layer, 0); } - auto* op = new TosaSerializationOperator(Op_ADD, - Attribute_NONE, - nullptr, - {input0Name, input1Name}, - {outputName}); - + TosaSerializationOperator* op = nullptr; + switch(type) + { + case LayerType::Addition: + { + op = new TosaSerializationOperator(Op_ADD, + Attribute_NONE, + nullptr, + {input0Name, input1Name}, + {outputName}); + blockName = std::string("Op_ADD_block_") + GetUniqueTosaMappingID(); + break; + } + case LayerType::Multiplication: + { + int32_t shift = 0; + TosaMulAttribute mulAttribute(shift); + op = new TosaSerializationOperator(Op_MUL, + Attribute_MulAttribute, + &mulAttribute, + {input0Name, input1Name}, + {outputName}); + blockName = std::string("Op_MUL_block_") + GetUniqueTosaMappingID(); + break; + } + case LayerType::Subtraction: + { + op = new TosaSerializationOperator(Op_SUB, + Attribute_NONE, + nullptr, + {input0Name, input1Name}, + {outputName}); + blockName = std::string("Op_SUB_block_") + GetUniqueTosaMappingID(); + break; + } + default: + throw armnn::Exception("ConvertElementwiseBinaryToTosaOperator: Unsupported layer type."); + } + ARMNN_ASSERT(op != nullptr); std::vector<TosaSerializationTensor*> tensors; - // Only add input tensors if connected layer is an input layer. // As intermediate or constant tensors will be created separately. // There also can't be duplicate tensor. @@ -45,15 +78,12 @@ TosaSerializationBasicBlock* ConvertAdditionToTosaOperator(const Layer* layer, { std::vector<int32_t> inputShape0 = GetTosaTensorShape(inputs[0]->GetShape()); DType inputDType0 = ArmNNToDType(inputs[0]->GetDataType()); - tensors.push_back(new TosaSerializationTensor(input0Name, inputShape0, inputDType0, {})); } - if(input1Name.find("input1_") != std::string::npos) { std::vector<int32_t> inputShape1 = GetTosaTensorShape(inputs[1]->GetShape()); DType inputDType1 = ArmNNToDType(inputs[1]->GetDataType()); - tensors.push_back(new TosaSerializationTensor(input1Name, inputShape1, inputDType1, {})); } @@ -63,10 +93,11 @@ TosaSerializationBasicBlock* ConvertAdditionToTosaOperator(const Layer* layer, tensors.push_back(new TosaSerializationTensor(outputName, outputShape0, outputDType0, {})); // operatorInputNames/operatorOutputNames ends up being the same as - // blockInputNames/blockOutputNames for one-to-one ArmNN to TOSA mappings + // blockInputNames/blockOutputNames for one-to-one ArmNN to Tosa mappings return new TosaSerializationBasicBlock(blockName, // name {op}, // operators tensors, // tensors {input0Name, input1Name}, // inputs {outputName}); // outputs -}
\ No newline at end of file +} + diff --git a/src/backends/tosaCommon/operatorMappings/ElementwiseBinaryOperator.hpp b/src/backends/tosaCommon/operatorMappings/ElementwiseBinaryOperator.hpp new file mode 100644 index 0000000000..86031c6e06 --- /dev/null +++ b/src/backends/tosaCommon/operatorMappings/ElementwiseBinaryOperator.hpp @@ -0,0 +1,20 @@ +// +// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include "TosaOperatorUtils.hpp" + +#include <Layer.hpp> + +#include <tosa_serialization_handler.h> + +using namespace armnn; +using namespace tosa; + +TosaSerializationBasicBlock* ConvertElementwiseBinaryToTosaOperator(const Layer* layer, + const LayerType type, + const std::vector<const TensorInfo*>& inputs, + const std::vector<const TensorInfo*>& outputs);
\ No newline at end of file diff --git a/src/backends/tosaCommon/operatorMappings/TosaCommonOperators.hpp b/src/backends/tosaCommon/operatorMappings/TosaCommonOperators.hpp index 052c54c3af..7b117d8443 100644 --- a/src/backends/tosaCommon/operatorMappings/TosaCommonOperators.hpp +++ b/src/backends/tosaCommon/operatorMappings/TosaCommonOperators.hpp @@ -5,12 +5,12 @@ #pragma once -#include "AdditionOperator.hpp" +#include "AvgPool2DIgnoreValueOperator.hpp" #include "ConcatOperator.hpp" #include "ConstantOperator.hpp" #include "Conv2dOperator.hpp" -#include "AvgPool2DIgnoreValueOperator.hpp" +#include "ElementwiseBinaryOperator.hpp" #include "Pooling2DOperator.hpp" #include "ReshapeOperator.hpp" #include "SliceOperator.hpp" -#include "TransposeConv2dOperator.hpp"
\ No newline at end of file +#include "TransposeConv2dOperator.hpp" |