IVGCVSW-4834 Add calls to increment REGISTERED_BACKENDS and UNREGISTERED_BACKENDS
authorFinn Williams <Finn.Williams@arm.com>
Fri, 15 May 2020 17:41:05 +0000 (18:41 +0100)
committerfinn.williams <finn.williams@arm.com>
Tue, 19 May 2020 11:45:57 +0000 (11:45 +0000)
Signed-off-by: Finn Williams <Finn.Williams@arm.com>
Change-Id: I3600dd15f97ccd4ab745deb87d06ba978e2a0b11

include/armnn/BackendRegistry.hpp
src/armnn/BackendRegistry.cpp
src/armnn/Runtime.cpp
src/backends/backendsCommon/test/BackendProfilingTests.cpp
src/profiling/ProfilingService.cpp

index 1aaa11c..fe6451c 100644 (file)
@@ -6,6 +6,7 @@
 
 #include <armnn/Types.hpp>
 #include <armnn/BackendId.hpp>
+#include <armnn/Optional.hpp>
 
 #include <memory>
 #include <unordered_map>
 namespace armnn
 {
 
+namespace profiling
+{
+    class ProfilingService;
+}
 class IBackendInternal;
 using IBackendInternalUniquePtr = std::unique_ptr<IBackendInternal>;
 
@@ -29,6 +34,7 @@ public:
     size_t Size() const;
     BackendIdSet GetBackendIds() const;
     std::string GetBackendIdsAsString() const;
+    void SetProfilingService(armnn::Optional<profiling::ProfilingService&> profilingService);
 
     BackendRegistry() {}
     virtual ~BackendRegistry() {}
@@ -56,6 +62,7 @@ private:
     BackendRegistry& operator=(const BackendRegistry&) = delete;
 
     FactoryStorage m_Factories;
+    armnn::Optional<profiling::ProfilingService&> m_ProfilingService;
 };
 
 BackendRegistry& BackendRegistryInstance();
index a79cdd0..ff63c82 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <armnn/BackendRegistry.hpp>
 #include <armnn/Exceptions.hpp>
+#include <ProfilingService.hpp>
 
 namespace armnn
 {
@@ -24,11 +25,25 @@ void BackendRegistry::Register(const BackendId& id, BackendRegistry::FactoryFunc
             CHECK_LOCATION());
     }
     m_Factories[id] = factory;
+
+    if (m_ProfilingService.has_value())
+    {
+        if (m_ProfilingService.has_value() && m_ProfilingService.value().IsProfilingEnabled())
+        {
+            m_ProfilingService.value().IncrementCounterValue(armnn::profiling::REGISTERED_BACKENDS);
+        }
+    }
+
 }
 
 void BackendRegistry::Deregister(const BackendId& id)
 {
     m_Factories.erase(id);
+
+    if (m_ProfilingService.has_value() && m_ProfilingService.value().IsProfilingEnabled())
+    {
+        m_ProfilingService.value().IncrementCounterValue(armnn::profiling::UNREGISTERED_BACKENDS);
+    }
 }
 
 bool BackendRegistry::IsBackendRegistered(const BackendId& id) const
@@ -86,5 +101,10 @@ void BackendRegistry::Swap(BackendRegistry& instance, BackendRegistry::FactorySt
     std::swap(instance.m_Factories, other);
 }
 
+void BackendRegistry::SetProfilingService(armnn::Optional<profiling::ProfilingService&> profilingService)
+{
+    m_ProfilingService = profilingService;
+}
+
 
 } // namespace armnn
index 483eea7..dbdd409 100644 (file)
@@ -220,6 +220,7 @@ Runtime::Runtime(const CreationOptions& options)
         }
     }
 
+    BackendRegistryInstance().SetProfilingService(m_ProfilingService);
     // pass configuration info to the profiling service
     m_ProfilingService.ConfigureProfilingService(options.m_ProfilingOptions);
 
@@ -269,6 +270,8 @@ Runtime::~Runtime()
     DynamicBackendUtils::DeregisterDynamicBackends(m_DeviceSpec.GetDynamicBackends());
     m_DeviceSpec.ClearDynamicBackends();
     m_BackendContexts.clear();
+
+    BackendRegistryInstance().SetProfilingService(armnn::EmptyOptional());
 }
 
 LoadedNetwork* Runtime::GetLoadedNetworkPtr(NetworkId networkId) const
index 52b6e23..66f99be 100644 (file)
@@ -118,7 +118,7 @@ BOOST_AUTO_TEST_CASE(BackendProfilingCounterRegisterMockBackendTest)
 {
     // Reset the profiling service to the uninitialized state
     armnn::IRuntime::CreationOptions options;
-    options.m_ProfilingOptions.m_EnableProfiling = true;;
+    options.m_ProfilingOptions.m_EnableProfiling = true;
 
     armnn::MockBackendInitialiser initialiser;
     // Create a runtime
index a26bba2..21972b4 100644 (file)
@@ -377,6 +377,10 @@ void ProfilingService::Initialize()
                                                    std::string("backends"));
         ARMNN_ASSERT(registeredBackendsCounter);
         InitializeCounterValue(registeredBackendsCounter->m_Uid);
+
+        // Due to backends being registered before the profiling service becomes active,
+        // we need to set the counter to the correct value here
+        SetCounterValue(armnn::profiling::REGISTERED_BACKENDS, static_cast<uint32_t>(BackendRegistryInstance().Size()));
     }
     // Register a counter for the number of registered backends
     if (!m_CounterDirectory.IsCounterRegistered("Backends unregistered"))