ArmNN
 25.11
Loading...
Searching...
No Matches
BackendSettings.hpp
Go to the documentation of this file.
1//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
8#include "DeviceSpec.hpp"
9
10#include <armnn/BackendId.hpp>
12
13#include <vector>
14
15namespace armnn
16{
17
19{
24
25 BackendSettings() = default;
26
27 BackendSettings(const BackendIdVector& preferredBackends,
28 const IDeviceSpec& deviceSpec)
29 {
30 Initialize(preferredBackends, deviceSpec);
31 }
32
40
41 bool IsBackendPreferred(const BackendId& backend) const
42 {
43 return IsBackendInCollection(backend, m_PreferredBackends);
44 }
45
46 bool IsBackendSupported(const BackendId& backend) const
47 {
48 return IsBackendInCollection(backend, m_SupportedBackends);
49 }
50
51 bool IsBackendSelected(const BackendId& backend) const
52 {
53 return IsBackendInCollection(backend, m_SelectedBackends);
54 }
55
56 bool IsBackendIgnored(const BackendId& backend) const
57 {
58 return IsBackendInCollection(backend, m_IgnoredBackends);
59 }
60
61 bool IsCpuRefUsed() const
62 {
63 BackendId cpuBackendId(Compute::CpuRef);
64 return IsBackendSupported(cpuBackendId) && IsBackendPreferred(cpuBackendId);
65 }
66
68 {
69 BackendIdVector availablePreferredBackends;
70 for (const BackendId& backend : m_PreferredBackends)
71 {
72 if (IsBackendSupported(backend) && !IsBackendIgnored(backend))
73 {
74 availablePreferredBackends.push_back(backend);
75 }
76 }
77 return availablePreferredBackends;
78 }
79
80private:
81 void Initialize(const BackendIdVector& preferredBackends,
82 const IDeviceSpec& deviceSpec)
83 {
84 // Copy preferred backends from input
85 m_PreferredBackends = preferredBackends;
86
87 // Obtain list of supported backends
88 const DeviceSpec& spec = *PolymorphicDowncast<const DeviceSpec*>(&deviceSpec);
90 }
91
92 template<typename Collection>
93 bool IsBackendInCollection(const BackendId& backend, const Collection& collection) const
94 {
95 return std::find(collection.begin(), collection.end(), backend) != collection.end();
96 }
97};
98
99} //namespace armnn
virtual const BackendIdSet & GetSupportedBackends() const override
Device specific knowledge to be passed to the optimizer.
Definition Types.hpp:302
Copyright (c) 2021 ARM Limited and Contributors.
std::unordered_set< BackendId > BackendIdSet
DestType PolymorphicDowncast(SourceType *value)
Polymorphic downcast for build in pointers only.
std::vector< BackendId > BackendIdVector
@ CpuRef
CPU Execution: Reference C++ kernels.
Definition BackendId.hpp:25
BackendSettings(const BackendIdVector &preferredBackends, const IDeviceSpec &deviceSpec)
BackendSettings(const BackendSettings &other)
bool IsBackendSupported(const BackendId &backend) const
bool IsBackendIgnored(const BackendId &backend) const
BackendIdVector GetAvailablePreferredBackends() const
bool IsBackendPreferred(const BackendId &backend) const
bool IsBackendSelected(const BackendId &backend) const
BackendIdVector m_PreferredBackends