Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 1 | // |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 2 | // Copyright © 2020-2023 Arm Ltd and Contributors. All rights reserved. |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include <DelegateOptions.hpp> |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 7 | #include <armnn/utility/NumericCast.hpp> |
| 8 | #include <armnn/utility/StringUtils.hpp> |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 9 | |
| 10 | namespace armnnDelegate |
| 11 | { |
| 12 | |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 13 | struct DelegateOptionsImpl |
| 14 | { |
| 15 | ~DelegateOptionsImpl() = default; |
| 16 | DelegateOptionsImpl() = default; |
| 17 | |
| 18 | explicit DelegateOptionsImpl(armnn::Compute computeDevice, |
Teresa Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 19 | const std::vector<armnn::BackendOptions>& backendOptions, |
| 20 | const armnn::Optional<armnn::LogSeverity> logSeverityLevel) |
| 21 | : m_Backends({computeDevice}), m_RuntimeOptions(), m_LoggingSeverity(logSeverityLevel) |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 22 | { |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 23 | m_RuntimeOptions.m_BackendOptions = backendOptions; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 24 | } |
| 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 Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 29 | : m_Backends(backends), m_RuntimeOptions(), m_LoggingSeverity(logSeverityLevel) |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 30 | { |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 31 | m_RuntimeOptions.m_BackendOptions = backendOptions; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | explicit DelegateOptionsImpl(armnn::Compute computeDevice, |
John Mcloughlin | c5ee0d7 | 2023-03-24 12:07:25 +0000 | [diff] [blame] | 35 | const armnn::OptimizerOptionsOpaque& optimizerOptions, |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 36 | const armnn::Optional<armnn::LogSeverity>& logSeverityLevel, |
| 37 | const armnn::Optional<armnn::DebugCallbackFunction>& func) |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 38 | : m_Backends({computeDevice}), |
| 39 | m_RuntimeOptions(), |
| 40 | m_OptimizerOptions(optimizerOptions), |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 41 | m_LoggingSeverity(logSeverityLevel), |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 42 | m_DebugCallbackFunc(func) |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 43 | { |
| 44 | } |
| 45 | |
| 46 | explicit DelegateOptionsImpl(const std::vector<armnn::BackendId>& backends, |
John Mcloughlin | c5ee0d7 | 2023-03-24 12:07:25 +0000 | [diff] [blame] | 47 | const armnn::OptimizerOptionsOpaque& optimizerOptions, |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 48 | const armnn::Optional<armnn::LogSeverity>& logSeverityLevel, |
| 49 | const armnn::Optional<armnn::DebugCallbackFunction>& func) |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 50 | : m_Backends(backends), |
| 51 | m_RuntimeOptions(), |
| 52 | m_OptimizerOptions(optimizerOptions), |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 53 | m_LoggingSeverity(logSeverityLevel), |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 54 | m_DebugCallbackFunc(func) |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 55 | { |
| 56 | } |
| 57 | |
| 58 | /// Which backend to run Delegate on. |
| 59 | /// Examples of possible values are: CpuRef, CpuAcc, GpuAcc. |
| 60 | /// CpuRef as default. |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 61 | std::vector<armnn::BackendId> m_Backends = {armnn::Compute::CpuRef }; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 62 | |
| 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 Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 66 | armnn::IRuntime::CreationOptions m_RuntimeOptions; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 67 | |
| 68 | /// Options for the optimization step for the network |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 69 | armnn::OptimizerOptionsOpaque m_OptimizerOptions; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 70 | |
| 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 Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 76 | armnn::ProfilingDetailsMethod m_InternalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 77 | |
| 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 Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 84 | armnn::Optional<armnn::DebugCallbackFunction> m_DebugCallbackFunc; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 85 | |
| 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 | |
| 94 | DelegateOptions::~DelegateOptions() = default; |
| 95 | |
| 96 | DelegateOptions::DelegateOptions() |
| 97 | : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>()) |
| 98 | { |
| 99 | } |
| 100 | |
| 101 | DelegateOptions::DelegateOptions(DelegateOptions const &other) |
| 102 | : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>(*other.p_DelegateOptionsImpl)) |
| 103 | { |
| 104 | } |
| 105 | |
Sadik Armagan | 4189cc5 | 2020-11-11 18:01:48 +0000 | [diff] [blame] | 106 | DelegateOptions::DelegateOptions(armnn::Compute computeDevice, |
Jan Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 107 | const std::vector<armnn::BackendOptions>& backendOptions, |
| 108 | const armnn::Optional<armnn::LogSeverity> logSeverityLevel) |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 109 | : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>(computeDevice, backendOptions, logSeverityLevel)) |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 110 | { |
| 111 | } |
| 112 | |
Sadik Armagan | 4189cc5 | 2020-11-11 18:01:48 +0000 | [diff] [blame] | 113 | DelegateOptions::DelegateOptions(const std::vector<armnn::BackendId>& backends, |
Jan Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 114 | const std::vector<armnn::BackendOptions>& backendOptions, |
| 115 | const armnn::Optional<armnn::LogSeverity> logSeverityLevel) |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 116 | : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>(backends, backendOptions, logSeverityLevel)) |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 117 | { |
| 118 | } |
| 119 | |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 120 | DelegateOptions::DelegateOptions(armnn::Compute computeDevice, |
John Mcloughlin | c5ee0d7 | 2023-03-24 12:07:25 +0000 | [diff] [blame] | 121 | const armnn::OptimizerOptionsOpaque& optimizerOptions, |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 122 | const armnn::Optional<armnn::LogSeverity>& logSeverityLevel, |
| 123 | const armnn::Optional<armnn::DebugCallbackFunction>& func) |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 124 | : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>(computeDevice, optimizerOptions, |
| 125 | logSeverityLevel, func)) |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 126 | { |
| 127 | } |
| 128 | |
| 129 | DelegateOptions::DelegateOptions(const std::vector<armnn::BackendId>& backends, |
John Mcloughlin | c5ee0d7 | 2023-03-24 12:07:25 +0000 | [diff] [blame] | 130 | const armnn::OptimizerOptionsOpaque& optimizerOptions, |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 131 | const armnn::Optional<armnn::LogSeverity>& logSeverityLevel, |
| 132 | const armnn::Optional<armnn::DebugCallbackFunction>& func) |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 133 | : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>(backends, optimizerOptions, |
| 134 | logSeverityLevel, func)) |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 135 | { |
| 136 | } |
| 137 | |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 138 | DelegateOptions::DelegateOptions(char const* const* options_keys, |
| 139 | char const* const* options_values, |
| 140 | size_t num_options, |
| 141 | void (*report_error)(const char*)) |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 142 | : p_DelegateOptionsImpl(std::make_unique<DelegateOptionsImpl>()) |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 143 | { |
| 144 | armnn::IRuntime::CreationOptions runtimeOptions; |
John Mcloughlin | c5ee0d7 | 2023-03-24 12:07:25 +0000 | [diff] [blame] | 145 | armnn::OptimizerOptionsOpaque optimizerOptions; |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 146 | bool internalProfilingState = false; |
| 147 | armnn::ProfilingDetailsMethod internalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents; |
Teresa Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 148 | |
| 149 | bool GpuAccFound = false; |
| 150 | bool CpuAccFound = false; |
| 151 | |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 152 | 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 McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 166 | SetBackends(backends); |
Teresa Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 167 | GpuAccFound = std::count(GetBackends().begin(), GetBackends().end(), "GpuAcc"); |
| 168 | CpuAccFound = std::count(GetBackends().begin(), GetBackends().end(), "CpuAcc"); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 169 | } |
| 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 McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 178 | SetLoggingSeverity(options_values[i]); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 179 | } |
| 180 | // Process GPU backend options |
| 181 | else if (std::string(options_keys[i]) == std::string("gpu-tuning-level")) |
| 182 | { |
Teresa Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 183 | 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 Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 194 | } |
| 195 | else if (std::string(options_keys[i]) == std::string("gpu-mlgo-tuning-file")) |
| 196 | { |
Teresa Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 197 | 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 Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 208 | } |
| 209 | else if (std::string(options_keys[i]) == std::string("gpu-tuning-file")) |
| 210 | { |
Teresa Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 211 | 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 Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 222 | } |
| 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 Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 229 | 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 Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 240 | } |
| 241 | else if (std::string(options_keys[i]) == std::string("save-cached-network")) |
| 242 | { |
Teresa Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 243 | 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 Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 254 | } |
| 255 | else if (std::string(options_keys[i]) == std::string("cached-network-filepath")) |
| 256 | { |
Teresa Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 257 | 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 Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 268 | } |
| 269 | // Process GPU & CPU backend options |
| 270 | else if (std::string(options_keys[i]) == std::string("enable-fast-math")) |
| 271 | { |
Teresa Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 272 | 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 Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 289 | } |
| 290 | // Process CPU backend options |
| 291 | else if (std::string(options_keys[i]) == std::string("number-of-threads")) |
| 292 | { |
Teresa Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 293 | 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 Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 305 | } |
| 306 | // Process reduce-fp32-to-fp16 option |
| 307 | else if (std::string(options_keys[i]) == std::string("reduce-fp32-to-fp16")) |
| 308 | { |
John Mcloughlin | c5ee0d7 | 2023-03-24 12:07:25 +0000 | [diff] [blame] | 309 | optimizerOptions.SetReduceFp32ToFp16(armnn::stringUtils::StringToBool(options_values[i])); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 310 | } |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 311 | // Process debug-data |
| 312 | else if (std::string(options_keys[i]) == std::string("debug-data")) |
| 313 | { |
John Mcloughlin | c5ee0d7 | 2023-03-24 12:07:25 +0000 | [diff] [blame] | 314 | optimizerOptions.SetDebugEnabled(armnn::stringUtils::StringToBool(options_values[i])); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 315 | } |
Mike Kelly | 80512b0 | 2022-05-16 23:10:42 +0100 | [diff] [blame] | 316 | // Infer output-shape |
| 317 | else if (std::string(options_keys[i]) == std::string("infer-output-shape")) |
| 318 | { |
Teresa Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 319 | if (armnn::stringUtils::StringToBool(options_values[i])) |
Mike Kelly | 80512b0 | 2022-05-16 23:10:42 +0100 | [diff] [blame] | 320 | { |
Teresa Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 321 | optimizerOptions.SetShapeInferenceMethod(armnn::ShapeInferenceMethod::InferAndValidate); |
| 322 | } |
| 323 | else |
| 324 | { |
| 325 | optimizerOptions.SetShapeInferenceMethod(armnn::ShapeInferenceMethod::ValidateOnly); |
| 326 | } |
Mike Kelly | 80512b0 | 2022-05-16 23:10:42 +0100 | [diff] [blame] | 327 | } |
| 328 | // Allow expanded dims |
| 329 | else if (std::string(options_keys[i]) == std::string("allow-expanded-dims")) |
| 330 | { |
Teresa Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 331 | optimizerOptions.SetAllowExpandedDims(armnn::stringUtils::StringToBool(options_values[i])); |
Mike Kelly | 80512b0 | 2022-05-16 23:10:42 +0100 | [diff] [blame] | 332 | } |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 333 | // Process memory-import |
| 334 | else if (std::string(options_keys[i]) == std::string("memory-import")) |
| 335 | { |
John Mcloughlin | c5ee0d7 | 2023-03-24 12:07:25 +0000 | [diff] [blame] | 336 | optimizerOptions.SetImportEnabled(armnn::stringUtils::StringToBool(options_values[i])); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 337 | } |
| 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 Mcloughlin | c5ee0d7 | 2023-03-24 12:07:25 +0000 | [diff] [blame] | 342 | optimizerOptions.SetProfilingEnabled(internalProfilingState); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 343 | } |
| 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 Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 364 | runtimeOptions.m_ProfilingOptions.m_EnableProfiling = armnn::stringUtils::StringToBool(options_values[i]); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 365 | } |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 366 | // Process timeline-profiling |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 367 | else if (std::string(options_keys[i]) == std::string("timeline-profiling")) |
| 368 | { |
Teresa Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 369 | runtimeOptions.m_ProfilingOptions.m_TimelineEnabled = armnn::stringUtils::StringToBool(options_values[i]); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 370 | } |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 371 | // Process outgoing-capture-file |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 372 | else if (std::string(options_keys[i]) == std::string("outgoing-capture-file")) |
| 373 | { |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 374 | runtimeOptions.m_ProfilingOptions.m_OutgoingCaptureFile = options_values[i]; |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 375 | } |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 376 | // Process incoming-capture-file |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 377 | else if (std::string(options_keys[i]) == std::string("incoming-capture-file")) |
| 378 | { |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 379 | runtimeOptions.m_ProfilingOptions.m_IncomingCaptureFile = options_values[i]; |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 380 | } |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 381 | // Process file-only-external-profiling |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 382 | else if (std::string(options_keys[i]) == std::string("file-only-external-profiling")) |
| 383 | { |
Teresa Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 384 | runtimeOptions.m_ProfilingOptions.m_FileOnly = armnn::stringUtils::StringToBool(options_values[i]); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 385 | } |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 386 | // Process counter-capture-period |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 387 | else if (std::string(options_keys[i]) == std::string("counter-capture-period")) |
| 388 | { |
Teresa Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 389 | runtimeOptions.m_ProfilingOptions.m_CapturePeriod = static_cast<uint32_t>(std::stoul(options_values[i])); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 390 | } |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 391 | // Process profiling-file-format |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 392 | else if (std::string(options_keys[i]) == std::string("profiling-file-format")) |
| 393 | { |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 394 | runtimeOptions.m_ProfilingOptions.m_FileFormat = options_values[i]; |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 395 | } |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 396 | // Process serialize-to-dot |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 397 | else if (std::string(options_keys[i]) == std::string("serialize-to-dot")) |
| 398 | { |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 399 | SetSerializeToDot(options_values[i]); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 400 | } |
Sadik Armagan | ca565c1 | 2022-08-16 12:17:24 +0100 | [diff] [blame] | 401 | |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 402 | // Process disable-tflite-runtime-fallback |
Sadik Armagan | ca565c1 | 2022-08-16 12:17:24 +0100 | [diff] [blame] | 403 | 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 Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 407 | else |
| 408 | { |
Teresa Charlin | 19ad816 | 2023-10-04 11:17:03 +0100 | [diff] [blame] | 409 | throw armnn::Exception("Unknown option for the ArmNN Delegate given: " + std::string(options_keys[i])); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 413 | SetRuntimeOptions(runtimeOptions); |
| 414 | SetOptimizerOptions(optimizerOptions); |
| 415 | SetInternalProfilingParams(internalProfilingState, internalProfilingDetail); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 416 | } |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 417 | |
| 418 | const std::vector<armnn::BackendId>& DelegateOptions::GetBackends() const |
| 419 | { |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 420 | return p_DelegateOptionsImpl->m_Backends; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | void DelegateOptions::SetBackends(const std::vector<armnn::BackendId>& backends) |
| 424 | { |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 425 | p_DelegateOptionsImpl->m_Backends = backends; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | void DelegateOptions::SetDynamicBackendsPath(const std::string& dynamicBackendsPath) |
| 429 | { |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 430 | p_DelegateOptionsImpl->m_RuntimeOptions.m_DynamicBackendsPath = dynamicBackendsPath; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | const std::string& DelegateOptions::GetDynamicBackendsPath() const |
| 434 | { |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 435 | return p_DelegateOptionsImpl->m_RuntimeOptions.m_DynamicBackendsPath; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | void DelegateOptions::SetGpuProfilingState(bool gpuProfilingState) |
| 439 | { |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 440 | p_DelegateOptionsImpl->m_RuntimeOptions.m_EnableGpuProfiling = gpuProfilingState; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | bool DelegateOptions::GetGpuProfilingState() |
| 444 | { |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 445 | return p_DelegateOptionsImpl->m_RuntimeOptions.m_EnableGpuProfiling; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | const std::vector<armnn::BackendOptions>& DelegateOptions::GetBackendOptions() const |
| 449 | { |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 450 | return p_DelegateOptionsImpl->m_RuntimeOptions.m_BackendOptions; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | void DelegateOptions::AddBackendOption(const armnn::BackendOptions& option) |
| 454 | { |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 455 | p_DelegateOptionsImpl->m_RuntimeOptions.m_BackendOptions.push_back(option); |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | void DelegateOptions::SetLoggingSeverity(const armnn::LogSeverity& level) |
| 459 | { |
| 460 | p_DelegateOptionsImpl->m_LoggingSeverity = level; |
| 461 | } |
| 462 | |
| 463 | void DelegateOptions::SetLoggingSeverity(const std::string& level) |
| 464 | { |
| 465 | p_DelegateOptionsImpl->m_LoggingSeverity = armnn::StringToLogLevel(level); |
| 466 | } |
| 467 | |
| 468 | armnn::LogSeverity DelegateOptions::GetLoggingSeverity() |
| 469 | { |
| 470 | return p_DelegateOptionsImpl->m_LoggingSeverity.value(); |
| 471 | } |
| 472 | |
| 473 | bool DelegateOptions::IsLoggingEnabled() |
| 474 | { |
| 475 | return p_DelegateOptionsImpl->m_LoggingSeverity.has_value(); |
| 476 | } |
| 477 | |
John Mcloughlin | c5ee0d7 | 2023-03-24 12:07:25 +0000 | [diff] [blame] | 478 | const armnn::OptimizerOptionsOpaque& DelegateOptions::GetOptimizerOptions() const |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 479 | { |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 480 | return p_DelegateOptionsImpl->m_OptimizerOptions; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 481 | } |
| 482 | |
John Mcloughlin | c5ee0d7 | 2023-03-24 12:07:25 +0000 | [diff] [blame] | 483 | void DelegateOptions::SetOptimizerOptions(const armnn::OptimizerOptionsOpaque& optimizerOptions) |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 484 | { |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 485 | p_DelegateOptionsImpl->m_OptimizerOptions = optimizerOptions; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | const armnn::Optional<armnn::DebugCallbackFunction>& DelegateOptions::GetDebugCallbackFunction() const |
| 489 | { |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 490 | return p_DelegateOptionsImpl->m_DebugCallbackFunc; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | void DelegateOptions::SetInternalProfilingParams(bool internalProfilingState, |
| 494 | const armnn::ProfilingDetailsMethod& internalProfilingDetail) |
| 495 | { |
| 496 | p_DelegateOptionsImpl->m_InternalProfilingEnabled = internalProfilingState; |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 497 | p_DelegateOptionsImpl->m_InternalProfilingDetail = internalProfilingDetail; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | bool DelegateOptions::GetInternalProfilingState() const |
| 501 | { |
| 502 | return p_DelegateOptionsImpl->m_InternalProfilingEnabled; |
| 503 | } |
| 504 | |
| 505 | const armnn::ProfilingDetailsMethod& DelegateOptions::GetInternalProfilingDetail() const |
| 506 | { |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 507 | return p_DelegateOptionsImpl->m_InternalProfilingDetail; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | void DelegateOptions::SetSerializeToDot(const std::string& serializeToDotFile) |
| 511 | { |
| 512 | p_DelegateOptionsImpl->m_SerializeToDot = serializeToDotFile; |
| 513 | } |
| 514 | |
| 515 | const std::string& DelegateOptions::GetSerializeToDot() const |
| 516 | { |
| 517 | return p_DelegateOptionsImpl->m_SerializeToDot; |
| 518 | } |
| 519 | |
| 520 | void DelegateOptions::SetRuntimeOptions(const armnn::IRuntime::CreationOptions& runtimeOptions) |
| 521 | { |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 522 | p_DelegateOptionsImpl->m_RuntimeOptions = runtimeOptions; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | const armnn::IRuntime::CreationOptions& DelegateOptions::GetRuntimeOptions() |
| 526 | { |
Francis Murtagh | e69cbfe | 2023-05-08 15:13:47 +0100 | [diff] [blame] | 527 | return p_DelegateOptionsImpl->m_RuntimeOptions; |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | void DelegateOptions::DisableTfLiteRuntimeFallback(bool fallbackState) |
| 531 | { |
| 532 | p_DelegateOptionsImpl->m_DisableTfLiteRuntimeFallback = fallbackState; |
| 533 | } |
| 534 | |
| 535 | bool DelegateOptions::TfLiteRuntimeFallbackDisabled() |
| 536 | { |
| 537 | return p_DelegateOptionsImpl->m_DisableTfLiteRuntimeFallback; |
| 538 | } |
| 539 | |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 540 | } // namespace armnnDelegate |