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