ArmNN
 24.02
ConcatOperator.cpp File Reference
#include "ConcatOperator.hpp"
Include dependency graph for ConcatOperator.cpp:

Go to the source code of this file.

Functions

TosaSerializationBasicBlock * ConvertConcatToTosaOperator (const Layer *layer, const std::vector< const TensorInfo * > &inputs, const std::vector< const TensorInfo * > &outputs, const OriginsDescriptor *concatDescriptor)
 

Function Documentation

◆ ConvertConcatToTosaOperator()

TosaSerializationBasicBlock* ConvertConcatToTosaOperator ( const Layer layer,
const std::vector< const TensorInfo * > &  inputs,
const std::vector< const TensorInfo * > &  outputs,
const OriginsDescriptor concatDescriptor 
)

Definition at line 8 of file ConcatOperator.cpp.

12 {
13  auto numInputs = inputs.size();
14  std::vector<std::string> inputNames;
15  inputNames.reserve(numInputs);
16  std::string outputName = std::string("output0_");
17  std::string blockName = std::string("Op_CONCAT_block_") + GetUniqueTosaMappingID();
18 
19  // Set input names for validation purposes only.
20  if (layer == nullptr)
21  {
22  for (uint32_t i = 0; i < numInputs; ++i)
23  {
24  inputNames.push_back("input"+ std::to_string(i) +"_");
25  }
26  }
27  // If a layer is present then the block will be used for execution, so input and output names need to be determined
28  // using the previous and following layers so the graph is connected correctly. For validation this doesn't matter.
29  else
30  {
31  // Get the layers connected to the input slots and determine unique tensor names.
32  for (uint32_t i = 0; i < numInputs; ++i)
33  {
34  Layer& connectedLayer = layer->GetInputSlot(i).GetConnectedOutputSlot()->GetOwningLayer();
35 
36  std::string inputName = GenerateUniqueName(connectedLayer, i);
37  inputNames.push_back(inputName);
38  }
39 
40  // Determine unique output tensor name.
41  outputName = GenerateUniqueOutputName(*layer, 0);
42  }
43 
44  auto axis = static_cast<int32_t>(concatDescriptor->GetConcatAxis());
45  TosaAxisAttribute attribute(axis);
46 
47  TosaSerializationOperator* op = new TosaSerializationOperator(Op_CONCAT,
48  Attribute_AxisAttribute,
49  &attribute,
50  inputNames,
51  {outputName});
52 
53  std::vector<TosaSerializationTensor*> tensors;
54  tensors.reserve(numInputs);
55 
56  for (uint32_t i = 0; i < numInputs; ++i)
57  {
58  // Only add input tensors for validation or when the connected layer is an input layer.
59  // As there can't be duplicate tensors and intermediate or constant tensors are created separately.
60  if(inputNames[i].find("input") != std::string::npos)
61  {
62  std::vector<int32_t> inputShape = GetTosaTensorShape(inputs[i]->GetShape());
63  DType inputDType = ArmNNToDType(inputs[i]->GetDataType());
64  tensors.push_back(new TosaSerializationTensor(inputNames[i], inputShape, inputDType, {}));
65  }
66  }
67 
68  std::vector<int32_t> outputShape0 = GetTosaTensorShape(outputs[0]->GetShape());
69  DType outputDType0 = ArmNNToDType(outputs[0]->GetDataType());
70 
71  TosaSerializationTensor* outputTensor0 = new TosaSerializationTensor(outputName, outputShape0, outputDType0, {});
72  tensors.push_back(outputTensor0);
73 
74  // operatorInputNames/operatorOutputNames ends up being the same as
75  // blockInputNames/blockOutputNames for one-to-one ArmNN to TOSA mappings
76  return new TosaSerializationBasicBlock(blockName, // name
77  mainName, // region name
78  {op}, // operators
79  tensors, // tensors
80  inputNames, // inputs
81  {outputName}); // outputs
82 }

References GenerateUniqueName(), GenerateUniqueOutputName(), OriginsDescriptor::GetConcatAxis(), InputSlot::GetConnectedOutputSlot(), Layer::GetInputSlot(), OutputSlot::GetOwningLayer(), GetTosaTensorShape(), and GetUniqueTosaMappingID().

Referenced by GetTosaMapping().

armnn::OriginsDescriptor::GetConcatAxis
unsigned int GetConcatAxis() const
Get the concatenation axis value.
Definition: Descriptors.cpp:162
armnn::Layer::GetInputSlot
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:337
armnn::Layer
Definition: Layer.hpp:230
mainName
const std::string mainName
Definition: TosaOperatorUtils.hpp:19
armnn::OutputSlot::GetOwningLayer
Layer & GetOwningLayer() const
Definition: Layer.hpp:132
ArmNNToDType
DType ArmNNToDType(const DataType &type)
Definition: TosaOperatorUtils.hpp:22
GenerateUniqueOutputName
std::string GenerateUniqueOutputName(const Layer &layer, uint32_t layerSlot)
Definition: TosaOperatorUtils.hpp:82
GenerateUniqueName
std::string GenerateUniqueName(const Layer &layer, uint32_t layerSlot)
Definition: TosaOperatorUtils.hpp:63
GetTosaTensorShape
std::vector< int32_t > GetTosaTensorShape(const TensorShape &shape)
Definition: TosaOperatorUtils.hpp:52
armnn::InputSlot::GetConnectedOutputSlot
const OutputSlot * GetConnectedOutputSlot() const
Definition: Layer.hpp:56
GetUniqueTosaMappingID
std::string GetUniqueTosaMappingID()
Definition: TosaOperatorUtils.hpp:100