aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/optimizations
diff options
context:
space:
mode:
authorIdriss Chaouch <idriss.chaouch@arm.com>2023-08-28 14:28:31 +0100
committerIdriss Chaouch <idriss.chaouch@arm.com>2023-08-31 11:26:28 +0100
commit98e383eadf4e670d057ad725c7fe7924fea8e36b (patch)
tree35acac15aa69ab405887289cb9674d388f06f96b /src/armnn/optimizations
parent2be039bce38a4fa436e8310dfe14ebfff20d57bd (diff)
downloadarmnn-98e383eadf4e670d057ad725c7fe7924fea8e36b.tar.gz
IVGCVSW-7525 Add broadcast_to operator
Signed-off-by: Idriss Chaouch <idriss.chaouch@arm.com> Signed-off-by: Narumol Prangnawarat <narumol.prangnawarat@arm.com> Change-Id: I94ec5f9120b2d736fdf98d00ec5137a4efd739b8
Diffstat (limited to 'src/armnn/optimizations')
-rw-r--r--src/armnn/optimizations/All.hpp5
-rw-r--r--src/armnn/optimizations/DeleteBroadcastTo.hpp37
2 files changed, 40 insertions, 2 deletions
diff --git a/src/armnn/optimizations/All.hpp b/src/armnn/optimizations/All.hpp
index 0e67516193..abf4cde442 100644
--- a/src/armnn/optimizations/All.hpp
+++ b/src/armnn/optimizations/All.hpp
@@ -1,5 +1,5 @@
//
-// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
+// Copyright © 2022, 2023 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
#pragma once
@@ -10,6 +10,7 @@
#include "ConvertConstDequantisationLayersToConstLayers.hpp"
#include "ConvertConstPermuteLayersToConstLayers.hpp"
#include "ConvertFp32NetworkToFp16.hpp"
+#include "DeleteBroadcastTo.hpp"
#include "FoldPadIntoLayer2d.hpp"
#include "FuseBatchNorm.hpp"
#include "MovePermuteUp.hpp"
@@ -21,4 +22,4 @@
#include "PermuteAndBatchToSpaceAsDepthToSpace.hpp"
#include "PermuteDepthwiseConv2dWeights.hpp"
#include "SquashEqualSiblings.hpp"
-#include "TransposeAsReshape.hpp" \ No newline at end of file
+#include "TransposeAsReshape.hpp"
diff --git a/src/armnn/optimizations/DeleteBroadcastTo.hpp b/src/armnn/optimizations/DeleteBroadcastTo.hpp
new file mode 100644
index 0000000000..9ea20907df
--- /dev/null
+++ b/src/armnn/optimizations/DeleteBroadcastTo.hpp
@@ -0,0 +1,37 @@
+//
+// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+#pragma once
+
+#include "Optimization.hpp"
+
+namespace armnn
+{
+namespace optimizations
+{
+class DeleteBroadcastToImpl
+{
+public:
+ /// Run for every BroadcastToLayer. Remove it if it is before an ElementWiseLayer.
+ /// Since ElementWiseBinary uses a brodcastLoop, using a broadcastTo layer is
+ /// not necessary so it will be deleted.
+ void Run(Graph&, BroadcastToLayer& layer) const
+ {
+ if(layer.GetType() == LayerType::BroadcastTo)
+ {
+ Layer& next = layer.GetOutputSlot(0).GetConnection(0)->GetOwningLayer();
+ if (next.GetType() == LayerType::ElementwiseBinary)
+ {
+ Layer& connectedLayer = layer.GetInputSlots()[0].GetConnectedOutputSlot()->GetOwningLayer();
+ layer.GetOutputSlot().MoveAllConnections(connectedLayer.GetOutputSlot());
+ }
+ }
+ }
+protected:
+ DeleteBroadcastToImpl() = default;
+ ~DeleteBroadcastToImpl() = default;
+};
+using BroadcastToOptimizationLayer = OptimizeForType<BroadcastToLayer, DeleteBroadcastToImpl>;
+}
+} \ No newline at end of file