ArmNN
 22.02
DelegateOptions.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <armnn/ArmNN.hpp>
9 #include <armnn/Logging.hpp>
10 #include <armnn/Optional.hpp>
11 
12 #include <set>
13 #include <string>
14 #include <vector>
15 
16 namespace armnnDelegate
17 {
18 
20 {
21 public:
22  DelegateOptions(armnn::Compute computeDevice,
23  const std::vector<armnn::BackendOptions>& backendOptions = {},
25 
26  DelegateOptions(const std::vector<armnn::BackendId>& backends,
27  const std::vector<armnn::BackendOptions>& backendOptions = {},
29 
30  DelegateOptions(armnn::Compute computeDevice,
31  const armnn::OptimizerOptions& optimizerOptions,
34 
35  DelegateOptions(const std::vector<armnn::BackendId>& backends,
36  const armnn::OptimizerOptions& optimizerOptions,
39 
40 
41  /**
42  * This constructor processes delegate options in form of command line arguments.
43  * It works in conjunction with the TfLite external delegate plugin.
44  *
45  * Available options:
46  *
47  * Option key: "backends" \n
48  * Possible values: ["EthosNPU"/"GpuAcc"/"CpuAcc"/"CpuRef"] \n
49  * Descriptions: A comma separated list without whitespaces of
50  * backends which should be used for execution. Falls
51  * back to next backend in list if previous doesn't
52  * provide support for operation. e.g. "GpuAcc,CpuAcc"
53  *
54  * Option key: "dynamic-backends-path" \n
55  * Possible values: [filenameString] \n
56  * Descriptions: This is the directory that will be searched for any dynamic backends.
57  *
58  * Option key: "logging-severity" \n
59  * Possible values: ["trace"/"debug"/"info"/"warning"/"error"/"fatal"] \n
60  * Description: Sets the logging severity level for ArmNN. Logging
61  * is turned off if this option is not provided.
62  *
63  * Option key: "gpu-tuning-level" \n
64  * Possible values: ["0"/"1"/"2"/"3"] \n
65  * Description: 0=UseOnly(default), 1=RapidTuning, 2=NormalTuning,
66  * 3=ExhaustiveTuning. Requires option gpu-tuning-file.
67  * 1,2 and 3 will create a tuning-file, 0 will apply the
68  * tunings from an existing file
69  *
70  * Option key: "gpu-mlgo-tuning-file" \n
71  * Possible values: [filenameString] \n
72  * Description: File name for the MLGO tuning file
73  *
74  * Option key: "gpu-tuning-file" \n
75  * Possible values: [filenameString] \n
76  * Description: File name for the tuning file.
77  *
78  * Option key: "gpu-enable-profiling" \n
79  * Possible values: ["true"/"false"] \n
80  * Description: Enables GPU profiling
81  *
82  * Option key: "gpu-kernel-profiling-enabled" \n
83  * Possible values: ["true"/"false"] \n
84  * Description: Enables GPU kernel profiling
85  *
86  * Option key: "save-cached-network" \n
87  * Possible values: ["true"/"false"] \n
88  * Description: Enables saving of the cached network to a file,
89  * specified with the cached-network-filepath option
90  *
91  * Option key: "cached-network-filepath" \n
92  * Possible values: [filenameString] \n
93  * Description: If non-empty, the given file will be used to load/save the cached network.
94  * If save-cached-network is given then the cached network will be saved to the given file.
95  * To save the cached network a file must already exist.
96  * If save-cached-network is not given then the cached network will be loaded from the given file.
97  * This will remove initial compilation time of kernels and speed up the first execution.
98  *
99  * Option key: "enable-fast-math" \n
100  * Possible values: ["true"/"false"] \n
101  * Description: Enables fast_math options in backends that support it
102  *
103  * Option key: "number-of-threads" \n
104  * Possible values: ["1"-"64"] \n
105  * Description: Assign the number of threads used by the CpuAcc backend.
106  * Default is set to 0 (Backend will decide number of threads to use).
107  *
108  * Option key: "reduce-fp32-to-fp16" \n
109  * Possible values: ["true"/"false"] \n
110  * Description: Reduce Fp32 data to Fp16 for faster processing
111  *
112  * Option key: "reduce-fp32-to-bf16" \n
113  * Possible values: ["true"/"false"] \n
114  * Description: Reduce Fp32 data to Bf16 for faster processing
115  *
116  * Option key: "debug-data" \n
117  * Possible values: ["true"/"false"] \n
118  * Description: Add debug data for easier troubleshooting
119  *
120  * Option key: "memory-import" \n
121  * Possible values: ["true"/"false"] \n
122  * Description: Enable memory import
123  *
124  * Option key: "enable-internal-profiling" \n
125  * Possible values: ["true"/"false"] \n
126  * Description: Enable the internal profiling feature.
127  *
128  * Option key: "internal-profiling-detail" \n
129  * Possible values: [1/2] \n
130  * Description: Set the detail on the internal profiling. 1 = DetailsWithEvents, 2 = DetailsOnly.
131  *
132  * Option key: "enable-external-profiling" \n
133  * Possible values: ["true"/"false"] \n
134  * Description: Enable the external profiling feature.
135  *
136  * Option key: "timeline-profiling" \n
137  * Possible values: ["true"/"false"] \n
138  * Description: Indicates whether external timeline profiling is enabled or not.
139  *
140  * Option key: "outgoing-capture-file" \n
141  * Possible values: [filenameString] \n
142  * Description: Path to a file in which outgoing timeline profiling messages will be stored.
143  *
144  * Option key: "incoming-capture-file" \n
145  * Possible values: [filenameString] \n
146  * Description: Path to a file in which incoming timeline profiling messages will be stored.
147  *
148  * Option key: "file-only-external-profiling" \n
149  * Possible values: ["true"/"false"] \n
150  * Description: Enable profiling output to file only.
151  *
152  * Option key: "counter-capture-period" \n
153  * Possible values: Integer, Default is 10000u
154  * Description: Value in microseconds of the profiling capture period. \n
155  *
156  * Option key: "profiling-file-format" \n
157  * Possible values: String of ["binary"] \n
158  * Description: The format of the file used for outputting profiling data. Currently on "binary" is supported.
159  *
160  * Option key: "serialize-to-dot" \n
161  * Possible values: [filenameString] \n
162  * Description: Serialize the optimized network to the file specified in "dot" format.
163  *
164  * @param[in] option_keys Delegate option names
165  * @param[in] options_values Delegate option values
166  * @param[in] num_options Number of delegate options
167  * @param[in,out] report_error Error callback function
168  *
169  */
170  DelegateOptions(char const* const* options_keys,
171  char const* const* options_values,
172  size_t num_options,
173  void (*report_error)(const char*));
174 
175  const std::vector<armnn::BackendId>& GetBackends() const { return m_Backends; }
176 
177  void SetBackends(const std::vector<armnn::BackendId>& backends) { m_Backends = backends; }
178 
179  void SetDynamicBackendsPath(const std::string& dynamicBackendsPath)
180  {
181  m_RuntimeOptions.m_DynamicBackendsPath = dynamicBackendsPath;
182  }
183  const std::string& GetDynamicBackendsPath() const
184  {
185  return m_RuntimeOptions.m_DynamicBackendsPath;
186  }
187 
188  void SetGpuProfilingState(bool gpuProfilingState)
189  {
190  m_RuntimeOptions.m_EnableGpuProfiling = gpuProfilingState;
191  }
193  {
194  return m_RuntimeOptions.m_EnableGpuProfiling;
195  }
196 
197  const std::vector<armnn::BackendOptions>& GetBackendOptions() const
198  {
199  return m_RuntimeOptions.m_BackendOptions;
200  }
201 
202  /// Appends a backend option to the list of backend options
204  {
205  m_RuntimeOptions.m_BackendOptions.push_back(option);
206  }
207 
208  /// Sets the severity level for logging within ArmNN that will be used on creation of the delegate
209  void SetLoggingSeverity(const armnn::LogSeverity& level) { m_LoggingSeverity = level; }
210  void SetLoggingSeverity(const std::string& level) { m_LoggingSeverity = armnn::StringToLogLevel(level); }
211 
212  /// Returns the severity level for logging within ArmNN
213  armnn::LogSeverity GetLoggingSeverity() { return m_LoggingSeverity.value(); }
214 
215  bool IsLoggingEnabled() { return m_LoggingSeverity.has_value(); }
216 
217  const armnn::OptimizerOptions& GetOptimizerOptions() const { return m_OptimizerOptions; }
218 
219  void SetOptimizerOptions(const armnn::OptimizerOptions& optimizerOptions) { m_OptimizerOptions = optimizerOptions; }
220 
222  { return m_DebugCallbackFunc; }
223 
224  void SetInternalProfilingParams(bool internalProfilingState,
225  const armnn::ProfilingDetailsMethod& internalProfilingDetail)
226  { m_InternalProfilingEnabled = internalProfilingState; m_InternalProfilingDetail = internalProfilingDetail; }
227 
228  bool GetInternalProfilingState() const { return m_InternalProfilingEnabled; }
229  const armnn::ProfilingDetailsMethod& GetInternalProfilingDetail() const { return m_InternalProfilingDetail; }
230 
232  const armnn::IRuntime::CreationOptions::ExternalProfilingOptions& externalProfilingParams)
233  { m_ProfilingOptions = externalProfilingParams; }
234 
236  { return m_ProfilingOptions; }
237 
238  void SetSerializeToDot(const std::string& serializeToDotFile) { m_SerializeToDot = serializeToDotFile; }
239  const std::string& GetSerializeToDot() const { return m_SerializeToDot; }
240 
241  /// @Note: This might overwrite options that were set with other setter functions of DelegateOptions
243  {
244  m_RuntimeOptions = runtimeOptions;
245  }
246 
248  {
249  return m_RuntimeOptions;
250  }
251 
252 private:
253  /// Which backend to run Delegate on.
254  /// Examples of possible values are: CpuRef, CpuAcc, GpuAcc.
255  /// CpuRef as default.
256  std::vector<armnn::BackendId> m_Backends = { armnn::Compute::CpuRef };
257 
258  /// Creation options for the ArmNN runtime
259  /// Contains options for global settings that are valid for the whole lifetime of ArmNN
260  /// i.e. BackendOptions, DynamicBackendPath, ExternalProfilingOptions and more
261  armnn::IRuntime::CreationOptions m_RuntimeOptions;
262 
263  /// Options for the optimization step for the network
264  armnn::OptimizerOptions m_OptimizerOptions;
265 
266  /// External profiling options.
268 
269  /// Internal profiling options.
270  /// Indicates whether internal profiling is enabled or not.
271  bool m_InternalProfilingEnabled = false;
272  /// Sets the level of detail output by the profiling. Options are DetailsWithEvents = 1 and DetailsOnly = 2
274 
275  /// Severity level for logging within ArmNN that will be used on creation of the delegate
276  armnn::Optional<armnn::LogSeverity> m_LoggingSeverity;
277 
278  /// A callback function to debug layers performing custom computations on intermediate tensors.
279  /// If a function is not registered, and debug is enabled in OptimizerOptions,
280  /// debug will print information of the intermediate tensors.
282 
283  /// If not empty then the optimized model will be serialized to a file with this file name in "dot" format.
284  std::string m_SerializeToDot = "";
285 };
286 
287 } // namespace armnnDelegate
CPU Execution: Reference C++ kernels.
void SetSerializeToDot(const std::string &serializeToDotFile)
LogSeverity StringToLogLevel(std::string level)
Definition: Logging.hpp:36
ProfilingDetailsMethod
Define the behaviour of the internal profiler when outputting network details.
Definition: Types.hpp:58
const std::string & GetDynamicBackendsPath() const
std::vector< BackendOptions > m_BackendOptions
Pass backend specific options.
Definition: IRuntime.hpp:187
const std::string & GetSerializeToDot() const
Compute
The Compute enum is now deprecated and it is now being replaced by BackendId.
Definition: BackendId.hpp:21
const armnn::OptimizerOptions & GetOptimizerOptions() const
DelegateOptions(armnn::Compute computeDevice, const std::vector< armnn::BackendOptions > &backendOptions={}, armnn::Optional< armnn::LogSeverity > logSeverityLevel=armnn::EmptyOptional())
const std::vector< armnn::BackendOptions > & GetBackendOptions() const
void SetLoggingSeverity(const armnn::LogSeverity &level)
Sets the severity level for logging within ArmNN that will be used on creation of the delegate...
bool has_value() const noexcept
Definition: Optional.hpp:53
const armnn::IRuntime::CreationOptions & GetRuntimeOptions()
ArmNN performs an optimization on each model/network before it gets loaded for execution.
Definition: INetwork.hpp:137
const armnn::ProfilingDetailsMethod & GetInternalProfilingDetail() const
Struct for the users to pass backend specific options.
std::string m_DynamicBackendsPath
Setting this value will override the paths set by the DYNAMIC_BACKEND_PATHS compiler directive Only a...
Definition: IRuntime.hpp:96
bool m_EnableGpuProfiling
Setting this flag will allow the user to obtain GPU profiling information from the runtime...
Definition: IRuntime.hpp:91
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
Definition: Optional.hpp:32
void SetExternalProfilingParams(const armnn::IRuntime::CreationOptions::ExternalProfilingOptions &externalProfilingParams)
void SetDynamicBackendsPath(const std::string &dynamicBackendsPath)
void SetBackends(const std::vector< armnn::BackendId > &backends)
const std::vector< armnn::BackendId > & GetBackends() const
const armnn::Optional< armnn::DebugCallbackFunction > & GetDebugCallbackFunction() const
void AddBackendOption(const armnn::BackendOptions &option)
Appends a backend option to the list of backend options.
const armnn::IRuntime::CreationOptions::ExternalProfilingOptions & GetExternalProfilingParams() const
armnn::LogSeverity GetLoggingSeverity()
Returns the severity level for logging within ArmNN.
void SetOptimizerOptions(const armnn::OptimizerOptions &optimizerOptions)
void SetGpuProfilingState(bool gpuProfilingState)
void SetLoggingSeverity(const std::string &level)
LogSeverity
Definition: Utils.hpp:14
void SetInternalProfilingParams(bool internalProfilingState, const armnn::ProfilingDetailsMethod &internalProfilingDetail)
void SetRuntimeOptions(const armnn::IRuntime::CreationOptions &runtimeOptions)
: This might overwrite options that were set with other setter functions of DelegateOptions ...