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