IVGCVSW-1991 : refactor m_SupportedComputes in DeviceSpecs
authorDavid Beck <david.beck@arm.com>
Mon, 22 Oct 2018 12:16:00 +0000 (13:16 +0100)
committerMatthew Bentham <matthew.bentham@arm.com>
Mon, 22 Oct 2018 15:57:54 +0000 (16:57 +0100)
Change-Id: Ied3d54dc356f5e4f87aeb59f66423ac1f893dd01

src/armnn/DeviceSpec.hpp
src/armnn/Network.cpp
src/armnn/Runtime.cpp

index af0d8f5..834ce09 100644 (file)
@@ -14,15 +14,19 @@ namespace armnn
 class DeviceSpec : public IDeviceSpec
 {
 public:
-    DeviceSpec() {}
+    DeviceSpec(const BackendIdSet& supportedBackends)
+        : m_SupportedBackends{supportedBackends} {}
+
     virtual ~DeviceSpec() {}
 
-    virtual std::vector<IBackendSharedPtr> GetBackends() const
+    virtual const BackendIdSet& GetSupportedBackends() const
     {
-        return std::vector<IBackendSharedPtr>();
+        return m_SupportedBackends;
     }
 
-    std::set<BackendId> m_SupportedComputeDevices;
+private:
+    DeviceSpec() = delete;
+    BackendIdSet m_SupportedBackends;
 };
 
 }
index 8c70e5d..f95e829 100644 (file)
@@ -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<const DeviceSpec*>(&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());
index 354a567..8a7023e 100644 (file)
@@ -4,7 +4,8 @@
 //
 #include "Runtime.hpp"
 
-#include "armnn/Version.hpp"
+#include <armnn/Version.hpp>
+#include <backends/BackendRegistry.hpp>
 
 #include <iostream>
 
@@ -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()