diff options
author | Matthew Sloyan <matthew.sloyan@arm.com> | 2021-05-03 12:22:03 +0100 |
---|---|---|
committer | TeresaARM <teresa.charlinreyes@arm.com> | 2021-05-20 13:57:36 +0000 |
commit | 5fc0fd6661f9647092deb052d052973a237bd52d (patch) | |
tree | f46c8ad169414ae400b22b046e25cedf7ba76c9d /src/backends/cl/ClBackend.cpp | |
parent | 1bed2f4f297d16f738b2c14f9e0fd24b7b03dade (diff) | |
download | armnn-5fc0fd6661f9647092deb052d052973a237bd52d.tar.gz |
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 <matthew.sloyan@arm.com>
Change-Id: I154b3698b5e6756b05b2a0b5a3f0896184efce72
Diffstat (limited to 'src/backends/cl/ClBackend.cpp')
-rw-r--r-- | src/backends/cl/ClBackend.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/backends/cl/ClBackend.cpp b/src/backends/cl/ClBackend.cpp index 35770d9219..a9ab237325 100644 --- a/src/backends/cl/ClBackend.cpp +++ b/src/backends/cl/ClBackend.cpp @@ -30,6 +30,7 @@ #include "workloads/ClDivisionWorkload.hpp" #include "workloads/ClFullyConnectedWorkload.hpp" #include "workloads/ClMultiplicationWorkload.hpp" +#include "workloads/ClReduceWorkload.hpp" #include "workloads/ClSubtractionWorkload.hpp" #include <Optimizer.hpp> @@ -220,6 +221,7 @@ OptimizationViews ClBackend::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 @@ -451,6 +453,25 @@ OptimizationViews ClBackend::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<ReduceLayer*>(&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<Layer*> layers = ChainReduceLayers<ReduceLayer>(optimizationViews, + baseLayer, + reduceDescriptor); + + // Replace existing baselayer with new subgraph. + ReplaceLayers<ReduceLayer>(optimizationViews, baseLayer, layers); + untouched.erase(baseLayer->GetGuid()); + } + } } if (optimizationViews.GetSubstitutions().empty()) |