blob: 5bc2e59070c041d7ffd3a23693af265cbb90bf40 [file] [log] [blame]
Sadik Armagan3c24f432020-10-19 17:35:30 +01001//
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 Eilers2cd18472020-12-15 10:42:38 +00009#include <armnn/Logging.hpp>
10#include <armnn/Optional.hpp>
Sadik Armagan3c24f432020-10-19 17:35:30 +010011
12#include <set>
13#include <string>
14#include <vector>
15
16namespace armnnDelegate
17{
18
19class DelegateOptions
20{
21public:
Jan Eilers2cd18472020-12-15 10:42:38 +000022 DelegateOptions(armnn::Compute computeDevice,
23 const std::vector<armnn::BackendOptions>& backendOptions = {},
24 armnn::Optional<armnn::LogSeverity> logSeverityLevel = armnn::EmptyOptional());
Sadik Armagan3c24f432020-10-19 17:35:30 +010025
Sadik Armagan4189cc52020-11-11 18:01:48 +000026 DelegateOptions(const std::vector<armnn::BackendId>& backends,
Jan Eilers2cd18472020-12-15 10:42:38 +000027 const std::vector<armnn::BackendOptions>& backendOptions = {},
28 armnn::Optional<armnn::LogSeverity> logSeverityLevel = armnn::EmptyOptional());
Sadik Armagan3c24f432020-10-19 17:35:30 +010029
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +000030 DelegateOptions(armnn::Compute computeDevice,
31 const armnn::OptimizerOptions& optimizerOptions,
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +000032 const armnn::Optional<armnn::LogSeverity>& logSeverityLevel = armnn::EmptyOptional(),
33 const armnn::Optional<armnn::DebugCallbackFunction>& func = armnn::EmptyOptional());
34
35 DelegateOptions(const std::vector<armnn::BackendId>& backends,
36 const armnn::OptimizerOptions& optimizerOptions,
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +000037 const armnn::Optional<armnn::LogSeverity>& logSeverityLevel = armnn::EmptyOptional(),
38 const armnn::Optional<armnn::DebugCallbackFunction>& func = armnn::EmptyOptional());
39
Jan Eilersf39f8d82021-10-26 16:57:34 +010040
41 /**
42 * This constructor processes delegate options in form of command line arguments.
43 * It works in conjunction with the TfLite external delegate plugin.
44 *
45 * Available options:
46 *
47 * Option key: "backends" \n
48 * Possible values: ["EthosNPU"/"GpuAcc"/"CpuAcc"/"CpuRef"] \n
49 * Descriptions: A comma separated list without whitespaces of
50 * backends which should be used for execution. Falls
51 * back to next backend in list if previous doesn't
52 * provide support for operation. e.g. "GpuAcc,CpuAcc"
53 *
54 * Option key: "dynamic-backends-path" \n
55 * Possible values: [filenameString] \n
56 * Descriptions: This is the directory that will be searched for any dynamic backends.
57 *
58 * Option key: "logging-severity" \n
59 * Possible values: ["trace"/"debug"/"info"/"warning"/"error"/"fatal"] \n
60 * Description: Sets the logging severity level for ArmNN. Logging
61 * is turned off if this option is not provided.
62 *
63 * Option key: "gpu-tuning-level" \n
64 * Possible values: ["0"/"1"/"2"/"3"] \n
65 * Description: 0=UseOnly(default), 1=RapidTuning, 2=NormalTuning,
66 * 3=ExhaustiveTuning. Requires option gpu-tuning-file.
67 * 1,2 and 3 will create a tuning-file, 0 will apply the
68 * tunings from an existing file
69 *
70 * Option key: "gpu-mlgo-tuning-file" \n
71 * Possible values: [filenameString] \n
72 * Description: File name for the MLGO tuning file
73 *
74 * Option key: "gpu-tuning-file" \n
75 * Possible values: [filenameString] \n
76 * Description: File name for the tuning file.
77 *
78 * Option key: "gpu-enable-profiling" \n
79 * Possible values: ["true"/"false"] \n
80 * Description: Enables GPU profiling
81 *
82 * Option key: "gpu-kernel-profiling-enabled" \n
83 * Possible values: ["true"/"false"] \n
84 * Description: Enables GPU kernel profiling
85 *
86 * Option key: "save-cached-network" \n
87 * Possible values: ["true"/"false"] \n
88 * Description: Enables saving of the cached network to a file,
89 * specified with the cached-network-filepath option
90 *
91 * Option key: "cached-network-filepath" \n
92 * Possible values: [filenameString] \n
93 * Description: If non-empty, the given file will be used to load/save the cached network.
94 * If save-cached-network is given then the cached network will be saved to the given file.
95 * To save the cached network a file must already exist.
96 * If save-cached-network is not given then the cached network will be loaded from the given file.
97 * This will remove initial compilation time of kernels and speed up the first execution.
98 *
99 * Option key: "enable-fast-math" \n
100 * Possible values: ["true"/"false"] \n
101 * Description: Enables fast_math options in backends that support it
102 *
103 * Option key: "number-of-threads" \n
104 * Possible values: ["1"-"64"] \n
105 * Description: Assign the number of threads used by the CpuAcc backend.
106 * Default is set to 0 (Backend will decide number of threads to use).
107 *
108 * Option key: "reduce-fp32-to-fp16" \n
109 * Possible values: ["true"/"false"] \n
110 * Description: Reduce Fp32 data to Fp16 for faster processing
111 *
112 * Option key: "reduce-fp32-to-bf16" \n
113 * Possible values: ["true"/"false"] \n
114 * Description: Reduce Fp32 data to Bf16 for faster processing
115 *
116 * Option key: "debug-data" \n
117 * Possible values: ["true"/"false"] \n
118 * Description: Add debug data for easier troubleshooting
119 *
120 * Option key: "memory-import" \n
121 * Possible values: ["true"/"false"] \n
122 * Description: Enable memory import
123 *
124 * Option key: "enable-internal-profiling" \n
125 * Possible values: ["true"/"false"] \n
126 * Description: Enable the internal profiling feature.
127 *
128 * Option key: "internal-profiling-detail" \n
129 * Possible values: [1/2] \n
130 * Description: Set the detail on the internal profiling. 1 = DetailsWithEvents, 2 = DetailsOnly.
131 *
132 * Option key: "enable-external-profiling" \n
133 * Possible values: ["true"/"false"] \n
134 * Description: Enable the external profiling feature.
135 *
136 * Option key: "timeline-profiling" \n
137 * Possible values: ["true"/"false"] \n
138 * Description: Indicates whether external timeline profiling is enabled or not.
139 *
140 * Option key: "outgoing-capture-file" \n
141 * Possible values: [filenameString] \n
142 * Description: Path to a file in which outgoing timeline profiling messages will be stored.
143 *
144 * Option key: "incoming-capture-file" \n
145 * Possible values: [filenameString] \n
146 * Description: Path to a file in which incoming timeline profiling messages will be stored.
147 *
148 * Option key: "file-only-external-profiling" \n
149 * Possible values: ["true"/"false"] \n
150 * Description: Enable profiling output to file only.
151 *
152 * Option key: "counter-capture-period" \n
153 * Possible values: Integer, Default is 10000u
154 * Description: Value in microseconds of the profiling capture period. \n
155 *
156 * Option key: "profiling-file-format" \n
157 * Possible values: String of ["binary"] \n
158 * Description: The format of the file used for outputting profiling data. Currently on "binary" is supported.
159 *
160 * Option key: "serialize-to-dot" \n
161 * Possible values: [filenameString] \n
162 * Description: Serialize the optimized network to the file specified in "dot" format.
163 *
164 * @param[in] option_keys Delegate option names
165 * @param[in] options_values Delegate option values
166 * @param[in] num_options Number of delegate options
167 * @param[in,out] report_error Error callback function
168 *
169 */
170 DelegateOptions(char const* const* options_keys,
171 char const* const* options_values,
172 size_t num_options,
173 void (*report_error)(const char*));
174
Sadik Armagan3c24f432020-10-19 17:35:30 +0100175 const std::vector<armnn::BackendId>& GetBackends() const { return m_Backends; }
176
177 void SetBackends(const std::vector<armnn::BackendId>& backends) { m_Backends = backends; }
178
Jan Eilersb1c62f12021-10-26 14:56:47 +0100179 void SetDynamicBackendsPath(const std::string& dynamicBackendsPath)
180 {
181 m_RuntimeOptions.m_DynamicBackendsPath = dynamicBackendsPath;
182 }
183 const std::string& GetDynamicBackendsPath() const
184 {
185 return m_RuntimeOptions.m_DynamicBackendsPath;
186 }
Colm Donelan3e32a872021-10-04 22:55:37 +0100187
Jan Eilersb1c62f12021-10-26 14:56:47 +0100188 void SetGpuProfilingState(bool gpuProfilingState)
189 {
190 m_RuntimeOptions.m_EnableGpuProfiling = gpuProfilingState;
191 }
192 bool GetGpuProfilingState()
193 {
194 return m_RuntimeOptions.m_EnableGpuProfiling;
195 }
Colm Donelan3e32a872021-10-04 22:55:37 +0100196
Jan Eilersb1c62f12021-10-26 14:56:47 +0100197 const std::vector<armnn::BackendOptions>& GetBackendOptions() const
198 {
199 return m_RuntimeOptions.m_BackendOptions;
200 }
Sadik Armagan4189cc52020-11-11 18:01:48 +0000201
Jan Eilers2cd18472020-12-15 10:42:38 +0000202 /// Appends a backend option to the list of backend options
Jan Eilersb1c62f12021-10-26 14:56:47 +0100203 void AddBackendOption(const armnn::BackendOptions& option)
204 {
205 m_RuntimeOptions.m_BackendOptions.push_back(option);
206 }
Jan Eilers2cd18472020-12-15 10:42:38 +0000207
208 /// Sets the severity level for logging within ArmNN that will be used on creation of the delegate
209 void SetLoggingSeverity(const armnn::LogSeverity& level) { m_LoggingSeverity = level; }
210 void SetLoggingSeverity(const std::string& level) { m_LoggingSeverity = armnn::StringToLogLevel(level); }
211
212 /// Returns the severity level for logging within ArmNN
213 armnn::LogSeverity GetLoggingSeverity() { return m_LoggingSeverity.value(); }
214
215 bool IsLoggingEnabled() { return m_LoggingSeverity.has_value(); }
216
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000217 const armnn::OptimizerOptions& GetOptimizerOptions() const { return m_OptimizerOptions; }
218
Narumol Prangnawarat74a3cf52021-01-29 15:38:54 +0000219 void SetOptimizerOptions(const armnn::OptimizerOptions& optimizerOptions) { m_OptimizerOptions = optimizerOptions; }
220
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000221 const armnn::Optional<armnn::DebugCallbackFunction>& GetDebugCallbackFunction() const
222 { return m_DebugCallbackFunc; }
223
Colm Donelan3e32a872021-10-04 22:55:37 +0100224 void SetInternalProfilingParams(bool internalProfilingState,
225 const armnn::ProfilingDetailsMethod& internalProfilingDetail)
226 { m_InternalProfilingEnabled = internalProfilingState; m_InternalProfilingDetail = internalProfilingDetail; }
227
228 bool GetInternalProfilingState() const { return m_InternalProfilingEnabled; }
229 const armnn::ProfilingDetailsMethod& GetInternalProfilingDetail() const { return m_InternalProfilingDetail; }
230
231 void SetExternalProfilingParams(
232 const armnn::IRuntime::CreationOptions::ExternalProfilingOptions& externalProfilingParams)
233 { m_ProfilingOptions = externalProfilingParams; }
234
235 const armnn::IRuntime::CreationOptions::ExternalProfilingOptions& GetExternalProfilingParams() const
236 { return m_ProfilingOptions; }
237
238 void SetSerializeToDot(const std::string& serializeToDotFile) { m_SerializeToDot = serializeToDotFile; }
239 const std::string& GetSerializeToDot() const { return m_SerializeToDot; }
240
Jan Eilersb1c62f12021-10-26 14:56:47 +0100241 /// @Note: This might overwrite options that were set with other setter functions of DelegateOptions
242 void SetRuntimeOptions(const armnn::IRuntime::CreationOptions& runtimeOptions)
243 {
244 m_RuntimeOptions = runtimeOptions;
245 }
246
247 const armnn::IRuntime::CreationOptions& GetRuntimeOptions()
248 {
249 return m_RuntimeOptions;
250 }
251
Sadik Armagan3c24f432020-10-19 17:35:30 +0100252private:
253 /// Which backend to run Delegate on.
254 /// Examples of possible values are: CpuRef, CpuAcc, GpuAcc.
255 /// CpuRef as default.
256 std::vector<armnn::BackendId> m_Backends = { armnn::Compute::CpuRef };
Sadik Armagan4189cc52020-11-11 18:01:48 +0000257
Jan Eilersb1c62f12021-10-26 14:56:47 +0100258 /// Creation options for the ArmNN runtime
259 /// Contains options for global settings that are valid for the whole lifetime of ArmNN
260 /// i.e. BackendOptions, DynamicBackendPath, ExternalProfilingOptions and more
261 armnn::IRuntime::CreationOptions m_RuntimeOptions;
Jan Eilers2cd18472020-12-15 10:42:38 +0000262
Jan Eilersb1c62f12021-10-26 14:56:47 +0100263 /// Options for the optimization step for the network
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000264 armnn::OptimizerOptions m_OptimizerOptions;
265
Colm Donelan3e32a872021-10-04 22:55:37 +0100266 /// External profiling options.
Colm Donelan3e32a872021-10-04 22:55:37 +0100267 armnn::IRuntime::CreationOptions::ExternalProfilingOptions m_ProfilingOptions;
268
269 /// Internal profiling options.
270 /// Indicates whether internal profiling is enabled or not.
271 bool m_InternalProfilingEnabled = false;
272 /// Sets the level of detail output by the profiling. Options are DetailsWithEvents = 1 and DetailsOnly = 2
273 armnn::ProfilingDetailsMethod m_InternalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents;
274
Jan Eilers2cd18472020-12-15 10:42:38 +0000275 /// Severity level for logging within ArmNN that will be used on creation of the delegate
276 armnn::Optional<armnn::LogSeverity> m_LoggingSeverity;
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000277
278 /// A callback function to debug layers performing custom computations on intermediate tensors.
279 /// If a function is not registered, and debug is enabled in OptimizerOptions,
280 /// debug will print information of the intermediate tensors.
Colm Donelan3e32a872021-10-04 22:55:37 +0100281 armnn::Optional<armnn::DebugCallbackFunction> m_DebugCallbackFunc;
282
283 /// If not empty then the optimized model will be serialized to a file with this file name in "dot" format.
284 std::string m_SerializeToDot = "";
Sadik Armagan3c24f432020-10-19 17:35:30 +0100285};
286
287} // namespace armnnDelegate