| 14 | } |
| 15 | |
| 16 | void Optimizer::Pass(Graph& graph, const Optimizations& optimizations) |
| 17 | { |
| 18 | ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "Optimizer_Pass"); |
| 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 | if (!*it) |
| 33 | { |
| 34 | throw armnn::NullPointerException("Layer must not be null."); |
| 35 | } |
| 36 | |
| 37 | optimization->Run(graph, **it); |
| 38 | |
| 39 | if ((*it)->IsOutputUnconnected()) |
| 40 | { |
| 41 | auto next = std::next(graph.GetPosInGraph(**it)); |
| 42 | graph.EraseLayer(it); |
| 43 | it = next; |
| 44 | graphNeedsSorting = true; |
| 45 | } |
| 46 | |
| 47 | // Add the names of erased layers as related layers to the new added layers |
| 48 | for (auto& erasedLayerName : erasedLayerNamesObservable) |
| 49 | { |
| 50 | for (auto& addedLayer : addedLayerObservable) |
| 51 | { |
| 52 | addedLayer->AddRelatedLayerName(erasedLayerName); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | erasedLayerNamesObservable.Clear(); |
| 57 | addedLayerObservable.Clear(); |
| 58 | |
| 59 | if (graphNeedsSorting) |
| 60 | { |
| 61 | graphNeedsSorting = false; |
| 62 | break; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | } // namespace armnn |
nothing calls this directly
no test coverage detected