blob: 4f157db73bc66995fc0bbb6c83dd229db376169f [file] [log] [blame]
Sadik Armagan3c24f432020-10-19 17:35:30 +01001//
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>
Jan Eilers2cd18472020-12-15 10:42:38 +00009#include <armnn/Logging.hpp>
10#include <armnn/Optional.hpp>
Jim Flynn27761832022-03-20 21:52:17 +000011
12#include <client/include/ProfilingOptions.hpp>
Sadik Armagan3c24f432020-10-19 17:35:30 +010013
14#include <set>
15#include <string>
16#include <vector>
17
18namespace armnnDelegate
19{
20
21class DelegateOptions
22{
23public:
Jan Eilers2cd18472020-12-15 10:42:38 +000024 DelegateOptions(armnn::Compute computeDevice,
25 const std::vector<armnn::BackendOptions>& backendOptions = {},
26 armnn::Optional<armnn::LogSeverity> logSeverityLevel = armnn::EmptyOptional());
Sadik Armagan3c24f432020-10-19 17:35:30 +010027
Sadik Armagan4189cc52020-11-11 18:01:48 +000028 DelegateOptions(const std::vector<armnn::BackendId>& backends,
Jan Eilers2cd18472020-12-15 10:42:38 +000029 const std::vector<armnn::BackendOptions>& backendOptions = {},
30 armnn::Optional<armnn::LogSeverity> logSeverityLevel = armnn::EmptyOptional());
Sadik Armagan3c24f432020-10-19 17:35:30 +010031
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +000032 DelegateOptions(armnn::Compute computeDevice,
33 const armnn::OptimizerOptions& optimizerOptions,
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +000034 const armnn::Optional<armnn::LogSeverity>& logSeverityLevel = armnn::EmptyOptional(),
35 const armnn::Optional<armnn::DebugCallbackFunction>& func = armnn::EmptyOptional());
36
37 DelegateOptions(const std::vector<armnn::BackendId>& backends,
38 const armnn::OptimizerOptions& optimizerOptions,
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +000039 const armnn::Optional<armnn::LogSeverity>& logSeverityLevel = armnn::EmptyOptional(),
40 const armnn::Optional<armnn::DebugCallbackFunction>& func = armnn::EmptyOptional());
41
Jan Eilersf39f8d82021-10-26 16:57:34 +010042
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
Ryan OShea31441592022-11-07 16:20:48 +0000116 * Description: This option is currently ignored. Please enable Fast Math in the CpuAcc or GpuAcc backends.
Jan Eilersf39f8d82021-10-26 16:57:34 +0100117 *
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 *
Mike Kelly80512b02022-05-16 23:10:42 +0100166 * 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 *
Sadik Armaganca565c12022-08-16 12:17:24 +0100177 * 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 *
Jan Eilersf39f8d82021-10-26 16:57:34 +0100183 * @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
Sadik Armagan3c24f432020-10-19 17:35:30 +0100194 const std::vector<armnn::BackendId>& GetBackends() const { return m_Backends; }
195
196 void SetBackends(const std::vector<armnn::BackendId>& backends) { m_Backends = backends; }
197
Jan Eilersb1c62f12021-10-26 14:56:47 +0100198 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 }
Colm Donelan3e32a872021-10-04 22:55:37 +0100206
Jan Eilersb1c62f12021-10-26 14:56:47 +0100207 void SetGpuProfilingState(bool gpuProfilingState)
208 {
209 m_RuntimeOptions.m_EnableGpuProfiling = gpuProfilingState;
210 }
211 bool GetGpuProfilingState()
212 {
213 return m_RuntimeOptions.m_EnableGpuProfiling;
214 }
Colm Donelan3e32a872021-10-04 22:55:37 +0100215
Jan Eilersb1c62f12021-10-26 14:56:47 +0100216 const std::vector<armnn::BackendOptions>& GetBackendOptions() const
217 {
218 return m_RuntimeOptions.m_BackendOptions;
219 }
Sadik Armagan4189cc52020-11-11 18:01:48 +0000220
Jan Eilers2cd18472020-12-15 10:42:38 +0000221 /// Appends a backend option to the list of backend options
Jan Eilersb1c62f12021-10-26 14:56:47 +0100222 void AddBackendOption(const armnn::BackendOptions& option)
223 {
224 m_RuntimeOptions.m_BackendOptions.push_back(option);
225 }
Jan Eilers2cd18472020-12-15 10:42:38 +0000226
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
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000236 const armnn::OptimizerOptions& GetOptimizerOptions() const { return m_OptimizerOptions; }
237
Narumol Prangnawarat74a3cf52021-01-29 15:38:54 +0000238 void SetOptimizerOptions(const armnn::OptimizerOptions& optimizerOptions) { m_OptimizerOptions = optimizerOptions; }
239
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000240 const armnn::Optional<armnn::DebugCallbackFunction>& GetDebugCallbackFunction() const
241 { return m_DebugCallbackFunc; }
242
Colm Donelan3e32a872021-10-04 22:55:37 +0100243 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
250 void SetExternalProfilingParams(
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000251 const arm::pipe::ProfilingOptions& externalProfilingParams)
Colm Donelan3e32a872021-10-04 22:55:37 +0100252 { m_ProfilingOptions = externalProfilingParams; }
253
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000254 const arm::pipe::ProfilingOptions& GetExternalProfilingParams() const
Colm Donelan3e32a872021-10-04 22:55:37 +0100255 { return m_ProfilingOptions; }
256
257 void SetSerializeToDot(const std::string& serializeToDotFile) { m_SerializeToDot = serializeToDotFile; }
258 const std::string& GetSerializeToDot() const { return m_SerializeToDot; }
259
Jan Eilersb1c62f12021-10-26 14:56:47 +0100260 /// @Note: This might overwrite options that were set with other setter functions of DelegateOptions
261 void SetRuntimeOptions(const armnn::IRuntime::CreationOptions& runtimeOptions)
262 {
263 m_RuntimeOptions = runtimeOptions;
264 }
265
266 const armnn::IRuntime::CreationOptions& GetRuntimeOptions()
267 {
268 return m_RuntimeOptions;
269 }
270
Sadik Armaganca565c12022-08-16 12:17:24 +0100271 void DisableTfLiteRuntimeFallback(bool fallbackState)
272 {
273 m_DisableTfLiteRuntimeFallback = fallbackState;
274 }
275 bool TfLiteRuntimeFallbackDisabled()
276 {
277 return m_DisableTfLiteRuntimeFallback;
278 }
279
Sadik Armagan3c24f432020-10-19 17:35:30 +0100280private:
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 };
Sadik Armagan4189cc52020-11-11 18:01:48 +0000285
Jan Eilersb1c62f12021-10-26 14:56:47 +0100286 /// 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;
Jan Eilers2cd18472020-12-15 10:42:38 +0000290
Jan Eilersb1c62f12021-10-26 14:56:47 +0100291 /// Options for the optimization step for the network
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000292 armnn::OptimizerOptions m_OptimizerOptions;
293
Colm Donelan3e32a872021-10-04 22:55:37 +0100294 /// External profiling options.
Cathal Corbett5aa9fd72022-02-25 15:33:28 +0000295 arm::pipe::ProfilingOptions m_ProfilingOptions;
Colm Donelan3e32a872021-10-04 22:55:37 +0100296
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
301 armnn::ProfilingDetailsMethod m_InternalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents;
302
Jan Eilers2cd18472020-12-15 10:42:38 +0000303 /// Severity level for logging within ArmNN that will be used on creation of the delegate
304 armnn::Optional<armnn::LogSeverity> m_LoggingSeverity;
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000305
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.
Colm Donelan3e32a872021-10-04 22:55:37 +0100309 armnn::Optional<armnn::DebugCallbackFunction> m_DebugCallbackFunc;
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 = "";
Sadik Armaganca565c12022-08-16 12:17:24 +0100313
314 /// Option to disable TfLite Runtime fallback for unsupported operators.
315 bool m_DisableTfLiteRuntimeFallback = false;
Sadik Armagan3c24f432020-10-19 17:35:30 +0100316};
317
318} // namespace armnnDelegate