ArmNN
 23.11
Graph.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include "LayersFwd.hpp"
8 #include "IGraphObservable.hpp"
9 #include "Profiling.hpp"
10 
11 #include <armnn/Types.hpp>
12 #include <armnn/TensorFwd.hpp>
13 #include <armnn/NetworkFwd.hpp>
14 #include <armnn/Exceptions.hpp>
15 #include <armnn/utility/Assert.hpp>
18 
19 #include <list>
20 #include <map>
21 #include <unordered_map>
22 #include <unordered_set>
23 #include <vector>
24 
25 namespace armnn
26 {
27 
28 class SubgraphView;
29 
30 class Graph
31 {
32 public:
33  template <typename LayerType>
34  static LayerType* PtrCast(Layer* const layer)
35  {
36  return PolymorphicDowncast<LayerType*>(layer);
37  }
38 
39  template <typename Func>
40  void ForEachLayer(Func func) const
41  {
42  for (auto it = m_Layers.begin(); it != m_Layers.end(); )
43  {
44  auto next = std::next(it);
45  func(*it);
46  it = next;
47  }
48  }
49 
50  using LayerList = std::list<Layer*>;
51 
52  // Const so pointers in the list can't be modified externally.
53  using Iterator = LayerList::const_iterator;
54  using IteratorDifference = Iterator::difference_type;
55 
56  using ConstIterator = TransformIterator<decltype(&PtrCast<const Layer>), Iterator>;
57  using ConstIteratorInputs = TransformIterator<decltype(&PtrCast<const InputLayer>), Iterator>;
58  using ConstIteratorOutputs = TransformIterator<decltype(&PtrCast<const OutputLayer>), Iterator>;
59 
60  /// Wrapper class returned by Graph::GetInputLayers()
62  {
63  explicit InputLayersAccessor(const Graph& graph) : m_Graph(graph) {}
64 
66  {
67  return { m_Graph.m_Layers.begin(), &(PtrCast<const InputLayer>) };
68  }
69 
71  {
72  return { std::next(m_Graph.m_Layers.begin(), static_cast<IteratorDifference>(m_Graph.GetNumInputs())),
73  &(PtrCast<const InputLayer>) };
74  }
75 
76  const Graph& m_Graph;
77  };
78 
79  /// Wrapper class returned by Graph::GetOutputLayers()
81  {
82  explicit OutputLayersAccessor(const Graph& graph) : m_Graph(graph) {}
83 
85  {
86  return { std::prev(m_Graph.m_Layers.end(), static_cast<IteratorDifference>(m_Graph.GetNumOutputs())),
87  &(PtrCast<const OutputLayer>) };
88  }
89 
91  {
92  return { m_Graph.m_Layers.end(), &(PtrCast<const OutputLayer>) };
93  }
94 
95  const Graph& m_Graph;
96  };
97 
98  Graph(bool shapeInferenceMethod = false, bool allowExpandedDims = false)
99  : m_LayersInOrder(true)
100  , m_AllowExpandedDims(allowExpandedDims)
101  , m_ShapeInferenceMethod(shapeInferenceMethod ? ShapeInferenceMethod::InferAndValidate :
103  , m_Profiler(std::make_shared<IProfiler>())
104  {}
105 
106  Graph(const Graph& other);
107 
108  Graph& operator=(const Graph& other) = delete;
109 
110  Graph(Graph&& other)
111  {
112  *this = std::move(other);
113  }
114 
116  {
117  m_InputIds = std::move(other.m_InputIds);
118  m_OutputIds = std::move(other.m_OutputIds);
119  m_LayersInOrder = std::move(other.m_LayersInOrder);
120  m_Views = std::move(other.m_Views);
121  m_Profiler = std::move(other.m_Profiler);
122  m_AllowExpandedDims = other.m_AllowExpandedDims;
123  m_ShapeInferenceMethod = other.m_ShapeInferenceMethod;
124  other.ForEachLayer([this](Layer* otherLayer)
125  {
126  otherLayer->Reparent(*this, m_Layers.end());
127  });
128 
129  ARMNN_ASSERT(other.m_PosInGraphMap.empty());
130  ARMNN_ASSERT(other.m_Layers.empty());
131 
132  return *this;
133  }
134 
136  {
137  ForEachLayer([](Layer* layer)
138  {
139  delete layer;
140  });
141  }
142 
143  Status Print(bool extended = false) const;
144 
145  Status SerializeToDot(std::ostream& stream);
146 
147  /// Adds a new layer, of type LayerType, to the graph constructed with the arguments passed.
148  template <typename LayerT, typename... Args>
149  LayerT* AddLayer(Args&&... args);
150 
151  /// Inserts a new layer between the output slot currently connected to insertBefore
152  /// and insertBefore itself.
153  template <typename LayerT, typename... Args>
154  LayerT* InsertNewLayer(InputSlot& insertBefore, Args&&... args);
155 
156  /// Inserts a new layer between insertAfter and the input slot(s) currently connected to it
157  template <typename LayerT, typename... Args>
158  LayerT* InsertNewLayer(OutputSlot& insertAfter, Args&&... args);
159 
160  /// Deletes the layer at the specified position.
161  void EraseLayer(Iterator pos);
162 
163  /// Deletes the layer. Sets @a layer to nullptr on return.
164  /// Templated to support pointers to any layer type.
165  template <typename LayerT>
166  void EraseLayer(LayerT*& layer);
167 
168  /// Returns iterator pointing to the beginning of the list. Lowercase for range-based for loops.
169  Iterator begin() { return m_Layers.begin(); }
170  /// Returns iterator pointing to the end of the list. Lowercase for range-based for loops.
171  Iterator end() { return m_Layers.end(); }
172 
173  /// Returns const iterator pointing to the beginning of the list. Lowercase for range-based for loops.
174  ConstIterator begin() const { return {m_Layers.begin(), &(PtrCast<const Layer>)}; }
175  /// Returns const iterator pointing to the end of the list. Lowercase for range-based for loops.
176  ConstIterator end() const { return {m_Layers.end(), &(PtrCast<const Layer>)}; }
177 
178  /// Returns const iterator pointing to the beginning of the list. Lowercase for range-based for loops.
179  ConstIterator cbegin() const { return begin(); }
180  /// Returns const iterator pointing to the end of the list. Lowercase for range-based for loops.
181  ConstIterator cend() const { return end(); }
182 
183  /// Sorts layers in topological order and return this.
184  Graph& TopologicalSort() { const_cast<const Graph*>(this)->TopologicalSort(); return *this; }
185  const Graph& TopologicalSort() const;
186 
187  size_t GetNumInputs() const { return m_InputIds.size(); }
188  size_t GetNumOutputs() const { return m_OutputIds.size(); }
189 
190  /// Returns a wrapper object with begin(), end() methods to iterate over the input layers
191  /// in a range-based for loop.
193 
194  /// Returns a wrapper object with begin(), end() methods to iterate over the output layers
195  /// in a range-based for loop.
197 
198  size_t GetNumLayers() const { return m_Layers.size(); }
199 
200  /// Allocates memory for all tensors under output tensor handers of each layer.
202 
203  /// Modifies the graph in-place, removing edges connecting layers using different compute devices,
204  /// and relinking them via an intermediary copy layers.
205  void AddCompatibilityLayers(std::map<BackendId, std::unique_ptr<class IBackendInternal>>& backends,
206  TensorHandleFactoryRegistry& registry);
207 
208  /// Substitutes the given sub-graph with either a new layer or a new sub-graph.
209  /// In either case, the given layer or all the layers in the given sub-graph must belong to this graph.
210  void SubstituteSubgraph(SubgraphView& subgraph, IConnectableLayer* substituteLayer);
211  void SubstituteSubgraph(SubgraphView& subgraph, const SubgraphView& substituteSubgraph);
212 
213  /// For each ConstantLayer in Graph, ensures TensorInfo is set on all output slots.
214  /// LayerValidationException thrown if no TensorInfo is set.
216 
217  void InferTensorInfos();
218 
219  void AttachObservable(IGraphObservable* const observable, GraphEvent notifyOnEvent) {
220  m_Views[notifyOnEvent].emplace_back(observable);
221  }
222 
223  void DetachObservable(IGraphObservable* const observable, GraphEvent notifyOnEvent) {
224  m_Views[notifyOnEvent].remove(observable);
225  }
226 
227  /// Gets the position of a layer in the graph.
228  Iterator GetPosInGraph(Layer& layer);
229 
230  const std::shared_ptr<IProfiler>& GetProfiler() const;
231 
232  void SetLayersOutOfOrder();
233 
234 private:
235  template <typename LayerT>
236  class LayerInGraphBase;
237 
238  template <typename LayerT>
239  class LayerInGraph;
240 
241  Iterator ForwardToEndOfInputs(Iterator it) const
242  {
243  while ((it != m_Layers.end()) && ((*it)->GetType() == LayerType::Input))
244  {
245  ++it;
246  }
247  return it;
248  }
249  Iterator ForwardToEndOfInputsAndConstants(Iterator it) const
250  {
251  while ((it != m_Layers.end()) &&
252  ((*it)->GetType() == LayerType::Input || (*it)->GetType() == LayerType::Constant))
253  {
254  ++it;
255  }
256  return it;
257  }
258 
259  Iterator RewindToBeginOfOutputs(Iterator it) const
260  {
261  while ((it != m_Layers.begin()) && ((*std::prev(it))->GetType() == LayerType::Output))
262  {
263  --it;
264  }
265  return it;
266  }
267 
268  void NotifyObservables(GraphEvent event, Layer* graphState)
269  {
270  // Iterate over all observables observing this event
271  for (auto& observable : m_Views[event])
272  {
273  observable->Update(graphState);
274  }
275  }
276 
277  std::unordered_set<LayerBindingId> m_InputIds;
278  std::unordered_set<LayerBindingId> m_OutputIds;
279  std::unordered_map<const Layer*, Iterator> m_PosInGraphMap;
280 
281  void ReplaceSubgraphConnections(const SubgraphView& subgraph, const SubgraphView& substituteSubgraph);
282  void EraseSubgraphLayers(SubgraphView &subgraph);
283 
284  /// Mutable to allow sorting on const object.
285  mutable LayerList m_Layers;
286  mutable bool m_LayersInOrder;
287 
288  bool m_AllowExpandedDims;
289 
290  std::map<const GraphEvent, std::list<IGraphObservable*>> m_Views;
291  ShapeInferenceMethod m_ShapeInferenceMethod;
292 
293  std::shared_ptr<IProfiler> m_Profiler;
294 
295  // Throws exception due to a layer input not being connected to an output slot.
296  /// Also verifies weights and bias are set for FullyConnected layers.
297  void ConstructErrorMessageForUnconnectedInputs(Layer* const layer,
298  unsigned int slotIndex);
299 
300  friend class SubgraphView;
301 };
302 
303 /// Common base class for layers in the graph.
304 template <typename LayerT>
305 class Graph::LayerInGraphBase : public LayerT
306 {
307 protected:
308  template <typename... Args>
309  LayerInGraphBase(Graph& graph, Iterator insertBefore, Args&&... args)
310  : LayerT(std::forward<Args>(args)...), m_Graph(&graph)
311  {
312  Insert(*m_Graph, insertBefore);
313  }
314  ~LayerInGraphBase()
315  {
316  Remove(*m_Graph);
317  }
318 
319  void Reparent(Graph& destGraph, Iterator insertBefore) override
320  {
321  Insert(destGraph, insertBefore);
322  Remove(*m_Graph);
323 
324  m_Graph = &destGraph;
325  }
326 
327 private:
328  void Insert(Graph& graph, Iterator insertBefore)
329  {
330  graph.m_PosInGraphMap.emplace(this, graph.m_Layers.emplace(insertBefore, this));
331  }
332 
333  void Remove(Graph& graph)
334  {
335  auto layerIt = graph.GetPosInGraph(*this);
336  graph.m_Layers.erase(layerIt);
337 
338  const size_t numErased = graph.m_PosInGraphMap.erase(this);
339  IgnoreUnused(numErased);
340  ARMNN_ASSERT(numErased == 1);
341  }
342 
343 protected:
344  Graph* m_Graph;
345 };
346 
347 /// Input/Output/Constant layers specialize this template.
348 template <typename LayerT>
349 class Graph::LayerInGraph final : public LayerInGraphBase<LayerT>
350 {
351 public:
352  template <typename... Args>
353  LayerInGraph(Graph& graph, Args&&... args)
354  : LayerInGraphBase<LayerT>(graph,
355  // Insert at the back of the intermediate layers (before outputs).
356  std::prev(graph.end(), IteratorDifference(graph.GetNumOutputs())),
357  std::forward<Args>(args)...)
358  {
359  }
360  template <typename... Args>
361  LayerInGraph(Graph& graph, Iterator insertBefore, Args&&... args)
362  : LayerInGraphBase<LayerT>(graph,
363  // Make sure it's inserted after all inputs and before all outputs.
364  graph.ForwardToEndOfInputsAndConstants(graph.RewindToBeginOfOutputs(insertBefore)),
365  std::forward<Args>(args)...)
366  {
367  }
368 };
369 
370 template <>
371 class Graph::LayerInGraph<ConstantLayer> final : public LayerInGraphBase<ConstantLayer>
372 {
373 public:
374  template <typename... Args>
375  LayerInGraph(Graph& graph, Args&&... args)
376  : LayerInGraphBase<ConstantLayer>(graph,
377  // Always add to the back of the inputs.
378  std::next(graph.begin(), IteratorDifference(graph.GetNumInputs())),
379  std::forward<Args>(args)...)
380  {}
381  template <typename... Args>
382  LayerInGraph(Graph& graph, Iterator, Args&&... args)
383  // Ignore Iterator argument. Always add to the back of the inputs.
384  : LayerInGraph(graph, std::forward<Args>(args)...)
385  {}
386  ~LayerInGraph() override
387  {}
388 };
389 
390 /// Inputs add/remove their binding id to m_InputIds in the graph.
391 template <>
392 class Graph::LayerInGraph<InputLayer> final : public LayerInGraphBase<InputLayer>
393 {
394 public:
395  template <typename... Args>
396  LayerInGraph(Graph& graph, Args&&... args)
397  : LayerInGraphBase<InputLayer>(graph,
398  // Always add to the back of the inputs.
399  std::next(graph.begin(), IteratorDifference(graph.GetNumInputs())),
400  std::forward<Args>(args)...)
401  {
402  const bool isNewId = m_Graph->m_InputIds.emplace(GetBindingId()).second;
403  if (!isNewId)
404  {
405  throw InvalidArgumentException("A layer already exists with the specified id");
406  }
407  }
408  template <typename... Args>
409  LayerInGraph(Graph& graph, Iterator, Args&&... args)
410  // Ignore Iterator argument. Always add to the back of the inputs.
411  : LayerInGraph(graph, std::forward<Args>(args)...)
412  {
413  }
414  ~LayerInGraph() override
415  {
416  const size_t numErased = m_Graph->m_InputIds.erase(GetBindingId());
417  IgnoreUnused(numErased);
418  ARMNN_ASSERT(numErased == 1);
419  }
420 };
421 
422 /// Outputs add/remove their binding id to m_OutputIds in the graph.
423 template <>
424 class Graph::LayerInGraph<OutputLayer> final : public LayerInGraphBase<OutputLayer>
425 {
426 public:
427  template <typename... Args>
428  LayerInGraph(Graph& graph, Args&&... args)
429  : LayerInGraphBase<OutputLayer>(graph,
430  // Always add to the back of the outputs.
431  graph.end(),
432  std::forward<Args>(args)...)
433  {
434  const bool isNewId = m_Graph->m_OutputIds.emplace(GetBindingId()).second;
435  if (!isNewId)
436  {
437  throw InvalidArgumentException("A layer already exists with the specified id");
438  }
439  }
440  ~LayerInGraph() override
441  {
442  const size_t numErased = m_Graph->m_OutputIds.erase(GetBindingId());
443  IgnoreUnused(numErased);
444  ARMNN_ASSERT(numErased == 1);
445  }
446 };
447 
449 {
450  auto it = m_PosInGraphMap.find(&layer);
451  ARMNN_ASSERT(it != m_PosInGraphMap.end());
452  return it->second;
453 }
454 
455 template <typename LayerT, typename... Args>
456 inline LayerT* Graph::AddLayer(Args&&... args)
457 {
458  m_LayersInOrder = m_LayersInOrder &&
459  ((LayerEnumOf<LayerT>() == LayerType::Input) || (LayerEnumOf<LayerT>() == LayerType::Output));
460  LayerT* const layer = new LayerInGraph<LayerT>(*this, std::forward<Args>(args)...);
461 
462  layer->SetShapeInferenceMethod(m_ShapeInferenceMethod);
463  layer->SetAllowExpandedDims(m_AllowExpandedDims);
464 
465  NotifyObservables(GraphEvent::LayerAdded, layer);
466 
467  return layer;
468 }
469 
470 template <typename LayerT, typename... Args>
471 inline LayerT* Graph::InsertNewLayer(InputSlot& insertBefore, Args&&... args)
472 {
473  // Insert after the parent if any, or before the child otherwise, so the topological order is kept.
474  OutputSlot* parentOut = insertBefore.GetConnectedOutputSlot();
475  const Iterator pos = (parentOut != nullptr)
476  ? std::next(GetPosInGraph(parentOut->GetOwningLayer()))
477  : GetPosInGraph(insertBefore.GetOwningLayer());
478  LayerT* const layer = new LayerInGraph<LayerT>(*this, pos, std::forward<Args>(args)...);
479  insertBefore.Insert(*layer);
480 
481  NotifyObservables(GraphEvent::LayerAdded, layer);
482 
483  return layer;
484 }
485 
486 template <typename LayerT, typename... Args>
487 inline LayerT* Graph::InsertNewLayer(OutputSlot& insertAfter, Args&&... args)
488 {
489  Layer& owningLayer = insertAfter.GetOwningLayer();
490 
491  const Iterator pos = std::next(GetPosInGraph(owningLayer));
492  LayerT* const layer = new LayerInGraph<LayerT>(*this, pos, std::forward<Args>(args)...);
493 
494  ARMNN_ASSERT(layer->GetNumInputSlots() == 1);
495 
496  insertAfter.MoveAllConnections(layer->GetOutputSlot());
497  insertAfter.Connect(layer->GetInputSlot(0));
498 
499  NotifyObservables(GraphEvent::LayerAdded, layer);
500 
501  return layer;
502 }
503 
504 inline void Graph::EraseLayer(Iterator pos)
505 {
506  NotifyObservables(GraphEvent::LayerErased, *pos);
507 
508  delete *pos;
509 }
510 
511 template <typename LayerT>
512 inline void Graph::EraseLayer(LayerT*& layer)
513 {
514  ARMNN_ASSERT(layer != nullptr);
515  EraseLayer(GetPosInGraph(*layer));
516  layer = nullptr;
517 }
518 
519 } // namespace armnn
armnn::InputLayer
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: InputLayer.hpp:13
ARMNN_ASSERT
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
armnn::Graph::LayerList
std::list< Layer * > LayerList
Definition: Graph.hpp:50
armnn::Graph::SetLayersOutOfOrder
void SetLayersOutOfOrder()
Definition: Graph.cpp:697
armnn::Graph::LayerInGraph< ConstantLayer >::LayerInGraph
LayerInGraph(Graph &graph, Iterator, Args &&... args)
Definition: Graph.hpp:382
armnn::Graph::OutputLayersAccessor::begin
ConstIteratorOutputs begin() const
Definition: Graph.hpp:84
armnn::Graph::~Graph
~Graph()
Definition: Graph.hpp:135
armnn::Graph::AllocateDynamicBuffers
Status AllocateDynamicBuffers()
Allocates memory for all tensors under output tensor handers of each layer.
Definition: Graph.cpp:207
armnn::InputSlot::GetOwningLayer
Layer & GetOwningLayer() const
Definition: Layer.hpp:53
armnn::Graph::ForEachLayer
void ForEachLayer(Func func) const
Definition: Graph.hpp:40
armnn::Graph::GetPosInGraph
Iterator GetPosInGraph(Layer &layer)
Gets the position of a layer in the graph.
Definition: Graph.hpp:448
armnn::GraphEvent
GraphEvent
Definition: IGraphObservable.hpp:12
armnn::Graph::EraseLayer
void EraseLayer(Iterator pos)
Deletes the layer at the specified position.
Definition: Graph.hpp:504
armnn::TensorHandleFactoryRegistry
Definition: TensorHandleFactoryRegistry.hpp:23
armnn::OutputSlot
Definition: Layer.hpp:100
armnn::Graph::SubstituteSubgraph
void SubstituteSubgraph(SubgraphView &subgraph, IConnectableLayer *substituteLayer)
Substitutes the given sub-graph with either a new layer or a new sub-graph.
Definition: Graph.cpp:461
armnn::Graph::cbegin
ConstIterator cbegin() const
Returns const iterator pointing to the beginning of the list. Lowercase for range-based for loops.
Definition: Graph.hpp:179
armnn::Graph::LayerInGraph< OutputLayer >::LayerInGraph
LayerInGraph(Graph &graph, Args &&... args)
Definition: Graph.hpp:428
IGraphObservable.hpp
armnn::Graph::SubgraphView
friend class SubgraphView
Definition: Graph.hpp:300
armnn::GraphEvent::LayerAdded
@ LayerAdded
Profiling.hpp
armnn::Graph::VerifyConstantLayerSetTensorInfo
void VerifyConstantLayerSetTensorInfo() const
For each ConstantLayer in Graph, ensures TensorInfo is set on all output slots.
Definition: Graph.cpp:581
armnn::Graph::LayerInGraph< ConstantLayer >::LayerInGraph
LayerInGraph(Graph &graph, Args &&... args)
Definition: Graph.hpp:375
armnn::Graph::InputLayersAccessor::m_Graph
const Graph & m_Graph
Definition: Graph.hpp:76
armnn::Graph::Iterator
LayerList::const_iterator Iterator
Definition: Graph.hpp:53
armnn::Graph::InputLayersAccessor::InputLayersAccessor
InputLayersAccessor(const Graph &graph)
Definition: Graph.hpp:63
armnn::Graph::OutputLayersAccessor
Wrapper class returned by Graph::GetOutputLayers()
Definition: Graph.hpp:80
armnn::Graph::InputLayersAccessor::end
ConstIteratorInputs end() const
Definition: Graph.hpp:70
armnn::OutputSlot::Connect
int Connect(InputSlot &destination)
Definition: Layer.cpp:112
armnn::Graph::IteratorDifference
Iterator::difference_type IteratorDifference
Definition: Graph.hpp:54
TransformIterator.hpp
armnn::Graph::cend
ConstIterator cend() const
Returns const iterator pointing to the end of the list. Lowercase for range-based for loops.
Definition: Graph.hpp:181
armnn::Layer
Definition: Layer.hpp:230
armnn::Graph::OutputLayersAccessor::m_Graph
const Graph & m_Graph
Definition: Graph.hpp:95
Assert.hpp
TensorFwd.hpp
armnn::OutputSlot::GetOwningLayer
Layer & GetOwningLayer() const
Definition: Layer.hpp:132
armnn::Graph::begin
Iterator begin()
Returns iterator pointing to the beginning of the list. Lowercase for range-based for loops.
Definition: Graph.hpp:169
armnn::Graph::LayerInGraph< InputLayer >::LayerInGraph
LayerInGraph(Graph &graph, Args &&... args)
Definition: Graph.hpp:396
armnn::Graph::Graph
Graph(Graph &&other)
Definition: Graph.hpp:110
armnn::Graph::LayerInGraph< OutputLayer >::~LayerInGraph
~LayerInGraph() override
Definition: Graph.hpp:440
armnn::Graph::OutputLayersAccessor::OutputLayersAccessor
OutputLayersAccessor(const Graph &graph)
Definition: Graph.hpp:82
PolymorphicDowncast.hpp
LayersFwd.hpp
armnn::Graph::GetOutputLayers
OutputLayersAccessor GetOutputLayers() const
Returns a wrapper object with begin(), end() methods to iterate over the output layers in a range-bas...
Definition: Graph.hpp:196
armnn::Graph::operator=
Graph & operator=(const Graph &other)=delete
armnn::OutputLayer
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: OutputLayer.hpp:13
armnn::InvalidArgumentException
Definition: Exceptions.hpp:80
armnn::Graph::Print
Status Print(bool extended=false) const
Definition: Graph.cpp:68
armnn::Graph::InputLayersAccessor
Wrapper class returned by Graph::GetInputLayers()
Definition: Graph.hpp:61
armnn::Graph::GetNumLayers
size_t GetNumLayers() const
Definition: Graph.hpp:198
armnn::Graph::GetProfiler
const std::shared_ptr< IProfiler > & GetProfiler() const
Definition: Graph.cpp:692
armnn::SubgraphView
The SubgraphView class represents a subgraph of a Graph.
Definition: SubgraphView.hpp:31
armnn::Graph::LayerInGraph< InputLayer >::~LayerInGraph
~LayerInGraph() override
Definition: Graph.hpp:414
armnn::Graph::GetNumInputs
size_t GetNumInputs() const
Definition: Graph.hpp:187
armnn::GraphEvent::LayerErased
@ LayerErased
armnn::Graph::InferTensorInfos
void InferTensorInfos()
Definition: Graph.cpp:604
armnn::OutputSlot::MoveAllConnections
void MoveAllConnections(OutputSlot &destination)
Moves all connections to another OutputSlot.
Definition: Layer.cpp:145
armnn::InputSlot
Definition: Layer.hpp:42
armnn::ShapeInferenceMethod::ValidateOnly
@ ValidateOnly
Validate all output shapes.
armnn::ShapeInferenceMethod::InferAndValidate
@ InferAndValidate
Infer missing output shapes and validate all output shapes.
armnn::InputSlot::Insert
void Insert(Layer &layer)
Definition: Layer.cpp:48
armnn::Graph::AddCompatibilityLayers
void AddCompatibilityLayers(std::map< BackendId, std::unique_ptr< class IBackendInternal >> &backends, TensorHandleFactoryRegistry &registry)
Modifies the graph in-place, removing edges connecting layers using different compute devices,...
Definition: Graph.cpp:329
armnn::Graph::GetInputLayers
InputLayersAccessor GetInputLayers() const
Returns a wrapper object with begin(), end() methods to iterate over the input layers in a range-base...
Definition: Graph.hpp:192
armnn::Graph::InputLayersAccessor::begin
ConstIteratorInputs begin() const
Definition: Graph.hpp:65
armnn::Status
Status
Definition: Types.hpp:42
armnn::Graph::end
Iterator end()
Returns iterator pointing to the end of the list. Lowercase for range-based for loops.
Definition: Graph.hpp:171
armnn::Graph::Graph
Graph(bool shapeInferenceMethod=false, bool allowExpandedDims=false)
Definition: Graph.hpp:98
std
Definition: BackendId.hpp:149
armnn::Graph::TopologicalSort
Graph & TopologicalSort()
Sorts layers in topological order and return this.
Definition: Graph.hpp:184
armnn::IgnoreUnused
void IgnoreUnused(Ts &&...)
Definition: IgnoreUnused.hpp:14
armnn::IGraphObservable
Definition: IGraphObservable.hpp:18
armnn::Graph::begin
ConstIterator begin() const
Returns const iterator pointing to the beginning of the list. Lowercase for range-based for loops.
Definition: Graph.hpp:174
armnn::Graph::SerializeToDot
Status SerializeToDot(std::ostream &stream)
Definition: Graph.cpp:146
armnn::Graph::AddLayer
LayerT * AddLayer(Args &&... args)
Adds a new layer, of type LayerType, to the graph constructed with the arguments passed.
Definition: Graph.hpp:456
armnn::BackendId
Definition: BackendId.hpp:75
armnn::Layer::Reparent
virtual void Reparent(Graph &dest, std::list< Layer * >::const_iterator iterator)=0
armnn::Graph::OutputLayersAccessor::end
ConstIteratorOutputs end() const
Definition: Graph.hpp:90
armnn::InputSlot::GetConnectedOutputSlot
const OutputSlot * GetConnectedOutputSlot() const
Definition: Layer.hpp:56
armnn::ConstantLayer
A layer that the constant data can be bound to.
Definition: ConstantLayer.hpp:15
Exceptions.hpp
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
Types.hpp
armnn::Graph::LayerInGraph< ConstantLayer >::~LayerInGraph
~LayerInGraph() override
Definition: Graph.hpp:386
armnn::Graph::end
ConstIterator end() const
Returns const iterator pointing to the end of the list. Lowercase for range-based for loops.
Definition: Graph.hpp:176
armnn::Graph::operator=
Graph & operator=(Graph &&other)
Definition: Graph.hpp:115
armnn::IProfiler
Definition: IProfiler.hpp:21
armnn::IConnectableLayer
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:80
armnn::LayerType::Input
@ Input
armnn::Graph::PtrCast
static LayerType * PtrCast(Layer *const layer)
Definition: Graph.hpp:34
armnn::ShapeInferenceMethod
ShapeInferenceMethod
The ShapeInferenceMethod modify how the output shapes are treated.
Definition: Types.hpp:235
armnn::Graph::LayerInGraph< InputLayer >::LayerInGraph
LayerInGraph(Graph &graph, Iterator, Args &&... args)
Definition: Graph.hpp:409
armnn::Graph::GetNumOutputs
size_t GetNumOutputs() const
Definition: Graph.hpp:188
armnn::Graph::AttachObservable
void AttachObservable(IGraphObservable *const observable, GraphEvent notifyOnEvent)
Definition: Graph.hpp:219
armnn::LayerType
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
Definition: Types.hpp:491
armnn::Graph::DetachObservable
void DetachObservable(IGraphObservable *const observable, GraphEvent notifyOnEvent)
Definition: Graph.hpp:223
NetworkFwd.hpp
armnn::Graph
Definition: Graph.hpp:30
armnn::Graph::InsertNewLayer
LayerT * InsertNewLayer(InputSlot &insertBefore, Args &&... args)
Inserts a new layer between the output slot currently connected to insertBefore and insertBefore itse...
Definition: Graph.hpp:471
armnn::LayerType::Output
@ Output
armnn::LayerType::Constant
@ Constant
armnn::TransformIterator
Definition: TransformIterator.hpp:21