ArmNN
 24.08
TransposeOperator.hpp File Reference
Include dependency graph for TransposeOperator.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

TosaSerializationBasicBlock * ConvertTransposeToTosaOperator (const Layer *layer, const std::vector< const TensorInfo * > &inputs, const std::vector< const TensorInfo * > &outputs, const TransposeDescriptor *transposeDescriptor)
 

Function Documentation

◆ ConvertTransposeToTosaOperator()

TosaSerializationBasicBlock* ConvertTransposeToTosaOperator ( const Layer layer,
const std::vector< const TensorInfo * > &  inputs,
const std::vector< const TensorInfo * > &  outputs,
const TransposeDescriptor transposeDescriptor 
)

Definition at line 8 of file TransposeOperator.cpp.

12 {
13  std::string input0Name = std::string("input_");
14  std::string outputName = std::string("output0_");
15  std::string blockName = std::string("Op_TRANSPOSE_block_") + GetUniqueTosaMappingID();
16 
17  // If a layer is present then the block will be used for execution, so input and output names need to be determined
18  // using the previous and following layers so the graph is connected correctly. For validation this doesn't matter.
19  if(layer != nullptr)
20  {
21  input0Name = GenerateUniqueInputName(layer->GetInputSlot(0));
22  outputName = GenerateUniqueOutputName(*layer);
23  }
24 
25  std::vector<int32_t> mappings(transposeDescriptor->m_DimMappings.begin(),
26  transposeDescriptor->m_DimMappings.end());
27  TosaTransposeAttribute attribute(mappings);
28 
29  auto* op = new TosaSerializationOperator(Op_TRANSPOSE,
30  Attribute_TransposeAttribute,
31  &attribute,
32  {input0Name},
33  {outputName});
34 
35 
36  std::vector<TosaSerializationTensor*> tensors;
37 
38  // Only add input tensors if connected layer is an input layer.
39  // As intermediate or constant tensors will be created separately.
40  // There also can't be duplicate tensor.
41  if(input0Name.find("input_") != std::string::npos)
42  {
43  std::vector<int32_t> inputShape0 = GetTosaTensorShape(inputs[0]->GetShape());
44  DType inputDType0 = ArmNNToDType(inputs[0]->GetDataType());
45 
46  tensors.push_back(new TosaSerializationTensor(input0Name, inputShape0, inputDType0, {}));
47  }
48 
49  std::vector<int32_t> outputShape0 = GetTosaTensorShape(outputs[0]->GetShape());
50  DType outputDType0 = ArmNNToDType(outputs[0]->GetDataType());
51 
52  tensors.push_back(new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}));
53 
54  // operatorInputNames/operatorOutputNames ends up being the same as
55  // blockInputNames/blockOutputNames for one-to-one ArmNN to TOSA mappings
56  return new TosaSerializationBasicBlock(blockName, // name
57  mainName, // region name
58  {op}, // operators
59  tensors, // tensors
60  {input0Name}, // inputs
61  {outputName}); // outputs
62 }

References PermutationVector::begin(), PermutationVector::end(), GenerateUniqueInputName(), GenerateUniqueOutputName(), Layer::GetInputSlot(), GetTosaTensorShape(), GetUniqueTosaMappingID(), and TransposeDescriptor::m_DimMappings.

Referenced by GetTosaMapping().

GenerateUniqueOutputName
std::string GenerateUniqueOutputName(const Layer &layer, uint32_t layerSlot=0)
Definition: TosaOperatorUtils.hpp:120
armnn::PermutationVector::begin
ConstIterator begin() const
Definition: Types.hpp:359
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::PermutationVector::end
ConstIterator end() const
Definition: Types.hpp:364
mainName
const std::string mainName
Definition: TosaOperatorUtils.hpp:19
ArmNNToDType
DType ArmNNToDType(const DataType &type)
Definition: TosaOperatorUtils.hpp:22
armnn::TransposeDescriptor::m_DimMappings
PermutationVector m_DimMappings
Indicates how to translate tensor elements from a given source into the target destination,...
Definition: Descriptors.hpp:1514
GetTosaTensorShape
std::vector< int32_t > GetTosaTensorShape(const TensorShape &shape)
Definition: TosaOperatorUtils.hpp:79
GenerateUniqueInputName
std::string GenerateUniqueInputName(const armnn::InputSlot &slot)
Definition: TosaOperatorUtils.hpp:109
GetUniqueTosaMappingID
std::string GetUniqueTosaMappingID()
Definition: TosaOperatorUtils.hpp:138