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> |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 11 | |
| 12 | #include <set> |
| 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
| 16 | namespace armnnDelegate |
| 17 | { |
| 18 | |
| 19 | class DelegateOptions |
| 20 | { |
| 21 | public: |
Jan Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 22 | DelegateOptions(armnn::Compute computeDevice, |
| 23 | const std::vector<armnn::BackendOptions>& backendOptions = {}, |
| 24 | armnn::Optional<armnn::LogSeverity> logSeverityLevel = armnn::EmptyOptional()); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 25 | |
Sadik Armagan | 4189cc5 | 2020-11-11 18:01:48 +0000 | [diff] [blame] | 26 | DelegateOptions(const std::vector<armnn::BackendId>& backends, |
Jan Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 27 | const std::vector<armnn::BackendOptions>& backendOptions = {}, |
| 28 | armnn::Optional<armnn::LogSeverity> logSeverityLevel = armnn::EmptyOptional()); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 29 | |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 30 | DelegateOptions(armnn::Compute computeDevice, |
| 31 | const armnn::OptimizerOptions& optimizerOptions, |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 32 | 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 Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 37 | const armnn::Optional<armnn::LogSeverity>& logSeverityLevel = armnn::EmptyOptional(), |
| 38 | const armnn::Optional<armnn::DebugCallbackFunction>& func = armnn::EmptyOptional()); |
| 39 | |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 40 | 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 Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 44 | 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 Armagan | 4189cc5 | 2020-11-11 18:01:48 +0000 | [diff] [blame] | 50 | const std::vector<armnn::BackendOptions>& GetBackendOptions() const { return m_BackendOptions; } |
| 51 | |
Jan Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 52 | /// 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 Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 64 | const armnn::OptimizerOptions& GetOptimizerOptions() const { return m_OptimizerOptions; } |
| 65 | |
Narumol Prangnawarat | 74a3cf5 | 2021-01-29 15:38:54 +0000 | [diff] [blame] | 66 | void SetOptimizerOptions(const armnn::OptimizerOptions& optimizerOptions) { m_OptimizerOptions = optimizerOptions; } |
| 67 | |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 68 | const armnn::Optional<armnn::DebugCallbackFunction>& GetDebugCallbackFunction() const |
| 69 | { return m_DebugCallbackFunc; } |
| 70 | |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 71 | 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 Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 88 | private: |
| 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 Armagan | 4189cc5 | 2020-11-11 18:01:48 +0000 | [diff] [blame] | 93 | |
| 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 Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 112 | |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 113 | /// 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 Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 120 | /// 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 Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 127 | /// Enable Import |
| 128 | /// bool m_ImportEnabled; |
| 129 | /// Enable Model Options |
| 130 | /// ModelOptions m_ModelOptions; |
| 131 | armnn::OptimizerOptions m_OptimizerOptions; |
| 132 | |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 133 | /// 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 Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 156 | /// Severity level for logging within ArmNN that will be used on creation of the delegate |
| 157 | armnn::Optional<armnn::LogSeverity> m_LoggingSeverity; |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 158 | |
| 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 Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 162 | 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 Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | } // namespace armnnDelegate |