40 #include <arm_compute/core/Types.h>
41 #include <arm_compute/runtime/Allocator.h>
54 return std::make_unique<NeonMemoryManager>(std::make_unique<arm_compute::Allocator>(),
61 return std::make_unique<NeonWorkloadFactory>(
62 PolymorphicPointerDowncast<NeonMemoryManager>(memoryManager));
68 return std::make_unique<NeonWorkloadFactory>(
75 auto memoryManager = std::make_shared<NeonMemoryManager>(std::make_unique<arm_compute::Allocator>(),
80 auto factory = std::make_unique<NeonTensorHandleFactory>(memoryManager);
87 return std::make_unique<NeonWorkloadFactory>(
88 PolymorphicPointerDowncast<NeonMemoryManager>(memoryManager));
94 auto memoryManager = std::make_shared<NeonMemoryManager>(std::make_unique<arm_compute::Allocator>(),
99 auto factory = std::make_unique<NeonTensorHandleFactory>(memoryManager);
105 return std::make_unique<NeonWorkloadFactory>(
145 auto it = subgraph.
end();
146 std::map<LayerGuid, Layer*> untouched;
148 while (it != subgraph.
begin())
151 Layer& base = *(PolymorphicDowncast<Layer*>(*it));
152 untouched.insert({base.
GetGuid(), &base});
156 while (it != subgraph.
begin())
159 Layer& base = *(PolymorphicDowncast<Layer*>(*it));
171 if (output->GetNumConnections() == 1)
173 for (
auto&& childInput : output->GetConnections())
176 (checkDataTypeInputandOutput(childInput->GetOwningLayer())))
178 Layer& child = childInput->GetOwningLayer();
180 auto* activationLayer = PolymorphicDowncast<ActivationLayer*>(&child);
183 if (untouched.find(activationLayer->GetGuid()) == untouched.end())
188 const std::string name = std::string(
"fused-") + child.
GetName() + std::string(
"-into-") +
207 activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(),
216 FuseConvolution2dLayer<Convolution2dLayer>(optimizationViews,
221 untouched.erase(baseLayer->
GetGuid());
222 untouched.erase(activationLayer->GetGuid());
228 PolymorphicDowncast<DepthwiseConvolution2dLayer*>(&base);
239 activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(),
247 FuseDepthwiseConvolution2dLayer<DepthwiseConvolution2dLayer>(optimizationViews,
252 untouched.erase(baseLayer->
GetGuid());
253 untouched.erase(activationLayer->GetGuid());
270 activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(),
278 FuseFullyConnectedLayer<FullyConnectedLayer>(optimizationViews,
283 untouched.erase(baseLayer->
GetGuid());
284 untouched.erase(activationLayer->GetGuid());
290 PolymorphicDowncast<BatchNormalizationLayer*>(&base);
294 activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(),
295 baseLayer->
m_Mean->GetTensorInfo(),
297 baseLayer->
m_Beta->GetTensorInfo(),
298 baseLayer->
m_Gamma->GetTensorInfo(),
305 FuseBatchNormalizationLayer<BatchNormalizationLayer>(optimizationViews,
311 replacementLayer->
m_Beta = std::move(baseLayer->
m_Beta);
313 replacementLayer->
m_Mean = std::move(baseLayer->
m_Mean);
315 untouched.erase(baseLayer->
GetGuid());
316 untouched.erase(activationLayer->GetGuid());
321 AdditionLayer* baseLayer = PolymorphicDowncast<AdditionLayer*>(&base);
326 activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(),
331 FuseAdditionLayer<AdditionLayer>(optimizationViews,
336 untouched.erase(baseLayer->
GetGuid());
337 untouched.erase(activationLayer->GetGuid());
342 DivisionLayer* baseLayer = PolymorphicDowncast<DivisionLayer*>(&base);
347 activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(),
352 FuseDivisionLayer<DivisionLayer>(optimizationViews,
357 untouched.erase(baseLayer->
GetGuid());
358 untouched.erase(activationLayer->GetGuid());
368 activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(),
373 FuseMultiplicationLayer<MultiplicationLayer>(optimizationViews,
378 untouched.erase(baseLayer->
GetGuid());
379 untouched.erase(activationLayer->GetGuid());
384 SubtractionLayer* baseLayer = PolymorphicDowncast<SubtractionLayer*>(&base);
389 activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(),
394 FuseSubtractionLayer<SubtractionLayer>(optimizationViews,
399 untouched.erase(baseLayer->
GetGuid());
400 untouched.erase(activationLayer->GetGuid());
412 activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(),
417 FuseElementwiseBinaryLayer<ElementwiseBinaryLayer>(optimizationViews,
423 untouched.erase(baseLayer->
GetGuid());
424 untouched.erase(activationLayer->GetGuid());
432 activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(),
437 FuseElementwiseBinaryLayer<ElementwiseBinaryLayer>(optimizationViews,
443 untouched.erase(baseLayer->
GetGuid());
444 untouched.erase(activationLayer->GetGuid());
452 activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(),
457 FuseElementwiseBinaryLayer<ElementwiseBinaryLayer>(optimizationViews,
463 untouched.erase(baseLayer->
GetGuid());
464 untouched.erase(activationLayer->GetGuid());
472 activationLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetTensorInfo(),
477 FuseElementwiseBinaryLayer<ElementwiseBinaryLayer>(optimizationViews,
483 untouched.erase(baseLayer->
GetGuid());
484 untouched.erase(activationLayer->GetGuid());
498 ReduceLayer* baseLayer = PolymorphicDowncast<ReduceLayer*>(&base);
501 if (!reduceDescriptor.
m_vAxis.empty() && reduceDescriptor.
m_vAxis.size() > 1)
504 std::vector<IConnectableLayer*> layers = ChainReduceLayers<ReduceLayer>(optimizationViews,
509 ReplaceLayers<ReduceLayer>(optimizationViews, baseLayer, layers);
510 untouched.erase(baseLayer->
GetGuid());
517 ReshapeLayer* baseLayer = PolymorphicDowncast<ReshapeLayer*>(&base);
528 Layer* layerList[4] = {
nullptr,
nullptr,
nullptr,
nullptr};
531 if (IsLayerSequence<BinaryOperation>(base,
537 bool fuseReLu =
false;
538 unsigned int numInputs = 0;
539 unsigned int numOutputs = 0;
540 std::vector<TensorInfo> inputInfos;
541 std::vector<TensorInfo> outputInfos;
544 if (BuildAddMulAddTensorInfoLists<Layer>(layerList,
549 activationDescriptor,
555 {outputInfos.begin(), outputInfos.end()},
557 activationDescriptor);
560 std::string fusedName;
568 FusedLayer* addMulAddFusedLayer = PolymorphicDowncast<FusedLayer*>(addMulAddLayer);
570 std::make_shared<ActivationDescriptor>(*activationDescriptor));
574 std::vector<IConnectableLayer*> originalLayers;
575 for (
unsigned int layerIdx = 0; layerIdx < 4; ++layerIdx)
577 if (layerList[layerIdx])
579 originalLayers.push_back(layerList[layerIdx]);
583 std::vector<SlotList> inputLayersSlotLists, outputLayersSlotLists;
584 BuildAddMulAddSlotLists<SlotList>(fuseReLu,
585 outputInfos.size() > 1,
586 inputLayersSlotLists,
587 outputLayersSlotLists);
589 ReplaceMultipleLayers<FusedLayer>(optimizationViews,
591 PolymorphicDowncast<FusedLayer*>(addMulAddLayer),
592 inputLayersSlotLists,
593 outputLayersSlotLists);
596 for (
unsigned int layerIdx = 0; layerIdx < 4; ++layerIdx)
598 if (layerList[layerIdx])
600 untouched.erase(layerList[layerIdx]->GetGuid());
617 return optimizationViews;
627 auto memoryManager = std::make_shared<NeonMemoryManager>(std::make_unique<arm_compute::Allocator>(),
632 auto factory = std::make_unique<NeonTensorHandleFactory>(memoryManager);
641 return std::make_unique<DefaultAllocator>();
This layer represents an addition operation.
This layer represents a batch normalization operation.
std::shared_ptr< ConstTensorHandle > m_Mean
A unique pointer to store Mean values.
std::shared_ptr< ConstTensorHandle > m_Gamma
A unique pointer to store Gamma values.
std::shared_ptr< ConstTensorHandle > m_Beta
A unique pointer to store Beta values.
std::shared_ptr< ConstTensorHandle > m_Variance
A unique pointer to store Variance values.
This layer represents a convolution 2d operation.
This layer represents a depthwise convolution 2d operation.
This layer represents a division operation.
This layer represents a elementwiseBinary operation.
This layer represents a fully connected operation.
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr
std::unique_ptr< IMemoryManager > IMemoryManagerUniquePtr
std::unique_ptr< arm::pipe::IBackendProfiling > IBackendProfilingPtr
std::shared_ptr< IBackendModelContext > IBackendSpecificModelContextPtr
std::shared_ptr< IMemoryManager > IMemoryManagerSharedPtr
std::unique_ptr< IWorkloadFactory > IWorkloadFactoryPtr
std::unique_ptr< IBackendContext > IBackendContextPtr
std::shared_ptr< arm::pipe::IBackendProfilingContext > IBackendProfilingContextPtr
This is the bridge between backend and backend profiling we'll keep it in the backend namespace.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
IConnectableLayer * AddFusedLayer(const FusedDescriptor &fusedDescriptor, const char *name=nullptr)
Adds a Fused layer to the network.
std::vector< OutputSlot >::iterator EndOutputSlots()
const char * GetName() const override
Returns the name of the layer.
std::vector< OutputSlot >::iterator BeginOutputSlots()
LayerGuid GetGuid() const final
Returns the unique id of the layer.
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
LayerType GetType() const override
Returns the armnn::LayerType of this layer.
void SetAdditionalInfoForObject(const AdditionalInfoObjectPtr &additionalInfo)
std::shared_ptr< T > GetAdditionalInformation() const
const Parameters & GetParameters() const override
If the layer has a descriptor return it.
This layer represents a multiplication operation.
static const BackendId & GetIdStatic()
IBackendInternal::IBackendSpecificModelContextPtr CreateBackendSpecificModelContext(const ModelOptions &modelOptions) const override
OptimizationViews OptimizeSubgraphView(const SubgraphView &subgraph, const ModelOptions &modelOptions) const override
void RegisterTensorHandleFactories(class TensorHandleFactoryRegistry ®istry) override
(Optional) Register TensorHandleFactories Either this method or CreateMemoryManager() and IWorkloadFa...
std::vector< ITensorHandleFactory::FactoryId > GetHandleFactoryPreferences() const override
(Optional) Returns a vector of supported TensorHandleFactory ids in preference order.
IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext(const IRuntime::CreationOptions &, IBackendProfilingPtr &backendProfiling) override
Create context specifically used for profiling interaction from backends.
IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions &) const override
Create the runtime context of the backend.
IWorkloadFactoryPtr CreateWorkloadFactory(const IBackendInternal::IMemoryManagerSharedPtr &memoryManager=nullptr) const override
IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override
IBackendInternal::IMemoryManagerUniquePtr CreateMemoryManager() const override
std::unique_ptr< ICustomAllocator > GetDefaultAllocator() const override
Returns the default memory allocator for the backend.
The NeonBackendModelContext is used to pass in Neon specific backend ModelOptions.
static const FactoryId & GetIdStatic()
void AddUntouchedSubgraph(SubgraphView &&subgraph)
const Substitutions & GetSubstitutions() const
const Subgraphs & GetDeletedSubgraphs() const
const TensorInfo & GetTensorInfo() const override
This layer represents a reduction operation.
This layer represents a reshape operation.
The SubgraphView class represents a subgraph of a Graph.
IConnectableLayerIterator begin()
IConnectableLayerIterator end()
This layer represents a subtraction operation.
void RegisterFactory(std::unique_ptr< ITensorHandleFactory > allocator)
Register a TensorHandleFactory and transfer ownership.
void RegisterMemoryManager(std::shared_ptr< IMemoryManager > memoryManger)
Register a memory manager with shared ownership.
void RegisterCopyAndImportFactoryPair(ITensorHandleFactory::FactoryId copyFactoryId, ITensorHandleFactory::FactoryId importFactoryId)
Register a pair of TensorHandleFactory Id for Memory Copy and TensorHandleFactory Id for Memory Impor...
Copyright (c) 2021 ARM Limited and Contributors.
void GetFusedName(Layer *layerList[4], std::string &fusedName)
arm_compute::Status NeonAdditionWorkloadValidate(const TensorInfo &input0, const TensorInfo &input1, const TensorInfo &output, const ActivationDescriptor *activationDescriptor)
constexpr const char * NeonBackendId()
arm_compute::Status NeonConvolution2dWorkloadValidate(const TensorInfo &input, const TensorInfo &output, const Convolution2dDescriptor &descriptor, const TensorInfo &weights, const Optional< TensorInfo > &biases, bool isFastMathEnabled, const ActivationDescriptor *activationDescriptor)
@ BoundedReLu
min(a, max(b, input)) ReLu1 & ReLu6.
void ReportUntouchedLayers(OptimizationViews &optimizationViews, std::map< LayerGuid, Layer * > untouched)
std::vector< BackendOptions > ModelOptions
arm_compute::Status NeonDepthwiseConvolutionWorkloadValidate(const TensorInfo &input, const TensorInfo &output, const DepthwiseConvolution2dDescriptor &descriptor, const TensorInfo &weights, const Optional< TensorInfo > &biases, const ActivationDescriptor *activationDescriptor)
arm_compute::Status NeonDivisionWorkloadValidate(const TensorInfo &input0, const TensorInfo &input1, const TensorInfo &output, const ActivationDescriptor *activationDescriptor)
arm_compute::Status NeonSubtractionWorkloadValidate(const TensorInfo &input0, const TensorInfo &input1, const TensorInfo &output, const ActivationDescriptor *activationDescriptor)
arm_compute::Status NeonFusedWorkloadValidate(const std::vector< std::reference_wrapper< TensorInfo >> &inputInfos, const std::vector< std::reference_wrapper< TensorInfo >> &outputInfos, const FusedDescriptor &fusedDescriptor, const ActivationDescriptor *activationDescriptor)
arm_compute::Status NeonBatchNormalizationValidate(const TensorInfo &input, const TensorInfo &output, const TensorInfo &mean, const TensorInfo &var, const TensorInfo &beta, const TensorInfo &gamma, const BatchNormalizationDescriptor &descriptor, const ActivationDescriptor *activationDescriptor)
bool ConnectedToLayerWithNCHW(Layer *baseLayer)
Checks if the Layer is connected to any Layer that has an NCHW layout.
arm_compute::Status NeonMultiplicationWorkloadValidate(const TensorInfo &input0, const TensorInfo &input1, const TensorInfo &output, const ActivationDescriptor *activationDescriptor)
arm_compute::Status NeonFullyConnectedWorkloadValidate(const TensorInfo &input, const TensorInfo &output, const TensorInfo &weights, const Optional< TensorInfo > &biases, const FullyConnectedDescriptor &descriptor, const ActivationDescriptor *activationDescriptor)
void RemoveReshapeLayer(ReshapeLayer *baseLayer, std::map< LayerGuid, Layer * > &untouched, OptimizationViews &optimizationViews)
An ActivationDescriptor for the ActivationLayer.
bool m_BiasEnabled
Enable/disable bias.
bool m_BiasEnabled
Enable/disable bias.
BinaryOperation m_Operation
Specifies the elementwiseBinary operation to execute.
A FullyConnectedDescriptor for the FullyConnectedLayer.
bool m_BiasEnabled
Enable/disable bias.
A FusedDescriptor for the FusedLayer.
A ReduceDescriptor for the REDUCE operators.
std::vector< uint32_t > m_vAxis
The indices of the dimensions to reduce.