blob: 5e50c01c09d2d681bd5beccda2ba66f976d7b113 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//
#include "Optimizer.hpp"
#include "Observable.hpp"
#include "optimizations/All.hpp"
namespace armnn
{
Optimizer::Optimizer()
{
}
void Optimizer::Pass(Graph& graph, const Optimizations& optimizations)
{
// Create observables to observe changes to the graph
AddedLayerObservable addedLayerObservable(graph);
ErasedLayerNamesObservable erasedLayerNamesObservable(graph);
bool graphNeedsSorting = false;
auto it = graph.TopologicalSort().end();
// Calls TopologicalSort() for every iteration to re-order the list in case layers were added/removed.
while (it != graph.TopologicalSort().begin())
{
--it;
for (auto&& optimization : optimizations)
{
optimization->Run(graph, **it);
if ((*it)->IsOutputUnconnected())
{
it = graph.EraseLayer(it);
graphNeedsSorting = true;
}
// Add the names of erased layers as related layers to the new added layers
for (auto& erasedLayerName : erasedLayerNamesObservable)
{
for (auto& addedLayer : addedLayerObservable)
{
addedLayer->AddRelatedLayerName(erasedLayerName);
}
}
erasedLayerNamesObservable.Clear();
addedLayerObservable.Clear();
if (graphNeedsSorting)
{
graphNeedsSorting = false;
break;
}
}
}
}
} // namespace armnn
|