1 //
2 // Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include "NeonBackendModelContext.hpp"
7
8 namespace
9 {
10
ParseBool(const armnn::BackendOptions::Var & value,bool defaultValue)11 bool ParseBool(const armnn::BackendOptions::Var& value, bool defaultValue)
12 {
13 if (value.IsBool())
14 {
15 return value.AsBool();
16 }
17 return defaultValue;
18 }
19
ParseUnsignedInt(const armnn::BackendOptions::Var & value,unsigned int defaultValue)20 unsigned int ParseUnsignedInt(const armnn::BackendOptions::Var& value, unsigned int defaultValue)
21 {
22 if (value.IsUnsignedInt())
23 {
24 return value.AsUnsignedInt();
25 }
26 return defaultValue;
27 }
28
29 } // namespace anonymous
30
31 namespace armnn
32 {
33
NeonBackendModelContext(const ModelOptions & modelOptions)34 NeonBackendModelContext::NeonBackendModelContext(const ModelOptions& modelOptions)
35 : m_IsFastMathEnabled(false), m_NumberOfThreads(0)
36 {
37 if (!modelOptions.empty())
38 {
39 ParseOptions(modelOptions, "CpuAcc", [&](std::string name, const BackendOptions::Var& value)
40 {
41 if (name == "FastMathEnabled")
42 {
43 m_IsFastMathEnabled |= ParseBool(value, false);
44 }
45 if (name == "NumberOfThreads")
46 {
47 m_NumberOfThreads |= ParseUnsignedInt(value, 0);
48 }
49 });
50 }
51 }
52
IsFastMathEnabled() const53 bool NeonBackendModelContext::IsFastMathEnabled() const
54 {
55 return m_IsFastMathEnabled;
56 }
57
GetNumberOfThreads() const58 unsigned int NeonBackendModelContext::GetNumberOfThreads() const
59 {
60 return m_NumberOfThreads;
61 }
62
63 } // namespace armnn