blob: 4596159fce66bba3cb8d2a256f6fc09a4c2c230c [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#include <DelegateOptions.hpp>
Jan Eilersf39f8d82021-10-26 16:57:34 +01007#include <armnn/utility/NumericCast.hpp>
8#include <armnn/utility/StringUtils.hpp>
Sadik Armagan3c24f432020-10-19 17:35:30 +01009
10namespace armnnDelegate
11{
12
John McLoughlin1bae8652023-03-14 11:47:15 +000013struct DelegateOptionsImpl
14{
15 ~DelegateOptionsImpl() = default;
16 DelegateOptionsImpl() = default;
17
18 explicit DelegateOptionsImpl(armnn::Compute computeDevice,
Teresa Charlin19ad8162023-10-04 11:17:03 +010019 const std::vector<armnn::BackendOptions>& backendOptions,
20 const armnn::Optional<armnn::LogSeverity> logSeverityLevel)
21 : m_Backends({computeDevice}), m_RuntimeOptions(), m_LoggingSeverity(logSeverityLevel)
John McLoughlin1bae8652023-03-14 11:47:15 +000022 {
Francis Murtaghe69cbfe2023-05-08 15:13:47 +010023 m_RuntimeOptions.m_BackendOptions = backendOptions;
John McLoughlin1bae8652023-03-14 11:47:15 +000024 }
25
26 explicit DelegateOptionsImpl(const std::vector<armnn::BackendId>& backends,
27 const std::vector<armnn::BackendOptions>& backendOptions,
28 const armnn::Optional<armnn::LogSeverity> logSeverityLevel)
Francis Murtaghe69cbfe2023-05-08 15:13:47 +010029 : m_Backends(backends), m_RuntimeOptions(), m_LoggingSeverity(logSeverityLevel)
John McLoughlin1bae8652023-03-14 11:47:15 +000030 {
Francis Murtaghe69cbfe2023-05-08 15:13:47 +010031 m_RuntimeOptions.m_BackendOptions = backendOptions;
John McLoughlin1bae8652023-03-14 11:47:15 +000032 }
33
34 explicit DelegateOptionsImpl(armnn::Compute computeDevice,
John Mcloughlinc5ee0d72023-03-24 12:07:25 +000035 const armnn::OptimizerOptionsOpaque& optimizerOptions,
John McLoughlin1bae8652023-03-14 11:47:15 +000036 const armnn::Optional<armnn::LogSeverity>& logSeverityLevel,
37 const armnn::Optional<armnn::DebugCallbackFunction>& func)
Francis Murtaghe69cbfe2023-05-08 15:13:47 +010038 : m_Backends({computeDevice}),
39 m_RuntimeOptions(),
40 m_OptimizerOptions(optimizerOptions),
John McLoughlin1bae8652023-03-14 11:47:15 +000041 m_LoggingSeverity(logSeverityLevel),
Francis Murtaghe69cbfe2023-05-08 15:13:47 +010042 m_DebugCallbackFunc(func)
John McLoughlin1bae8652023-03-14 11:47:15 +000043 {
44 }
45
46 explicit DelegateOptionsImpl(const std::vector<armnn::BackendId>& backends,
John Mcloughlinc5ee0d72023-03-24 12:07:25 +000047 const armnn::OptimizerOptionsOpaque& optimizerOptions,
John McLoughlin1bae8652023-03-14 11:47:15 +000048 const armnn::Optional<armnn::LogSeverity>& logSeverityLevel,
49 const armnn::Optional<armnn::DebugCallbackFunction>& func)
Francis Murtaghe69cbfe2023-05-08 15:13:47 +010050 : m_Backends(backends),
51 m_RuntimeOptions(),
52 m_OptimizerOptions(optimizerOptions),
John McLoughlin1bae8652023-03-14 11:47:15 +000053 m_LoggingSeverity(logSeverityLevel),
Francis Murtaghe69cbfe2023-05-08 15:13:47 +010054 m_DebugCallbackFunc(func)
John McLoughlin1bae8652023-03-14 11:47:15 +000055 {
56 }
57
58 /// Which backend to run Delegate on.
59 /// Examples of possible values are: CpuRef, CpuAcc, GpuAcc.
60 /// CpuRef as default.
Francis Murtaghe69cbfe2023-05-08 15:13:47 +010061 std::vector<armnn::BackendId> m_Backends = {armnn::Compute::CpuRef };
John McLoughlin1bae8652023-03-14 11:47:15 +000062
63 /// Creation options for the ArmNN runtime
64 /// Contains options for global settings that are valid for the whole lifetime of ArmNN
65 /// i.e. BackendOptions, DynamicBackendPath, ExternalProfilingOptions and more
Francis Murtaghe69cbfe2023-05-08 15:13:47 +010066 armnn::IRuntime::CreationOptions m_RuntimeOptions;
John McLoughlin1bae8652023-03-14 11:47:15 +000067
68 /// Options for the optimization step for the network
Francis Murtaghe69cbfe2023-05-08 15:13:47 +010069 armnn::OptimizerOptionsOpaque m_OptimizerOptions;
John McLoughlin1bae8652023-03-14 11:47:15 +000070
71 /// Internal profiling options. Written to INetworkProperties during model load.
72 /// Indicates whether internal profiling is enabled or not.
73 bool m_InternalProfilingEnabled = false;
74
75 /// Sets the level of detail output by the profiling. Options are DetailsWithEvents = 1 and DetailsOnly = 2
Francis Murtaghe69cbfe2023-05-08 15:13:47 +010076 armnn::ProfilingDetailsMethod m_InternalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents;
John McLoughlin1bae8652023-03-14 11:47:15 +000077
78 /// Severity level for logging within ArmNN that will be used on creation of the delegate
79 armnn::Optional<armnn::LogSeverity> m_LoggingSeverity;
80
81 /// A callback function to debug layers performing custom computations on intermediate tensors.
82 /// If a function is not registered, and debug is enabled in OptimizerOptions,
83 /// debug will print information of the intermediate tensors.
Francis Murtaghe69cbfe2023-05-08 15:13:47 +010084 armnn::Optional<armnn::DebugCallbackFunction> m_DebugCallbackFunc;
John McLoughlin1bae8652023-03-14 11:47:15 +000085
86 /// If not empty then the optimized model will be serialized to a file with this file name in "dot" format.
87 std::string m_SerializeToDot = "";
88
89 /// Option to disable TfLite Runtime fallback for unsupported operators.
90 bool m_DisableTfLiteRuntimeFallback = false;
91
92};
93
94DelegateOptions::~DelegateOptions() = default;
95
96DelegateOptions::DelegateOptions()
97 : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>())
98{
99}
100
101DelegateOptions::DelegateOptions(DelegateOptions const &other)
102 : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>(*other.p_DelegateOptionsImpl))
103{
104}
105
Sadik Armagan4189cc52020-11-11 18:01:48 +0000106DelegateOptions::DelegateOptions(armnn::Compute computeDevice,
Jan Eilers2cd18472020-12-15 10:42:38 +0000107 const std::vector<armnn::BackendOptions>& backendOptions,
108 const armnn::Optional<armnn::LogSeverity> logSeverityLevel)
John McLoughlin1bae8652023-03-14 11:47:15 +0000109 : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>(computeDevice, backendOptions, logSeverityLevel))
Sadik Armagan3c24f432020-10-19 17:35:30 +0100110{
111}
112
Sadik Armagan4189cc52020-11-11 18:01:48 +0000113DelegateOptions::DelegateOptions(const std::vector<armnn::BackendId>& backends,
Jan Eilers2cd18472020-12-15 10:42:38 +0000114 const std::vector<armnn::BackendOptions>& backendOptions,
115 const armnn::Optional<armnn::LogSeverity> logSeverityLevel)
John McLoughlin1bae8652023-03-14 11:47:15 +0000116 : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>(backends, backendOptions, logSeverityLevel))
Sadik Armagan3c24f432020-10-19 17:35:30 +0100117{
118}
119
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000120DelegateOptions::DelegateOptions(armnn::Compute computeDevice,
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000121 const armnn::OptimizerOptionsOpaque& optimizerOptions,
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000122 const armnn::Optional<armnn::LogSeverity>& logSeverityLevel,
123 const armnn::Optional<armnn::DebugCallbackFunction>& func)
John McLoughlin1bae8652023-03-14 11:47:15 +0000124 : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>(computeDevice, optimizerOptions,
125 logSeverityLevel, func))
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000126{
127}
128
129DelegateOptions::DelegateOptions(const std::vector<armnn::BackendId>& backends,
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000130 const armnn::OptimizerOptionsOpaque& optimizerOptions,
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000131 const armnn::Optional<armnn::LogSeverity>& logSeverityLevel,
132 const armnn::Optional<armnn::DebugCallbackFunction>& func)
John McLoughlin1bae8652023-03-14 11:47:15 +0000133 : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>(backends, optimizerOptions,
134 logSeverityLevel, func))
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000135{
136}
137
Jan Eilersf39f8d82021-10-26 16:57:34 +0100138DelegateOptions::DelegateOptions(char const* const* options_keys,
139 char const* const* options_values,
140 size_t num_options,
141 void (*report_error)(const char*))
John McLoughlin1bae8652023-03-14 11:47:15 +0000142 : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>())
Jan Eilersf39f8d82021-10-26 16:57:34 +0100143{
144 armnn::IRuntime::CreationOptions runtimeOptions;
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000145 armnn::OptimizerOptionsOpaque optimizerOptions;
Jan Eilersf39f8d82021-10-26 16:57:34 +0100146 bool internalProfilingState = false;
147 armnn::ProfilingDetailsMethod internalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents;
Teresa Charlin19ad8162023-10-04 11:17:03 +0100148
149 bool GpuAccFound = false;
150 bool CpuAccFound = false;
151
Jan Eilersf39f8d82021-10-26 16:57:34 +0100152 for (size_t i = 0; i < num_options; ++i)
153 {
154 // Process backends
155 if (std::string(options_keys[i]) == std::string("backends"))
156 {
157 // The backend option is a comma separated string of backendIDs that needs to be split
158 std::vector<armnn::BackendId> backends;
159 char* dup = strdup(options_values[i]);
160 char* pch = std::strtok(dup, ",");
161 while (pch != NULL)
162 {
163 backends.push_back(pch);
164 pch = strtok (NULL, ",");
165 }
John McLoughlin1bae8652023-03-14 11:47:15 +0000166 SetBackends(backends);
Teresa Charlin19ad8162023-10-04 11:17:03 +0100167 GpuAccFound = std::count(GetBackends().begin(), GetBackends().end(), "GpuAcc");
168 CpuAccFound = std::count(GetBackends().begin(), GetBackends().end(), "CpuAcc");
Jan Eilersf39f8d82021-10-26 16:57:34 +0100169 }
170 // Process dynamic-backends-path
171 else if (std::string(options_keys[i]) == std::string("dynamic-backends-path"))
172 {
173 runtimeOptions.m_DynamicBackendsPath = std::string(options_values[i]);
174 }
175 // Process logging level
176 else if (std::string(options_keys[i]) == std::string("logging-severity"))
177 {
John McLoughlin1bae8652023-03-14 11:47:15 +0000178 SetLoggingSeverity(options_values[i]);
Jan Eilersf39f8d82021-10-26 16:57:34 +0100179 }
180 // Process GPU backend options
181 else if (std::string(options_keys[i]) == std::string("gpu-tuning-level"))
182 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100183 if (GpuAccFound)
184 {
185 armnn::BackendOptions option("GpuAcc", {{"TuningLevel",
186 atoi(options_values[i])}});
187 runtimeOptions.m_BackendOptions.push_back(option);
188 }
189 else
190 {
191 ARMNN_LOG(warning) <<
192 "WARNING: TuningLevel is enabled, but no backends that accept this option are set.";
193 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100194 }
195 else if (std::string(options_keys[i]) == std::string("gpu-mlgo-tuning-file"))
196 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100197 if (GpuAccFound)
198 {
199 armnn::BackendOptions option("GpuAcc", {{"MLGOTuningFilePath",
200 std::string(options_values[i])}});
201 optimizerOptions.AddModelOption(option);
202 }
203 else
204 {
205 ARMNN_LOG(warning) <<
206 "WARNING: MLGOTuningFilePath is enabled, but no backends that accept this option are set.";
207 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100208 }
209 else if (std::string(options_keys[i]) == std::string("gpu-tuning-file"))
210 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100211 if (GpuAccFound)
212 {
213 armnn::BackendOptions option("GpuAcc", {{"TuningFile",
214 std::string(options_values[i])}});
215 runtimeOptions.m_BackendOptions.push_back(option);
216 }
217 else
218 {
219 ARMNN_LOG(warning) <<
220 "WARNING: TuningFile is enabled, but no backends that accept this option are set.";
221 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100222 }
223 else if (std::string(options_keys[i]) == std::string("gpu-enable-profiling"))
224 {
225 runtimeOptions.m_EnableGpuProfiling = (*options_values[i] != '0');
226 }
227 else if (std::string(options_keys[i]) == std::string("gpu-kernel-profiling-enabled"))
228 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100229 if (GpuAccFound)
230 {
231 armnn::BackendOptions option("GpuAcc", {{"KernelProfilingEnabled",
232 armnn::stringUtils::StringToBool(options_values[i])}});
233 runtimeOptions.m_BackendOptions.push_back(option);
234 }
235 else
236 {
237 ARMNN_LOG(warning) <<
238 "WARNING: KernelProfilingEnabled is enabled, but no backends that accept this option are set.";
239 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100240 }
241 else if (std::string(options_keys[i]) == std::string("save-cached-network"))
242 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100243 if (GpuAccFound)
244 {
245 armnn::BackendOptions option("GpuAcc", {{"SaveCachedNetwork",
246 armnn::stringUtils::StringToBool(options_values[i])}});
247 optimizerOptions.AddModelOption(option);
248 }
249 else
250 {
251 ARMNN_LOG(warning) <<
252 "WARNING: SaveCachedNetwork is enabled, but no backends that accept this option are set.";
253 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100254 }
255 else if (std::string(options_keys[i]) == std::string("cached-network-filepath"))
256 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100257 if (GpuAccFound)
258 {
259 armnn::BackendOptions option("GpuAcc", {{"CachedNetworkFilePath",
260 std::string(options_values[i])}});
261 optimizerOptions.AddModelOption(option);
262 }
263 else
264 {
265 ARMNN_LOG(warning) <<
266 "WARNING: CachedNetworkFilePath is enabled, but no backends that accept this option are set.";
267 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100268 }
269 // Process GPU & CPU backend options
270 else if (std::string(options_keys[i]) == std::string("enable-fast-math"))
271 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100272 if (GpuAccFound)
273 {
274 armnn::BackendOptions modelOptionGpu("GpuAcc", {{"FastMathEnabled",
275 armnn::stringUtils::StringToBool(options_values[i])}});
276 optimizerOptions.AddModelOption(modelOptionGpu);
277 }
278 if (CpuAccFound)
279 {
280 armnn::BackendOptions modelOptionCpu("CpuAcc", {{"FastMathEnabled",
281 armnn::stringUtils::StringToBool(options_values[i])}});
282 optimizerOptions.AddModelOption(modelOptionCpu);
283 }
284 if (!GpuAccFound and !CpuAccFound)
285 {
286 ARMNN_LOG(warning) <<
287 "WARNING: Fastmath is enabled, but no backends that accept this option are set.";
288 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100289 }
290 // Process CPU backend options
291 else if (std::string(options_keys[i]) == std::string("number-of-threads"))
292 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100293 if (CpuAccFound)
294 {
295 unsigned int numberOfThreads = armnn::numeric_cast<unsigned int>(atoi(options_values[i]));
296 armnn::BackendOptions modelOption("CpuAcc",
297 {{"NumberOfThreads", numberOfThreads}});
298 optimizerOptions.AddModelOption(modelOption);
299 }
300 else
301 {
302 ARMNN_LOG(warning) <<
303 "WARNING: NumberOfThreads is enabled, but no backends that accept this option are set.";
304 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100305 }
306 // Process reduce-fp32-to-fp16 option
307 else if (std::string(options_keys[i]) == std::string("reduce-fp32-to-fp16"))
308 {
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000309 optimizerOptions.SetReduceFp32ToFp16(armnn::stringUtils::StringToBool(options_values[i]));
Jan Eilersf39f8d82021-10-26 16:57:34 +0100310 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100311 // Process debug-data
312 else if (std::string(options_keys[i]) == std::string("debug-data"))
313 {
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000314 optimizerOptions.SetDebugEnabled(armnn::stringUtils::StringToBool(options_values[i]));
Jan Eilersf39f8d82021-10-26 16:57:34 +0100315 }
Mike Kelly80512b02022-05-16 23:10:42 +0100316 // Infer output-shape
317 else if (std::string(options_keys[i]) == std::string("infer-output-shape"))
318 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100319 if (armnn::stringUtils::StringToBool(options_values[i]))
Mike Kelly80512b02022-05-16 23:10:42 +0100320 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100321 optimizerOptions.SetShapeInferenceMethod(armnn::ShapeInferenceMethod::InferAndValidate);
322 }
323 else
324 {
325 optimizerOptions.SetShapeInferenceMethod(armnn::ShapeInferenceMethod::ValidateOnly);
326 }
Mike Kelly80512b02022-05-16 23:10:42 +0100327 }
328 // Allow expanded dims
329 else if (std::string(options_keys[i]) == std::string("allow-expanded-dims"))
330 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100331 optimizerOptions.SetAllowExpandedDims(armnn::stringUtils::StringToBool(options_values[i]));
Mike Kelly80512b02022-05-16 23:10:42 +0100332 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100333 // Process memory-import
334 else if (std::string(options_keys[i]) == std::string("memory-import"))
335 {
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000336 optimizerOptions.SetImportEnabled(armnn::stringUtils::StringToBool(options_values[i]));
Jan Eilersf39f8d82021-10-26 16:57:34 +0100337 }
338 // Process enable-internal-profiling
339 else if (std::string(options_keys[i]) == std::string("enable-internal-profiling"))
340 {
341 internalProfilingState = *options_values[i] != '0';
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000342 optimizerOptions.SetProfilingEnabled(internalProfilingState);
Jan Eilersf39f8d82021-10-26 16:57:34 +0100343 }
344 // Process internal-profiling-detail
345 else if (std::string(options_keys[i]) == std::string("internal-profiling-detail"))
346 {
347 uint32_t detailLevel = static_cast<uint32_t>(std::stoul(options_values[i]));
348 switch (detailLevel)
349 {
350 case 1:
351 internalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents;
352 break;
353 case 2:
354 internalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsOnly;
355 break;
356 default:
357 internalProfilingDetail = armnn::ProfilingDetailsMethod::Undefined;
358 break;
359 }
360 }
361 // Process enable-external-profiling
362 else if (std::string(options_keys[i]) == std::string("enable-external-profiling"))
363 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100364 runtimeOptions.m_ProfilingOptions.m_EnableProfiling = armnn::stringUtils::StringToBool(options_values[i]);
Jan Eilersf39f8d82021-10-26 16:57:34 +0100365 }
Colm Donelan35a06892023-02-06 15:01:57 +0000366 // Process timeline-profiling
Jan Eilersf39f8d82021-10-26 16:57:34 +0100367 else if (std::string(options_keys[i]) == std::string("timeline-profiling"))
368 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100369 runtimeOptions.m_ProfilingOptions.m_TimelineEnabled = armnn::stringUtils::StringToBool(options_values[i]);
Jan Eilersf39f8d82021-10-26 16:57:34 +0100370 }
Colm Donelan35a06892023-02-06 15:01:57 +0000371 // Process outgoing-capture-file
Jan Eilersf39f8d82021-10-26 16:57:34 +0100372 else if (std::string(options_keys[i]) == std::string("outgoing-capture-file"))
373 {
Colm Donelan35a06892023-02-06 15:01:57 +0000374 runtimeOptions.m_ProfilingOptions.m_OutgoingCaptureFile = options_values[i];
Jan Eilersf39f8d82021-10-26 16:57:34 +0100375 }
Colm Donelan35a06892023-02-06 15:01:57 +0000376 // Process incoming-capture-file
Jan Eilersf39f8d82021-10-26 16:57:34 +0100377 else if (std::string(options_keys[i]) == std::string("incoming-capture-file"))
378 {
Colm Donelan35a06892023-02-06 15:01:57 +0000379 runtimeOptions.m_ProfilingOptions.m_IncomingCaptureFile = options_values[i];
Jan Eilersf39f8d82021-10-26 16:57:34 +0100380 }
Colm Donelan35a06892023-02-06 15:01:57 +0000381 // Process file-only-external-profiling
Jan Eilersf39f8d82021-10-26 16:57:34 +0100382 else if (std::string(options_keys[i]) == std::string("file-only-external-profiling"))
383 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100384 runtimeOptions.m_ProfilingOptions.m_FileOnly = armnn::stringUtils::StringToBool(options_values[i]);
Jan Eilersf39f8d82021-10-26 16:57:34 +0100385 }
Colm Donelan35a06892023-02-06 15:01:57 +0000386 // Process counter-capture-period
Jan Eilersf39f8d82021-10-26 16:57:34 +0100387 else if (std::string(options_keys[i]) == std::string("counter-capture-period"))
388 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100389 runtimeOptions.m_ProfilingOptions.m_CapturePeriod = static_cast<uint32_t>(std::stoul(options_values[i]));
Jan Eilersf39f8d82021-10-26 16:57:34 +0100390 }
Colm Donelan35a06892023-02-06 15:01:57 +0000391 // Process profiling-file-format
Jan Eilersf39f8d82021-10-26 16:57:34 +0100392 else if (std::string(options_keys[i]) == std::string("profiling-file-format"))
393 {
Colm Donelan35a06892023-02-06 15:01:57 +0000394 runtimeOptions.m_ProfilingOptions.m_FileFormat = options_values[i];
Jan Eilersf39f8d82021-10-26 16:57:34 +0100395 }
Colm Donelan35a06892023-02-06 15:01:57 +0000396 // Process serialize-to-dot
Jan Eilersf39f8d82021-10-26 16:57:34 +0100397 else if (std::string(options_keys[i]) == std::string("serialize-to-dot"))
398 {
John McLoughlin1bae8652023-03-14 11:47:15 +0000399 SetSerializeToDot(options_values[i]);
Jan Eilersf39f8d82021-10-26 16:57:34 +0100400 }
Sadik Armaganca565c12022-08-16 12:17:24 +0100401
John McLoughlin1bae8652023-03-14 11:47:15 +0000402 // Process disable-tflite-runtime-fallback
Sadik Armaganca565c12022-08-16 12:17:24 +0100403 else if (std::string(options_keys[i]) == std::string("disable-tflite-runtime-fallback"))
404 {
405 this->DisableTfLiteRuntimeFallback(armnn::stringUtils::StringToBool(options_values[i]));
406 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100407 else
408 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100409 throw armnn::Exception("Unknown option for the ArmNN Delegate given: " + std::string(options_keys[i]));
Jan Eilersf39f8d82021-10-26 16:57:34 +0100410 }
411 }
412
John McLoughlin1bae8652023-03-14 11:47:15 +0000413 SetRuntimeOptions(runtimeOptions);
414 SetOptimizerOptions(optimizerOptions);
415 SetInternalProfilingParams(internalProfilingState, internalProfilingDetail);
Jan Eilersf39f8d82021-10-26 16:57:34 +0100416}
John McLoughlin1bae8652023-03-14 11:47:15 +0000417
418const std::vector<armnn::BackendId>& DelegateOptions::GetBackends() const
419{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100420 return p_DelegateOptionsImpl->m_Backends;
John McLoughlin1bae8652023-03-14 11:47:15 +0000421}
422
423void DelegateOptions::SetBackends(const std::vector<armnn::BackendId>& backends)
424{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100425 p_DelegateOptionsImpl->m_Backends = backends;
John McLoughlin1bae8652023-03-14 11:47:15 +0000426}
427
428void DelegateOptions::SetDynamicBackendsPath(const std::string& dynamicBackendsPath)
429{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100430 p_DelegateOptionsImpl->m_RuntimeOptions.m_DynamicBackendsPath = dynamicBackendsPath;
John McLoughlin1bae8652023-03-14 11:47:15 +0000431}
432
433const std::string& DelegateOptions::GetDynamicBackendsPath() const
434{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100435 return p_DelegateOptionsImpl->m_RuntimeOptions.m_DynamicBackendsPath;
John McLoughlin1bae8652023-03-14 11:47:15 +0000436}
437
438void DelegateOptions::SetGpuProfilingState(bool gpuProfilingState)
439{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100440 p_DelegateOptionsImpl->m_RuntimeOptions.m_EnableGpuProfiling = gpuProfilingState;
John McLoughlin1bae8652023-03-14 11:47:15 +0000441}
442
443bool DelegateOptions::GetGpuProfilingState()
444{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100445 return p_DelegateOptionsImpl->m_RuntimeOptions.m_EnableGpuProfiling;
John McLoughlin1bae8652023-03-14 11:47:15 +0000446}
447
448const std::vector<armnn::BackendOptions>& DelegateOptions::GetBackendOptions() const
449{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100450 return p_DelegateOptionsImpl->m_RuntimeOptions.m_BackendOptions;
John McLoughlin1bae8652023-03-14 11:47:15 +0000451}
452
453void DelegateOptions::AddBackendOption(const armnn::BackendOptions& option)
454{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100455 p_DelegateOptionsImpl->m_RuntimeOptions.m_BackendOptions.push_back(option);
John McLoughlin1bae8652023-03-14 11:47:15 +0000456}
457
458void DelegateOptions::SetLoggingSeverity(const armnn::LogSeverity& level)
459{
460 p_DelegateOptionsImpl->m_LoggingSeverity = level;
461}
462
463void DelegateOptions::SetLoggingSeverity(const std::string& level)
464{
465 p_DelegateOptionsImpl->m_LoggingSeverity = armnn::StringToLogLevel(level);
466}
467
468armnn::LogSeverity DelegateOptions::GetLoggingSeverity()
469{
470 return p_DelegateOptionsImpl->m_LoggingSeverity.value();
471}
472
473bool DelegateOptions::IsLoggingEnabled()
474{
475 return p_DelegateOptionsImpl->m_LoggingSeverity.has_value();
476}
477
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000478const armnn::OptimizerOptionsOpaque& DelegateOptions::GetOptimizerOptions() const
John McLoughlin1bae8652023-03-14 11:47:15 +0000479{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100480 return p_DelegateOptionsImpl->m_OptimizerOptions;
John McLoughlin1bae8652023-03-14 11:47:15 +0000481}
482
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000483void DelegateOptions::SetOptimizerOptions(const armnn::OptimizerOptionsOpaque& optimizerOptions)
John McLoughlin1bae8652023-03-14 11:47:15 +0000484{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100485 p_DelegateOptionsImpl->m_OptimizerOptions = optimizerOptions;
John McLoughlin1bae8652023-03-14 11:47:15 +0000486}
487
488const armnn::Optional<armnn::DebugCallbackFunction>& DelegateOptions::GetDebugCallbackFunction() const
489{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100490 return p_DelegateOptionsImpl->m_DebugCallbackFunc;
John McLoughlin1bae8652023-03-14 11:47:15 +0000491}
492
493void DelegateOptions::SetInternalProfilingParams(bool internalProfilingState,
494 const armnn::ProfilingDetailsMethod& internalProfilingDetail)
495{
496 p_DelegateOptionsImpl->m_InternalProfilingEnabled = internalProfilingState;
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100497 p_DelegateOptionsImpl->m_InternalProfilingDetail = internalProfilingDetail;
John McLoughlin1bae8652023-03-14 11:47:15 +0000498}
499
500bool DelegateOptions::GetInternalProfilingState() const
501{
502 return p_DelegateOptionsImpl->m_InternalProfilingEnabled;
503}
504
505const armnn::ProfilingDetailsMethod& DelegateOptions::GetInternalProfilingDetail() const
506{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100507 return p_DelegateOptionsImpl->m_InternalProfilingDetail;
John McLoughlin1bae8652023-03-14 11:47:15 +0000508}
509
510void DelegateOptions::SetSerializeToDot(const std::string& serializeToDotFile)
511{
512 p_DelegateOptionsImpl->m_SerializeToDot = serializeToDotFile;
513}
514
515const std::string& DelegateOptions::GetSerializeToDot() const
516{
517 return p_DelegateOptionsImpl->m_SerializeToDot;
518}
519
520void DelegateOptions::SetRuntimeOptions(const armnn::IRuntime::CreationOptions& runtimeOptions)
521{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100522 p_DelegateOptionsImpl->m_RuntimeOptions = runtimeOptions;
John McLoughlin1bae8652023-03-14 11:47:15 +0000523}
524
525const armnn::IRuntime::CreationOptions& DelegateOptions::GetRuntimeOptions()
526{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100527 return p_DelegateOptionsImpl->m_RuntimeOptions;
John McLoughlin1bae8652023-03-14 11:47:15 +0000528}
529
530void DelegateOptions::DisableTfLiteRuntimeFallback(bool fallbackState)
531{
532 p_DelegateOptionsImpl->m_DisableTfLiteRuntimeFallback = fallbackState;
533}
534
535bool DelegateOptions::TfLiteRuntimeFallbackDisabled()
536{
537 return p_DelegateOptionsImpl->m_DisableTfLiteRuntimeFallback;
538}
539
Sadik Armagan3c24f432020-10-19 17:35:30 +0100540} // namespace armnnDelegate