ArmNN
 20.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 
10 
11 namespace armnn
12 {
13 namespace optimizations
14 {
15 
16 template <typename PermuteType>
18 {
19 public:
20  /// Run for every connection between a base PermuteLayer and a child PermuteLayer.
21  /// Bypasses both layers for that connection if one is the inverse of the other.
22  void Run(Graph& graph, InputSlot& connection) const
23  {
24  IgnoreUnused(graph);
25  Layer& base = connection.GetConnectedOutputSlot()->GetOwningLayer();
26  auto child = boost::polymorphic_downcast<PermuteType*>(&connection.GetOwningLayer());
27 
28  if (child->IsInverse(*boost::polymorphic_downcast<PermuteType*>(&base)))
29  {
30  // Bypass both layers. Child will be removed as it's left unconnected.
31  // Base layer will be removed if left unconnected.
33  }
34  }
35 
36 protected:
37  OptimizeInversePermutesImpl() = default;
38  ~OptimizeInversePermutesImpl() = default;
39 };
40 
45 
46 } // namespace optimizations
47 } // namespace armnn
Layer & GetOwningLayer() const
Definition: Layer.hpp:115
Copyright (c) 2020 ARM Limited.
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:310
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:312
void MoveAllConnections(OutputSlot &destination)
Moves all connections to another OutputSlot.
Definition: Layer.cpp:112