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)
76 template <
typename Descriptor>
81 constexpr
unsigned int batchIndex = 0;
83 constexpr
auto noPad = std::make_pair(0U, 0U);
91 const auto& padList = padDescriptor.
m_PadList;
96 layerDescriptor.m_PadLeft += padList[layout.
GetWidthIndex()].first;
97 layerDescriptor.m_PadRight += padList[layout.
GetWidthIndex()].second;
98 layerDescriptor.m_PadTop += padList[layout.
GetHeightIndex()].first;
99 layerDescriptor.m_PadBottom += padList[layout.
GetHeightIndex()].second;
107 const auto poolingPadValues = std::make_tuple(poolDescriptor.
m_PadLeft, poolDescriptor.
m_PadRight,
109 bool poolHasPadding =
false;
110 if (poolingPadValues != std::make_tuple(0U, 0U, 0U, 0U))
112 poolHasPadding =
true;
125 return TryFoldPadIntoLayer2d<Pooling2dDescriptor>(padDescriptor, poolDescriptor, tensorInfo);
128 template <
typename Layer2dT>
132 Layer2dT& layer2d = *PolymorphicDowncast<Layer2dT*>(&connection.
GetOwningLayer());
135 auto newLayer2dDescriptor = layer2d.GetParameters();
146 const std::string name = std::string(
"folded-") + padLayer.
GetName() +
"-into-" + layer2d.GetName();
150 newLayer2d.GetOutputSlot().MoveAllConnections(parentSlot);
155 layer2d.GetOutputSlot().MoveAllConnections(newLayer2d.GetOutputSlot());
165 const auto newConv2dLayer = FoldPadIntoLayer2dImpl<Convolution2dLayer>(graph, connection);
167 if (newConv2dLayer !=
nullptr)
169 const auto conv2dLayer = PolymorphicDowncast<Convolution2dLayer*>(&connection.
GetOwningLayer());
172 "FoldPadIntoConvolution2d: Weights data should not be null.");
173 newConv2dLayer->m_Weight = std::move(conv2dLayer->m_Weight);
175 if (conv2dLayer->GetParameters().m_BiasEnabled)
178 "FoldPadIntoConvolution2d: Bias data should not be null if bias is enabled.");
179 newConv2dLayer->m_Bias = std::move(conv2dLayer->m_Bias);
194 const auto newConv2dLayer = FoldPadIntoLayer2dImpl<DepthwiseConvolution2dLayer>(graph, connection);
196 if (newConv2dLayer !=
nullptr)
198 const auto conv2dLayer = PolymorphicDowncast<DepthwiseConvolution2dLayer*>(&connection.
GetOwningLayer());
201 "FoldPadIntoDepthwiseConvolution2d: Weights data should not be null.");
202 newConv2dLayer->m_Weight = std::move(conv2dLayer->m_Weight);
204 if (conv2dLayer->GetParameters().m_BiasEnabled)
207 "FoldPadIntoDepthwiseConvolution2d: Bias data should not be null if bias is enabled.");
208 newConv2dLayer->m_Bias = std::move(conv2dLayer->m_Bias);
223 FoldPadIntoLayer2dImpl<Pooling2dLayer>(graph, connection);
uint32_t m_PadBottom
Padding bottom value in the height dimension.
const Parameters & GetParameters() const
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
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.
This layer represents a pad operation.
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
float GetZeroElement(const TensorInfo &tensorInfo)
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)