aboutsummaryrefslogtreecommitdiff
path: root/src/backends/reference/RefBackend.cpp
diff options
context:
space:
mode:
authorCathal Corbett <cathal.corbett@arm.com>2022-07-22 16:03:36 +0100
committerNikhil Raj <nikhil.raj@arm.com>2022-08-05 15:50:57 +0100
commit3883b2776cec33f16f0ea9a2d795de2b7c766df7 (patch)
tree6842e15904037d73426d814d5751945b3d9c2376 /src/backends/reference/RefBackend.cpp
parent9d63fee68081b65bd72de3a70da76c2696c6c6ed (diff)
downloadarmnn-3883b2776cec33f16f0ea9a2d795de2b7c766df7.tar.gz
GitHub #667: Neon fold padding into average pool 2D quantization bug fix.
* Originated from a GitHub issue: https://github.com/ARM-software/armnn/issues/667 * Initially, Arm NN supports the pool 2D operation because there is no padding on the pool2d. Neon failure occurs when padding is followed by average pool 2D due to folding optimization. * Here we prevent the folding optimization from happening for the above special case and add it in as a backend specific optimization. Signed-off-by: Cathal Corbett <cathal.corbett@arm.com> Change-Id: Ia0fd90c3a6b4b9d29c81106f154617d2e893e26b
Diffstat (limited to 'src/backends/reference/RefBackend.cpp')
-rw-r--r--src/backends/reference/RefBackend.cpp59
1 files changed, 55 insertions, 4 deletions
diff --git a/src/backends/reference/RefBackend.cpp b/src/backends/reference/RefBackend.cpp
index a33a7756a0..8c8879c8be 100644
--- a/src/backends/reference/RefBackend.cpp
+++ b/src/backends/reference/RefBackend.cpp
@@ -14,6 +14,7 @@
#include <armnn/backends/IMemoryManager.hpp>
#include <armnn/utility/PolymorphicDowncast.hpp>
#include <backendsCommon/DefaultAllocator.hpp>
+#include <backendsCommon/SubgraphUtils.hpp>
#include <Optimizer.hpp>
@@ -70,11 +71,61 @@ IBackendInternal::ILayerSupportSharedPtr RefBackend::GetLayerSupport() const
return layerSupport;
}
-OptimizationViews RefBackend::OptimizeSubgraphView(const SubgraphView& subgraph) const
+OptimizationViews RefBackend::OptimizeSubgraphView(const SubgraphView& subgraph,
+ const ModelOptions& modelOptions) const
{
- OptimizationViews optimizationViews;
-
- optimizationViews.AddUntouchedSubgraph(SubgraphView(subgraph));
+ OptimizationViews optimizationViews(modelOptions);
+
+ auto it = subgraph.endIConnectable();
+ std::map<LayerGuid, Layer*> untouched;
+
+ while (it != subgraph.beginIConnectable())
+ {
+ --it;
+ Layer& base = *(PolymorphicDowncast<Layer*>(*it));
+ untouched.insert({base.GetGuid(), &base});
+ }
+
+ it = subgraph.endIConnectable();
+ while (it != subgraph.beginIConnectable())
+ {
+ --it;
+ Layer& base = *(PolymorphicDowncast<Layer*>(*it));
+
+ // Special case to fuse padding into average pooling 2d for quantized datatype.
+ // Required to be done as a backend specific optimization as Neon does not support this special case.
+ if (base.GetType() == LayerType::Pooling2d)
+ {
+ Pooling2dLayer* baseLayer = PolymorphicDowncast<Pooling2dLayer*>(&base);
+ Pooling2dDescriptor poolingDescriptor = baseLayer->GetParameters();
+
+ if (baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer().GetType() == LayerType::Pad)
+ {
+ PadLayer* padLayer = PolymorphicDowncast<PadLayer*>(
+ &baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer());
+ if (padLayer->GetOutputSlot(0).GetNumConnections() == 1 &&
+ optimizations::pad_fold::TryFoldPadIntoLayer2d(padLayer->GetParameters(),
+ poolingDescriptor,
+ padLayer->GetOutputSlot().GetTensorInfo(),
+ true))
+ {
+ FoldPadIntoAveragePool2d<Pooling2dLayer>(optimizationViews, baseLayer,
+ poolingDescriptor, padLayer);
+ untouched.erase(baseLayer->GetGuid());
+ untouched.erase(padLayer->GetGuid());
+ }
+ }
+ }
+ }
+
+ if (optimizationViews.GetSubstitutions().empty())
+ {
+ optimizationViews.AddUntouchedSubgraph(SubgraphView(subgraph));
+ }
+ else
+ {
+ ReportUntouchedLayers(optimizationViews, untouched);
+ }
return optimizationViews;
}