ArmNN  NotReleased
IRuntime.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include "BackendOptions.hpp"
8 #include "INetwork.hpp"
9 #include "IProfiler.hpp"
10 #include "Tensor.hpp"
11 #include "Types.hpp"
12 #include "TypesUtils.hpp"
13 
14 #include <memory>
15 
16 namespace armnn
17 {
18 
19 using NetworkId = int;
20 
22 
23 class IRuntime;
24 using IRuntimePtr = std::unique_ptr<IRuntime, void(*)(IRuntime* runtime)>;
25 
27 {
28  INetworkProperties(bool importEnabled = false, bool exportEnabled = false)
29  : m_ImportEnabled(importEnabled),
30  m_ExportEnabled(exportEnabled) {}
31 
32  const bool m_ImportEnabled;
33  const bool m_ExportEnabled;
34 
35  virtual ~INetworkProperties() {}
36 };
37 
38 class IRuntime
39 {
40 public:
42  {
44  : m_GpuAccTunedParameters(nullptr)
45  , m_EnableGpuProfiling(false)
46  , m_DynamicBackendsPath("")
47  {}
48 
51  std::shared_ptr<IGpuAccTunedParameters> m_GpuAccTunedParameters;
52 
53  // Setting this flag will allow the user to obtain GPU profiling information from the runtime.
55 
56  // Setting this value will override the paths set by the DYNAMIC_BACKEND_PATHS compiler directive
57  // Only a single path is allowed for the override
58  std::string m_DynamicBackendsPath;
59 
61  {
66  , m_FileOnly(false)
68  {}
69 
71  std::string m_OutgoingCaptureFile;
72  std::string m_IncomingCaptureFile;
73  bool m_FileOnly;
74  uint32_t m_CapturePeriod;
75  };
77 
90 
98 
104  std::vector<BackendOptions> m_BackendOptions;
105  };
106 
107  static IRuntime* CreateRaw(const CreationOptions& options);
108  static IRuntimePtr Create(const CreationOptions& options);
109  static void Destroy(IRuntime* runtime);
110 
116  virtual Status LoadNetwork(NetworkId& networkIdOut, IOptimizedNetworkPtr network) = 0;
117 
124  virtual Status LoadNetwork(NetworkId& networkIdOut,
125  IOptimizedNetworkPtr network,
126  std::string& errorMessage) = 0;
127 
128  virtual Status LoadNetwork(NetworkId& networkIdOut,
129  IOptimizedNetworkPtr network,
130  std::string& errorMessage,
131  const INetworkProperties& networkProperties) = 0;
132 
133  virtual TensorInfo GetInputTensorInfo(NetworkId networkId, LayerBindingId layerId) const = 0;
134  virtual TensorInfo GetOutputTensorInfo(NetworkId networkId, LayerBindingId layerId) const = 0;
135 
137  virtual Status EnqueueWorkload(NetworkId networkId,
138  const InputTensors& inputTensors,
139  const OutputTensors& outputTensors) = 0;
140 
146  virtual Status UnloadNetwork(NetworkId networkId) = 0;
147 
148  virtual const IDeviceSpec& GetDeviceSpec() const = 0;
149 
153  virtual const std::shared_ptr<IProfiler> GetProfiler(NetworkId networkId) const = 0;
154 
158  virtual void RegisterDebugCallback(NetworkId networkId, const DebugCallbackFunction& func) = 0;
159 
160 protected:
162 };
163 
164 
166 using IGpuAccTunedParametersPtr = std::shared_ptr<IGpuAccTunedParameters>;
167 
180 {
181 public:
182  enum class Mode
183  {
184  UseTunedParameters,
185  UpdateTunedParameters
186  };
187 
188  enum class TuningLevel
189  {
190  Rapid = 0,
191  Normal = 1,
192  Exhaustive = 2
193  };
194 
197  static IGpuAccTunedParameters* CreateRaw(Mode mode, TuningLevel tunerMode);
198  static IGpuAccTunedParametersPtr Create(Mode mode, TuningLevel tunerMode);
200  static void Destroy(IGpuAccTunedParameters* params);
201 
204  virtual void Load(const char* filename) = 0;
205 
208  virtual void Save(const char* filename) const = 0;
209 
210 protected:
212 };
213 
214 } // namespace armnn
Status
Definition: Types.hpp:26
std::shared_ptr< IGpuAccTunedParameters > IGpuAccTunedParametersPtr
The following API is replaced by the backend options API.
Definition: IRuntime.hpp:166
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
Definition: Tensor.hpp:226
TensorInfo GetInputTensorInfo(const Network *network)
DataLayout::NHWC false
INetworkProperties(bool importEnabled=false, bool exportEnabled=false)
Definition: IRuntime.hpp:28
constexpr unsigned int LOWEST_CAPTURE_PERIOD
Definition: Types.hpp:21
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:76
std::function< void(LayerGuid guid, unsigned int slotIndex, ITensorHandle *tensorHandle)> DebugCallbackFunction
Definition: Types.hpp:241
const bool m_ExportEnabled
Definition: IRuntime.hpp:33
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
Definition: Tensor.hpp:225
const bool m_ImportEnabled
Definition: IRuntime.hpp:32
options m_EnableProfiling
virtual ~INetworkProperties()
Definition: IRuntime.hpp:35
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Definition: INetwork.hpp:544
std::shared_ptr< IGpuAccTunedParameters > m_GpuAccTunedParameters
Definition: IRuntime.hpp:51
options m_IncomingCaptureFile
options m_OutgoingCaptureFile
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
int NetworkId
Definition: IRuntime.hpp:19
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
Definition: IRuntime.hpp:24
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
Definition: Types.hpp:168
Device specific knowledge to be passed to the optimizer.
Definition: Types.hpp:158
std::vector< BackendOptions > m_BackendOptions
Definition: IRuntime.hpp:104