aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColm Donelan <Colm.Donelan@arm.com>2020-02-05 17:48:59 +0000
committerColm Donelan <colm.donelan@arm.com>2020-02-07 09:28:35 +0000
commit1aff393b359b518925f66901439466f9bc14c49d (patch)
tree9d31aa1d3dabb4b637093f6fd1a9f1549621c653
parent3446057492907d0c7695605a5b9a961a78158d7e (diff)
downloadarmnn-1aff393b359b518925f66901439466f9bc14c49d.tar.gz
IVGCVSW-4317 Implement the Profiling Context Initialisation
* Call CreateBackendProfilingContext on each backend from Runtime passing an instance of the BackendProfiling interface. * Modify the signature of CreateBackendProfilingContext to remove const and return a shared_ptr to BackendProfilingContext * Add concrete BackendProfiling class. * Store BackendProfilingContexts in Profiling service. Signed-off-by: Colm Donelan <Colm.Donelan@arm.com> Change-Id: I975eaa2093ae91fa623835f65f9e5b25eb65117a
-rw-r--r--Android.mk3
-rw-r--r--CMakeLists.txt2
-rw-r--r--include/armnn/backends/IBackendInternal.hpp5
-rw-r--r--include/armnn/backends/profiling/IBackendProfiling.hpp20
-rw-r--r--include/armnn/backends/profiling/IBackendProfilingContext.hpp1
-rw-r--r--src/armnn/Runtime.cpp16
-rw-r--r--src/backends/backendsCommon/IBackendInternal.cpp2
-rw-r--r--src/backends/backendsCommon/test/MockBackend.cpp2
-rw-r--r--src/backends/backendsCommon/test/MockBackend.hpp25
-rw-r--r--src/backends/cl/ClBackend.cpp3
-rw-r--r--src/backends/cl/ClBackend.hpp4
-rw-r--r--src/backends/neon/NeonBackend.cpp3
-rw-r--r--src/backends/neon/NeonBackend.hpp4
-rw-r--r--src/backends/reference/RefBackend.cpp2
-rw-r--r--src/backends/reference/RefBackend.hpp3
-rw-r--r--src/profiling/ProfilingService.cpp1
-rw-r--r--src/profiling/ProfilingService.hpp10
-rw-r--r--src/profiling/backends/BackendProfiling.cpp48
-rw-r--r--src/profiling/backends/BackendProfiling.hpp49
19 files changed, 166 insertions, 37 deletions
diff --git a/Android.mk b/Android.mk
index 65e5380c87..ba7f3b52cf 100644
--- a/Android.mk
+++ b/Android.mk
@@ -205,7 +205,8 @@ LOCAL_SRC_FILES := \
src/profiling/SendTimelinePacket.cpp \
src/profiling/SocketProfilingConnection.cpp \
src/profiling/TimelinePacketWriterFactory.cpp \
- src/profiling/TimelineUtilityMethods.cpp
+ src/profiling/TimelineUtilityMethods.cpp \
+ src/profiling/backends/BackendProfiling.cpp
LOCAL_STATIC_LIBRARIES := \
armnn-arm_compute \
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 950ad4a946..38566639b6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -515,6 +515,8 @@ list(APPEND armnn_sources
src/profiling/TimelinePacketWriterFactory.hpp
src/profiling/TimelineUtilityMethods.cpp
src/profiling/TimelineUtilityMethods.hpp
+ src/profiling/backends/BackendProfiling.cpp
+ src/profiling/backends/BackendProfiling.hpp
third-party/half/half.hpp
)
diff --git a/include/armnn/backends/IBackendInternal.hpp b/include/armnn/backends/IBackendInternal.hpp
index 6c919ee5d4..6ad9bba546 100644
--- a/include/armnn/backends/IBackendInternal.hpp
+++ b/include/armnn/backends/IBackendInternal.hpp
@@ -80,7 +80,8 @@ public:
using IWorkloadFactoryPtr = std::unique_ptr<IWorkloadFactory>;
using IBackendContextPtr = std::unique_ptr<IBackendContext>;
// This is the bridge between backend and backend profiling we'll keep it in the backend namespace.
- using IBackendProfilingContextPtr = std::unique_ptr<armnn::profiling::IBackendProfilingContext>;
+ using IBackendProfilingContextPtr = std::shared_ptr<armnn::profiling::IBackendProfilingContext>;
+ using IBackendProfilingPtr = std::unique_ptr<armnn::profiling::IBackendProfiling>;
using OptimizationPtr = std::unique_ptr<Optimization>;
using Optimizations = std::vector<OptimizationPtr>;
using ILayerSupportSharedPtr = std::shared_ptr<ILayerSupport>;
@@ -126,7 +127,7 @@ public:
/// Create context specifically used for profiling interaction from backends.
virtual IBackendProfilingContextPtr CreateBackendProfilingContext(const IRuntime::CreationOptions& creationOptions,
- armnn::profiling::IBackendProfiling& backendProfiling) const;
+ IBackendProfilingPtr& backendProfiling);
virtual ILayerSupportSharedPtr GetLayerSupport() const = 0;
diff --git a/include/armnn/backends/profiling/IBackendProfiling.hpp b/include/armnn/backends/profiling/IBackendProfiling.hpp
index 4c463a8128..d3c52996f4 100644
--- a/include/armnn/backends/profiling/IBackendProfiling.hpp
+++ b/include/armnn/backends/profiling/IBackendProfiling.hpp
@@ -68,27 +68,25 @@ public:
class IBackendProfiling
{
-protected:
- IBackendProfiling(const IRuntime::CreationOptions&)
- {}
-
public:
virtual ~IBackendProfiling()
{}
- IRegisterBackendCounters& GetCounterRegistrationInterface(uint16_t currentMaxGlobalCounterID);
+ virtual std::unique_ptr<IRegisterBackendCounters>
+ GetCounterRegistrationInterface(uint16_t currentMaxGlobalCounterID) = 0;
+
+ virtual std::unique_ptr<ISendTimelinePacket> GetSendTimelinePacket() = 0;
- ISendTimelinePacket& GetSendTimelinePacket();
+ virtual IProfilingGuidGenerator& GetProfilingGuidGenerator() = 0;
- IProfilingGuidGenerator& GetProfilingGuidGenerator();
+ virtual void ReportCounters(const std::vector<Timestamp>& counterValues) = 0;
- void ReportCounters(const std::vector<Timestamp>& counterValues);
+ virtual CounterStatus GetCounterStatus(uint16_t backendCounterId) = 0;
- CounterStatus GetCounterStatus(uint16_t backendCounterId);
+ virtual std::vector<CounterStatus> GetActiveCounters() = 0;
- std::vector<CounterStatus> GetActiveCounters();
+ virtual bool IsProfilingEnabled() const = 0;
- bool IsProfilingEnabled() const;
};
} // namespace profiling
} // namespace armnn \ No newline at end of file
diff --git a/include/armnn/backends/profiling/IBackendProfilingContext.hpp b/include/armnn/backends/profiling/IBackendProfilingContext.hpp
index d5d918322e..33c8bba91b 100644
--- a/include/armnn/backends/profiling/IBackendProfilingContext.hpp
+++ b/include/armnn/backends/profiling/IBackendProfilingContext.hpp
@@ -4,6 +4,7 @@
//
#pragma once
+#include "IBackendProfiling.hpp"
#include <armnn/IRuntime.hpp>
#include <vector>
diff --git a/src/armnn/Runtime.cpp b/src/armnn/Runtime.cpp
index 47c998a6fd..c1416f94d7 100644
--- a/src/armnn/Runtime.cpp
+++ b/src/armnn/Runtime.cpp
@@ -16,6 +16,7 @@
#include <iostream>
#include <boost/polymorphic_cast.hpp>
+#include <backends/BackendProfiling.hpp>
using namespace armnn;
using namespace std;
@@ -181,6 +182,19 @@ Runtime::Runtime(const CreationOptions& options)
m_BackendContexts.emplace(std::make_pair(id, std::move(context)));
}
supportedBackends.emplace(id);
+
+ unique_ptr<armnn::profiling::IBackendProfiling> profilingIface =
+ std::make_unique<armnn::profiling::BackendProfiling>(armnn::profiling::BackendProfiling(
+ options, armnn::profiling::ProfilingService::Instance(), id));
+
+ // Backends may also provide a profiling context. Ask for it now.
+ auto profilingContext = backend->CreateBackendProfilingContext(options, profilingIface);
+ // Backends that don't support profiling will return a null profiling context.
+ if (profilingContext)
+ {
+ // Pass the context onto the profiling service.
+ armnn::profiling::ProfilingService::Instance().AddBackendProfilingContext(id, profilingContext);
+ }
}
catch (const BackendUnavailableException&)
{
@@ -230,9 +244,11 @@ Runtime::~Runtime()
}
}
+
// Clear all dynamic backends.
DynamicBackendUtils::DeregisterDynamicBackends(m_DeviceSpec.GetDynamicBackends());
m_DeviceSpec.ClearDynamicBackends();
+ m_BackendContexts.clear();
}
LoadedNetwork* Runtime::GetLoadedNetworkPtr(NetworkId networkId) const
diff --git a/src/backends/backendsCommon/IBackendInternal.cpp b/src/backends/backendsCommon/IBackendInternal.cpp
index c86d026e96..a9d5a5493d 100644
--- a/src/backends/backendsCommon/IBackendInternal.cpp
+++ b/src/backends/backendsCommon/IBackendInternal.cpp
@@ -45,7 +45,7 @@ IBackendInternal::IBackendContextPtr IBackendInternal::CreateBackendContext(cons
}
IBackendInternal::IBackendProfilingContextPtr IBackendInternal::CreateBackendProfilingContext(
- const IRuntime::CreationOptions&, armnn::profiling::IBackendProfiling&) const
+ const IRuntime::CreationOptions&, IBackendProfilingPtr&)
{
return IBackendProfilingContextPtr{};
}
diff --git a/src/backends/backendsCommon/test/MockBackend.cpp b/src/backends/backendsCommon/test/MockBackend.cpp
index d8f8cfe701..ac99738a92 100644
--- a/src/backends/backendsCommon/test/MockBackend.cpp
+++ b/src/backends/backendsCommon/test/MockBackend.cpp
@@ -99,7 +99,7 @@ IBackendInternal::IBackendContextPtr MockBackend::CreateBackendContext(const IRu
}
IBackendInternal::IBackendProfilingContextPtr MockBackend::CreateBackendProfilingContext(
- const IRuntime::CreationOptions&, armnn::profiling::IBackendProfiling&) const
+ const IRuntime::CreationOptions&, IBackendProfilingPtr&)
{
return IBackendProfilingContextPtr{};
}
diff --git a/src/backends/backendsCommon/test/MockBackend.hpp b/src/backends/backendsCommon/test/MockBackend.hpp
index 3fe3100986..d1a0082e2e 100644
--- a/src/backends/backendsCommon/test/MockBackend.hpp
+++ b/src/backends/backendsCommon/test/MockBackend.hpp
@@ -5,14 +5,15 @@
#pragma once
+#include <LayerSupportCommon.hpp>
#include <armnn/backends/IBackendInternal.hpp>
#include <armnn/backends/OptimizationViews.hpp>
-#include <LayerSupportCommon.hpp>
#include <backendsCommon/LayerSupportBase.hpp>
namespace armnn
{
+
class MockBackend : public IBackendInternal
{
public:
@@ -20,17 +21,20 @@ public:
~MockBackend() = default;
static const BackendId& GetIdStatic();
- const BackendId& GetId() const override { return GetIdStatic(); }
+ const BackendId& GetId() const override
+ {
+ return GetIdStatic();
+ }
IBackendInternal::IMemoryManagerUniquePtr CreateMemoryManager() const override;
- IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory(
- const IBackendInternal::IMemoryManagerSharedPtr& memoryManager = nullptr) const override;
+ IBackendInternal::IWorkloadFactoryPtr
+ CreateWorkloadFactory(const IBackendInternal::IMemoryManagerSharedPtr& memoryManager = nullptr) const override;
IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const override;
- IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext(
- const IRuntime::CreationOptions& creationOptions,
- armnn::profiling::IBackendProfiling& backendProfiling) const override;
+ IBackendInternal::IBackendProfilingContextPtr
+ CreateBackendProfilingContext(const IRuntime::CreationOptions& creationOptions,
+ IBackendProfilingPtr& backendProfiling) override;
IBackendInternal::Optimizations GetOptimizations() const override;
IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override;
@@ -38,7 +42,8 @@ public:
OptimizationViews OptimizeSubgraphView(const SubgraphView& subgraph) const override;
};
-class MockLayerSupport : public LayerSupportBase {
+class MockLayerSupport : public LayerSupportBase
+{
public:
bool IsInputSupported(const TensorInfo& /*input*/,
Optional<std::string&> /*reasonIfUnsupported = EmptyOptional()*/) const override
@@ -47,7 +52,7 @@ public:
}
bool IsOutputSupported(const TensorInfo& /*input*/,
- Optional<std::string&> /*reasonIfUnsupported = EmptyOptional()*/) const override
+ Optional<std::string&> /*reasonIfUnsupported = EmptyOptional()*/) const override
{
return true;
}
@@ -71,4 +76,4 @@ public:
}
};
-} // namespace armnn
+} // namespace armnn
diff --git a/src/backends/cl/ClBackend.cpp b/src/backends/cl/ClBackend.cpp
index 8e839aec85..f662754693 100644
--- a/src/backends/cl/ClBackend.cpp
+++ b/src/backends/cl/ClBackend.cpp
@@ -75,8 +75,7 @@ ClBackend::CreateBackendContext(const IRuntime::CreationOptions& options) const
}
IBackendInternal::IBackendProfilingContextPtr ClBackend::CreateBackendProfilingContext(
- const IRuntime::CreationOptions&,
- armnn::profiling::IBackendProfiling&) const
+ const IRuntime::CreationOptions&, IBackendProfilingPtr&)
{
return IBackendProfilingContextPtr{};
}
diff --git a/src/backends/cl/ClBackend.hpp b/src/backends/cl/ClBackend.hpp
index 703ae1723d..e85c616505 100644
--- a/src/backends/cl/ClBackend.hpp
+++ b/src/backends/cl/ClBackend.hpp
@@ -31,8 +31,8 @@ public:
void RegisterTensorHandleFactories(TensorHandleFactoryRegistry& registry) override;
IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const override;
- IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext(const IRuntime::CreationOptions&,
- armnn::profiling::IBackendProfiling&) const override;
+ IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext(
+ const IRuntime::CreationOptions&, IBackendProfilingPtr& backendProfiling) override;
IBackendInternal::Optimizations GetOptimizations() const override;
IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override;
diff --git a/src/backends/neon/NeonBackend.cpp b/src/backends/neon/NeonBackend.cpp
index 1d482974e1..4201ba8c9a 100644
--- a/src/backends/neon/NeonBackend.cpp
+++ b/src/backends/neon/NeonBackend.cpp
@@ -62,8 +62,7 @@ IBackendInternal::IBackendContextPtr NeonBackend::CreateBackendContext(const IRu
}
IBackendInternal::IBackendProfilingContextPtr NeonBackend::CreateBackendProfilingContext(
- const IRuntime::CreationOptions&,
- armnn::profiling::IBackendProfiling&) const
+ const IRuntime::CreationOptions&, IBackendProfilingPtr&)
{
return IBackendProfilingContextPtr{};
}
diff --git a/src/backends/neon/NeonBackend.hpp b/src/backends/neon/NeonBackend.hpp
index b1eeeb6ba7..ad4ac8dde2 100644
--- a/src/backends/neon/NeonBackend.hpp
+++ b/src/backends/neon/NeonBackend.hpp
@@ -27,8 +27,8 @@ public:
class TensorHandleFactoryRegistry& tensorHandleFactoryRegistry) const override;
IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const override;
- IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext(const IRuntime::CreationOptions&,
- armnn::profiling::IBackendProfiling&) const override;
+ IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext(
+ const IRuntime::CreationOptions&, IBackendProfilingPtr& backendProfiling) override;
IBackendInternal::Optimizations GetOptimizations() const override;
IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override;
diff --git a/src/backends/reference/RefBackend.cpp b/src/backends/reference/RefBackend.cpp
index d006c72d98..584ce78fdb 100644
--- a/src/backends/reference/RefBackend.cpp
+++ b/src/backends/reference/RefBackend.cpp
@@ -49,7 +49,7 @@ IBackendInternal::IBackendContextPtr RefBackend::CreateBackendContext(const IRun
}
IBackendInternal::IBackendProfilingContextPtr RefBackend::CreateBackendProfilingContext(
- const IRuntime::CreationOptions&, armnn::profiling::IBackendProfiling&) const
+ const IRuntime::CreationOptions&, IBackendProfilingPtr&)
{
return IBackendProfilingContextPtr{};
}
diff --git a/src/backends/reference/RefBackend.hpp b/src/backends/reference/RefBackend.hpp
index e647b75454..92d392dde6 100644
--- a/src/backends/reference/RefBackend.hpp
+++ b/src/backends/reference/RefBackend.hpp
@@ -29,8 +29,7 @@ public:
IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const override;
IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext(
- const IRuntime::CreationOptions& creationOptions,
- armnn::profiling::IBackendProfiling& backendProfiling) const override;
+ const IRuntime::CreationOptions& creationOptions, IBackendProfilingPtr& backendProfiling) override;
IBackendInternal::Optimizations GetOptimizations() const override;
IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override;
diff --git a/src/profiling/ProfilingService.cpp b/src/profiling/ProfilingService.cpp
index 926e54a5bd..5cee477bd5 100644
--- a/src/profiling/ProfilingService.cpp
+++ b/src/profiling/ProfilingService.cpp
@@ -391,6 +391,7 @@ void ProfilingService::Reset()
// ...finally reset the profiling state machine
m_StateMachine.Reset();
+ m_BackendProfilingContexts.clear();
}
void ProfilingService::Stop()
diff --git a/src/profiling/ProfilingService.hpp b/src/profiling/ProfilingService.hpp
index e510589caa..4438952853 100644
--- a/src/profiling/ProfilingService.hpp
+++ b/src/profiling/ProfilingService.hpp
@@ -22,6 +22,7 @@
#include "SendCounterPacket.hpp"
#include "SendTimelinePacket.hpp"
#include "TimelinePacketWriterFactory.hpp"
+#include <armnn/backends/profiling/IBackendProfilingContext.hpp>
namespace armnn
{
@@ -63,6 +64,13 @@ public:
// Disconnects the profiling service from the external server
void Disconnect();
+ // Store a profiling context returned from a backend that support profiling.
+ void AddBackendProfilingContext(const BackendId backendId,
+ std::shared_ptr<armnn::profiling::IBackendProfilingContext> profilingContext)
+ {
+ m_BackendProfilingContexts.emplace(backendId, std::move(profilingContext));
+ }
+
const ICounterDirectory& GetCounterDirectory() const;
ICounterRegistry& GetCounterRegistry();
ProfilingState GetCurrentState() const;
@@ -132,6 +140,8 @@ private:
PerJobCounterSelectionCommandHandler m_PerJobCounterSelectionCommandHandler;
ProfilingGuidGenerator m_GuidGenerator;
TimelinePacketWriterFactory m_TimelinePacketWriterFactory;
+ std::unordered_map<BackendId,
+ std::shared_ptr<armnn::profiling::IBackendProfilingContext>> m_BackendProfilingContexts;
protected:
// Default constructor/destructor kept protected for testing
diff --git a/src/profiling/backends/BackendProfiling.cpp b/src/profiling/backends/BackendProfiling.cpp
new file mode 100644
index 0000000000..a49122a7a1
--- /dev/null
+++ b/src/profiling/backends/BackendProfiling.cpp
@@ -0,0 +1,48 @@
+//
+// Copyright © 2020 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "BackendProfiling.hpp"
+#include "RegisterBackendCounters.hpp"
+
+namespace armnn
+{
+
+namespace profiling
+{
+
+std::unique_ptr<IRegisterBackendCounters>
+ BackendProfiling::GetCounterRegistrationInterface(uint16_t currentMaxGlobalCounterID)
+{
+ return std::make_unique<RegisterBackendCounters>(RegisterBackendCounters(currentMaxGlobalCounterID, m_backendId));
+}
+
+std::unique_ptr<ISendTimelinePacket> BackendProfiling::GetSendTimelinePacket()
+{
+ return m_ProfilingService.GetSendTimelinePacket();
+}
+
+IProfilingGuidGenerator& BackendProfiling::GetProfilingGuidGenerator()
+{
+ // The profiling service is our Guid Generator.
+ return m_ProfilingService;
+}
+
+CounterStatus BackendProfiling::GetCounterStatus(uint16_t)
+{
+ return CounterStatus();
+}
+
+std::vector<CounterStatus> BackendProfiling::GetActiveCounters()
+{
+ return std::vector<CounterStatus>();
+}
+
+bool BackendProfiling::IsProfilingEnabled() const
+{
+ return m_ProfilingService.IsProfilingEnabled();
+}
+
+} // namespace profiling
+} // namespace armnn
diff --git a/src/profiling/backends/BackendProfiling.hpp b/src/profiling/backends/BackendProfiling.hpp
new file mode 100644
index 0000000000..2bc365a1de
--- /dev/null
+++ b/src/profiling/backends/BackendProfiling.hpp
@@ -0,0 +1,49 @@
+//
+// Copyright © 2020 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include <ProfilingService.hpp>
+#include <armnn/backends/profiling/IBackendProfiling.hpp>
+
+namespace armnn
+{
+
+namespace profiling
+{
+
+class BackendProfiling : public IBackendProfiling
+{
+public:
+ BackendProfiling(const IRuntime::CreationOptions& options, ProfilingService& profilingService, const BackendId& id)
+ : m_options(options)
+ , m_ProfilingService(profilingService)
+ , m_backendId(id)
+ {}
+
+ ~BackendProfiling()
+ {}
+
+ std::unique_ptr<IRegisterBackendCounters>
+ GetCounterRegistrationInterface(uint16_t currentMaxGlobalCounterID) override;
+
+ std::unique_ptr<ISendTimelinePacket> GetSendTimelinePacket() override;
+
+ IProfilingGuidGenerator& GetProfilingGuidGenerator() override;
+
+ void ReportCounters(const std::vector<Timestamp>&) override
+ {}
+
+ CounterStatus GetCounterStatus(uint16_t backendCounterId) override;
+
+ std::vector<CounterStatus> GetActiveCounters() override;
+
+ bool IsProfilingEnabled() const override;
+
+private:
+ IRuntime::CreationOptions m_options;
+ ProfilingService& m_ProfilingService;
+ BackendId m_backendId;
+};
+} // namespace profiling
+} // namespace armnn \ No newline at end of file