diff options
author | Cathal Corbett <cathal.corbett@arm.com> | 2022-12-07 11:50:50 +0000 |
---|---|---|
committer | Cathal Corbett <cathal.corbett@arm.com> | 2022-12-12 20:09:36 +0000 |
commit | b30e6554ad41f21c8326e387aa2c1f8a5d4e6445 (patch) | |
tree | 7267ad8027a9eed45348b3808da5fcf901b0b767 /src/backends/tosaCommon/operatorMappings/ReshapeOperator.cpp | |
parent | ec67a0f08e0f96a5aebf3cac65331c67f6649f5e (diff) | |
download | armnn-b30e6554ad41f21c8326e387aa2c1f8a5d4e6445.tar.gz |
IVGCVSW-7174 Add Reshape support to TOSA Reference Backend
* Spelling corrections and code refactors added to TosaCommon
* TosaDTypeToString() implemented and used in TosaRef IsLayerSupported()
instead of enum integer.
* Using namespace armnn in TosaCommon OneToOneMappingTests and
TosaReference TosaRefLayerSupportTests instead of armnn::ClassName.
* Updated VerifyTosaAttribute() to also verify certain attributes
from input and output shapes.
Signed-off-by: Cathal Corbett <cathal.corbett@arm.com>
Change-Id: I71dfca404d081a665f748ab724153c6dc36b7eca
Diffstat (limited to 'src/backends/tosaCommon/operatorMappings/ReshapeOperator.cpp')
-rw-r--r-- | src/backends/tosaCommon/operatorMappings/ReshapeOperator.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/backends/tosaCommon/operatorMappings/ReshapeOperator.cpp b/src/backends/tosaCommon/operatorMappings/ReshapeOperator.cpp new file mode 100644 index 0000000000..b88a6ef894 --- /dev/null +++ b/src/backends/tosaCommon/operatorMappings/ReshapeOperator.cpp @@ -0,0 +1,54 @@ +// +// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "ReshapeOperator.hpp" + +TosaSerializationBasicBlock* ConvertReshapeToTosaOperator(const Layer* layer, + const std::vector<const TensorInfo*>& inputs, + const std::vector<const TensorInfo*>& outputs, + const ReshapeDescriptor* reshapeDescriptor) +{ + std::string inputName = std::string("input0_"); + std::string outputName = std::string("output0_"); + std::string blockName = std::string("Op_RESHAPE_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 layers connected to the input slots and determine unique layer names. + Layer& connectedLayer = layer->GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer(); + inputName = GenerateUniqueName(connectedLayer, 0); + + // Get the layer connected to the output slot and determine unique layer name. + Layer& connectedOutputLayer = layer->GetOutputSlot().GetConnection(0)->GetOwningLayer(); + outputName = GenerateUniqueName(connectedOutputLayer, 0); + } + + TosaReshapeAttribute attribute(GetTosaTensorShape(reshapeDescriptor->m_TargetShape)); + + auto* op = new TosaSerializationOperator(Op_RESHAPE, + Attribute_ReshapeAttribute, + &attribute, + {inputName}, + {outputName}); + + std::vector<int32_t> inputShape = GetTosaTensorShape(inputs[0]->GetShape()); + DType inputDType = ArmNNToDType(inputs[0]->GetDataType()); + + std::vector<int32_t> outputShape = GetTosaTensorShape(outputs[0]->GetShape()); + DType outputDType = ArmNNToDType(outputs[0]->GetDataType()); + + auto* inputTensor = new TosaSerializationTensor(inputName, inputShape, inputDType, {}); + auto* outputTensor = new TosaSerializationTensor(outputName, outputShape, outputDType, {}); + + // 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 + {inputTensor, outputTensor}, // tensors + {inputName}, // inputs + {outputName}); // outputs +}
\ No newline at end of file |