diff options
author | Kevin May <kevin.may@arm.com> | 2022-12-15 10:15:21 +0000 |
---|---|---|
committer | Teresa Charlin <teresa.charlinreyes@arm.com> | 2022-12-15 17:16:12 +0000 |
commit | 5b58e31109f661f70331048e22f8a66934e74d15 (patch) | |
tree | 7ad8f88bf7427a1dd2622b53fcd0b4b8632ee34e /src/backends/tosaCommon/operatorMappings/ConcatOperator.cpp | |
parent | 3fbad94012ee6b1c6ec8e93d760619b15d98c464 (diff) | |
download | armnn-5b58e31109f661f70331048e22f8a66934e74d15.tar.gz |
IVGCVSW-7170 Add Concat support to TOSA Reference Backend
* Change comment for the unique tensor names in all tosa common operators
Signed-off-by: Kevin May <kevin.may@arm.com>
Change-Id: I247b4b2365d5f0173218c5dfd11fba12d2399959
Diffstat (limited to 'src/backends/tosaCommon/operatorMappings/ConcatOperator.cpp')
-rw-r--r-- | src/backends/tosaCommon/operatorMappings/ConcatOperator.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/backends/tosaCommon/operatorMappings/ConcatOperator.cpp b/src/backends/tosaCommon/operatorMappings/ConcatOperator.cpp new file mode 100644 index 0000000000..8c651be052 --- /dev/null +++ b/src/backends/tosaCommon/operatorMappings/ConcatOperator.cpp @@ -0,0 +1,81 @@ +// +// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "ConcatOperator.hpp" + +TosaSerializationBasicBlock* ConvertConcatToTosaOperator(const Layer* layer, + const std::vector<const TensorInfo*>& inputs, + const std::vector<const TensorInfo*>& outputs, + const OriginsDescriptor* concatDescriptor) +{ + auto numInputs = inputs.size(); + std::vector<std::string> inputNames; + inputNames.reserve(numInputs); + std::string outputName = std::string("output0_"); + std::string blockName = std::string("Op_CONCAT_block_") + GetUniqueTosaMappingID(); + + // Set input names for validation purposes only. + if (layer == nullptr) + { + for (uint32_t i = 0; i < numInputs; ++i) + { + inputNames.push_back("input"+ std::to_string(i) +"_"); + } + } + // 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. + else + { + // Get the layers connected to the input slots and determine unique tensor names. + for (uint32_t i = 0; i < numInputs; ++i) + { + Layer& connectedLayer = layer->GetInputSlot(i).GetConnectedOutputSlot()->GetOwningLayer(); + + std::string inputName = GenerateUniqueName(connectedLayer, i); + inputNames.push_back(inputName); + } + + // Determine unique output tensor name. + outputName = GenerateUniqueOutputName(*layer, 0); + } + + auto axis = static_cast<int32_t>(concatDescriptor->GetConcatAxis()); + TosaAxisAttribute attribute(axis); + + TosaSerializationOperator* op = new TosaSerializationOperator(Op_CONCAT, + Attribute_AxisAttribute, + &attribute, + inputNames, + {outputName}); + + std::vector<TosaSerializationTensor*> tensors; + tensors.reserve(numInputs); + + for (uint32_t i = 0; i < numInputs; ++i) + { + // Only add input tensors for validation or when the connected layer is an input layer. + // As there can't be duplicate tensors and intermediate or constant tensors are created separately. + if(inputNames[i].find("input") != std::string::npos) + { + std::vector<int32_t> inputShape = GetTosaTensorShape(inputs[i]->GetShape()); + DType inputDType = ArmNNToDType(inputs[i]->GetDataType()); + tensors.push_back(new TosaSerializationTensor(inputNames[i], inputShape, inputDType, {})); + } + } + + std::vector<int32_t> outputShape0 = GetTosaTensorShape(outputs[0]->GetShape()); + DType outputDType0 = ArmNNToDType(outputs[0]->GetDataType()); + + TosaSerializationTensor* outputTensor0 = new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}); + tensors.push_back(outputTensor0); + + // 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 + inputNames, // inputs + {outputName}); // outputs +}
\ No newline at end of file |