17 namespace optimizations
28 constexpr
float negativeInfinity = -std::numeric_limits<float>::infinity();
35 return armnnUtils::SelectiveQuantize<armnn::Half>(negativeInfinity, scale, offset);
37 return armnnUtils::SelectiveQuantize<float>(negativeInfinity, scale, offset);
39 return armnnUtils::SelectiveQuantize<uint8_t>(negativeInfinity, scale, offset);
41 return armnnUtils::SelectiveQuantize<int16_t>(negativeInfinity, scale, offset);
45 return armnnUtils::SelectiveQuantize<int8_t>(negativeInfinity, scale, offset);
47 return armnnUtils::SelectiveQuantize<armnn::BFloat16>(negativeInfinity, scale, offset);
63 const float tensorValue)
78 const auto poolingPadValues = std::make_tuple(poolDescriptor.
m_PadLeft, poolDescriptor.
m_PadRight,
80 if (poolingPadValues != std::make_tuple(0U, 0U, 0U, 0U))
87 template <
typename Descriptor>
92 constexpr
unsigned int batchIndex = 0;
94 constexpr
auto noPad = std::make_pair(0U, 0U);
102 const auto& padList = padDescriptor.
m_PadList;
107 layerDescriptor.m_PadLeft += padList[layout.
GetWidthIndex()].first;
108 layerDescriptor.m_PadRight += padList[layout.
GetWidthIndex()].second;
109 layerDescriptor.m_PadTop += padList[layout.
GetHeightIndex()].first;
110 layerDescriptor.m_PadBottom += padList[layout.
GetHeightIndex()].second;
118 bool isBackendOptimization =
false)
130 if (!isBackendOptimization &&
140 return TryFoldPadIntoLayer2d<Pooling2dDescriptor>(padDescriptor, poolDescriptor, tensorInfo);
143 template <
typename Layer2dT>
147 Layer2dT& layer2d = *PolymorphicDowncast<Layer2dT*>(&connection.
GetOwningLayer());
150 auto newLayer2dDescriptor = layer2d.GetParameters();
164 const TensorShape& filterShape = layer2d.GetInputSlot(1).GetTensorInfo().GetShape();
165 unsigned int filterWidth = filterShape[dataLayoutIndex.
GetWidthIndex()];
166 unsigned int filterHeight = filterShape[dataLayoutIndex.
GetHeightIndex()];
168 auto horizontalPadding = newLayer2dDescriptor.m_PadLeft + newLayer2dDescriptor.m_PadRight;
169 auto verticalPadding = newLayer2dDescriptor.m_PadTop + newLayer2dDescriptor.m_PadBottom;
170 if ((filterWidth == 1) && (horizontalPadding >= filterWidth))
174 else if ((filterHeight == 1) && (verticalPadding >= filterHeight))
184 const std::string name = std::string(
"folded-") + padLayer.
GetName() +
"-into-" + layer2d.GetName();
187 newLayer2d.GetOutputSlot().MoveAllConnections(parentSlot);
189 for (
unsigned int i = 1; i < layer2d.GetNumInputSlots(); ++i)
191 if (layer2d.GetInputSlot(i).GetConnectedOutputSlot() !=
nullptr)
203 layer2d.GetOutputSlot().MoveAllConnections(newLayer2d.GetOutputSlot());
213 const auto newConv2dLayer = FoldPadIntoLayer2dImpl<Convolution2dLayer>(graph, connection);
215 if (newConv2dLayer !=
nullptr)
217 const auto conv2dLayer = PolymorphicDowncast<Convolution2dLayer*>(&connection.
GetOwningLayer());
218 ARMNN_ASSERT_MSG(newConv2dLayer->GetInputSlot(1).GetConnection() !=
nullptr,
219 "FoldPadIntoConvolution2d: New convolution layer is missing connection to weights layer");
221 if (conv2dLayer->GetParameters().m_BiasEnabled)
223 ARMNN_ASSERT_MSG(newConv2dLayer->GetInputSlot(2).GetConnection() !=
nullptr,
224 "FoldPadIntoConvolution2d: New convolution layer is missing "
225 "connection to bias layer.");
240 const auto newConv2dLayer = FoldPadIntoLayer2dImpl<DepthwiseConvolution2dLayer>(graph, connection);
242 if (newConv2dLayer !=
nullptr)
244 const auto conv2dLayer = PolymorphicDowncast<DepthwiseConvolution2dLayer*>(&connection.
GetOwningLayer());
245 ARMNN_ASSERT_MSG(newConv2dLayer->GetInputSlot(1).GetConnection() !=
nullptr,
246 "FoldPadIntoDepthwiseConvolution2d: New convolution layer is missing "
247 "connection to weights layer");
249 if (conv2dLayer->GetParameters().m_BiasEnabled)
251 ARMNN_ASSERT_MSG(newConv2dLayer->GetInputSlot(2).GetConnection() !=
nullptr,
252 "FoldPadIntoConvolution2d: New convolution layer is missing "
253 "connection to bias layer.");
267 FoldPadIntoLayer2dImpl<Pooling2dLayer>(graph, connection);