ArmNN
 25.11
Loading...
Searching...
No Matches
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.

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}
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)

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

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


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