IVGCVSW-4316 First draft of IBackendProfiling and IBackendProfilingContext
authorColm Donelan <Colm.Donelan@arm.com>
Wed, 29 Jan 2020 15:22:43 +0000 (15:22 +0000)
committerColm Donelan <Colm.Donelan@arm.com>
Wed, 29 Jan 2020 16:23:48 +0000 (16:23 +0000)
* Introduce two new backend profiling interfaces IBackendProfiling
  and IBackendProfilingContext.
* Add a mechanism to pull a context from a backend through IBackendInternal
* Update CL, Neon and Ref backends to return an empty profiling backend.

Signed-off-by: Colm Donelan <Colm.Donelan@arm.com>
Change-Id: I6e7438fcb126ad7a073a226862dc44836c9998b7

14 files changed:
include/armnn/backends/CMakeLists.txt
include/armnn/backends/IBackendInternal.hpp
include/armnn/backends/profiling/IBackendProfiling.hpp [new file with mode: 0644]
include/armnn/backends/profiling/IBackendProfilingContext.hpp [new file with mode: 0644]
src/backends/README.md
src/backends/backendsCommon/IBackendInternal.cpp
src/backends/backendsCommon/test/MockBackend.cpp
src/backends/backendsCommon/test/MockBackend.hpp
src/backends/cl/ClBackend.cpp
src/backends/cl/ClBackend.hpp
src/backends/neon/NeonBackend.cpp
src/backends/neon/NeonBackend.hpp
src/backends/reference/RefBackend.cpp
src/backends/reference/RefBackend.hpp

index 258ea8b..90a022a 100644 (file)
@@ -12,6 +12,8 @@ list(APPEND armnnBackendsAPI_sources
      IMemoryManager.hpp
      ITensorHandle.hpp
      OptimizationViews.hpp
+     profiling/IBackendProfiling.hpp
+     profiling/IBackendProfilingContext.hpp
 )
 
 add_library(armnnBackendsAPI OBJECT ${armnnBackendsAPI_sources})
index 3533ace..29097b4 100644 (file)
@@ -14,6 +14,8 @@
 #include <optimizations/Optimization.hpp>
 
 #include "IBackendContext.hpp"
+#include "armnn/backends/profiling/IBackendProfiling.hpp"
+#include "armnn/backends/profiling/IBackendProfilingContext.hpp"
 #include "IMemoryManager.hpp"
 #include "ITensorHandleFactory.hpp"
 #include "OptimizationViews.hpp"
@@ -77,6 +79,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 OptimizationPtr = std::unique_ptr<Optimization>;
     using Optimizations = std::vector<OptimizationPtr>;
     using ILayerSupportSharedPtr = std::shared_ptr<ILayerSupport>;
@@ -113,6 +117,10 @@ public:
 
     virtual IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const;
 
+    // Context specifically used for profiling interaction from backends.
+    virtual IBackendProfilingContextPtr CreateBackendProfilingContext(const IRuntime::CreationOptions& creationOptions,
+        armnn::profiling::IBackendProfiling& backendProfiling) const;
+
     virtual ILayerSupportSharedPtr GetLayerSupport() const = 0;
 
     virtual OptimizationViews OptimizeSubgraphView(const SubgraphView& subgraph) const;
