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, |
| 19 | const std::vector<armnn::BackendOptions>& backendOptions, |
| 20 | const armnn::Optional<armnn::LogSeverity> logSeverityLevel) |
| 21 | : p_Backends({computeDevice}), p_RuntimeOptions(), m_LoggingSeverity(logSeverityLevel) |
| 22 | { |
| 23 | p_RuntimeOptions.m_BackendOptions = backendOptions; |
| 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) |
| 29 | : p_Backends(backends), p_RuntimeOptions(), m_LoggingSeverity(logSeverityLevel) |
| 30 | { |
| 31 | p_RuntimeOptions.m_BackendOptions = backendOptions; |
| 32 | } |
| 33 | |
| 34 | explicit DelegateOptionsImpl(armnn::Compute computeDevice, |
| 35 | const armnn::OptimizerOptions& optimizerOptions, |
| 36 | const armnn::Optional<armnn::LogSeverity>& logSeverityLevel, |
| 37 | const armnn::Optional<armnn::DebugCallbackFunction>& func) |
| 38 | : p_Backends({computeDevice}), |
| 39 | p_RuntimeOptions(), |
| 40 | p_OptimizerOptions(optimizerOptions), |
| 41 | m_LoggingSeverity(logSeverityLevel), |
| 42 | p_DebugCallbackFunc(func) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | explicit DelegateOptionsImpl(const std::vector<armnn::BackendId>& backends, |
| 47 | const armnn::OptimizerOptions& optimizerOptions, |
| 48 | const armnn::Optional<armnn::LogSeverity>& logSeverityLevel, |
| 49 | const armnn::Optional<armnn::DebugCallbackFunction>& func) |
| 50 | : p_Backends(backends), |
| 51 | p_RuntimeOptions(), |
| 52 | p_OptimizerOptions(optimizerOptions), |
| 53 | m_LoggingSeverity(logSeverityLevel), |
| 54 | p_DebugCallbackFunc(func) |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | /// Which backend to run Delegate on. |
| 59 | /// Examples of possible values are: CpuRef, CpuAcc, GpuAcc. |
| 60 | /// CpuRef as default. |
| 61 | std::vector<armnn::BackendId> p_Backends = {armnn::Compute::CpuRef }; |
| 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 |
| 66 | armnn::IRuntime::CreationOptions p_RuntimeOptions; |
| 67 | |
| 68 | /// Options for the optimization step for the network |
| 69 | armnn::OptimizerOptions p_OptimizerOptions; |
| 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 |
| 76 | armnn::ProfilingDetailsMethod p_InternalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents; |
| 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. |
| 84 | armnn::Optional<armnn::DebugCallbackFunction> p_DebugCallbackFunc; |
| 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, |
| 121 | const armnn::OptimizerOptions& 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, |
| 130 | const armnn::OptimizerOptions& 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; |
| 145 | armnn::OptimizerOptions optimizerOptions; |
| 146 | bool internalProfilingState = false; |
| 147 | armnn::ProfilingDetailsMethod internalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents; |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 148 | for (size_t i = 0; i < num_options; ++i) |
| 149 | { |
| 150 | // Process backends |
| 151 | if (std::string(options_keys[i]) == std::string("backends")) |
| 152 | { |
| 153 | // The backend option is a comma separated string of backendIDs that needs to be split |
| 154 | std::vector<armnn::BackendId> backends; |
| 155 | char* dup = strdup(options_values[i]); |
| 156 | char* pch = std::strtok(dup, ","); |
| 157 | while (pch != NULL) |
| 158 | { |
| 159 | backends.push_back(pch); |
| 160 | pch = strtok (NULL, ","); |
| 161 | } |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame^] | 162 | SetBackends(backends); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 163 | } |
| 164 | // Process dynamic-backends-path |
| 165 | else if (std::string(options_keys[i]) == std::string("dynamic-backends-path")) |
| 166 | { |
| 167 | runtimeOptions.m_DynamicBackendsPath = std::string(options_values[i]); |
| 168 | } |
| 169 | // Process logging level |
| 170 | else if (std::string(options_keys[i]) == std::string("logging-severity")) |
| 171 | { |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame^] | 172 | SetLoggingSeverity(options_values[i]); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 173 | } |
| 174 | // Process GPU backend options |
| 175 | else if (std::string(options_keys[i]) == std::string("gpu-tuning-level")) |
| 176 | { |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame^] | 177 | armnn::BackendOptions option("GpuAcc", {{"TuningLevel", |
| 178 | atoi(options_values[i])}}); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 179 | runtimeOptions.m_BackendOptions.push_back(option); |
| 180 | } |
| 181 | else if (std::string(options_keys[i]) == std::string("gpu-mlgo-tuning-file")) |
| 182 | { |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame^] | 183 | armnn::BackendOptions option("GpuAcc", {{"MLGOTuningFilePath", |
| 184 | std::string(options_values[i])}}); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 185 | optimizerOptions.m_ModelOptions.push_back(option); |
| 186 | } |
| 187 | else if (std::string(options_keys[i]) == std::string("gpu-tuning-file")) |
| 188 | { |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame^] | 189 | armnn::BackendOptions option("GpuAcc", {{"TuningFile", |
| 190 | std::string(options_values[i])}}); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 191 | runtimeOptions.m_BackendOptions.push_back(option); |
| 192 | } |
| 193 | else if (std::string(options_keys[i]) == std::string("gpu-enable-profiling")) |
| 194 | { |
| 195 | runtimeOptions.m_EnableGpuProfiling = (*options_values[i] != '0'); |
| 196 | } |
| 197 | else if (std::string(options_keys[i]) == std::string("gpu-kernel-profiling-enabled")) |
| 198 | { |
| 199 | armnn::BackendOptions option("GpuAcc", {{"KernelProfilingEnabled", |
| 200 | armnn::stringUtils::StringToBool(options_values[i])}}); |
| 201 | runtimeOptions.m_BackendOptions.push_back(option); |
| 202 | } |
| 203 | else if (std::string(options_keys[i]) == std::string("save-cached-network")) |
| 204 | { |
| 205 | armnn::BackendOptions option("GpuAcc", {{"SaveCachedNetwork", |
| 206 | armnn::stringUtils::StringToBool(options_values[i])}}); |
| 207 | optimizerOptions.m_ModelOptions.push_back(option); |
| 208 | } |
| 209 | else if (std::string(options_keys[i]) == std::string("cached-network-filepath")) |
| 210 | { |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame^] | 211 | armnn::BackendOptions option("GpuAcc", {{"CachedNetworkFilePath", |
| 212 | std::string(options_values[i])}}); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 213 | optimizerOptions.m_ModelOptions.push_back(option); |
| 214 | } |
| 215 | // Process GPU & CPU backend options |
| 216 | else if (std::string(options_keys[i]) == std::string("enable-fast-math")) |
| 217 | { |
| 218 | armnn::BackendOptions modelOptionGpu("GpuAcc", {{"FastMathEnabled", |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame^] | 219 | armnn::stringUtils::StringToBool(options_values[i])}}); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 220 | optimizerOptions.m_ModelOptions.push_back(modelOptionGpu); |
| 221 | |
| 222 | armnn::BackendOptions modelOptionCpu("CpuAcc", {{"FastMathEnabled", |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame^] | 223 | armnn::stringUtils::StringToBool(options_values[i])}}); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 224 | optimizerOptions.m_ModelOptions.push_back(modelOptionCpu); |
| 225 | } |
| 226 | // Process CPU backend options |
| 227 | else if (std::string(options_keys[i]) == std::string("number-of-threads")) |
| 228 | { |
| 229 | unsigned int numberOfThreads = armnn::numeric_cast<unsigned int>(atoi(options_values[i])); |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame^] | 230 | armnn::BackendOptions modelOption("CpuAcc", |
| 231 | {{"NumberOfThreads", numberOfThreads}}); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 232 | optimizerOptions.m_ModelOptions.push_back(modelOption); |
| 233 | } |
| 234 | // Process reduce-fp32-to-fp16 option |
| 235 | else if (std::string(options_keys[i]) == std::string("reduce-fp32-to-fp16")) |
| 236 | { |
| 237 | optimizerOptions.m_ReduceFp32ToFp16 = armnn::stringUtils::StringToBool(options_values[i]); |
| 238 | } |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 239 | // Process debug-data |
| 240 | else if (std::string(options_keys[i]) == std::string("debug-data")) |
| 241 | { |
| 242 | optimizerOptions.m_Debug = armnn::stringUtils::StringToBool(options_values[i]); |
| 243 | } |
Mike Kelly | 80512b0 | 2022-05-16 23:10:42 +0100 | [diff] [blame] | 244 | // Infer output-shape |
| 245 | else if (std::string(options_keys[i]) == std::string("infer-output-shape")) |
| 246 | { |
| 247 | armnn::BackendOptions backendOption("ShapeInferenceMethod", |
| 248 | { |
| 249 | { "InferAndValidate", armnn::stringUtils::StringToBool(options_values[i]) } |
| 250 | }); |
| 251 | optimizerOptions.m_ModelOptions.push_back(backendOption); |
| 252 | } |
| 253 | // Allow expanded dims |
| 254 | else if (std::string(options_keys[i]) == std::string("allow-expanded-dims")) |
| 255 | { |
| 256 | armnn::BackendOptions backendOption("AllowExpandedDims", |
| 257 | { |
| 258 | { "AllowExpandedDims", armnn::stringUtils::StringToBool(options_values[i]) } |
| 259 | }); |
| 260 | optimizerOptions.m_ModelOptions.push_back(backendOption); |
| 261 | } |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 262 | // Process memory-import |
| 263 | else if (std::string(options_keys[i]) == std::string("memory-import")) |
| 264 | { |
| 265 | optimizerOptions.m_ImportEnabled = armnn::stringUtils::StringToBool(options_values[i]); |
| 266 | } |
| 267 | // Process enable-internal-profiling |
| 268 | else if (std::string(options_keys[i]) == std::string("enable-internal-profiling")) |
| 269 | { |
| 270 | internalProfilingState = *options_values[i] != '0'; |
| 271 | optimizerOptions.m_ProfilingEnabled = internalProfilingState; |
| 272 | } |
| 273 | // Process internal-profiling-detail |
| 274 | else if (std::string(options_keys[i]) == std::string("internal-profiling-detail")) |
| 275 | { |
| 276 | uint32_t detailLevel = static_cast<uint32_t>(std::stoul(options_values[i])); |
| 277 | switch (detailLevel) |
| 278 | { |
| 279 | case 1: |
| 280 | internalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents; |
| 281 | break; |
| 282 | case 2: |
| 283 | internalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsOnly; |
| 284 | break; |
| 285 | default: |
| 286 | internalProfilingDetail = armnn::ProfilingDetailsMethod::Undefined; |
| 287 | break; |
| 288 | } |
| 289 | } |
| 290 | // Process enable-external-profiling |
| 291 | else if (std::string(options_keys[i]) == std::string("enable-external-profiling")) |
| 292 | { |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 293 | runtimeOptions.m_ProfilingOptions.m_EnableProfiling = |
| 294 | armnn::stringUtils::StringToBool(options_values[i]); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 295 | } |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 296 | // Process timeline-profiling |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 297 | else if (std::string(options_keys[i]) == std::string("timeline-profiling")) |
| 298 | { |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame^] | 299 | runtimeOptions.m_ProfilingOptions.m_TimelineEnabled = |
| 300 | armnn::stringUtils::StringToBool(options_values[i]); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 301 | } |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 302 | // Process outgoing-capture-file |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 303 | else if (std::string(options_keys[i]) == std::string("outgoing-capture-file")) |
| 304 | { |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 305 | runtimeOptions.m_ProfilingOptions.m_OutgoingCaptureFile = options_values[i]; |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 306 | } |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 307 | // Process incoming-capture-file |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 308 | else if (std::string(options_keys[i]) == std::string("incoming-capture-file")) |
| 309 | { |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 310 | runtimeOptions.m_ProfilingOptions.m_IncomingCaptureFile = options_values[i]; |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 311 | } |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 312 | // Process file-only-external-profiling |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 313 | else if (std::string(options_keys[i]) == std::string("file-only-external-profiling")) |
| 314 | { |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 315 | runtimeOptions.m_ProfilingOptions.m_FileOnly = armnn::stringUtils::StringToBool(options_values[i]); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 316 | } |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 317 | // Process counter-capture-period |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 318 | else if (std::string(options_keys[i]) == std::string("counter-capture-period")) |
| 319 | { |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame^] | 320 | runtimeOptions.m_ProfilingOptions.m_CapturePeriod = |
| 321 | static_cast<uint32_t>(std::stoul(options_values[i])); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 322 | } |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 323 | // Process profiling-file-format |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 324 | else if (std::string(options_keys[i]) == std::string("profiling-file-format")) |
| 325 | { |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 326 | runtimeOptions.m_ProfilingOptions.m_FileFormat = options_values[i]; |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 327 | } |
Colm Donelan | 35a0689 | 2023-02-06 15:01:57 +0000 | [diff] [blame] | 328 | // Process serialize-to-dot |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 329 | else if (std::string(options_keys[i]) == std::string("serialize-to-dot")) |
| 330 | { |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame^] | 331 | SetSerializeToDot(options_values[i]); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 332 | } |
Sadik Armagan | ca565c1 | 2022-08-16 12:17:24 +0100 | [diff] [blame] | 333 | |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame^] | 334 | // Process disable-tflite-runtime-fallback |
Sadik Armagan | ca565c1 | 2022-08-16 12:17:24 +0100 | [diff] [blame] | 335 | else if (std::string(options_keys[i]) == std::string("disable-tflite-runtime-fallback")) |
| 336 | { |
| 337 | this->DisableTfLiteRuntimeFallback(armnn::stringUtils::StringToBool(options_values[i])); |
| 338 | } |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 339 | else |
| 340 | { |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame^] | 341 | throw armnn::Exception("Unknown option for the ArmNN Delegate given: " + |
| 342 | std::string(options_keys[i])); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame^] | 346 | SetRuntimeOptions(runtimeOptions); |
| 347 | SetOptimizerOptions(optimizerOptions); |
| 348 | SetInternalProfilingParams(internalProfilingState, internalProfilingDetail); |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 349 | } |
John McLoughlin | 1bae865 | 2023-03-14 11:47:15 +0000 | [diff] [blame^] | 350 | |
| 351 | const std::vector<armnn::BackendId>& DelegateOptions::GetBackends() const |
| 352 | { |
| 353 | return p_DelegateOptionsImpl->p_Backends; |
| 354 | } |
| 355 | |
| 356 | void DelegateOptions::SetBackends(const std::vector<armnn::BackendId>& backends) |
| 357 | { |
| 358 | p_DelegateOptionsImpl->p_Backends = backends; |
| 359 | } |
| 360 | |
| 361 | void DelegateOptions::SetDynamicBackendsPath(const std::string& dynamicBackendsPath) |
| 362 | { |
| 363 | p_DelegateOptionsImpl->p_RuntimeOptions.m_DynamicBackendsPath = dynamicBackendsPath; |
| 364 | } |
| 365 | |
| 366 | const std::string& DelegateOptions::GetDynamicBackendsPath() const |
| 367 | { |
| 368 | return p_DelegateOptionsImpl->p_RuntimeOptions.m_DynamicBackendsPath; |
| 369 | } |
| 370 | |
| 371 | void DelegateOptions::SetGpuProfilingState(bool gpuProfilingState) |
| 372 | { |
| 373 | p_DelegateOptionsImpl->p_RuntimeOptions.m_EnableGpuProfiling = gpuProfilingState; |
| 374 | } |
| 375 | |
| 376 | bool DelegateOptions::GetGpuProfilingState() |
| 377 | { |
| 378 | return p_DelegateOptionsImpl->p_RuntimeOptions.m_EnableGpuProfiling; |
| 379 | } |
| 380 | |
| 381 | const std::vector<armnn::BackendOptions>& DelegateOptions::GetBackendOptions() const |
| 382 | { |
| 383 | return p_DelegateOptionsImpl->p_RuntimeOptions.m_BackendOptions; |
| 384 | } |
| 385 | |
| 386 | void DelegateOptions::AddBackendOption(const armnn::BackendOptions& option) |
| 387 | { |
| 388 | p_DelegateOptionsImpl->p_RuntimeOptions.m_BackendOptions.push_back(option); |
| 389 | } |
| 390 | |
| 391 | void DelegateOptions::SetLoggingSeverity(const armnn::LogSeverity& level) |
| 392 | { |
| 393 | p_DelegateOptionsImpl->m_LoggingSeverity = level; |
| 394 | } |
| 395 | |
| 396 | void DelegateOptions::SetLoggingSeverity(const std::string& level) |
| 397 | { |
| 398 | p_DelegateOptionsImpl->m_LoggingSeverity = armnn::StringToLogLevel(level); |
| 399 | } |
| 400 | |
| 401 | armnn::LogSeverity DelegateOptions::GetLoggingSeverity() |
| 402 | { |
| 403 | return p_DelegateOptionsImpl->m_LoggingSeverity.value(); |
| 404 | } |
| 405 | |
| 406 | bool DelegateOptions::IsLoggingEnabled() |
| 407 | { |
| 408 | return p_DelegateOptionsImpl->m_LoggingSeverity.has_value(); |
| 409 | } |
| 410 | |
| 411 | const armnn::OptimizerOptions& DelegateOptions::GetOptimizerOptions() const |
| 412 | { |
| 413 | return p_DelegateOptionsImpl->p_OptimizerOptions; |
| 414 | } |
| 415 | |
| 416 | void DelegateOptions::SetOptimizerOptions(const armnn::OptimizerOptions& optimizerOptions) |
| 417 | { |
| 418 | p_DelegateOptionsImpl->p_OptimizerOptions = optimizerOptions; |
| 419 | } |
| 420 | |
| 421 | const armnn::Optional<armnn::DebugCallbackFunction>& DelegateOptions::GetDebugCallbackFunction() const |
| 422 | { |
| 423 | return p_DelegateOptionsImpl->p_DebugCallbackFunc; |
| 424 | } |
| 425 | |
| 426 | void DelegateOptions::SetInternalProfilingParams(bool internalProfilingState, |
| 427 | const armnn::ProfilingDetailsMethod& internalProfilingDetail) |
| 428 | { |
| 429 | p_DelegateOptionsImpl->m_InternalProfilingEnabled = internalProfilingState; |
| 430 | p_DelegateOptionsImpl->p_InternalProfilingDetail = internalProfilingDetail; |
| 431 | } |
| 432 | |
| 433 | bool DelegateOptions::GetInternalProfilingState() const |
| 434 | { |
| 435 | return p_DelegateOptionsImpl->m_InternalProfilingEnabled; |
| 436 | } |
| 437 | |
| 438 | const armnn::ProfilingDetailsMethod& DelegateOptions::GetInternalProfilingDetail() const |
| 439 | { |
| 440 | return p_DelegateOptionsImpl->p_InternalProfilingDetail; |
| 441 | } |
| 442 | |
| 443 | void DelegateOptions::SetSerializeToDot(const std::string& serializeToDotFile) |
| 444 | { |
| 445 | p_DelegateOptionsImpl->m_SerializeToDot = serializeToDotFile; |
| 446 | } |
| 447 | |
| 448 | const std::string& DelegateOptions::GetSerializeToDot() const |
| 449 | { |
| 450 | return p_DelegateOptionsImpl->m_SerializeToDot; |
| 451 | } |
| 452 | |
| 453 | void DelegateOptions::SetRuntimeOptions(const armnn::IRuntime::CreationOptions& runtimeOptions) |
| 454 | { |
| 455 | p_DelegateOptionsImpl->p_RuntimeOptions = runtimeOptions; |
| 456 | } |
| 457 | |
| 458 | const armnn::IRuntime::CreationOptions& DelegateOptions::GetRuntimeOptions() |
| 459 | { |
| 460 | return p_DelegateOptionsImpl->p_RuntimeOptions; |
| 461 | } |
| 462 | |
| 463 | void DelegateOptions::DisableTfLiteRuntimeFallback(bool fallbackState) |
| 464 | { |
| 465 | p_DelegateOptionsImpl->m_DisableTfLiteRuntimeFallback = fallbackState; |
| 466 | } |
| 467 | |
| 468 | bool DelegateOptions::TfLiteRuntimeFallbackDisabled() |
| 469 | { |
| 470 | return p_DelegateOptionsImpl->m_DisableTfLiteRuntimeFallback; |
| 471 | } |
| 472 | |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 473 | } // namespace armnnDelegate |