diff options
author | Mike Kelly <mike.kelly@arm.com> | 2023-07-07 15:43:06 +0100 |
---|---|---|
committer | Mike Kelly <mike.kelly@arm.com> | 2023-07-14 00:00:53 +0100 |
commit | 4cc341cf8b5a6e6bb0543504cbbfde6fa11a2cdb (patch) | |
tree | 7cac128e9ec6f2fd27f1afdb55f44b870f39e0b3 /src/backends/neon/NeonBackend.cpp | |
parent | 6963b33221c23af4a8eff19ff4a5773230b0befd (diff) | |
download | armnn-4cc341cf8b5a6e6bb0543504cbbfde6fa11a2cdb.tar.gz |
IVGCVSW-7830 Add backend optimizations to remove Reshapes where possible
* Added optimization to remove reshapes for Neon and Ref Backends
by using overridden TensorInfos
* Added ability to delete Subgraphs during Optimization
* Fixed naming error in NeonEndToEndTests and CLEndToEndTests
* Added LayerNameAndTypeCheck for testing.
* Fixed error where layers were not marked as altered when removed in
CLBackend
Signed-off-by: Mike Kelly <mike.kelly@arm.com>
Change-Id: I1ac25cd4ec9821470d961831ae2c8d24882276cc
Diffstat (limited to 'src/backends/neon/NeonBackend.cpp')
-rw-r--r-- | src/backends/neon/NeonBackend.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/backends/neon/NeonBackend.cpp b/src/backends/neon/NeonBackend.cpp index cea2aa3eba..098b1ff109 100644 --- a/src/backends/neon/NeonBackend.cpp +++ b/src/backends/neon/NeonBackend.cpp @@ -505,9 +505,39 @@ OptimizationViews NeonBackend::OptimizeSubgraphView(const SubgraphView& subgraph untouched.erase(baseLayer->GetGuid()); } } + + // Remove Reshape where possible + if (base.GetType() == LayerType::Reshape) + { + ReshapeLayer* baseLayer = PolymorphicDowncast<ReshapeLayer*>(&base); + Layer& parentLayer = baseLayer->GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer(); + + // Cannot currently remove the Reshape if it's connected to any layer that has an NCHW layout + if (IsNCHW(parentLayer)) + { + continue; + } + bool isNCHW = false; + + for (unsigned int i = 0; i < baseLayer->GetOutputSlot(0).GetNumConnections(); ++i) + { + Layer& nextLayer = baseLayer->GetOutputSlot(0).GetConnection(i)->GetOwningLayer(); + + if (IsNCHW(nextLayer)) + { + isNCHW = true; + break; + } + } + if (isNCHW) + { + continue; + } + RemoveReshapeLayer(baseLayer, untouched, optimizationViews); + } } - if (optimizationViews.GetSubstitutions().empty()) + if (optimizationViews.GetSubstitutions().empty() && optimizationViews.GetDeletedSubgraphs().empty()) { optimizationViews.AddUntouchedSubgraph(SubgraphView(subgraph)); } |