ArmNN
 21.02
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.
34  }
35  }
36 
37 protected:
38  OptimizeInversePermutesImpl() = default;
39  ~OptimizeInversePermutesImpl() = default;
40 };
41 
46 
47 } // namespace optimizations
48 } // namespace armnn
Layer & GetOwningLayer() const
Definition: Layer.hpp:115
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
This layer represents a permutation operation.
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:316
void Run(Graph &graph, InputSlot &connection) const
Run for every connection between a base PermuteLayer and a child PermuteLayer.
const OutputSlot * GetConnectedOutputSlot() const
Definition: Layer.hpp:55
Layer & GetOwningLayer() const
Definition: Layer.hpp:52
This layer represents a transpose operation.
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition: Layer.hpp:318
void MoveAllConnections(OutputSlot &destination)
Moves all connections to another OutputSlot.
Definition: Layer.cpp:116