aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/BackendSettings.hpp
diff options
context:
space:
mode:
authorMatteo Martincigh <matteo.martincigh@arm.com>2019-01-11 13:25:59 +0000
committerMatteo Martincigh <matteo.martincigh@arm.com>2019-01-15 08:59:50 +0000
commit4912402497a51c6afe0898b3900f87feefa006a6 (patch)
tree4e9b5161781d2b0be041aec17227193da5977443 /src/armnn/BackendSettings.hpp
parentd0a1608e2c41639d8f3e3f9305d79c5f92c9cff8 (diff)
downloadarmnn-4912402497a51c6afe0898b3900f87feefa006a6.tar.gz
IVGCVSW-2454 Merge together the pluggable backends work (was in a
separate branch) and master * Brings in all the changes done for the pluggable backends * Added sub-graph support and tests * Added precompiled layer support and tests * Moved BackendSettings to a separate file * Removed the backend-specific code * Ported DebugLayer and associated functionality * Included fixes to make those changes work with master Change-Id: Id7028fa7917527b844628d5aff5732e3d94c0488
Diffstat (limited to 'src/armnn/BackendSettings.hpp')
-rw-r--r--src/armnn/BackendSettings.hpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/armnn/BackendSettings.hpp b/src/armnn/BackendSettings.hpp
new file mode 100644
index 0000000000..931a0681db
--- /dev/null
+++ b/src/armnn/BackendSettings.hpp
@@ -0,0 +1,87 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <armnn/BackendId.hpp>
+#include <vector>
+
+namespace armnn
+{
+
+struct BackendSettings
+{
+ BackendIdVector m_PreferredBackends;
+ BackendIdSet m_SupportedBackends;
+ BackendIdSet m_SelectedBackends;
+ BackendIdSet m_IgnoredBackends;
+
+ BackendSettings() = default;
+
+ BackendSettings(const BackendIdVector& preferredBackends,
+ const IDeviceSpec& deviceSpec)
+ {
+ Initialize(preferredBackends, deviceSpec);
+ }
+
+ bool IsBackendPreferred(const BackendId& backend) const
+ {
+ return IsBackendInCollection(backend, m_PreferredBackends);
+ }
+
+ bool IsBackendSupported(const BackendId& backend) const
+ {
+ return IsBackendInCollection(backend, m_SupportedBackends);
+ }
+
+ bool IsBackendSelected(const BackendId& backend) const
+ {
+ return IsBackendInCollection(backend, m_SelectedBackends);
+ }
+
+ bool IsBackendIgnored(const BackendId& backend) const
+ {
+ return IsBackendInCollection(backend, m_IgnoredBackends);
+ }
+
+ bool IsCpuRefUsed() const
+ {
+ BackendId cpuBackendId(Compute::CpuRef);
+ return IsBackendSupported(cpuBackendId) && IsBackendPreferred(cpuBackendId);
+ }
+
+ BackendIdVector GetAvailablePreferredBackends() const
+ {
+ BackendIdVector availablePreferredBackends;
+ for (const BackendId& backend : m_PreferredBackends)
+ {
+ if (IsBackendSupported(backend) && !IsBackendIgnored(backend))
+ {
+ availablePreferredBackends.push_back(backend);
+ }
+ }
+ return availablePreferredBackends;
+ }
+
+private:
+ void Initialize(const BackendIdVector& preferredBackends,
+ const IDeviceSpec& deviceSpec)
+ {
+ // Copy preferred backends from input
+ m_PreferredBackends = preferredBackends;
+
+ // Obtain list of supported backends
+ const DeviceSpec& spec = *boost::polymorphic_downcast<const DeviceSpec*>(&deviceSpec);
+ m_SupportedBackends = spec.GetSupportedBackends();
+ }
+
+ template<typename Collection>
+ bool IsBackendInCollection(const BackendId& backend, const Collection& collection) const
+ {
+ return std::find(collection.begin(), collection.end(), backend) != collection.end();
+ }
+};
+
+} //namespace armnn