15 struct BackendOptions;
28 static const bool value = std::is_same<T, int>::value ||
29 std::is_same<T, unsigned int>::value ||
30 std::is_same<T, float>::value ||
31 std::is_same<T, bool>::value ||
32 std::is_same<T, std::string>::value ||
33 std::is_same<T, const char*>::value;
43 explicit Var(
int i) : m_Vals(i), m_Type(VarTypes::Integer) {};
44 explicit Var(
unsigned int u) : m_Vals(u), m_Type(VarTypes::UnsignedInteger) {};
45 explicit Var(
float f) : m_Vals(f), m_Type(VarTypes::Float) {};
46 explicit Var(
bool b) : m_Vals(b), m_Type(VarTypes::
Boolean) {};
47 explicit Var(
const char* s) : m_Vals(s), m_Type(VarTypes::String) {};
48 explicit Var(std::string s) : m_Vals(s), m_Type(VarTypes::String) {};
51 template<
typename DisallowedType>
54 static_assert(CheckAllowed<DisallowedType>::value,
"Type is not allowed for Var<DisallowedType>.");
55 assert(
false &&
"Unreachable code");
60 : m_Type(other.m_Type)
64 case VarTypes::String:
66 new (&m_Vals.s) std::string(other.m_Vals.s);
71 DoOp(other, [](
auto& a,
auto& b)
84 if (m_Type == VarTypes::String)
89 m_Type = other.m_Type;
92 case VarTypes::String:
95 new (&m_Vals.s) std::string(other.m_Vals.s);
100 DoOp(other, [](
auto& a,
auto& b)
112 bool IsBool()
const {
return m_Type == VarTypes::Boolean; }
113 bool IsInt()
const {
return m_Type == VarTypes::Integer; }
115 bool IsFloat()
const {
return m_Type == VarTypes::Float; }
116 bool IsString()
const {
return m_Type == VarTypes::String; }
127 else if (
IsInt()) {
return std::to_string(
AsInt()); }
140 DoOp(*
this, [
this](
auto& a,
auto&)
146 template<
typename Func>
147 void DoOp(
const Var& other, Func func)
151 func(m_Vals.b, other.m_Vals.b);
153 else if (other.
IsInt())
155 func(m_Vals.i, other.m_Vals.i);
159 func(m_Vals.u, other.m_Vals.u);
163 func(m_Vals.f, other.m_Vals.f);
167 func(m_Vals.s, other.m_Vals.s);
171 template<
typename Destructable>
172 void Destruct(Destructable& d)
174 if (std::is_destructible<Destructable>::value)
203 explicit Vals(
int i) : i(i) {};
204 explicit Vals(
unsigned int u) : u(u) {};
205 explicit Vals(
float f) : f(f) {};
206 explicit Vals(
bool b) : b(b) {};
207 explicit Vals(
const char* s) : s(
std::string(s)) {}
208 explicit Vals(std::string s) : s(s) {}
219 : m_Name(name), m_Value(value)
222 : m_Name(name), m_Value(value)
225 : m_Name(name), m_Value(value)
228 : m_Name(name), m_Value(value)
231 : m_Name(name), m_Value(value)
234 : m_Name(name), m_Value(value)
237 template<
typename DisallowedType>
241 static_assert(CheckAllowed<DisallowedType>::value,
"Type is not allowed for BackendOption.");
242 assert(
false &&
"Unreachable code");
251 std::string
GetName()
const {
return m_Name; }
260 : m_TargetBackend(backend)
264 : m_TargetBackend(backend)
275 m_Options.push_back(option);
280 m_Options.push_back(option);
292 std::vector<BackendOption> m_Options;
296 template <
typename F>
299 for (
auto optionsGroup : options)
301 if (optionsGroup.GetBackendId() == backend)
303 for (
size_t i=0; i < optionsGroup.GetOptionCount(); i++)
334 return value.
AsInt();
Very basic type safe variant.
Var(DisallowedType)
Disallow implicit conversions from types not explicitly allowed below.
bool IsUnsignedInt() const
std::string AsString() const
Var & operator=(const Var &other)
Copy operator.
Var(const Var &other)
Copy Construct.
unsigned int AsUnsignedInt() const
bool AsBool() const
Value getters.
bool IsBool() const
Type getters.
Copyright (c) 2021 ARM Limited and Contributors.
std::vector< BackendOptions > NetworkOptions
std::vector< BackendOptions > ModelOptions
std::string ParseStringBackendOption(const armnn::BackendOptions::Var &value, std::string defaultValue)
int ParseIntBackendOption(const armnn::BackendOptions::Var &value, int defaultValue)
bool ParseBooleanBackendOption(const armnn::BackendOptions::Var &value, bool defaultValue)
void ParseOptions(const std::vector< BackendOptions > &options, BackendId backend, F f)
BackendOption(const BackendOption &other)=default
BackendOption(BackendOption &&other)=default
BackendOption & operator=(BackendOption &&other)=default
BackendOption(std::string name, std::string value)
BackendOption(std::string name, int value)
std::string GetName() const
BackendOption(std::string name, float value)
BackendOption(std::string name, const char *value)
BackendOption & operator=(const BackendOption &other)=default
BackendOption(std::string name, bool value)
BackendOption(std::string name, unsigned int value)
BackendOption(std::string, DisallowedType)
Struct for the users to pass backend specific options.
BackendOptions & operator=(const BackendOptions &other)=default
BackendOptions(const BackendOptions &other)=default
const BackendId & GetBackendId() const noexcept
BackendOptions(BackendId backend, std::initializer_list< BackendOption > options)
void AddOption(BackendOption &&option)
const BackendOption & GetOption(size_t idx) const
void AddOption(const BackendOption &option)
size_t GetOptionCount() const noexcept
BackendOptions(BackendId backend)
BackendOptions & operator=(BackendOptions &&other)=default
BackendOptions(BackendOptions &&other)=default