From 056be3cbe0306f4e1409c10952a8a73676a4acdd Mon Sep 17 00:00:00 2001 From: David Beck Date: Mon, 22 Oct 2018 13:16:00 +0100 Subject: IVGCVSW-1991 : refactor m_SupportedComputes in DeviceSpecs Change-Id: Ied3d54dc356f5e4f87aeb59f66423ac1f893dd01 --- src/armnn/DeviceSpec.hpp | 12 ++++++++---- src/armnn/Network.cpp | 7 +++---- src/armnn/Runtime.cpp | 12 +++--------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/armnn/DeviceSpec.hpp b/src/armnn/DeviceSpec.hpp index af0d8f578b..834ce0921d 100644 --- a/src/armnn/DeviceSpec.hpp +++ b/src/armnn/DeviceSpec.hpp @@ -14,15 +14,19 @@ namespace armnn class DeviceSpec : public IDeviceSpec { public: - DeviceSpec() {} + DeviceSpec(const BackendIdSet& supportedBackends) + : m_SupportedBackends{supportedBackends} {} + virtual ~DeviceSpec() {} - virtual std::vector GetBackends() const + virtual const BackendIdSet& GetSupportedBackends() const { - return std::vector(); + return m_SupportedBackends; } - std::set m_SupportedComputeDevices; +private: + DeviceSpec() = delete; + BackendIdSet m_SupportedBackends; }; } diff --git a/src/armnn/Network.cpp b/src/armnn/Network.cpp index 8c70e5d793..f95e829cb9 100644 --- a/src/armnn/Network.cpp +++ b/src/armnn/Network.cpp @@ -129,6 +129,7 @@ IOptimizedNetworkPtr Optimize(const INetwork& inNetwork, // We know that DeviceSpec should be the only implementation of IDeviceSpec. const DeviceSpec& spec = *boost::polymorphic_downcast(&deviceSpec); + auto const& supportedBackends = spec.GetSupportedBackends(); // determine which of the preferred backends we have available for use // and whether we have specified CpuRef as one of those backends. @@ -137,9 +138,7 @@ IOptimizedNetworkPtr Optimize(const INetwork& inNetwork, for (const auto& backend : backendPreferences) { // Check if the backend is in the available backend devices. - if (std::find(spec.m_SupportedComputeDevices.begin(), - spec.m_SupportedComputeDevices.end(), backend) != - spec.m_SupportedComputeDevices.end()) + if (supportedBackends.count(backend) > 0) { availablePreferredBackends.push_back(backend); if (backend == armnn::Compute::CpuRef) { @@ -150,7 +149,7 @@ IOptimizedNetworkPtr Optimize(const INetwork& inNetwork, if (availablePreferredBackends.empty()) { std::stringstream failureMsg; failureMsg << "ERROR: None of the preferred backends " << backendPreferences - << " are supported. Current platform provides " << spec.m_SupportedComputeDevices; + << " are supported. Current platform provides " << supportedBackends; BOOST_LOG_TRIVIAL(warning) << failureMsg.str(); if (errMessages) { errMessages.value().push_back(failureMsg.str()); diff --git a/src/armnn/Runtime.cpp b/src/armnn/Runtime.cpp index 354a567f88..8a7023ed76 100644 --- a/src/armnn/Runtime.cpp +++ b/src/armnn/Runtime.cpp @@ -4,7 +4,8 @@ // #include "Runtime.hpp" -#include "armnn/Version.hpp" +#include +#include #include @@ -133,16 +134,9 @@ Runtime::Runtime(const CreationOptions& options) : m_ClContextControl(options.m_GpuAccTunedParameters.get(), options.m_EnableGpuProfiling) , m_NetworkIdCounter(0) + , m_DeviceSpec{BackendRegistryInstance().GetBackendIds()} { BOOST_LOG_TRIVIAL(info) << "ArmNN v" << ARMNN_VERSION << "\n"; - - m_DeviceSpec.m_SupportedComputeDevices.insert(armnn::Compute::CpuRef); - #if ARMCOMPUTECL_ENABLED - m_DeviceSpec.m_SupportedComputeDevices.insert(armnn::Compute::GpuAcc); - #endif - #if ARMCOMPUTENEON_ENABLED - m_DeviceSpec.m_SupportedComputeDevices.insert(armnn::Compute::CpuAcc); - #endif } Runtime::~Runtime() -- cgit v1.2.1