diff --git a/include/armnn/backends/profiling/IBackendProfiling.hpp b/include/armnn/backends/profiling/IBackendProfiling.hpp
new file mode 100644 (file)
index 0000000..6ed7aba
--- /dev/null
@@ -0,0 +1,92 @@
+//
+// Copyright © 2020 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+#pragma once
+
+#include <armnn/IRuntime.hpp>
+#include <armnn/profiling/IProfilingGuidGenerator.hpp>
+#include <armnn/profiling/ISendTimelinePacket.hpp>
+#include <memory>
+#include <vector>
+
+namespace armnn
+{
+
+namespace profiling
+{
+
+struct CounterValue
+{
+    uint16_t counterId;
+    uint32_t counterValue;
+};
+
+struct Timestamp
+{
+    uint64_t timestamp;
+    std::vector<CounterValue> counterValues;
+};
+
+struct CounterStatus
+{
+    uint16_t m_BackendCounterId;
+    uint16_t m_GlobalCounterId;
+    bool     m_Enabled;
+    uint32_t m_SamplingRateInMicroseconds;
+};
+
+class IRegisterBackendCounters
+{
+public:
+    uint16_t RegisterCategory(const std::string& categoryName,
+                              const Optional<uint16_t>& deviceUid     = EmptyOptional(),
+                              const Optional<uint16_t>& counterSetUid = EmptyOptional());
+
+    uint16_t RegisterDevice(const std::string& deviceName,
+                            uint16_t cores                                  = 0,
+                            const Optional<std::string>& parentCategoryName = EmptyOptional());
+
+    uint16_t RegisterCounterSet(const std::string& counterSetName,
+                                uint16_t count                                  = 0,
+                                const Optional<std::string>& parentCategoryName = EmptyOptional());
+
+    uint16_t RegisterCounter(const uint16_t uid,
+                             const std::string& parentCategoryName,
+                             uint16_t counterClass,
+                             uint16_t interpolation,
+                             double multiplier,
+                             const std::string& name,
+                             const std::string& description,
+                             const Optional<std::string>& units      = EmptyOptional(),
+                             const Optional<uint16_t>& numberOfCores = EmptyOptional(),
+                             const Optional<uint16_t>& deviceUid     = EmptyOptional(),
+                             const Optional<uint16_t>& counterSetUid = EmptyOptional());
+};
+
+class IBackendProfiling
+{
+protected:
+    IBackendProfiling(const IRuntime::CreationOptions&)
+    {}
+
+public:
+    virtual ~IBackendProfiling()
+    {}
+
+    IRegisterBackendCounters GetCounterRegistrationInterface(uint16_t currentMaxGlobalCounterID);
+
+    ISendTimelinePacket& GetSendTimelinePacket();
+
+    IProfilingGuidGenerator& GetProfilingGuidGenerator();
+
+    void ReportCounters(const std::vector<Timestamp>& counterValues);
+
+    CounterStatus GetCounterStatus(uint16_t backendCounterId);
+
+    std::vector<CounterStatus> GetActiveCounters();
+
+    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
new file mode 100644 (file)
index 0000000..d5d9183
--- /dev/null
@@ -0,0 +1,32 @@
+//
+// Copyright © 2020 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+#pragma once
+
+#include <armnn/IRuntime.hpp>
+#include <vector>
+
+namespace armnn
+{
+namespace profiling
+{
+
+class IBackendProfilingContext
+{
+protected:
+    IBackendProfilingContext(const IRuntime::CreationOptions&)
+    {}
+
+public:
+    virtual ~IBackendProfilingContext()
+    {}
+    virtual uint16_t RegisterCounters(uint16_t currentMaxGlobalCounterID);
+    virtual void ActivateCounters(uint32_t capturePeriod, const std::vector<uint16_t>& counterIds);
+    virtual std::vector<Timestamp> ReportCounterValues();
+    virtual void EnableProfiling(bool flag);
+};
+
+using IBackendProfilingContextUniquePtr = std::unique_ptr<IBackendProfilingContext>;
+}    // namespace profiling
+}    // namespace armnn
\ No newline at end of file
index 6005fac..b337609 100644 (file)
@@ -113,6 +113,8 @@ The interface functions to be implemented are:
     virtual IWorkloadFactoryPtr CreateWorkloadFactory(
             const IMemoryManagerSharedPtr& memoryManager = nullptr) const = 0;
     virtual IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const = 0;
+    virtual IBackendProfilingContextPtr CreateBackendProfilingContext(const IRuntime::CreationOptions& creationOptions,
+            armnn::profiling::IBackendProfiling& backendProfiling) const = 0;
     virtual ILayerSupportSharedPtr GetLayerSupport() const = 0;
     virtual Optimizations GetOptimizations() const = 0;
     virtual SubgraphUniquePtr OptimizeSubgraph(const SubgraphView& subgraph, bool& optimizationAttempted) const;
index ad09730..c86d026 100644 (file)
@@ -44,6 +44,12 @@ IBackendInternal::IBackendContextPtr IBackendInternal::CreateBackendContext(cons
     return IBackendContextPtr{};
 }
 
+IBackendInternal::IBackendProfilingContextPtr IBackendInternal::CreateBackendProfilingContext(
+    const IRuntime::CreationOptions&, armnn::profiling::IBackendProfiling&) const
+{
+    return IBackendProfilingContextPtr{};
+}
+
 // Default implementation of OptimizeSubgraphView for backward compatibility with the old API.
 // Override this method with a custom optimization implementation.
 OptimizationViews IBackendInternal::OptimizeSubgraphView(const SubgraphView& subgraph) const
index 367d9cb..d8f8cfe 100644 (file)
@@ -98,6 +98,12 @@ IBackendInternal::IBackendContextPtr MockBackend::CreateBackendContext(const IRu
     return IBackendContextPtr{};
 }
 
+IBackendInternal::IBackendProfilingContextPtr MockBackend::CreateBackendProfilingContext(
+    const IRuntime::CreationOptions&, armnn::profiling::IBackendProfiling&) const
+{
+    return IBackendProfilingContextPtr{};
+}
+
 IBackendInternal::IMemoryManagerUniquePtr MockBackend::CreateMemoryManager() const
 {
     return IMemoryManagerUniquePtr{};
index 771e499..3fe3100 100644 (file)
@@ -28,6 +28,9 @@ public:
         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::Optimizations GetOptimizations() const override;
     IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override;
index 0e6b5ab..8e839ae 100644 (file)
@@ -74,6 +74,13 @@ ClBackend::CreateBackendContext(const IRuntime::CreationOptions& options) const
     return IBackendContextPtr{new ClBackendContext{options}};
 }
 
+IBackendInternal::IBackendProfilingContextPtr ClBackend::CreateBackendProfilingContext(
+    const IRuntime::CreationOptions&,
+    armnn::profiling::IBackendProfiling&) const
+{
+    return IBackendProfilingContextPtr{};
+}
+
 IBackendInternal::Optimizations ClBackend::GetOptimizations() const
 {
     return Optimizations{};
index bb27bb2..703ae17 100644 (file)
@@ -31,6 +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::Optimizations GetOptimizations() const override;
     IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override;
index 2ecd270..1d48297 100644 (file)
@@ -61,6 +61,13 @@ IBackendInternal::IBackendContextPtr NeonBackend::CreateBackendContext(const IRu
     return IBackendContextPtr{};
 }
 
+IBackendInternal::IBackendProfilingContextPtr NeonBackend::CreateBackendProfilingContext(
+    const IRuntime::CreationOptions&,
+    armnn::profiling::IBackendProfiling&) const
+{
+    return IBackendProfilingContextPtr{};
+}
+
 IBackendInternal::Optimizations NeonBackend::GetOptimizations() const
 {
     return Optimizations{};
index a2edbaf..b1eeeb6 100644 (file)
@@ -27,7 +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::Optimizations GetOptimizations() const override;
     IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override;
 
index 7195d23..d006c72 100644 (file)
@@ -16,7 +16,6 @@
 
 #include <Optimizer.hpp>
 
-#include <boost/cast.hpp>
 #include <boost/polymorphic_pointer_cast.hpp>
 
 namespace armnn
@@ -49,6 +48,12 @@ IBackendInternal::IBackendContextPtr RefBackend::CreateBackendContext(const IRun
     return IBackendContextPtr{};
 }
 
+IBackendInternal::IBackendProfilingContextPtr RefBackend::CreateBackendProfilingContext(
+    const IRuntime::CreationOptions&, armnn::profiling::IBackendProfiling&) const
+{
+    return IBackendProfilingContextPtr{};
+}
+
 IBackendInternal::IMemoryManagerUniquePtr RefBackend::CreateMemoryManager() const
 {
     return std::make_unique<RefMemoryManager>();
index 850a1c1..e647b75 100644 (file)
@@ -28,6 +28,10 @@ public:
 
     IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const override;
 
+    IBackendInternal::IBackendProfilingContextPtr CreateBackendProfilingContext(
+        const IRuntime::CreationOptions& creationOptions,
+        armnn::profiling::IBackendProfiling& backendProfiling) const override;
+
     IBackendInternal::Optimizations GetOptimizations() const override;
     IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override;