diff options
Diffstat (limited to 'src/backends/tosaCommon/operatorMappings/SliceOperator.cpp')
-rw-r--r-- | src/backends/tosaCommon/operatorMappings/SliceOperator.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/backends/tosaCommon/operatorMappings/SliceOperator.cpp b/src/backends/tosaCommon/operatorMappings/SliceOperator.cpp new file mode 100644 index 0000000000..fc2e40a95c --- /dev/null +++ b/src/backends/tosaCommon/operatorMappings/SliceOperator.cpp @@ -0,0 +1,57 @@ +// +// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "SliceOperator.hpp" + +TosaSerializationBasicBlock* ConvertSliceToTosaOperator(const Layer* layer, + const std::vector<const TensorInfo*>& inputs, + const std::vector<const TensorInfo*>& outputs, + const SliceDescriptor* sliceDescriptor) +{ + std::string inputName = std::string("input0_"); + std::string outputName = std::string("output0_"); + std::string blockName = std::string("Op_SLICE_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); + } + + std::vector<int32_t> begin(sliceDescriptor->m_Begin.begin(), sliceDescriptor->m_Begin.end()); + std::vector<int32_t> size(sliceDescriptor->m_Size.begin(), sliceDescriptor->m_Size.end()); + + TosaSliceAttribute attribute(begin, size); + + auto* op = new TosaSerializationOperator(Op_SLICE, + Attribute_SliceAttribute, + &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 |