ArmNN
 24.08
OptimizeInversePermutes.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include "Optimization.hpp"
8 
11 
12 namespace armnn
13 {
14 namespace optimizations
15 {
16 
17 template <typename PermuteType>
19 {
20 public:
21  /// Run for every connection between a base PermuteLayer and a child PermuteLayer.
22  /// Bypasses both layers for that connection if one is the inverse of the other.
23  void Run(Graph& graph, InputSlot& connection) const
24  {
25  IgnoreUnused(graph);
26  Layer& base = connection.GetConnectedOutputSlot()->GetOwningLayer();
27  auto child = PolymorphicDowncast<PermuteType*>(&connection.GetOwningLayer());
28 
29  if (child->IsInverse(*PolymorphicDowncast<PermuteType*>(&base)))
30  {
31  // Bypass both layers. Child will be removed as it's left unconnected.
32  // Base layer will be removed if left unconnected.
33  child->GetOutputSlot().MoveAllConnections(*base.GetInputSlot(0).GetConnectedOutputSlot());
34  }
35  }
36 
37 protected:
38  OptimizeInversePermutesImpl() = default;
39  ~OptimizeInversePermutesImpl() = default;
40 };
41 
46 
47 } // namespace optimizations
48 } // namespace armnn
armnn::InputSlot::GetOwningLayer
Layer & GetOwningLayer() const
Definition: Layer.hpp:53
armnn::optimizations::OptimizeInversePermutes
OptimizeForConnection< PermuteLayer, PermuteLayer, OptimizeInversePermutesImpl< PermuteLayer > > OptimizeInversePermutes
Definition: OptimizeInversePermutes.hpp:43
armnn::optimizations::OptimizeInversePermutesImpl::~OptimizeInversePermutesImpl
~OptimizeInversePermutesImpl()=default
IgnoreUnused.hpp
Optimization.hpp
armnn::Layer::GetInputSlot
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:337
armnn::Layer
Definition: Layer.hpp:230
armnn::TransposeLayer
This layer represents a transpose operation.
Definition: TransposeLayer.hpp:15
armnn::OutputSlot::GetOwningLayer
Layer & GetOwningLayer() const
Definition: Layer.hpp:132
armnn::OptimizeForConnection
Definition: Optimization.hpp:118
PolymorphicDowncast.hpp
armnn::optimizations::OptimizeInversePermutesImpl::Run
void Run(Graph &graph, InputSlot &connection) const
Run for every connection between a base PermuteLayer and a child PermuteLayer.
Definition: OptimizeInversePermutes.hpp:23
armnn::InputSlot
Definition: Layer.hpp:42
armnn::IgnoreUnused
void IgnoreUnused(Ts &&...)
Definition: IgnoreUnused.hpp:14
armnn::optimizations::OptimizeInversePermutesImpl
Definition: OptimizeInversePermutes.hpp:18
armnn::InputSlot::GetConnectedOutputSlot
const OutputSlot * GetConnectedOutputSlot() const
Definition: Layer.hpp:56
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::PermuteLayer
This layer represents a permutation operation.
Definition: PermuteLayer.hpp:15
armnn::Graph
Definition: Graph.hpp:30
armnn::optimizations::OptimizeInversePermutesImpl::OptimizeInversePermutesImpl
OptimizeInversePermutesImpl()=default