24.08
|
Go to the documentation of this file.
19 class CheckForNCHW :
public StrategyBase<NoThrowStrategy>
27 const std::vector<armnn::ConstTensor>& constants,
121 template<
typename Descriptor>
122 void CheckDescForNCHW(
const Descriptor& descriptor)
127 bool m_Result =
false;
137 for (
auto&& layer : layers)
154 for (
auto &&layer: layers)
166 typedef std::vector<int> SlotList;
168 template<
typename ILayerType>
170 const std::vector<SlotList>& layersSlotLists)
176 for (
unsigned int layerIdx = 0; layerIdx < layers.size(); ++layerIdx)
178 const SlotList& slotList = layersSlotLists[layerIdx];
179 for (
unsigned int slotIdx = 0 ; slotIdx < layers[layerIdx]->GetNumInputSlots(); ++slotIdx)
181 if (std::find(slotList.begin(), slotList.end(), slotIdx) != slotList.end())
183 result.push_back(&(layers[layerIdx]->GetInputSlot(slotIdx)));
190 template<
typename ILayerType>
192 const std::vector<SlotList>& layersSlotLists)
197 for (
unsigned int layerIdx = 0; layerIdx < layers.size(); ++layerIdx)
199 const SlotList& slotList = layersSlotLists[layerIdx];
200 for (
unsigned int slotIdx = 0; slotIdx < layers[layerIdx]->GetNumOutputSlots(); ++slotIdx)
202 bool foundIt = std::find(slotList.begin(), slotList.end(), slotIdx) != slotList.end();
205 result.push_back(&(layers[layerIdx]->GetOutputSlot(slotIdx)));
217 return check.Result();
222 std::vector<Layer*> untouchedVector;
223 for (
const auto& pair : untouched)
225 Layer* layer = pair.second;
227 CreateIInputsFrom({layer}),
228 CreateIOutputsFrom({layer}));
233 template<
typename LayerType>
239 SubgraphView substitutionSubgraph({padLayer, baseLayer},
240 CreateIInputsFrom({padLayer}),
241 CreateIOutputsFrom({baseLayer}));
244 optimizationViews.
AddSubstitution({substitutionSubgraph, replacementSubgraph});
246 return replacementLayer;
258 for (
unsigned int i = 0; i < baseLayer->
GetOutputSlot(0).GetNumConnections(); ++i)
280 for (
unsigned int i = 0; i < baseLayer->
GetOutputSlot(0).GetNumConnections(); ++i)
294 std::map<LayerGuid, Layer*>& untouched,
297 if (baseLayer ==
nullptr)
311 for (
unsigned int i = 0; i < baseLayer->
GetOutputSlot(0).GetNumConnections(); ++i)
320 auto it = untouched.find(baseLayer->
GetGuid());
321 if (it == untouched.end())
329 for (
unsigned int i = 0; i < baseLayer->
GetOutputSlot(0).GetNumConnections(); ++i)
340 template<
typename LayerType>
348 LayerType* replacementLayer = PolymorphicDowncast<LayerType*>(replacement);
355 return replacementLayer;
364 return layer.
GetType() == type;
370 (PolymorphicDowncast<ElementwiseBinaryLayer*>(&layer)->GetParameters().m_Operation == type);
374 template<
typename TYPE>
380 bool handleValidActivates,
381 const std::vector<ActivationFunction>& validActivates)
383 auto PreviousLayer = [](
Layer& layer)
385 return &layer.
GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer();
388 auto NextLayer = [](
Layer& layer)
393 auto LayerIncomingConnectionDataType = [](
Layer& layer)
404 DataType dataType = LayerIncomingConnectionDataType(currentLayer);
407 layerList[2] = ¤tLayer;
410 Layer *prevLayer = PreviousLayer(currentLayer);
413 bool dataTypesMatch = (dataType == LayerIncomingConnectionDataType(*prevLayer));
414 if (! dataTypesMatch)
419 layerList[1] = prevLayer;
420 prevLayer = PreviousLayer(*prevLayer);
423 dataTypesMatch = (dataType == LayerIncomingConnectionDataType(*prevLayer));
424 if (! dataTypesMatch)
429 layerList[0] = prevLayer;
434 if (handleValidActivates)
436 Layer *nextLayer = NextLayer(currentLayer);
443 PolymorphicDowncast<ActivationLayer*>(nextLayer)->GetParameters().m_Function;
444 long count = std::count(validActivates.cbegin(),
445 validActivates.cend(),
449 layerList[3] = nextLayer;
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
void AddUntouchedSubgraph(SubgraphView &&subgraph)
std::vector< IOutputSlot * > IOutputSlots
virtual unsigned int GetNumInputSlots() const =0
Returns the number of connectable input slots.
const TensorInfo & GetTensorInfo() const override
A Pooling3dDescriptor for the Pooling3dLayer.
An InstanceNormalizationDescriptor for InstanceNormalizationLayer.
bool ConnectedToLayerType(Layer *baseLayer, LayerType layerType, unsigned int dimSize=0)
Checks the Layer's Connections to see if it's connected to a Layer with the provided layerType.
bool IsLayerSequence(Layer ¤tLayer, TYPE first, TYPE second, TYPE third, Layer *layerList[4], bool handleValidActivates, const std::vector< ActivationFunction > &validActivates)
A L2NormalizationDescriptor for the L2NormalizationLayer.
bool IsSequenceLayerType(Layer &layer, LayerType type)
A NormalizationDescriptor for the NormalizationLayer.
unsigned int GetNumDimensions() const
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
LayerType * FoldPadLayer(OptimizationViews &optimizationViews, LayerType *baseLayer, LayerType *replacementLayer, PadLayer *padLayer)
bool IsNCHW(armnn::Layer &layer)
virtual unsigned int GetNumOutputSlots() const =0
Returns the number of connectable output slots.
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
const Parameters & GetParameters() const override
If the layer has a descriptor return it.
Layer & GetOwningLayer() const
This layer represents a reshape operation.
virtual const IInputSlot * GetConnection(unsigned int index) const =0
void RemoveReshapeLayer(ReshapeLayer *baseLayer, std::map< LayerGuid, Layer * > &untouched, OptimizationViews &optimizationViews)
#define ARMNN_THROW_INVALIDARG_IF_FALSE(_cond)
LayerType * FoldPadIntoAveragePool2d(OptimizationViews &optimizationViews, Pooling2dLayer *baseLayer, Pooling2dDescriptor &poolDescriptor, PadLayer *padLayer)
A ReshapeDescriptor for the ReshapeLayer.
std::vector< IInputSlot * > IInputSlots
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
LayerGuid GetGuid() const final
Returns the unique id of the layer.
A BatchMatMulDescriptor for the BatchMatMul operator.
virtual LayerType GetType() const =0
Returns the armnn::LayerType of this layer.
The SubgraphView class represents a subgraph of a Graph.
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
A Convolution3dDescriptor for the Convolution3dLayer.
TensorShape m_TargetShape
Target shape value.
This layer represents a pooling 2d operation.
Base class for all descriptors.
void AddSubstitution(SubstitutionPair &&substitution)
DataType GetDataType() const
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
A Convolution2dDescriptor for the Convolution2dLayer.
LayerType GetType() const override
Returns the armnn::LayerType of this layer.
A StridedSliceDescriptor for the StridedSliceLayer.
void ExecuteStrategy(IStrategy &strategy) const override
Apply a visitor to this layer.
IConnectableLayer * AddPooling2dLayer(const Pooling2dDescriptor &pooling2dDescriptor, const char *name=nullptr)
Adds a 2D pooling layer to the network.
void AddDeletedSubgraph(SubgraphView &&subgraph)
void IgnoreUnused(Ts &&...)
void SetShape(const TensorShape &newShape)
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
Copyright (c) 2021 ARM Limited and Contributors.
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
void ReportUntouchedLayers(OptimizationViews &optimizationViews, std::map< LayerGuid, Layer * > untouched)
bool ConnectedToLayerWithNCHW(Layer *baseLayer)
Checks if the Layer is connected to any Layer that has an NCHW layout.
A Pooling2dDescriptor for the Pooling2dLayer.
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
const InputSlot * GetConnection(unsigned int index) const override
This layer represents a pad operation.
A SpaceToDepthDescriptor for the SpaceToDepthLayer.