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