diff options
author | David Monahan <david.monahan@arm.com> | 2023-01-12 14:53:34 +0000 |
---|---|---|
committer | David Monahan <david.monahan@arm.com> | 2023-01-13 11:28:52 +0000 |
commit | d7fca093be53b314e100e15a8fa080cb506b60a3 (patch) | |
tree | faf4adbdd3154ffa6101bcbbf8c4839179ad180b /src/backends/tosaCommon/operatorMappings | |
parent | c17a35f4b016c223add511a148ed3bb741770593 (diff) | |
download | armnn-d7fca093be53b314e100e15a8fa080cb506b60a3.tar.gz |
IVGCVSW-7173 Add Rsqrt to Tosa Ref Backend
* Added ElementwiseUnary support with a mapping for Rsqrt
* Added unittests
* Added Rsqrt EndtoEnd tests for all backends
* Changed TosaRefLayerSupport to default to false on unsupported layers
Signed-off-by: David Monahan <david.monahan@arm.com>
Change-Id: I3eaa9c684647ead61520a563815581aa68bee51b
Diffstat (limited to 'src/backends/tosaCommon/operatorMappings')
4 files changed, 96 insertions, 2 deletions
diff --git a/src/backends/tosaCommon/operatorMappings/CMakeLists.txt b/src/backends/tosaCommon/operatorMappings/CMakeLists.txt index 2ec052cd43..26f51b643f 100644 --- a/src/backends/tosaCommon/operatorMappings/CMakeLists.txt +++ b/src/backends/tosaCommon/operatorMappings/CMakeLists.txt @@ -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 # @@ -14,6 +14,8 @@ list(APPEND armnnTosaBackendOperators_sources Conv2dOperator.cpp ElementwiseBinaryOperator.hpp ElementwiseBinaryOperator.cpp + ElementwiseUnaryOperator.cpp + ElementwiseUnaryOperator.hpp Pooling2DOperator.hpp Pooling2DOperator.cpp ReshapeOperator.hpp diff --git a/src/backends/tosaCommon/operatorMappings/ElementwiseUnaryOperator.cpp b/src/backends/tosaCommon/operatorMappings/ElementwiseUnaryOperator.cpp new file mode 100644 index 0000000000..15fb9d746b --- /dev/null +++ b/src/backends/tosaCommon/operatorMappings/ElementwiseUnaryOperator.cpp @@ -0,0 +1,72 @@ +// +// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "ElementwiseUnaryOperator.hpp" + +TosaSerializationBasicBlock* ConvertElementwiseUnaryOperator(const Layer* layer, + const std::vector<const TensorInfo*>& inputs, + const std::vector<const TensorInfo*>& outputs, + const ElementwiseUnaryDescriptor* unaryDescriptor) +{ + std::string input0Name = std::string("input0_"); + std::string outputName = std::string("output0_"); + std::string blockName = std::string("Op_ELEMENTWISEUNARY_block_") + GetUniqueTosaMappingID(); + + + // 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 layer connected to the input slot and determine unique the tensor name. + Layer& connectedLayer0 = layer->GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer(); + input0Name = GenerateUniqueName(connectedLayer0, 0); + + // Determine unique output tensor name. + outputName = GenerateUniqueOutputName(*layer, 0); + } + + TosaSerializationOperator* op = nullptr; + switch(unaryDescriptor->m_Operation) + { + case UnaryOperation::Rsqrt: + { + op = new TosaSerializationOperator(tosa::Op_RSQRT, + Attribute_NONE, + nullptr, + {input0Name}, + {outputName}); + blockName = std::string("Op_RSQRT_block_") + GetUniqueTosaMappingID(); + break; + } + default: + throw armnn::Exception("ConvertElementwiseUnaryToTosaOperator: Unsupported layer type."); + } + + ARMNN_ASSERT(op != nullptr); + + std::vector<TosaSerializationTensor*> tensors; + // Only add input tensor if connected layer is an input layer. + // As intermediate or constant tensors will be created separately. + // There also can't be duplicate tensor. + if(input0Name.find("input0_") != std::string::npos) + { + std::vector<int32_t> inputShape0 = GetTosaTensorShape(inputs[0]->GetShape()); + DType inputDType0 = ArmNNToDType(inputs[0]->GetDataType()); + tensors.push_back(new TosaSerializationTensor(input0Name, inputShape0, inputDType0, {})); + } + + std::vector<int32_t> outputShape0 = GetTosaTensorShape(outputs[0]->GetShape()); + DType outputDType0 = ArmNNToDType(outputs[0]->GetDataType()); + + 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 + return new TosaSerializationBasicBlock(blockName, // name + {op}, // operators + tensors, // tensors + {input0Name}, // inputs + {outputName}); // outputs +}
\ No newline at end of file diff --git a/src/backends/tosaCommon/operatorMappings/ElementwiseUnaryOperator.hpp b/src/backends/tosaCommon/operatorMappings/ElementwiseUnaryOperator.hpp new file mode 100644 index 0000000000..d13428ca5a --- /dev/null +++ b/src/backends/tosaCommon/operatorMappings/ElementwiseUnaryOperator.hpp @@ -0,0 +1,19 @@ +// +// Copyright © 2023 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* ConvertElementwiseUnaryOperator(const Layer* layer, + const std::vector<const TensorInfo*>& inputs, + const std::vector<const TensorInfo*>& outputs, + const ElementwiseUnaryDescriptor* unaryDescriptor); diff --git a/src/backends/tosaCommon/operatorMappings/TosaCommonOperators.hpp b/src/backends/tosaCommon/operatorMappings/TosaCommonOperators.hpp index 3f27371295..66dc1b342a 100644 --- a/src/backends/tosaCommon/operatorMappings/TosaCommonOperators.hpp +++ b/src/backends/tosaCommon/operatorMappings/TosaCommonOperators.hpp @@ -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 // @@ -10,6 +10,7 @@ #include "ConstantOperator.hpp" #include "Conv2dOperator.hpp" #include "ElementwiseBinaryOperator.hpp" +#include "ElementwiseUnaryOperator.hpp" #include "Pooling2DOperator.hpp" #include "ReshapeOperator.hpp" #include "SliceOperator.hpp" |