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