blob: 24a2e5c597117dbe3587720b6a4eabc197491b5e [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
Jan Eilersb1c62f12021-10-26 14:56:47 +010044 void SetDynamicBackendsPath(const std::string& dynamicBackendsPath)
45 {
46 m_RuntimeOptions.m_DynamicBackendsPath = dynamicBackendsPath;
47 }
48 const std::string& GetDynamicBackendsPath() const
49 {
50 return m_RuntimeOptions.m_DynamicBackendsPath;
51 }
Colm Donelan3e32a872021-10-04 22:55:37 +010052
Jan Eilersb1c62f12021-10-26 14:56:47 +010053 void SetGpuProfilingState(bool gpuProfilingState)
54 {
55 m_RuntimeOptions.m_EnableGpuProfiling = gpuProfilingState;
56 }
57 bool GetGpuProfilingState()
58 {
59 return m_RuntimeOptions.m_EnableGpuProfiling;
60 }
Colm Donelan3e32a872021-10-04 22:55:37 +010061
Jan Eilersb1c62f12021-10-26 14:56:47 +010062 const std::vector<armnn::BackendOptions>& GetBackendOptions() const
63 {
64 return m_RuntimeOptions.m_BackendOptions;
65 }
Sadik Armagan4189cc52020-11-11 18:01:48 +000066
Jan Eilers2cd18472020-12-15 10:42:38 +000067 /// Appends a backend option to the list of backend options
Jan Eilersb1c62f12021-10-26 14:56:47 +010068 void AddBackendOption(const armnn::BackendOptions& option)
69 {
70 m_RuntimeOptions.m_BackendOptions.push_back(option);
71 }
Jan Eilers2cd18472020-12-15 10:42:38 +000072
73 /// Sets the severity level for logging within ArmNN that will be used on creation of the delegate
74 void SetLoggingSeverity(const armnn::LogSeverity& level) { m_LoggingSeverity = level; }
75 void SetLoggingSeverity(const std::string& level) { m_LoggingSeverity = armnn::StringToLogLevel(level); }
76
77 /// Returns the severity level for logging within ArmNN
78 armnn::LogSeverity GetLoggingSeverity() { return m_LoggingSeverity.value(); }
79
80 bool IsLoggingEnabled() { return m_LoggingSeverity.has_value(); }
81
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +000082 const armnn::OptimizerOptions& GetOptimizerOptions() const { return m_OptimizerOptions; }
83
Narumol Prangnawarat74a3cf52021-01-29 15:38:54 +000084 void SetOptimizerOptions(const armnn::OptimizerOptions& optimizerOptions) { m_OptimizerOptions = optimizerOptions; }
85
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +000086 const armnn::Optional<armnn::DebugCallbackFunction>& GetDebugCallbackFunction() const
87 { return m_DebugCallbackFunc; }
88
Colm Donelan3e32a872021-10-04 22:55:37 +010089 void SetInternalProfilingParams(bool internalProfilingState,
90 const armnn::ProfilingDetailsMethod& internalProfilingDetail)
91 { m_InternalProfilingEnabled = internalProfilingState; m_InternalProfilingDetail = internalProfilingDetail; }
92
93 bool GetInternalProfilingState() const { return m_InternalProfilingEnabled; }
94 const armnn::ProfilingDetailsMethod& GetInternalProfilingDetail() const { return m_InternalProfilingDetail; }
95
96 void SetExternalProfilingParams(
97 const armnn::IRuntime::CreationOptions::ExternalProfilingOptions& externalProfilingParams)
98 { m_ProfilingOptions = externalProfilingParams; }
99
100 const armnn::IRuntime::CreationOptions::ExternalProfilingOptions& GetExternalProfilingParams() const
101 { return m_ProfilingOptions; }
102
103 void SetSerializeToDot(const std::string& serializeToDotFile) { m_SerializeToDot = serializeToDotFile; }
104 const std::string& GetSerializeToDot() const { return m_SerializeToDot; }
105
Jan Eilersb1c62f12021-10-26 14:56:47 +0100106 /// @Note: This might overwrite options that were set with other setter functions of DelegateOptions
107 void SetRuntimeOptions(const armnn::IRuntime::CreationOptions& runtimeOptions)
108 {
109 m_RuntimeOptions = runtimeOptions;
110 }
111
112 const armnn::IRuntime::CreationOptions& GetRuntimeOptions()
113 {
114 return m_RuntimeOptions;
115 }
116
Sadik Armagan3c24f432020-10-19 17:35:30 +0100117private:
118 /// Which backend to run Delegate on.
119 /// Examples of possible values are: CpuRef, CpuAcc, GpuAcc.
120 /// CpuRef as default.
121 std::vector<armnn::BackendId> m_Backends = { armnn::Compute::CpuRef };
Sadik Armagan4189cc52020-11-11 18:01:48 +0000122
Jan Eilersb1c62f12021-10-26 14:56:47 +0100123 /// Creation options for the ArmNN runtime
124 /// Contains options for global settings that are valid for the whole lifetime of ArmNN
125 /// i.e. BackendOptions, DynamicBackendPath, ExternalProfilingOptions and more
126 armnn::IRuntime::CreationOptions m_RuntimeOptions;
Jan Eilers2cd18472020-12-15 10:42:38 +0000127
Jan Eilersb1c62f12021-10-26 14:56:47 +0100128 /// Options for the optimization step for the network
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000129 armnn::OptimizerOptions m_OptimizerOptions;
130
Colm Donelan3e32a872021-10-04 22:55:37 +0100131 /// External profiling options.
Colm Donelan3e32a872021-10-04 22:55:37 +0100132 armnn::IRuntime::CreationOptions::ExternalProfilingOptions m_ProfilingOptions;
133
134 /// Internal profiling options.
135 /// Indicates whether internal profiling is enabled or not.
136 bool m_InternalProfilingEnabled = false;
137 /// Sets the level of detail output by the profiling. Options are DetailsWithEvents = 1 and DetailsOnly = 2
138 armnn::ProfilingDetailsMethod m_InternalProfilingDetail = armnn::ProfilingDetailsMethod::DetailsWithEvents;
139
Jan Eilers2cd18472020-12-15 10:42:38 +0000140 /// Severity level for logging within ArmNN that will be used on creation of the delegate
141 armnn::Optional<armnn::LogSeverity> m_LoggingSeverity;
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000142
143 /// A callback function to debug layers performing custom computations on intermediate tensors.
144 /// If a function is not registered, and debug is enabled in OptimizerOptions,
145 /// debug will print information of the intermediate tensors.
Colm Donelan3e32a872021-10-04 22:55:37 +0100146 armnn::Optional<armnn::DebugCallbackFunction> m_DebugCallbackFunc;
147
148 /// If not empty then the optimized model will be serialized to a file with this file name in "dot" format.
149 std::string m_SerializeToDot = "";
Sadik Armagan3c24f432020-10-19 17:35:30 +0100150};
151
152} // namespace armnnDelegate