ArmNN
 25.02
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Pooling2DOperator.hpp File Reference
Include dependency graph for Pooling2DOperator.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

TosaSerializationBasicBlock * ConvertPooling2DToTosaOperator (const Layer *layer, const std::vector< const TensorInfo * > &inputs, const std::vector< const TensorInfo * > &outputs, const Pooling2dDescriptor *poolDescriptor)
 

Function Documentation

◆ ConvertPooling2DToTosaOperator()

TosaSerializationBasicBlock* ConvertPooling2DToTosaOperator ( const Layer layer,
const std::vector< const TensorInfo * > &  inputs,
const std::vector< const TensorInfo * > &  outputs,
const Pooling2dDescriptor poolDescriptor 
)

Definition at line 8 of file Pooling2DOperator.cpp.

12 {
13  std::string poolType = (poolDescriptor->m_PoolType == PoolingAlgorithm::Max) ? "Op_MAX" : "Op_AVG";
14  Op opcode = (poolDescriptor->m_PoolType == PoolingAlgorithm::Max) ? Op_MAX_POOL2D : Op_AVG_POOL2D;
15 
16  std::string input0Name = std::string("input_");
17  std::string outputName = std::string("output0_");
18  std::string blockName = std::string("Op_") + poolType + std::string("_POOL2D_block_") + GetUniqueTosaMappingID();
19 
20  // If a layer is present then the block will be used for execution, so input and output names need to be determined
21  // using the previous and following layers so the graph is connected correctly. For validation this doesn't matter.
22  if(layer != nullptr)
23  {
24  input0Name = GenerateUniqueInputName(layer->GetInputSlot(0));
25  outputName = GenerateUniqueOutputName(*layer);
26  }
27 
28  std::vector<int> pad = {static_cast<int>(poolDescriptor->m_PadTop),
29  static_cast<int>(poolDescriptor->m_PadBottom),
30  static_cast<int>(poolDescriptor->m_PadLeft),
31  static_cast<int>(poolDescriptor->m_PadRight)};
32  std::vector<int> kernel = {static_cast<int>(poolDescriptor->m_PoolHeight),
33  static_cast<int>(poolDescriptor->m_PoolWidth)};
34  std::vector<int> stride = {static_cast<int>(poolDescriptor->m_StrideY),
35  static_cast<int>(poolDescriptor->m_StrideX)};
36 
37  DType accType = DType_INT32;
38  DType inputDType0 = ArmNNToDType(inputs[0]->GetDataType());
39  if (inputDType0 == DType_FP32)
40  {
41  accType = DType_FP32;
42  }
43  else if (inputDType0 == DType_FP16)
44  {
45  accType = DType_FP16;
46  }
47 
48  TosaPoolAttribute attribute(pad, kernel, stride, 0, 0, accType);
49 
50  auto* op = new TosaSerializationOperator(opcode,
51  Attribute_PoolAttribute,
52  &attribute,
53  {input0Name},
54  {outputName});
55 
56  std::vector<TosaSerializationTensor*> tensors;
57 
58  // Only add input tensors if connected layer is an input layer.
59  // As intermediate or constant tensors will be created separately.
60  // There also can't be duplicate tensor.
61  if(input0Name.find("input_") != std::string::npos)
62  {
63  std::vector<int32_t> inputShape0 = GetTosaTensorShape(inputs[0]->GetShape());
64 
65  tensors.push_back(new TosaSerializationTensor(input0Name, inputShape0, inputDType0, {}));
66  }
67 
68  std::vector<int32_t> outputShape0 = GetTosaTensorShape(outputs[0]->GetShape());
69  DType outputDType0 = ArmNNToDType(outputs[0]->GetDataType());
70 
71  tensors.push_back(new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}));
72 
73  // operatorInputNames/operatorOutputNames ends up being the same as
74  // blockInputNames/blockOutputNames for one-to-one ArmNN to TOSA mappings
75  return new TosaSerializationBasicBlock(blockName, // name
76  mainName, // region name
77  {op}, // operators
78  tensors, // tensors
79  {input0Name}, // inputs
80  {outputName}); // outputs
81 }
std::string GenerateUniqueOutputName(const Layer &layer, uint32_t layerSlot=0)
const std::string mainName
DType ArmNNToDType(const DataType &type)
std::vector< int32_t > GetTosaTensorShape(const TensorShape &shape)
std::string GenerateUniqueInputName(const armnn::InputSlot &slot)
std::string GetUniqueTosaMappingID()
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:337
uint32_t m_PadRight
Padding right value in the width dimension.
PoolingAlgorithm m_PoolType
The pooling algorithm to use (Max. Average, L2).
uint32_t m_PoolHeight
Pooling height value.
uint32_t m_PadTop
Padding top value in the height dimension.
uint32_t m_PoolWidth
Pooling width value.
uint32_t m_PadBottom
Padding bottom value in the height dimension.
uint32_t m_PadLeft
Padding left value in the width dimension.
uint32_t m_StrideY
Stride value when proceeding through input for the height dimension.
uint32_t m_StrideX
Stride value when proceeding through input for the width dimension.

References ArmNNToDType(), GenerateUniqueInputName(), GenerateUniqueOutputName(), Layer::GetInputSlot(), GetTosaTensorShape(), GetUniqueTosaMappingID(), Pooling2dDescriptor::m_PadBottom, Pooling2dDescriptor::m_PadLeft, Pooling2dDescriptor::m_PadRight, Pooling2dDescriptor::m_PadTop, Pooling2dDescriptor::m_PoolHeight, Pooling2dDescriptor::m_PoolType, Pooling2dDescriptor::m_PoolWidth, Pooling2dDescriptor::m_StrideX, and Pooling2dDescriptor::m_StrideY.

Referenced by GetTosaMapping().