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 | |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame^] | 44 | 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 Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 52 | |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame^] | 53 | void SetGpuProfilingState(bool gpuProfilingState) |
| 54 | { |
| 55 | m_RuntimeOptions.m_EnableGpuProfiling = gpuProfilingState; |
| 56 | } |
| 57 | bool GetGpuProfilingState() |
| 58 | { |
| 59 | return m_RuntimeOptions.m_EnableGpuProfiling; |
| 60 | } |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 61 | |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame^] | 62 | const std::vector<armnn::BackendOptions>& GetBackendOptions() const |
| 63 | { |
| 64 | return m_RuntimeOptions.m_BackendOptions; |
| 65 | } |
Sadik Armagan | 4189cc5 | 2020-11-11 18:01:48 +0000 | [diff] [blame] | 66 | |
Jan Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 67 | /// Appends a backend option to the list of backend options |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame^] | 68 | void AddBackendOption(const armnn::BackendOptions& option) |
| 69 | { |
| 70 | m_RuntimeOptions.m_BackendOptions.push_back(option); |
| 71 | } |
Jan Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 72 | |
| 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 Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 82 | const armnn::OptimizerOptions& GetOptimizerOptions() const { return m_OptimizerOptions; } |
| 83 | |
Narumol Prangnawarat | 74a3cf5 | 2021-01-29 15:38:54 +0000 | [diff] [blame] | 84 | void SetOptimizerOptions(const armnn::OptimizerOptions& optimizerOptions) { m_OptimizerOptions = optimizerOptions; } |
| 85 | |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 86 | const armnn::Optional<armnn::DebugCallbackFunction>& GetDebugCallbackFunction() const |
| 87 | { return m_DebugCallbackFunc; } |
| 88 | |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 89 | 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 Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame^] | 106 | /// @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 Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 117 | private: |
| 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 Armagan | 4189cc5 | 2020-11-11 18:01:48 +0000 | [diff] [blame] | 122 | |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame^] | 123 | /// 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 Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 127 | |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame^] | 128 | /// Options for the optimization step for the network |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 129 | armnn::OptimizerOptions m_OptimizerOptions; |
| 130 | |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 131 | /// External profiling options. |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 132 | 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 Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 140 | /// Severity level for logging within ArmNN that will be used on creation of the delegate |
| 141 | armnn::Optional<armnn::LogSeverity> m_LoggingSeverity; |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 142 | |
| 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 Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 146 | 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 Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | } // namespace armnnDelegate |