ArmNN
 26.07
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 inputName = 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  inputName = GenerateUniqueInputName(layer->GetInputSlot(0));
25  outputName = GenerateUniqueOutputName(*layer);
26  }
27 
28  DType accType = DType_INT32;
29  DType inputDType0 = ArmNNToDType(inputs[0]->GetDataType());
30  if (inputDType0 == DType_FP32)
31  {
32  accType = DType_FP32;
33  }
34  else if (inputDType0 == DType_FP16)
35  {
36  accType = DType_FP16;
37  }
38 
39  std::vector<TosaSerializationTensor*> tensors;
40  std::vector<TosaSerializationOperator*> operators;
41 
42  // Only add input tensors if connected layer is an input layer.
43  // As intermediate or constant tensors will be created separately.
44  // There also can't be duplicate tensor.
45  std::vector<int32_t> inputShape0 = GetTosaTensorShape(inputs[0]->GetShape());
46  if(inputName.find("input_") != std::string::npos)
47  {
48  tensors.push_back(new TosaSerializationTensor(inputName, inputShape0, inputDType0, {}));
49  }
50 
51  std::vector<int32_t> outputShape0 = GetTosaTensorShape(outputs[0]->GetShape());
52  DType outputDType0 = ArmNNToDType(outputs[0]->GetDataType());
53 
54  tensors.push_back(new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}));
55 
56  std::vector<int> pad = {static_cast<int>(poolDescriptor->m_PadTop),
57  static_cast<int>(poolDescriptor->m_PadBottom),
58  static_cast<int>(poolDescriptor->m_PadLeft),
59  static_cast<int>(poolDescriptor->m_PadRight)};
60  std::vector<int> kernel = {static_cast<int>(poolDescriptor->m_PoolHeight),
61  static_cast<int>(poolDescriptor->m_PoolWidth)};
62  std::vector<int> stride = {static_cast<int>(poolDescriptor->m_StrideY),
63  static_cast<int>(poolDescriptor->m_StrideX)};
64  std::vector<int> dilation = {1, 1};
65 
66  std::string sliceOutputName = GetInputSlicedToItsUsedSize(inputShape0,
67  inputName,
68  poolDescriptor->m_DataLayout,
69  inputDType0,
70  kernel,
71  pad,
72  stride,
73  dilation,
74  tensors,
75  operators,
76  true);
77 
78  TosaPoolAttribute attribute(pad, kernel, stride, 0, 0, accType);
79 
80  operators.push_back(new TosaSerializationOperator(opcode,
81  Attribute_PoolAttribute,
82  &attribute,
83  {sliceOutputName},
84  {outputName}));
85 
86  // operatorInputNames/operatorOutputNames ends up being the same as
87  // blockInputNames/blockOutputNames for one-to-one ArmNN to TOSA mappings
88  return new TosaSerializationBasicBlock(blockName, // name
89  mainName, // region name
90  operators, // operators
91  tensors, // tensors
92  {sliceOutputName}, // inputs
93  {outputName}); // outputs
94 }
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 GetInputSlicedToItsUsedSize(const std::vector< int32_t > &inputShape, const std::string &inputName, const DataLayout layout, const DType datatype, const std::vector< int32_t > &kernel, const std::vector< int32_t > &pad, const std::vector< int32_t > &stride, const std::vector< int32_t > &dilations, std::vector< TosaSerializationTensor * > &tensors, std::vector< TosaSerializationOperator * > &operators, const bool isPoolingOp=false)
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.
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
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(), and Pooling2dDescriptor::m_PoolType.

Referenced by GetTosaMapping().