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();
161 const std::string name = std::string(
"folded-") + padLayer.
GetName() +
"-into-" + layer2d.GetName();
164 newLayer2d.GetOutputSlot().MoveAllConnections(parentSlot);
166 for (
unsigned int i = 1; i < layer2d.GetNumInputSlots(); ++i)
168 if (layer2d.GetInputSlot(i).GetConnectedOutputSlot() !=
nullptr)
184 layer2d.GetOutputSlot().MoveAllConnections(newLayer2d.GetOutputSlot());
194 const auto newConv2dLayer = FoldPadIntoLayer2dImpl<Convolution2dLayer>(graph, connection);
196 if (newConv2dLayer !=
nullptr)
198 const auto conv2dLayer = PolymorphicDowncast<Convolution2dLayer*>(&connection.
GetOwningLayer());
200 ARMNN_ASSERT_MSG(newConv2dLayer->GetInputSlot(1).GetConnection() !=
nullptr,
201 "FoldPadIntoConvolution2d: New convolution layer is missing connection to weights layer");
204 newConv2dLayer->m_Weight = std::move(conv2dLayer->m_Weight);
206 if (conv2dLayer->GetParameters().m_BiasEnabled)
208 ARMNN_ASSERT_MSG(newConv2dLayer->GetInputSlot(2).GetConnection() !=
nullptr,
209 "FoldPadIntoConvolution2d: New convolution layer is missing " 210 "connection to bias layer.");
213 newConv2dLayer->m_Bias = std::move(conv2dLayer->m_Bias);
228 const auto newConv2dLayer = FoldPadIntoLayer2dImpl<DepthwiseConvolution2dLayer>(graph, connection);
230 if (newConv2dLayer !=
nullptr)
232 const auto conv2dLayer = PolymorphicDowncast<DepthwiseConvolution2dLayer*>(&connection.
GetOwningLayer());
234 ARMNN_ASSERT_MSG(newConv2dLayer->GetInputSlot(1).GetConnection() !=
nullptr,
235 "FoldPadIntoDepthwiseConvolution2d: New convolution layer is missing connection to weights layer");
238 newConv2dLayer->m_Weight = std::move(conv2dLayer->m_Weight);
240 if (conv2dLayer->GetParameters().m_BiasEnabled)
242 ARMNN_ASSERT_MSG(newConv2dLayer->GetInputSlot(2).GetConnection() !=
nullptr,
243 "FoldPadIntoConvolution2d: New convolution layer is missing " 244 "connection to bias layer.");
246 newConv2dLayer->m_Bias = std::move(conv2dLayer->m_Bias);
261 FoldPadIntoLayer2dImpl<Pooling2dLayer>(graph, connection);
uint32_t m_PadBottom
Padding bottom value in the height dimension.
unsigned int GetWidthIndex() const
FoldPadIntoConvolution2dImpl()=default
uint32_t m_PadLeft
Padding left value in the width dimension.
void Run(Graph &graph, InputSlot &connection) const
float m_PadValue
Optional value to use for padding, defaults to 0.
Layer2dT * FoldPadIntoLayer2dImpl(Graph &graph, InputSlot &connection)
void Run(Graph &graph, InputSlot &connection) const
This layer represents a depthwise convolution 2d operation.
A Convolution2dDescriptor for the Convolution2dLayer.
Layer & GetOwningLayer() const
int Connect(InputSlot &destination)
The padding fields don't count and are ignored.
PaddingMethod m_PaddingMethod
The padding method to be used. (Exclude, IgnoreValue).
uint32_t m_PadTop
Padding top value in the height dimension.
std::vector< std::pair< unsigned int, unsigned int > > m_PadList
Specifies the padding for input dimension.
Copyright (c) 2021 ARM Limited and Contributors.
const Parameters & GetParameters() const override
If the layer has a descriptor return it.
This layer represents a pad operation.
void Disconnect(InputSlot &slot)
unsigned int GetHeightIndex() const
A PadDescriptor for the PadLayer.
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
bool TryFoldPadIntoLayer2d(const PadDescriptor &padDescriptor, Descriptor &layerDescriptor, const TensorInfo &tensorInfo)
uint32_t m_PadRight
Padding right value in the width dimension.
#define ARMNN_ASSERT_MSG(COND, MSG)
int32_t GetQuantizationOffset() const
float GetQuantizationScale() const
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout...
DataType GetDataType() const
bool IsPooling2dPadded(const Pooling2dDescriptor &poolDescriptor)
LayerType GetType() const override
Returns the armnn::LayerType of this layer.
float GetZeroElement(const TensorInfo &tensorInfo)
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
void Run(Graph &graph, InputSlot &connection) const
PoolingAlgorithm m_PoolType
The pooling algorithm to use (Max. Average, L2).
~FoldPadIntoConvolution2dImpl()=default
The padding fields count, but are ignored.
float GetLowestElement(const TensorInfo &tensorInfo)
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
const char * GetName() const override
Returns the name of the layer.
A Pooling2dDescriptor for the Pooling2dLayer.
LayerT * InsertNewLayer(InputSlot &insertBefore, Args &&... args)
Inserts a new layer between the output slot currently connected to insertBefore and insertBefore itse...
const TensorInfo & GetTensorInfo() const override
unsigned int GetChannelsIndex() const
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
bool IsNeutralElement(const Convolution2dDescriptor &, const TensorInfo &tensorInfo, const float tensorValue)