From 5fc0fd6661f9647092deb052d052973a237bd52d Mon Sep 17 00:00:00 2001 From: Matthew Sloyan Date: Mon, 3 May 2021 12:22:03 +0100 Subject: MLCE-418 Reduce layer does not support multiple axes * Added backend specific optimization to chain new reduces layers for each axis to simulate behaviour of a layer with multiple axes. * Added function to calculate reduced output shape. * Added unit tests. * Includes rework to fix IVGCVSW-5987. Signed-off-by: Matthew Sloyan Change-Id: I154b3698b5e6756b05b2a0b5a3f0896184efce72 --- src/backends/neon/NeonBackend.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/backends/neon/NeonBackend.cpp') diff --git a/src/backends/neon/NeonBackend.cpp b/src/backends/neon/NeonBackend.cpp index a1299fb458..b496238cf3 100644 --- a/src/backends/neon/NeonBackend.cpp +++ b/src/backends/neon/NeonBackend.cpp @@ -29,6 +29,7 @@ #include "workloads/NeonDivisionWorkload.hpp" #include "workloads/NeonFullyConnectedWorkload.hpp" #include "workloads/NeonMultiplicationWorkload.hpp" +#include "workloads/NeonReduceWorkload.hpp" #include "workloads/NeonSubtractionWorkload.hpp" #include @@ -161,6 +162,7 @@ OptimizationViews NeonBackend::OptimizeSubgraphView(const SubgraphView& subgraph --it; Layer& base = **it; + // Fuse activation into previous layer if supported by backend if ((base.GetType() == LayerType::DepthwiseConvolution2d || base.GetType() == LayerType::Convolution2d || base.GetType() == LayerType::BatchNormalization || base.GetType() == LayerType::FullyConnected || base.GetType() == LayerType::Addition || base.GetType() == LayerType::Multiplication @@ -393,6 +395,25 @@ OptimizationViews NeonBackend::OptimizeSubgraphView(const SubgraphView& subgraph } } } + + // Separate reduce layer with multiple axes into multiple reduce layers with 1 axis. + if (base.GetType() == LayerType::Reduce) + { + ReduceLayer* baseLayer = PolymorphicDowncast(&base); + ReduceDescriptor reduceDescriptor = baseLayer->GetParameters(); + + if (!reduceDescriptor.m_vAxis.empty() && reduceDescriptor.m_vAxis.size() > 1) + { + // Add new layers to the graph and connect them. + std::vector layers = ChainReduceLayers(optimizationViews, + baseLayer, + reduceDescriptor); + + // Replace existing baselayer with new subgraph. + ReplaceLayers(optimizationViews, baseLayer, layers); + untouched.erase(baseLayer->GetGuid()); + } + } } if (optimizationViews.GetSubstitutions().empty()) -- cgit v1.2.1