ArmNN
 22.05
Optimizer Class Reference

#include <Optimizer.hpp>

Public Types

using OptimizationPtr = std::unique_ptr< Optimization >
 
using Optimizations = std::vector< OptimizationPtr >
 

Static Public Member Functions

static void Pass (Graph &graph, const Optimizations &optimizations)
 

Detailed Description

Definition at line 14 of file Optimizer.hpp.

Member Typedef Documentation

◆ OptimizationPtr

using OptimizationPtr = std::unique_ptr<Optimization>

Definition at line 17 of file Optimizer.hpp.

◆ Optimizations

using Optimizations = std::vector<OptimizationPtr>

Definition at line 18 of file Optimizer.hpp.

Member Function Documentation

◆ Pass()

void Pass ( Graph graph,
const Optimizations optimizations 
)
static

Definition at line 16 of file Optimizer.cpp.

References ARMNN_ASSERT, ARMNN_SCOPED_PROFILING_EVENT, Graph::begin(), GraphObservable< ObservedType >::Clear(), Graph::end(), Graph::EraseLayer(), Graph::GetPosInGraph(), Graph::TopologicalSort(), and armnn::Undefined.

Referenced by armnn::ApplyBackendOptimizations(), armnn::Optimize(), and TEST_SUITE().

17 {
19  // Create observables to observe changes to the graph
20  AddedLayerObservable addedLayerObservable(graph);
21  ErasedLayerNamesObservable erasedLayerNamesObservable(graph);
22 
23  bool graphNeedsSorting = false;
24  auto it = graph.TopologicalSort().end();
25 
26  // Calls TopologicalSort() for every iteration to re-order the list in case layers were added/removed.
27  while (it != graph.TopologicalSort().begin())
28  {
29  --it;
30  for (auto&& optimization : optimizations)
31  {
32  ARMNN_ASSERT(*it);
33  optimization->Run(graph, **it);
34 
35  if ((*it)->IsOutputUnconnected())
36  {
37  auto next = std::next(graph.GetPosInGraph(**it));
38  graph.EraseLayer(it);
39  it = next;
40  graphNeedsSorting = true;
41  }
42 
43  // Add the names of erased layers as related layers to the new added layers
44  for (auto& erasedLayerName : erasedLayerNamesObservable)
45  {
46  for (auto& addedLayer : addedLayerObservable)
47  {
48  addedLayer->AddRelatedLayerName(erasedLayerName);
49  }
50  }
51 
52  erasedLayerNamesObservable.Clear();
53  addedLayerObservable.Clear();
54 
55  if (graphNeedsSorting)
56  {
57  graphNeedsSorting = false;
58  break;
59  }
60  }
61  }
62 }
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:220
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14

The documentation for this class was generated from the following files: