From e49755b914a2c8f6f8b836adfcc61bf8f9a5b3a3 Mon Sep 17 00:00:00 2001 From: Colm Donelan Date: Wed, 29 Jan 2020 15:22:43 +0000 Subject: IVGCVSW-4316 First draft of IBackendProfiling and IBackendProfilingContext * 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 Change-Id: I6e7438fcb126ad7a073a226862dc44836c9998b7 --- include/armnn/backends/CMakeLists.txt | 2 + include/armnn/backends/IBackendInternal.hpp | 8 ++ .../armnn/backends/profiling/IBackendProfiling.hpp | 92 ++++++++++++++++++++++ .../profiling/IBackendProfilingContext.hpp | 32 ++++++++ src/backends/README.md | 2 + src/backends/backendsCommon/IBackendInternal.cpp | 6 ++ src/backends/backendsCommon/test/MockBackend.cpp | 6 ++ src/backends/backendsCommon/test/MockBackend.hpp | 3 + src/backends/cl/ClBackend.cpp | 7 ++ src/backends/cl/ClBackend.hpp | 2 + src/backends/neon/NeonBackend.cpp | 7 ++ src/backends/neon/NeonBackend.hpp | 3 +- src/backends/reference/RefBackend.cpp | 7 +- src/backends/reference/RefBackend.hpp | 4 + 14 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 include/armnn/backends/profiling/IBackendProfiling.hpp create mode 100644 include/armnn/backends/profiling/IBackendProfilingContext.hpp diff --git a/include/armnn/backends/CMakeLists.txt b/include/armnn/backends/CMakeLists.txt index 258ea8b9f9..90a022aad7 100644 --- a/include/armnn/backends/CMakeLists.txt +++ b/include/armnn/backends/CMakeLists.txt @@ -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}) diff --git a/include/armnn/backends/IBackendInternal.hpp b/include/armnn/backends/IBackendInternal.hpp index 3533aceb3c..29097b4ae7 100644 --- a/include/armnn/backends/IBackendInternal.hpp +++ b/include/armnn/backends/IBackendInternal.hpp @@ -14,6 +14,8 @@ #include #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; using IBackendContextPtr = std::unique_ptr; + // This is the bridge between backend and backend profiling we'll keep it in the backend namespace. + using IBackendProfilingContextPtr = std::unique_ptr; using OptimizationPtr = std::unique_ptr; using Optimizations = std::vector; using ILayerSupportSharedPtr = std::shared_ptr; @@ -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 index 0000000000..6ed7aba97d --- /dev/null +++ b/include/armnn/backends/profiling/IBackendProfiling.hpp @@ -0,0 +1,92 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// +#pragma once + +#include +#include +#include +#include +#include + +namespace armnn +{ + +namespace profiling +{ + +struct CounterValue +{ + uint16_t counterId; + uint32_t counterValue; +}; + +struct Timestamp +{ + uint64_t timestamp; + std::vector 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& deviceUid = EmptyOptional(), + const Optional& counterSetUid = EmptyOptional()); + + uint16_t RegisterDevice(const std::string& deviceName, + uint16_t cores = 0, + const Optional& parentCategoryName = EmptyOptional()); + + uint16_t RegisterCounterSet(const std::string& counterSetName, + uint16_t count = 0, + const Optional& 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& units = EmptyOptional(), + const Optional& numberOfCores = EmptyOptional(), + const Optional& deviceUid = EmptyOptional(), + const Optional& 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& counterValues); + + CounterStatus GetCounterStatus(uint16_t backendCounterId); + + std::vector 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 index 0000000000..d5d918322e --- /dev/null +++ b/include/armnn/backends/profiling/IBackendProfilingContext.hpp @@ -0,0 +1,32 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// +#pragma once + +#include +#include + +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& counterIds); + virtual std::vector ReportCounterValues(); + virtual void EnableProfiling(bool flag); +}; + +using IBackendProfilingContextUniquePtr = std::unique_ptr; +} // namespace profiling +} // namespace armnn \ No newline at end of file diff --git a/src/backends/README.md b/src/backends/README.md index 6005facacb..b3376099d4 100644 --- a/src/backends/README.md +++ b/src/backends/README.md @@ -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; diff --git a/src/backends/backendsCommon/IBackendInternal.cpp b/src/backends/backendsCommon/IBackendInternal.cpp index ad09730e33..c86d026e96 100644 --- a/src/backends/backendsCommon/IBackendInternal.cpp +++ b/src/backends/backendsCommon/IBackendInternal.cpp @@ -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 diff --git a/src/backends/backendsCommon/test/MockBackend.cpp b/src/backends/backendsCommon/test/MockBackend.cpp index 367d9cb8a5..d8f8cfe701 100644 --- a/src/backends/backendsCommon/test/MockBackend.cpp +++ b/src/backends/backendsCommon/test/MockBackend.cpp @@ -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{}; diff --git a/src/backends/backendsCommon/test/MockBackend.hpp b/src/backends/backendsCommon/test/MockBackend.hpp index 771e499280..3fe3100986 100644 --- a/src/backends/backendsCommon/test/MockBackend.hpp +++ b/src/backends/backendsCommon/test/MockBackend.hpp @@ -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; diff --git a/src/backends/cl/ClBackend.cpp b/src/backends/cl/ClBackend.cpp index 0e6b5ab2d5..8e839aec85 100644 --- a/src/backends/cl/ClBackend.cpp +++ b/src/backends/cl/ClBackend.cpp @@ -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{}; diff --git a/src/backends/cl/ClBackend.hpp b/src/backends/cl/ClBackend.hpp index bb27bb23b0..703ae1723d 100644 --- a/src/backends/cl/ClBackend.hpp +++ b/src/backends/cl/ClBackend.hpp @@ -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; diff --git a/src/backends/neon/NeonBackend.cpp b/src/backends/neon/NeonBackend.cpp index 2ecd270bd2..1d482974e1 100644 --- a/src/backends/neon/NeonBackend.cpp +++ b/src/backends/neon/NeonBackend.cpp @@ -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{}; diff --git a/src/backends/neon/NeonBackend.hpp b/src/backends/neon/NeonBackend.hpp index a2edbaf020..b1eeeb6ba7 100644 --- a/src/backends/neon/NeonBackend.hpp +++ b/src/backends/neon/NeonBackend.hpp @@ -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; diff --git a/src/backends/reference/RefBackend.cpp b/src/backends/reference/RefBackend.cpp index 7195d231bc..d006c72d98 100644 --- a/src/backends/reference/RefBackend.cpp +++ b/src/backends/reference/RefBackend.cpp @@ -16,7 +16,6 @@ #include -#include #include 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(); diff --git a/src/backends/reference/RefBackend.hpp b/src/backends/reference/RefBackend.hpp index 850a1c17c3..e647b75454 100644 --- a/src/backends/reference/RefBackend.hpp +++ b/src/backends/reference/RefBackend.hpp @@ -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; -- cgit v1.2.1