ArmNN
 21.02
LoadedNetwork.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include <armnn/Tensor.hpp>
8 #include <armnn/Types.hpp>
9 
10 #include "Network.hpp"
11 #include "LayerFwd.hpp"
12 #include "Profiling.hpp"
13 
18 #include <ProfilingService.hpp>
20 
21 #include <mutex>
22 #include <unordered_map>
23 
24 namespace cl
25 {
26  class Context;
27  class CommandQueue;
28  class Device;
29 }
30 
31 namespace armnn
32 {
33 
35 {
36 public:
37  using WorkloadQueue = std::vector< std::unique_ptr<IWorkload> >;
38  ~LoadedNetwork(){ FreeWorkingMemory(); }
39 
41  TensorInfo GetOutputTensorInfo(LayerBindingId layerId) const;
42 
43  Status EnqueueWorkload(const InputTensors& inputTensors, const OutputTensors& outputTensors);
44 
45  static std::unique_ptr<LoadedNetwork> MakeLoadedNetwork(std::unique_ptr<IOptimizedNetwork> net,
46  std::string & errorMessage,
47  const INetworkProperties& networkProperties,
48  profiling::ProfilingService& profilingService);
49 
50  // NOTE we return by reference as the purpose of this method is only to provide
51  // access to the private m_Profiler and in theory we should not need to increment
52  // the shared_ptr's reference counter
53  const std::shared_ptr<IProfiler>& GetProfiler() const { return m_Profiler; }
54 
55  void FreeWorkingMemory();
56 
57  void RegisterDebugCallback(const DebugCallbackFunction& func);
58 
59  void SendNetworkStructure();
60 
61  profiling::ProfilingGuid GetNetworkGuid();
62 
63 private:
64  void AllocateWorkingMemory(std::lock_guard<std::mutex>& lock);
65 
66  LoadedNetwork(std::unique_ptr<IOptimizedNetwork> net,
67  const INetworkProperties& networkProperties,
68  profiling::ProfilingService& profilingService);
69 
70  void EnqueueInput(const BindableLayer& layer, ITensorHandle* tensorHandle, const TensorInfo& tensorInfo);
71 
72  void EnqueueOutput(const BindableLayer& layer, ITensorHandle* tensorHandle, const TensorInfo& tensorInfo);
73 
74  bool Execute(std::unique_ptr<profiling::TimelineUtilityMethods>& timelineUtils,
75  profiling::ProfilingGuid inferenceGuid);
76 
77 
78  const IWorkloadFactory& GetWorkloadFactory(const Layer& layer) const;
79 
80  using BackendPtrMap = std::unordered_map<BackendId, IBackendInternalUniquePtr>;
81 
82  using WorkloadFactoryWithMemoryManager =
83  std::pair<IBackendInternal::IWorkloadFactoryPtr, IBackendInternal::IMemoryManagerSharedPtr>;
84 
85  using WorkloadFactoryMap = std::unordered_map<BackendId, WorkloadFactoryWithMemoryManager>;
86 
87  BackendPtrMap m_Backends;
88  WorkloadFactoryMap m_WorkloadFactories;
89 
90  std::unique_ptr<IOptimizedNetwork> m_OptimizedNetwork;
91  WorkloadQueue m_InputQueue;
92  WorkloadQueue m_WorkloadQueue;
93  WorkloadQueue m_OutputQueue;
94  std::shared_ptr<IProfiler> m_Profiler;
95 
96  mutable std::mutex m_WorkingMemMutex;
97 
98  bool m_IsWorkingMemAllocated=false;
99  bool m_IsImportEnabled=false;
100  bool m_IsExportEnabled=false;
101 
102  TensorHandleFactoryRegistry m_TensorHandleFactoryRegistry;
103 
104  profiling::ProfilingService& m_ProfilingService;
105 };
106 
107 }
std::vector< std::unique_ptr< IWorkload > > WorkloadQueue
TensorInfo GetInputTensorInfo(const INetwork *network)
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
Definition: Tensor.hpp:340
Copyright (c) 2021 ARM Limited and Contributors.
std::function< void(LayerGuid guid, unsigned int slotIndex, ITensorHandle *tensorHandle)> DebugCallbackFunction
Define the type of callback for the Debug layer to call.
Definition: Types.hpp:283
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
Definition: Types.hpp:210
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
Definition: Tensor.hpp:341
Status
enumeration
Definition: Types.hpp:26
const std::shared_ptr< IProfiler > & GetProfiler() const