ArmNN
 21.02
DelegateOptions.hpp
Go to the documentation of this file.
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>
9 #include <armnn/Logging.hpp>
10 #include <armnn/Optional.hpp>
11 
12 #include <set>
13 #include <string>
14 #include <vector>
15 
16 namespace armnnDelegate
17 {
18 
20 {
21 public:
22  DelegateOptions(armnn::Compute computeDevice,
23  const std::vector<armnn::BackendOptions>& backendOptions = {},
25 
26  DelegateOptions(const std::vector<armnn::BackendId>& backends,
27  const std::vector<armnn::BackendOptions>& backendOptions = {},
29 
30  DelegateOptions(armnn::Compute computeDevice,
31  const armnn::OptimizerOptions& optimizerOptions,
34 
35  DelegateOptions(const std::vector<armnn::BackendId>& backends,
36  const armnn::OptimizerOptions& optimizerOptions,
39 
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 
44  const std::vector<armnn::BackendOptions>& GetBackendOptions() const { return m_BackendOptions; }
45 
46  /// Appends a backend option to the list of backend options
47  void AddBackendOption(const armnn::BackendOptions& option) { m_BackendOptions.push_back(option); }
48 
49  /// Sets the severity level for logging within ArmNN that will be used on creation of the delegate
50  void SetLoggingSeverity(const armnn::LogSeverity& level) { m_LoggingSeverity = level; }
51  void SetLoggingSeverity(const std::string& level) { m_LoggingSeverity = armnn::StringToLogLevel(level); }
52 
53  /// Returns the severity level for logging within ArmNN
54  armnn::LogSeverity GetLoggingSeverity() { return m_LoggingSeverity.value(); }
55 
56  bool IsLoggingEnabled() { return m_LoggingSeverity.has_value(); }
57 
58  const armnn::OptimizerOptions& GetOptimizerOptions() const { return m_OptimizerOptions; }
59 
60  void SetOptimizerOptions(const armnn::OptimizerOptions& optimizerOptions) { m_OptimizerOptions = optimizerOptions; }
61 
63  { return m_DebugCallbackFunc; }
64 
65 private:
66  /// Which backend to run Delegate on.
67  /// Examples of possible values are: CpuRef, CpuAcc, GpuAcc.
68  /// CpuRef as default.
69  std::vector<armnn::BackendId> m_Backends = { armnn::Compute::CpuRef };
70 
71  /// Pass backend specific options to Delegate
72  ///
73  /// For example, tuning can be enabled on GpuAcc like below
74  /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
75  /// m_BackendOptions.emplace_back(
76  /// BackendOptions{"GpuAcc",
77  /// {
78  /// {"TuningLevel", 2},
79  /// {"TuningFile", filename}
80  /// }
81  /// });
82  /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83  /// The following backend options are available:
84  /// GpuAcc:
85  /// "TuningLevel" : int [0..3] (0=UseOnly(default) | 1=RapidTuning | 2=NormalTuning | 3=ExhaustiveTuning)
86  /// "TuningFile" : string [filenameString]
87  /// "KernelProfilingEnabled" : bool [true | false]
88  std::vector<armnn::BackendOptions> m_BackendOptions;
89 
90  /// OptimizerOptions
91  /// Reduce Fp32 data to Fp16 for faster processing
92  /// bool m_ReduceFp32ToFp16;
93  /// Add debug data for easier troubleshooting
94  /// bool m_Debug;
95  /// Reduce Fp32 data to Bf16 for faster processing
96  /// bool m_ReduceFp32ToBf16;
97  /// Enable Import
98  /// bool m_ImportEnabled;
99  /// Enable Model Options
100  /// ModelOptions m_ModelOptions;
101  armnn::OptimizerOptions m_OptimizerOptions;
102 
103  /// Severity level for logging within ArmNN that will be used on creation of the delegate
104  armnn::Optional<armnn::LogSeverity> m_LoggingSeverity;
105 
106  /// A callback function to debug layers performing custom computations on intermediate tensors.
107  /// If a function is not registered, and debug is enabled in OptimizerOptions,
108  /// debug will print information of the intermediate tensors.
110 };
111 
112 } // namespace armnnDelegate
CPU Execution: Reference C++ kernels.
LogSeverity StringToLogLevel(std::string level)
Definition: Logging.hpp:36
Compute
The Compute enum is now deprecated and it is now being replaced by BackendId.
Definition: BackendId.hpp:21
const armnn::OptimizerOptions & GetOptimizerOptions() const
DelegateOptions(armnn::Compute computeDevice, const std::vector< armnn::BackendOptions > &backendOptions={}, armnn::Optional< armnn::LogSeverity > logSeverityLevel=armnn::EmptyOptional())
const std::vector< armnn::BackendOptions > & GetBackendOptions() const
void SetLoggingSeverity(const armnn::LogSeverity &level)
Sets the severity level for logging within ArmNN that will be used on creation of the delegate...
bool has_value() const noexcept
Definition: Optional.hpp:53
Struct for the users to pass backend specific options.
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
Definition: Optional.hpp:32
void SetBackends(const std::vector< armnn::BackendId > &backends)
const std::vector< armnn::BackendId > & GetBackends() const
const armnn::Optional< armnn::DebugCallbackFunction > & GetDebugCallbackFunction() const
void AddBackendOption(const armnn::BackendOptions &option)
Appends a backend option to the list of backend options.
armnn::LogSeverity GetLoggingSeverity()
Returns the severity level for logging within ArmNN.
void SetOptimizerOptions(const armnn::OptimizerOptions &optimizerOptions)
void SetLoggingSeverity(const std::string &level)
LogSeverity
Definition: Utils.hpp:13