ArmNN
 22.05
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: Reduce Fp32 data to Bf16 for faster processing
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  * @param[in] option_keys Delegate option names
178  * @param[in] options_values Delegate option values
179  * @param[in] num_options Number of delegate options
180  * @param[in,out] report_error Error callback function
181  *
182  */
183  DelegateOptions(char const* const* options_keys,
184  char const* const* options_values,
185  size_t num_options,
186  void (*report_error)(const char*));
187 
188  const std::vector<armnn::BackendId>& GetBackends() const { return m_Backends; }
189 
190  void SetBackends(const std::vector<armnn::BackendId>& backends) { m_Backends = backends; }
191 
192  void SetDynamicBackendsPath(const std::string& dynamicBackendsPath)
193  {
194  m_RuntimeOptions.m_DynamicBackendsPath = dynamicBackendsPath;
195  }
196  const std::string& GetDynamicBackendsPath() const
197  {
198  return m_RuntimeOptions.m_DynamicBackendsPath;
199  }
200 
201  void SetGpuProfilingState(bool gpuProfilingState)
202  {
203  m_RuntimeOptions.m_EnableGpuProfiling = gpuProfilingState;
204  }
206  {
207  return m_RuntimeOptions.m_EnableGpuProfiling;
208  }
209 
210  const std::vector<armnn::BackendOptions>& GetBackendOptions() const
211  {
212  return m_RuntimeOptions.m_BackendOptions;
213  }
214 
215  /// Appends a backend option to the list of backend options
217  {
218  m_RuntimeOptions.m_BackendOptions.push_back(option);
219  }
220 
221  /// Sets the severity level for logging within ArmNN that will be used on creation of the delegate
222  void SetLoggingSeverity(const armnn::LogSeverity& level) { m_LoggingSeverity = level; }
223  void SetLoggingSeverity(const std::string& level) { m_LoggingSeverity = armnn::StringToLogLevel(level); }
224 
225  /// Returns the severity level for logging within ArmNN
226  armnn::LogSeverity GetLoggingSeverity() { return m_LoggingSeverity.value(); }
227 
228  bool IsLoggingEnabled() { return m_LoggingSeverity.has_value(); }
229 
230  const armnn::OptimizerOptions& GetOptimizerOptions() const { return m_OptimizerOptions; }
231 
232  void SetOptimizerOptions(const armnn::OptimizerOptions& optimizerOptions) { m_OptimizerOptions = optimizerOptions; }
233 
235  { return m_DebugCallbackFunc; }
236 
237  void SetInternalProfilingParams(bool internalProfilingState,
238  const armnn::ProfilingDetailsMethod& internalProfilingDetail)
239  { m_InternalProfilingEnabled = internalProfilingState; m_InternalProfilingDetail = internalProfilingDetail; }
240 
241  bool GetInternalProfilingState() const { return m_InternalProfilingEnabled; }
242  const armnn::ProfilingDetailsMethod& GetInternalProfilingDetail() const { return m_InternalProfilingDetail; }
243 
245  const arm::pipe::ProfilingOptions& externalProfilingParams)
246  { m_ProfilingOptions = externalProfilingParams; }
247 
248  const arm::pipe::ProfilingOptions& GetExternalProfilingParams() const
249  { return m_ProfilingOptions; }
250 
251  void SetSerializeToDot(const std::string& serializeToDotFile) { m_SerializeToDot = serializeToDotFile; }
252  const std::string& GetSerializeToDot() const { return m_SerializeToDot; }
253 
254  /// @Note: This might overwrite options that were set with other setter functions of DelegateOptions
256  {
257  m_RuntimeOptions = runtimeOptions;
258  }
259 
261  {
262  return m_RuntimeOptions;
263  }
264 
265 private:
266  /// Which backend to run Delegate on.
267  /// Examples of possible values are: CpuRef, CpuAcc, GpuAcc.
268  /// CpuRef as default.
269  std::vector<armnn::BackendId> m_Backends = { armnn::Compute::CpuRef };
270 
271  /// Creation options for the ArmNN runtime
272  /// Contains options for global settings that are valid for the whole lifetime of ArmNN
273  /// i.e. BackendOptions, DynamicBackendPath, ExternalProfilingOptions and more
274  armnn::IRuntime::CreationOptions m_RuntimeOptions;
275 
276  /// Options for the optimization step for the network
277  armnn::OptimizerOptions m_OptimizerOptions;
278 
279  /// External profiling options.
280  arm::pipe::ProfilingOptions m_ProfilingOptions;
281 
282  /// Internal profiling options.
283  /// Indicates whether internal profiling is enabled or not.
284  bool m_InternalProfilingEnabled = false;
285  /// Sets the level of detail output by the profiling. Options are DetailsWithEvents = 1 and DetailsOnly = 2
287 
288  /// Severity level for logging within ArmNN that will be used on creation of the delegate
289  armnn::Optional<armnn::LogSeverity> m_LoggingSeverity;
290 
291  /// A callback function to debug layers performing custom computations on intermediate tensors.
292  /// If a function is not registered, and debug is enabled in OptimizerOptions,
293  /// debug will print information of the intermediate tensors.
295 
296  /// If not empty then the optimized model will be serialized to a file with this file name in "dot" format.
297  std::string m_SerializeToDot = "";
298 };
299 
300 } // 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:71
const std::string & GetDynamicBackendsPath() const
void SetExternalProfilingParams(const arm::pipe::ProfilingOptions &externalProfilingParams)
std::vector< BackendOptions > m_BackendOptions
Pass backend specific options.
Definition: IRuntime.hpp:189
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:98
bool m_EnableGpuProfiling
Setting this flag will allow the user to obtain GPU profiling information from the runtime...
Definition: IRuntime.hpp:93
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
Definition: Optional.hpp:32
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.
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)
const arm::pipe::ProfilingOptions & GetExternalProfilingParams() const
void SetRuntimeOptions(const armnn::IRuntime::CreationOptions &runtimeOptions)
: This might overwrite options that were set with other setter functions of DelegateOptions ...