blob: b8847440ed847d2a7086104c4df8f5a7f8f9d6db [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
Sadik Armagan3c24f432020-10-19 17:35:30 +010040 const std::vector<armnn::BackendId>& GetBackends() const { return m_Backends; }
41
42 void SetBackends(const std::vector<armnn::BackendId>& backends) { m_Backends = backends; }
43
Colm Donelan3e32a872021-10-04 22:55:37 +010044 void SetDynamicBackendsPath(const std::string& dynamicBackendsPath) { m_DynamicBackendsPath = dynamicBackendsPath; }
45 const std::string& GetDynamicBackendsPath() const { return m_DynamicBackendsPath; }
46
47 void SetGpuProfilingState(bool gpuProfilingState) { m_EnableGpuProfiling = gpuProfilingState; }
48 bool GetGpuProfilingState() { return m_EnableGpuProfiling; }
49
Sadik Armagan4189cc52020-11-11 18:01:48 +000050 const std::vector<armnn::BackendOptions>& GetBackendOptions() const { return m_BackendOptions; }
51
Jan Eilers2cd18472020-12-15 10:42:38 +000052 /// Appends a backend option to the list of backend options
53 void AddBackendOption(const armnn::BackendOptions& option) { m_BackendOptions.push_back(option); }
54
55 /// Sets the severity level for logging within ArmNN that will be used on creation of the delegate
56 void SetLoggingSeverity(const armnn::LogSeverity& level) { m_LoggingSeverity = level; }
57 void SetLoggingSeverity(const std::string& level) { m_LoggingSeverity = armnn::StringToLogLevel(level); }
58
59 /// Returns the severity level for logging within ArmNN
60 armnn::LogSeverity GetLoggingSeverity() { return m_LoggingSeverity.value(); }
61
62 bool IsLoggingEnabled() { return m_LoggingSeverity.has_value(); }
63
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +000064 const armnn::OptimizerOptions& GetOptimizerOptions() const { return m_OptimizerOptions; }
65
Narumol Prangnawarat74a3cf52021-01-29 15:38:54 +000066 void SetOptimizerOptions(const armnn::OptimizerOptions& optimizerOptions) { m_OptimizerOptions = optimizerOptions; }
67
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +000068 const armnn::Optional<armnn::DebugCallbackFunction>& GetDebugCallbackFunction() const
69 { return m_DebugCallbackFunc; }
70
Colm Donelan3e32a872021-10-04 22:55:37 +010071 void SetInternalProfilingParams(bool internalProfilingState,
72 const armnn::ProfilingDetailsMethod& internalProfilingDetail)
73 { m_InternalProfilingEnabled = internalProfilingState; m_InternalProfilingDetail = internalProfilingDetail; }
74
75 bool GetInternalProfilingState() const { return m_InternalProfilingEnabled; }
76 const armnn::ProfilingDetailsMethod& GetInternalProfilingDetail() const { return m_InternalProfilingDetail; }
77
78 void SetExternalProfilingParams(
79 const armnn::IRuntime::CreationOptions::ExternalProfilingOptions& externalProfilingParams)
80 { m_ProfilingOptions = externalProfilingParams; }
81
82 const armnn::IRuntime::CreationOptions::ExternalProfilingOptions& GetExternalProfilingParams() const
83 { return m_ProfilingOptions; }
84
85 void SetSerializeToDot(const std::string& serializeToDotFile) { m_SerializeToDot = serializeToDotFile; }
86 const std::string& GetSerializeToDot() const { return m_SerializeToDot; }
87
Sadik Armagan3c24f432020-10-19 17:35:30 +010088private:
89 /// Which backend to run Delegate on.
90 /// Examples of possible values are: CpuRef, CpuAcc, GpuAcc.
91 /// CpuRef as default.
92 std::vector<armnn::BackendId> m_Backends = { armnn::Compute::CpuRef };
Sadik Armagan4189cc52020-11-11 18:01:48 +000093
94 /// Pass backend specific options to Delegate
95 ///
96 /// For example, tuning can be enabled on GpuAcc like below
97 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
98 /// m_BackendOptions.emplace_back(
99 /// BackendOptions{"GpuAcc",
100 /// {
101 /// {"TuningLevel", 2},
102 /// {"TuningFile", filename}
103 /// }
104 /// });
105 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
106 /// The following backend options are available:
107 /// GpuAcc:
108 /// "TuningLevel" : int [0..3] (0=UseOnly(default) | 1=RapidTuning | 2=NormalTuning | 3=ExhaustiveTuning)
109 /// "TuningFile" : string [filenameString]
110 /// "KernelProfilingEnabled" : bool [true | false]
111 std::vector<armnn::BackendOptions> m_BackendOptions;
Jan Eilers2cd18472020-12-15 10:42:38 +0000112
Colm Donelan3e32a872021-10-04 22:55:37 +0100113 /// Dynamic backend path.
114 /// This is the directory that will be searched for any dynamic backends.
115 std::string m_DynamicBackendsPath = "";
116
117 /// Enable Gpu Profiling.
118 bool m_EnableGpuProfiling = false;
119
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000120 /// OptimizerOptions
121 /// Reduce Fp32 data to Fp16 for faster processing
122 /// bool m_ReduceFp32ToFp16;
123 /// Add debug data for easier troubleshooting
124 /// bool m_Debug;
125 /// Reduce Fp32 data to Bf16 for faster processing
126 /// bool m_ReduceFp32ToBf16;
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000127 /// Enable Import
128 /// bool m_ImportEnabled;
129 /// Enable Model Options
130 /// ModelOptions m_ModelOptions;
131 armnn::OptimizerOptions m_OptimizerOptions;
132
Colm Donelan3e32a872021-10-04 22:55:37 +0100133 /// External profiling options.
134 /// Indicates whether external profiling is enabled or not.
135 /// bool m_EnableProfiling
136 /// Indicates whether external timeline profiling is enabled or not.
137 /// bool m_TimelineEnabled
138 /// Path to a file in which outgoing timeline profiling messages will be stored.
139 /// std::string m_OutgoingCaptureFile
140 /// Path to a file in which incoming timeline profiling messages will be stored.
141 /// std::string m_IncomingCaptureFile
142 /// Enable profiling output to file only.
143 /// bool m_FileOnly
144 /// The duration at which captured profiling messages will be flushed.
145 /// uint32_t m_CapturePeriod
146 /// The format of the file used for outputting profiling data.
147 /// std::string m_FileFormat
148 armnn::IRuntime::CreationOptions::ExternalProfilingOptions m_ProfilingOptions;
149
150 /// Internal profiling options.
151 /// Indicates whether internal profiling is enabled or not.
152 bool m_InternalProfilingEnabled = false;
153 /// Sets the level of detail output by the profiling. Options are DetailsWithEvents = 1 and DetailsOnly = 2
154 armnn::ProfilingDetailsMethod m_InternalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents;
155
Jan Eilers2cd18472020-12-15 10:42:38 +0000156 /// Severity level for logging within ArmNN that will be used on creation of the delegate
157 armnn::Optional<armnn::LogSeverity> m_LoggingSeverity;
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000158
159 /// A callback function to debug layers performing custom computations on intermediate tensors.
160 /// If a function is not registered, and debug is enabled in OptimizerOptions,
161 /// debug will print information of the intermediate tensors.
Colm Donelan3e32a872021-10-04 22:55:37 +0100162 armnn::Optional<armnn::DebugCallbackFunction> m_DebugCallbackFunc;
163
164 /// If not empty then the optimized model will be serialized to a file with this file name in "dot" format.
165 std::string m_SerializeToDot = "";
Sadik Armagan3c24f432020-10-19 17:35:30 +0100166};
167
168} // namespace armnnDelegate