Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include <armnn/ArmNN.hpp> |
Jan Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 9 | #include <armnn/Logging.hpp> |
| 10 | #include <armnn/Optional.hpp> |
Jim Flynn | 2776183 | 2022-03-20 21:52:17 +0000 | [diff] [blame] | 11 | |
| 12 | #include <client/include/ProfilingOptions.hpp> |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 13 | |
| 14 | #include <set> |
| 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
| 18 | namespace armnnDelegate |
| 19 | { |
| 20 | |
| 21 | class DelegateOptions |
| 22 | { |
| 23 | public: |
Jan Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 24 | DelegateOptions(armnn::Compute computeDevice, |
| 25 | const std::vector<armnn::BackendOptions>& backendOptions = {}, |
| 26 | armnn::Optional<armnn::LogSeverity> logSeverityLevel = armnn::EmptyOptional()); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 27 | |
Sadik Armagan | 4189cc5 | 2020-11-11 18:01:48 +0000 | [diff] [blame] | 28 | DelegateOptions(const std::vector<armnn::BackendId>& backends, |
Jan Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 29 | const std::vector<armnn::BackendOptions>& backendOptions = {}, |
| 30 | armnn::Optional<armnn::LogSeverity> logSeverityLevel = armnn::EmptyOptional()); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 31 | |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 32 | DelegateOptions(armnn::Compute computeDevice, |
| 33 | const armnn::OptimizerOptions& optimizerOptions, |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 34 | const armnn::Optional<armnn::LogSeverity>& logSeverityLevel = armnn::EmptyOptional(), |
| 35 | const armnn::Optional<armnn::DebugCallbackFunction>& func = armnn::EmptyOptional()); |
| 36 | |
| 37 | DelegateOptions(const std::vector<armnn::BackendId>& backends, |
| 38 | const armnn::OptimizerOptions& optimizerOptions, |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 39 | const armnn::Optional<armnn::LogSeverity>& logSeverityLevel = armnn::EmptyOptional(), |
| 40 | const armnn::Optional<armnn::DebugCallbackFunction>& func = armnn::EmptyOptional()); |
| 41 | |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * This constructor processes delegate options in form of command line arguments. |
| 45 | * It works in conjunction with the TfLite external delegate plugin. |
| 46 | * |
| 47 | * Available options: |
| 48 | * |
| 49 | * Option key: "backends" \n |
| 50 | * Possible values: ["EthosNPU"/"GpuAcc"/"CpuAcc"/"CpuRef"] \n |
| 51 | * Descriptions: A comma separated list without whitespaces of |
| 52 | * backends which should be used for execution. Falls |
| 53 | * back to next backend in list if previous doesn't |
| 54 | * provide support for operation. e.g. "GpuAcc,CpuAcc" |
| 55 | * |
| 56 | * Option key: "dynamic-backends-path" \n |
| 57 | * Possible values: [filenameString] \n |
| 58 | * Descriptions: This is the directory that will be searched for any dynamic backends. |
| 59 | * |
| 60 | * Option key: "logging-severity" \n |
| 61 | * Possible values: ["trace"/"debug"/"info"/"warning"/"error"/"fatal"] \n |
| 62 | * Description: Sets the logging severity level for ArmNN. Logging |
| 63 | * is turned off if this option is not provided. |
| 64 | * |
| 65 | * Option key: "gpu-tuning-level" \n |
| 66 | * Possible values: ["0"/"1"/"2"/"3"] \n |
| 67 | * Description: 0=UseOnly(default), 1=RapidTuning, 2=NormalTuning, |
| 68 | * 3=ExhaustiveTuning. Requires option gpu-tuning-file. |
| 69 | * 1,2 and 3 will create a tuning-file, 0 will apply the |
| 70 | * tunings from an existing file |
| 71 | * |
| 72 | * Option key: "gpu-mlgo-tuning-file" \n |
| 73 | * Possible values: [filenameString] \n |
| 74 | * Description: File name for the MLGO tuning file |
| 75 | * |
| 76 | * Option key: "gpu-tuning-file" \n |
| 77 | * Possible values: [filenameString] \n |
| 78 | * Description: File name for the tuning file. |
| 79 | * |
| 80 | * Option key: "gpu-enable-profiling" \n |
| 81 | * Possible values: ["true"/"false"] \n |
| 82 | * Description: Enables GPU profiling |
| 83 | * |
| 84 | * Option key: "gpu-kernel-profiling-enabled" \n |
| 85 | * Possible values: ["true"/"false"] \n |
| 86 | * Description: Enables GPU kernel profiling |
| 87 | * |
| 88 | * Option key: "save-cached-network" \n |
| 89 | * Possible values: ["true"/"false"] \n |
| 90 | * Description: Enables saving of the cached network to a file, |
| 91 | * specified with the cached-network-filepath option |
| 92 | * |
| 93 | * Option key: "cached-network-filepath" \n |
| 94 | * Possible values: [filenameString] \n |
| 95 | * Description: If non-empty, the given file will be used to load/save the cached network. |
| 96 | * If save-cached-network is given then the cached network will be saved to the given file. |
| 97 | * To save the cached network a file must already exist. |
| 98 | * If save-cached-network is not given then the cached network will be loaded from the given file. |
| 99 | * This will remove initial compilation time of kernels and speed up the first execution. |
| 100 | * |
| 101 | * Option key: "enable-fast-math" \n |
| 102 | * Possible values: ["true"/"false"] \n |
| 103 | * Description: Enables fast_math options in backends that support it |
| 104 | * |
| 105 | * Option key: "number-of-threads" \n |
| 106 | * Possible values: ["1"-"64"] \n |
| 107 | * Description: Assign the number of threads used by the CpuAcc backend. |
| 108 | * Default is set to 0 (Backend will decide number of threads to use). |
| 109 | * |
| 110 | * Option key: "reduce-fp32-to-fp16" \n |
| 111 | * Possible values: ["true"/"false"] \n |
| 112 | * Description: Reduce Fp32 data to Fp16 for faster processing |
| 113 | * |
| 114 | * Option key: "reduce-fp32-to-bf16" \n |
| 115 | * Possible values: ["true"/"false"] \n |
| 116 | * Description: Reduce Fp32 data to Bf16 for faster processing |
| 117 | * |
| 118 | * Option key: "debug-data" \n |
| 119 | * Possible values: ["true"/"false"] \n |
| 120 | * Description: Add debug data for easier troubleshooting |
| 121 | * |
| 122 | * Option key: "memory-import" \n |
| 123 | * Possible values: ["true"/"false"] \n |
| 124 | * Description: Enable memory import |
| 125 | * |
| 126 | * Option key: "enable-internal-profiling" \n |
| 127 | * Possible values: ["true"/"false"] \n |
| 128 | * Description: Enable the internal profiling feature. |
| 129 | * |
| 130 | * Option key: "internal-profiling-detail" \n |
| 131 | * Possible values: [1/2] \n |
| 132 | * Description: Set the detail on the internal profiling. 1 = DetailsWithEvents, 2 = DetailsOnly. |
| 133 | * |
| 134 | * Option key: "enable-external-profiling" \n |
| 135 | * Possible values: ["true"/"false"] \n |
| 136 | * Description: Enable the external profiling feature. |
| 137 | * |
| 138 | * Option key: "timeline-profiling" \n |
| 139 | * Possible values: ["true"/"false"] \n |
| 140 | * Description: Indicates whether external timeline profiling is enabled or not. |
| 141 | * |
| 142 | * Option key: "outgoing-capture-file" \n |
| 143 | * Possible values: [filenameString] \n |
| 144 | * Description: Path to a file in which outgoing timeline profiling messages will be stored. |
| 145 | * |
| 146 | * Option key: "incoming-capture-file" \n |
| 147 | * Possible values: [filenameString] \n |
| 148 | * Description: Path to a file in which incoming timeline profiling messages will be stored. |
| 149 | * |
| 150 | * Option key: "file-only-external-profiling" \n |
| 151 | * Possible values: ["true"/"false"] \n |
| 152 | * Description: Enable profiling output to file only. |
| 153 | * |
| 154 | * Option key: "counter-capture-period" \n |
| 155 | * Possible values: Integer, Default is 10000u |
| 156 | * Description: Value in microseconds of the profiling capture period. \n |
| 157 | * |
| 158 | * Option key: "profiling-file-format" \n |
| 159 | * Possible values: String of ["binary"] \n |
| 160 | * Description: The format of the file used for outputting profiling data. Currently on "binary" is supported. |
| 161 | * |
| 162 | * Option key: "serialize-to-dot" \n |
| 163 | * Possible values: [filenameString] \n |
| 164 | * Description: Serialize the optimized network to the file specified in "dot" format. |
| 165 | * |
Mike Kelly | 80512b0 | 2022-05-16 23:10:42 +0100 | [diff] [blame] | 166 | * Option key: "infer-output-shape" \n |
| 167 | * Possible values: ["true"/"false"] \n |
| 168 | * Description: Infers output tensor shape from input tensor shape and validate where applicable. |
| 169 | * |
| 170 | * Option key: "allow-expanded-dims" \n |
| 171 | * Possible values: ["true"/"false"] \n |
| 172 | * Description: If true will disregard dimensions with a size of 1 when validating tensor shapes but tensor |
| 173 | * sizes must still match. \n |
| 174 | * This is an Experimental parameter that is incompatible with "infer-output-shape". \n |
| 175 | * This parameter may be removed in a later update. |
| 176 | * |
Jan Eilers | f39f8d8 | 2021-10-26 16:57:34 +0100 | [diff] [blame] | 177 | * @param[in] option_keys Delegate option names |
| 178 | * @param[in] options_values Delegate option values |
| 179 | * @param[in] num_options Number of delegate options |
| 180 | * @param[in,out] report_error Error callback function |
| 181 | * |
| 182 | */ |
| 183 | DelegateOptions(char const* const* options_keys, |
| 184 | char const* const* options_values, |
| 185 | size_t num_options, |
| 186 | void (*report_error)(const char*)); |
| 187 | |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 188 | const std::vector<armnn::BackendId>& GetBackends() const { return m_Backends; } |
| 189 | |
| 190 | void SetBackends(const std::vector<armnn::BackendId>& backends) { m_Backends = backends; } |
| 191 | |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame] | 192 | void SetDynamicBackendsPath(const std::string& dynamicBackendsPath) |
| 193 | { |
| 194 | m_RuntimeOptions.m_DynamicBackendsPath = dynamicBackendsPath; |
| 195 | } |
| 196 | const std::string& GetDynamicBackendsPath() const |
| 197 | { |
| 198 | return m_RuntimeOptions.m_DynamicBackendsPath; |
| 199 | } |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 200 | |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame] | 201 | void SetGpuProfilingState(bool gpuProfilingState) |
| 202 | { |
| 203 | m_RuntimeOptions.m_EnableGpuProfiling = gpuProfilingState; |
| 204 | } |
| 205 | bool GetGpuProfilingState() |
| 206 | { |
| 207 | return m_RuntimeOptions.m_EnableGpuProfiling; |
| 208 | } |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 209 | |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame] | 210 | const std::vector<armnn::BackendOptions>& GetBackendOptions() const |
| 211 | { |
| 212 | return m_RuntimeOptions.m_BackendOptions; |
| 213 | } |
Sadik Armagan | 4189cc5 | 2020-11-11 18:01:48 +0000 | [diff] [blame] | 214 | |
Jan Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 215 | /// Appends a backend option to the list of backend options |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame] | 216 | void AddBackendOption(const armnn::BackendOptions& option) |
| 217 | { |
| 218 | m_RuntimeOptions.m_BackendOptions.push_back(option); |
| 219 | } |
Jan Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 220 | |
| 221 | /// Sets the severity level for logging within ArmNN that will be used on creation of the delegate |
| 222 | void SetLoggingSeverity(const armnn::LogSeverity& level) { m_LoggingSeverity = level; } |
| 223 | void SetLoggingSeverity(const std::string& level) { m_LoggingSeverity = armnn::StringToLogLevel(level); } |
| 224 | |
| 225 | /// Returns the severity level for logging within ArmNN |
| 226 | armnn::LogSeverity GetLoggingSeverity() { return m_LoggingSeverity.value(); } |
| 227 | |
| 228 | bool IsLoggingEnabled() { return m_LoggingSeverity.has_value(); } |
| 229 | |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 230 | const armnn::OptimizerOptions& GetOptimizerOptions() const { return m_OptimizerOptions; } |
| 231 | |
Narumol Prangnawarat | 74a3cf5 | 2021-01-29 15:38:54 +0000 | [diff] [blame] | 232 | void SetOptimizerOptions(const armnn::OptimizerOptions& optimizerOptions) { m_OptimizerOptions = optimizerOptions; } |
| 233 | |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 234 | const armnn::Optional<armnn::DebugCallbackFunction>& GetDebugCallbackFunction() const |
| 235 | { return m_DebugCallbackFunc; } |
| 236 | |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 237 | void SetInternalProfilingParams(bool internalProfilingState, |
| 238 | const armnn::ProfilingDetailsMethod& internalProfilingDetail) |
| 239 | { m_InternalProfilingEnabled = internalProfilingState; m_InternalProfilingDetail = internalProfilingDetail; } |
| 240 | |
| 241 | bool GetInternalProfilingState() const { return m_InternalProfilingEnabled; } |
| 242 | const armnn::ProfilingDetailsMethod& GetInternalProfilingDetail() const { return m_InternalProfilingDetail; } |
| 243 | |
| 244 | void SetExternalProfilingParams( |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 245 | const arm::pipe::ProfilingOptions& externalProfilingParams) |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 246 | { m_ProfilingOptions = externalProfilingParams; } |
| 247 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 248 | const arm::pipe::ProfilingOptions& GetExternalProfilingParams() const |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 249 | { return m_ProfilingOptions; } |
| 250 | |
| 251 | void SetSerializeToDot(const std::string& serializeToDotFile) { m_SerializeToDot = serializeToDotFile; } |
| 252 | const std::string& GetSerializeToDot() const { return m_SerializeToDot; } |
| 253 | |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame] | 254 | /// @Note: This might overwrite options that were set with other setter functions of DelegateOptions |
| 255 | void SetRuntimeOptions(const armnn::IRuntime::CreationOptions& runtimeOptions) |
| 256 | { |
| 257 | m_RuntimeOptions = runtimeOptions; |
| 258 | } |
| 259 | |
| 260 | const armnn::IRuntime::CreationOptions& GetRuntimeOptions() |
| 261 | { |
| 262 | return m_RuntimeOptions; |
| 263 | } |
| 264 | |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 265 | private: |
| 266 | /// Which backend to run Delegate on. |
| 267 | /// Examples of possible values are: CpuRef, CpuAcc, GpuAcc. |
| 268 | /// CpuRef as default. |
| 269 | std::vector<armnn::BackendId> m_Backends = { armnn::Compute::CpuRef }; |
Sadik Armagan | 4189cc5 | 2020-11-11 18:01:48 +0000 | [diff] [blame] | 270 | |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame] | 271 | /// Creation options for the ArmNN runtime |
| 272 | /// Contains options for global settings that are valid for the whole lifetime of ArmNN |
| 273 | /// i.e. BackendOptions, DynamicBackendPath, ExternalProfilingOptions and more |
| 274 | armnn::IRuntime::CreationOptions m_RuntimeOptions; |
Jan Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 275 | |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame] | 276 | /// Options for the optimization step for the network |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 277 | armnn::OptimizerOptions m_OptimizerOptions; |
| 278 | |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 279 | /// External profiling options. |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 280 | arm::pipe::ProfilingOptions m_ProfilingOptions; |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 281 | |
| 282 | /// Internal profiling options. |
| 283 | /// Indicates whether internal profiling is enabled or not. |
| 284 | bool m_InternalProfilingEnabled = false; |
| 285 | /// Sets the level of detail output by the profiling. Options are DetailsWithEvents = 1 and DetailsOnly = 2 |
| 286 | armnn::ProfilingDetailsMethod m_InternalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents; |
| 287 | |
Jan Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 288 | /// Severity level for logging within ArmNN that will be used on creation of the delegate |
| 289 | armnn::Optional<armnn::LogSeverity> m_LoggingSeverity; |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 290 | |
| 291 | /// A callback function to debug layers performing custom computations on intermediate tensors. |
| 292 | /// If a function is not registered, and debug is enabled in OptimizerOptions, |
| 293 | /// debug will print information of the intermediate tensors. |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 294 | armnn::Optional<armnn::DebugCallbackFunction> m_DebugCallbackFunc; |
| 295 | |
| 296 | /// If not empty then the optimized model will be serialized to a file with this file name in "dot" format. |
| 297 | std::string m_SerializeToDot = ""; |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | } // namespace armnnDelegate |