blob: 3b839971d891ae0a8fefe9271eefee87e2b17d38 [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
Teresa Charlin3e4b6082023-10-19 19:13:29 +0100149 // Process backends
Teresa Charlin19ad8162023-10-04 11:17:03 +0100150 bool GpuAccFound = false;
151 bool CpuAccFound = false;
Jan Eilersf39f8d82021-10-26 16:57:34 +0100152 for (size_t i = 0; i < num_options; ++i)
153 {
Jan Eilersf39f8d82021-10-26 16:57:34 +0100154 if (std::string(options_keys[i]) == std::string("backends"))
155 {
156 // The backend option is a comma separated string of backendIDs that needs to be split
157 std::vector<armnn::BackendId> backends;
Teresa Charlin3e4b6082023-10-19 19:13:29 +0100158 char *dup = strdup(options_values[i]);
159 char *pch = std::strtok(dup, ",");
Jan Eilersf39f8d82021-10-26 16:57:34 +0100160 while (pch != NULL)
161 {
162 backends.push_back(pch);
Teresa Charlin3e4b6082023-10-19 19:13:29 +0100163 pch = strtok(NULL, ",");
Jan Eilersf39f8d82021-10-26 16:57:34 +0100164 }
John McLoughlin1bae8652023-03-14 11:47:15 +0000165 SetBackends(backends);
Teresa Charlin19ad8162023-10-04 11:17:03 +0100166 GpuAccFound = std::count(GetBackends().begin(), GetBackends().end(), "GpuAcc");
167 CpuAccFound = std::count(GetBackends().begin(), GetBackends().end(), "CpuAcc");
Teresa Charlin3e4b6082023-10-19 19:13:29 +0100168 break;
Jan Eilersf39f8d82021-10-26 16:57:34 +0100169 }
Teresa Charlin3e4b6082023-10-19 19:13:29 +0100170 }
171
172 // Rest of options after knowing the backend
173 for (size_t i = 0; i < num_options; ++i)
174 {
175 if (std::string(options_keys[i]) == std::string("backends"))
176 {
177 continue;
178 }
179 // Process dynamic-backends-path
Jan Eilersf39f8d82021-10-26 16:57:34 +0100180 else if (std::string(options_keys[i]) == std::string("dynamic-backends-path"))
181 {
182 runtimeOptions.m_DynamicBackendsPath = std::string(options_values[i]);
183 }
Teresa Charlin3e4b6082023-10-19 19:13:29 +0100184 // Process logging level
Jan Eilersf39f8d82021-10-26 16:57:34 +0100185 else if (std::string(options_keys[i]) == std::string("logging-severity"))
186 {
John McLoughlin1bae8652023-03-14 11:47:15 +0000187 SetLoggingSeverity(options_values[i]);
Jan Eilersf39f8d82021-10-26 16:57:34 +0100188 }
Teresa Charlin3e4b6082023-10-19 19:13:29 +0100189 // Process GPU backend options
Jan Eilersf39f8d82021-10-26 16:57:34 +0100190 else if (std::string(options_keys[i]) == std::string("gpu-tuning-level"))
191 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100192 if (GpuAccFound)
193 {
194 armnn::BackendOptions option("GpuAcc", {{"TuningLevel",
195 atoi(options_values[i])}});
196 runtimeOptions.m_BackendOptions.push_back(option);
197 }
198 else
199 {
200 ARMNN_LOG(warning) <<
201 "WARNING: TuningLevel is enabled, but no backends that accept this option are set.";
202 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100203 }
204 else if (std::string(options_keys[i]) == std::string("gpu-mlgo-tuning-file"))
205 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100206 if (GpuAccFound)
207 {
208 armnn::BackendOptions option("GpuAcc", {{"MLGOTuningFilePath",
209 std::string(options_values[i])}});
210 optimizerOptions.AddModelOption(option);
211 }
212 else
213 {
214 ARMNN_LOG(warning) <<
215 "WARNING: MLGOTuningFilePath is enabled, but no backends that accept this option are set.";
216 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100217 }
218 else if (std::string(options_keys[i]) == std::string("gpu-tuning-file"))
219 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100220 if (GpuAccFound)
221 {
222 armnn::BackendOptions option("GpuAcc", {{"TuningFile",
223 std::string(options_values[i])}});
224 runtimeOptions.m_BackendOptions.push_back(option);
225 }
226 else
227 {
228 ARMNN_LOG(warning) <<
229 "WARNING: TuningFile is enabled, but no backends that accept this option are set.";
230 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100231 }
232 else if (std::string(options_keys[i]) == std::string("gpu-enable-profiling"))
233 {
234 runtimeOptions.m_EnableGpuProfiling = (*options_values[i] != '0');
235 }
236 else if (std::string(options_keys[i]) == std::string("gpu-kernel-profiling-enabled"))
237 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100238 if (GpuAccFound)
239 {
240 armnn::BackendOptions option("GpuAcc", {{"KernelProfilingEnabled",
241 armnn::stringUtils::StringToBool(options_values[i])}});
242 runtimeOptions.m_BackendOptions.push_back(option);
243 }
244 else
245 {
246 ARMNN_LOG(warning) <<
247 "WARNING: KernelProfilingEnabled is enabled, but no backends that accept this option are set.";
248 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100249 }
250 else if (std::string(options_keys[i]) == std::string("save-cached-network"))
251 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100252 if (GpuAccFound)
253 {
254 armnn::BackendOptions option("GpuAcc", {{"SaveCachedNetwork",
255 armnn::stringUtils::StringToBool(options_values[i])}});
256 optimizerOptions.AddModelOption(option);
257 }
258 else
259 {
260 ARMNN_LOG(warning) <<
261 "WARNING: SaveCachedNetwork is enabled, but no backends that accept this option are set.";
262 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100263 }
264 else if (std::string(options_keys[i]) == std::string("cached-network-filepath"))
265 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100266 if (GpuAccFound)
267 {
268 armnn::BackendOptions option("GpuAcc", {{"CachedNetworkFilePath",
269 std::string(options_values[i])}});
270 optimizerOptions.AddModelOption(option);
271 }
272 else
273 {
274 ARMNN_LOG(warning) <<
275 "WARNING: CachedNetworkFilePath is enabled, but no backends that accept this option are set.";
276 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100277 }
Teresa Charlin3e4b6082023-10-19 19:13:29 +0100278 // Process GPU & CPU backend options
Jan Eilersf39f8d82021-10-26 16:57:34 +0100279 else if (std::string(options_keys[i]) == std::string("enable-fast-math"))
280 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100281 if (GpuAccFound)
282 {
283 armnn::BackendOptions modelOptionGpu("GpuAcc", {{"FastMathEnabled",
284 armnn::stringUtils::StringToBool(options_values[i])}});
285 optimizerOptions.AddModelOption(modelOptionGpu);
286 }
287 if (CpuAccFound)
288 {
289 armnn::BackendOptions modelOptionCpu("CpuAcc", {{"FastMathEnabled",
290 armnn::stringUtils::StringToBool(options_values[i])}});
291 optimizerOptions.AddModelOption(modelOptionCpu);
292 }
293 if (!GpuAccFound and !CpuAccFound)
294 {
295 ARMNN_LOG(warning) <<
296 "WARNING: Fastmath is enabled, but no backends that accept this option are set.";
297 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100298 }
Teresa Charlin3e4b6082023-10-19 19:13:29 +0100299 // Process CPU backend options
Jan Eilersf39f8d82021-10-26 16:57:34 +0100300 else if (std::string(options_keys[i]) == std::string("number-of-threads"))
301 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100302 if (CpuAccFound)
303 {
304 unsigned int numberOfThreads = armnn::numeric_cast<unsigned int>(atoi(options_values[i]));
305 armnn::BackendOptions modelOption("CpuAcc",
306 {{"NumberOfThreads", numberOfThreads}});
307 optimizerOptions.AddModelOption(modelOption);
308 }
309 else
310 {
311 ARMNN_LOG(warning) <<
312 "WARNING: NumberOfThreads is enabled, but no backends that accept this option are set.";
313 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100314 }
Teresa Charlin3e4b6082023-10-19 19:13:29 +0100315 // Process reduce-fp32-to-fp16 option
Jan Eilersf39f8d82021-10-26 16:57:34 +0100316 else if (std::string(options_keys[i]) == std::string("reduce-fp32-to-fp16"))
317 {
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000318 optimizerOptions.SetReduceFp32ToFp16(armnn::stringUtils::StringToBool(options_values[i]));
Jan Eilersf39f8d82021-10-26 16:57:34 +0100319 }
Teresa Charlin3e4b6082023-10-19 19:13:29 +0100320 // Process debug-data
Jan Eilersf39f8d82021-10-26 16:57:34 +0100321 else if (std::string(options_keys[i]) == std::string("debug-data"))
322 {
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000323 optimizerOptions.SetDebugEnabled(armnn::stringUtils::StringToBool(options_values[i]));
Jan Eilersf39f8d82021-10-26 16:57:34 +0100324 }
Teresa Charlin3e4b6082023-10-19 19:13:29 +0100325 // Infer output-shape
Mike Kelly80512b02022-05-16 23:10:42 +0100326 else if (std::string(options_keys[i]) == std::string("infer-output-shape"))
327 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100328 if (armnn::stringUtils::StringToBool(options_values[i]))
Mike Kelly80512b02022-05-16 23:10:42 +0100329 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100330 optimizerOptions.SetShapeInferenceMethod(armnn::ShapeInferenceMethod::InferAndValidate);
331 }
332 else
333 {
334 optimizerOptions.SetShapeInferenceMethod(armnn::ShapeInferenceMethod::ValidateOnly);
335 }
Mike Kelly80512b02022-05-16 23:10:42 +0100336 }
Teresa Charlin3e4b6082023-10-19 19:13:29 +0100337 // Allow expanded dims
Mike Kelly80512b02022-05-16 23:10:42 +0100338 else if (std::string(options_keys[i]) == std::string("allow-expanded-dims"))
339 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100340 optimizerOptions.SetAllowExpandedDims(armnn::stringUtils::StringToBool(options_values[i]));
Mike Kelly80512b02022-05-16 23:10:42 +0100341 }
Teresa Charlin3e4b6082023-10-19 19:13:29 +0100342 // Process memory-import
Jan Eilersf39f8d82021-10-26 16:57:34 +0100343 else if (std::string(options_keys[i]) == std::string("memory-import"))
344 {
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000345 optimizerOptions.SetImportEnabled(armnn::stringUtils::StringToBool(options_values[i]));
Jan Eilersf39f8d82021-10-26 16:57:34 +0100346 }
Teresa Charlin3e4b6082023-10-19 19:13:29 +0100347 // Process enable-internal-profiling
Jan Eilersf39f8d82021-10-26 16:57:34 +0100348 else if (std::string(options_keys[i]) == std::string("enable-internal-profiling"))
349 {
350 internalProfilingState = *options_values[i] != '0';
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000351 optimizerOptions.SetProfilingEnabled(internalProfilingState);
Jan Eilersf39f8d82021-10-26 16:57:34 +0100352 }
Teresa Charlin3e4b6082023-10-19 19:13:29 +0100353 // Process internal-profiling-detail
Jan Eilersf39f8d82021-10-26 16:57:34 +0100354 else if (std::string(options_keys[i]) == std::string("internal-profiling-detail"))
355 {
356 uint32_t detailLevel = static_cast<uint32_t>(std::stoul(options_values[i]));
357 switch (detailLevel)
358 {
359 case 1:
360 internalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents;
361 break;
362 case 2:
363 internalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsOnly;
364 break;
365 default:
366 internalProfilingDetail = armnn::ProfilingDetailsMethod::Undefined;
367 break;
368 }
369 }
Teresa Charlin3e4b6082023-10-19 19:13:29 +0100370 // Process enable-external-profiling
Jan Eilersf39f8d82021-10-26 16:57:34 +0100371 else if (std::string(options_keys[i]) == std::string("enable-external-profiling"))
372 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100373 runtimeOptions.m_ProfilingOptions.m_EnableProfiling = armnn::stringUtils::StringToBool(options_values[i]);
Jan Eilersf39f8d82021-10-26 16:57:34 +0100374 }
Colm Donelan35a06892023-02-06 15:01:57 +0000375 // Process timeline-profiling
Jan Eilersf39f8d82021-10-26 16:57:34 +0100376 else if (std::string(options_keys[i]) == std::string("timeline-profiling"))
377 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100378 runtimeOptions.m_ProfilingOptions.m_TimelineEnabled = armnn::stringUtils::StringToBool(options_values[i]);
Jan Eilersf39f8d82021-10-26 16:57:34 +0100379 }
Colm Donelan35a06892023-02-06 15:01:57 +0000380 // Process outgoing-capture-file
Jan Eilersf39f8d82021-10-26 16:57:34 +0100381 else if (std::string(options_keys[i]) == std::string("outgoing-capture-file"))
382 {
Colm Donelan35a06892023-02-06 15:01:57 +0000383 runtimeOptions.m_ProfilingOptions.m_OutgoingCaptureFile = options_values[i];
Jan Eilersf39f8d82021-10-26 16:57:34 +0100384 }
Colm Donelan35a06892023-02-06 15:01:57 +0000385 // Process incoming-capture-file
Jan Eilersf39f8d82021-10-26 16:57:34 +0100386 else if (std::string(options_keys[i]) == std::string("incoming-capture-file"))
387 {
Colm Donelan35a06892023-02-06 15:01:57 +0000388 runtimeOptions.m_ProfilingOptions.m_IncomingCaptureFile = options_values[i];
Jan Eilersf39f8d82021-10-26 16:57:34 +0100389 }
Colm Donelan35a06892023-02-06 15:01:57 +0000390 // Process file-only-external-profiling
Jan Eilersf39f8d82021-10-26 16:57:34 +0100391 else if (std::string(options_keys[i]) == std::string("file-only-external-profiling"))
392 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100393 runtimeOptions.m_ProfilingOptions.m_FileOnly = armnn::stringUtils::StringToBool(options_values[i]);
Jan Eilersf39f8d82021-10-26 16:57:34 +0100394 }
Colm Donelan35a06892023-02-06 15:01:57 +0000395 // Process counter-capture-period
Jan Eilersf39f8d82021-10-26 16:57:34 +0100396 else if (std::string(options_keys[i]) == std::string("counter-capture-period"))
397 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100398 runtimeOptions.m_ProfilingOptions.m_CapturePeriod = static_cast<uint32_t>(std::stoul(options_values[i]));
Jan Eilersf39f8d82021-10-26 16:57:34 +0100399 }
Colm Donelan35a06892023-02-06 15:01:57 +0000400 // Process profiling-file-format
Jan Eilersf39f8d82021-10-26 16:57:34 +0100401 else if (std::string(options_keys[i]) == std::string("profiling-file-format"))
402 {
Colm Donelan35a06892023-02-06 15:01:57 +0000403 runtimeOptions.m_ProfilingOptions.m_FileFormat = options_values[i];
Jan Eilersf39f8d82021-10-26 16:57:34 +0100404 }
Colm Donelan35a06892023-02-06 15:01:57 +0000405 // Process serialize-to-dot
Jan Eilersf39f8d82021-10-26 16:57:34 +0100406 else if (std::string(options_keys[i]) == std::string("serialize-to-dot"))
407 {
John McLoughlin1bae8652023-03-14 11:47:15 +0000408 SetSerializeToDot(options_values[i]);
Jan Eilersf39f8d82021-10-26 16:57:34 +0100409 }
John McLoughlin1bae8652023-03-14 11:47:15 +0000410 // Process disable-tflite-runtime-fallback
Sadik Armaganca565c12022-08-16 12:17:24 +0100411 else if (std::string(options_keys[i]) == std::string("disable-tflite-runtime-fallback"))
412 {
413 this->DisableTfLiteRuntimeFallback(armnn::stringUtils::StringToBool(options_values[i]));
414 }
Jan Eilersf39f8d82021-10-26 16:57:34 +0100415 else
416 {
Teresa Charlin19ad8162023-10-04 11:17:03 +0100417 throw armnn::Exception("Unknown option for the ArmNN Delegate given: " + std::string(options_keys[i]));
Jan Eilersf39f8d82021-10-26 16:57:34 +0100418 }
419 }
420
John McLoughlin1bae8652023-03-14 11:47:15 +0000421 SetRuntimeOptions(runtimeOptions);
422 SetOptimizerOptions(optimizerOptions);
423 SetInternalProfilingParams(internalProfilingState, internalProfilingDetail);
Jan Eilersf39f8d82021-10-26 16:57:34 +0100424}
John McLoughlin1bae8652023-03-14 11:47:15 +0000425
426const std::vector<armnn::BackendId>& DelegateOptions::GetBackends() const
427{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100428 return p_DelegateOptionsImpl->m_Backends;
John McLoughlin1bae8652023-03-14 11:47:15 +0000429}
430
431void DelegateOptions::SetBackends(const std::vector<armnn::BackendId>& backends)
432{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100433 p_DelegateOptionsImpl->m_Backends = backends;
John McLoughlin1bae8652023-03-14 11:47:15 +0000434}
435
436void DelegateOptions::SetDynamicBackendsPath(const std::string& dynamicBackendsPath)
437{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100438 p_DelegateOptionsImpl->m_RuntimeOptions.m_DynamicBackendsPath = dynamicBackendsPath;
John McLoughlin1bae8652023-03-14 11:47:15 +0000439}
440
441const std::string& DelegateOptions::GetDynamicBackendsPath() const
442{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100443 return p_DelegateOptionsImpl->m_RuntimeOptions.m_DynamicBackendsPath;
John McLoughlin1bae8652023-03-14 11:47:15 +0000444}
445
446void DelegateOptions::SetGpuProfilingState(bool gpuProfilingState)
447{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100448 p_DelegateOptionsImpl->m_RuntimeOptions.m_EnableGpuProfiling = gpuProfilingState;
John McLoughlin1bae8652023-03-14 11:47:15 +0000449}
450
451bool DelegateOptions::GetGpuProfilingState()
452{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100453 return p_DelegateOptionsImpl->m_RuntimeOptions.m_EnableGpuProfiling;
John McLoughlin1bae8652023-03-14 11:47:15 +0000454}
455
456const std::vector<armnn::BackendOptions>& DelegateOptions::GetBackendOptions() const
457{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100458 return p_DelegateOptionsImpl->m_RuntimeOptions.m_BackendOptions;
John McLoughlin1bae8652023-03-14 11:47:15 +0000459}
460
461void DelegateOptions::AddBackendOption(const armnn::BackendOptions& option)
462{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100463 p_DelegateOptionsImpl->m_RuntimeOptions.m_BackendOptions.push_back(option);
John McLoughlin1bae8652023-03-14 11:47:15 +0000464}
465
466void DelegateOptions::SetLoggingSeverity(const armnn::LogSeverity& level)
467{
468 p_DelegateOptionsImpl->m_LoggingSeverity = level;
469}
470
471void DelegateOptions::SetLoggingSeverity(const std::string& level)
472{
473 p_DelegateOptionsImpl->m_LoggingSeverity = armnn::StringToLogLevel(level);
474}
475
476armnn::LogSeverity DelegateOptions::GetLoggingSeverity()
477{
478 return p_DelegateOptionsImpl->m_LoggingSeverity.value();
479}
480
481bool DelegateOptions::IsLoggingEnabled()
482{
483 return p_DelegateOptionsImpl->m_LoggingSeverity.has_value();
484}
485
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000486const armnn::OptimizerOptionsOpaque& DelegateOptions::GetOptimizerOptions() const
John McLoughlin1bae8652023-03-14 11:47:15 +0000487{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100488 return p_DelegateOptionsImpl->m_OptimizerOptions;
John McLoughlin1bae8652023-03-14 11:47:15 +0000489}
490
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000491void DelegateOptions::SetOptimizerOptions(const armnn::OptimizerOptionsOpaque& optimizerOptions)
John McLoughlin1bae8652023-03-14 11:47:15 +0000492{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100493 p_DelegateOptionsImpl->m_OptimizerOptions = optimizerOptions;
John McLoughlin1bae8652023-03-14 11:47:15 +0000494}
495
496const armnn::Optional<armnn::DebugCallbackFunction>& DelegateOptions::GetDebugCallbackFunction() const
497{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100498 return p_DelegateOptionsImpl->m_DebugCallbackFunc;
John McLoughlin1bae8652023-03-14 11:47:15 +0000499}
500
501void DelegateOptions::SetInternalProfilingParams(bool internalProfilingState,
502 const armnn::ProfilingDetailsMethod& internalProfilingDetail)
503{
504 p_DelegateOptionsImpl->m_InternalProfilingEnabled = internalProfilingState;
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100505 p_DelegateOptionsImpl->m_InternalProfilingDetail = internalProfilingDetail;
John McLoughlin1bae8652023-03-14 11:47:15 +0000506}
507
508bool DelegateOptions::GetInternalProfilingState() const
509{
510 return p_DelegateOptionsImpl->m_InternalProfilingEnabled;
511}
512
513const armnn::ProfilingDetailsMethod& DelegateOptions::GetInternalProfilingDetail() const
514{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100515 return p_DelegateOptionsImpl->m_InternalProfilingDetail;
John McLoughlin1bae8652023-03-14 11:47:15 +0000516}
517
518void DelegateOptions::SetSerializeToDot(const std::string& serializeToDotFile)
519{
520 p_DelegateOptionsImpl->m_SerializeToDot = serializeToDotFile;
521}
522
523const std::string& DelegateOptions::GetSerializeToDot() const
524{
525 return p_DelegateOptionsImpl->m_SerializeToDot;
526}
527
528void DelegateOptions::SetRuntimeOptions(const armnn::IRuntime::CreationOptions& runtimeOptions)
529{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100530 p_DelegateOptionsImpl->m_RuntimeOptions = runtimeOptions;
John McLoughlin1bae8652023-03-14 11:47:15 +0000531}
532
533const armnn::IRuntime::CreationOptions& DelegateOptions::GetRuntimeOptions()
534{
Francis Murtaghe69cbfe2023-05-08 15:13:47 +0100535 return p_DelegateOptionsImpl->m_RuntimeOptions;
John McLoughlin1bae8652023-03-14 11:47:15 +0000536}
537
538void DelegateOptions::DisableTfLiteRuntimeFallback(bool fallbackState)
539{
540 p_DelegateOptionsImpl->m_DisableTfLiteRuntimeFallback = fallbackState;
541}
542
543bool DelegateOptions::TfLiteRuntimeFallbackDisabled()
544{
545 return p_DelegateOptionsImpl->m_DisableTfLiteRuntimeFallback;
546}
547
Sadik Armagan3c24f432020-10-19 17:35:30 +0100548} // namespace armnnDelegate