From af947729dc2aa7cdb6d4a716e2edf307710a8155 Mon Sep 17 00:00:00 2001 From: Jim Flynn Date: Wed, 2 Mar 2022 11:04:47 +0000 Subject: IVGCVSW-6811 replace ProfilingService includes with IProfilingService Change-Id: I00521756c8a19d10bfdc98c6ef4204c7f84901c6 Signed-off-by: Jim Flynn --- src/profiling/IProfilingService.cpp | 49 +++++++++++++++++++++++++++++ src/profiling/IProfilingService.hpp | 37 ++++++++++++++++++++-- src/profiling/ProfilingService.cpp | 27 ---------------- src/profiling/ProfilingService.hpp | 43 ++++++------------------- src/profiling/ProfilingState.hpp | 24 ++++++++++++++ src/profiling/ProfilingStateMachine.hpp | 11 ++----- src/profiling/RegisterBackendCounters.hpp | 8 ++--- src/profiling/TimelineUtilityMethods.cpp | 26 +++++++-------- src/profiling/TimelineUtilityMethods.hpp | 4 +-- src/profiling/backends/BackendProfiling.hpp | 4 +-- src/profiling/test/ProfilingTestUtils.hpp | 9 +++--- 11 files changed, 145 insertions(+), 97 deletions(-) create mode 100644 src/profiling/IProfilingService.cpp create mode 100644 src/profiling/ProfilingState.hpp (limited to 'src/profiling') diff --git a/src/profiling/IProfilingService.cpp b/src/profiling/IProfilingService.cpp new file mode 100644 index 0000000000..9b1aac5a4e --- /dev/null +++ b/src/profiling/IProfilingService.cpp @@ -0,0 +1,49 @@ +// +// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "IProfilingService.hpp" +#include "ProfilingService.hpp" + +namespace arm +{ + +namespace pipe +{ + +std::unique_ptr IProfilingService::CreateProfilingService( + armnn::Optional reportStructure) +{ + return std::make_unique(reportStructure); +} + +ProfilingGuidGenerator IProfilingService::m_GuidGenerator; + +ProfilingDynamicGuid IProfilingService::GetNextGuid() +{ + return m_GuidGenerator.NextGuid(); +} + +ProfilingStaticGuid IProfilingService::GetStaticId(const std::string& str) +{ + return m_GuidGenerator.GenerateStaticId(str); +} + +void IProfilingService::ResetGuidGenerator() +{ + m_GuidGenerator.Reset(); +} + +ProfilingDynamicGuid IProfilingService::NextGuid() +{ + return IProfilingService::GetNextGuid(); +} + +ProfilingStaticGuid IProfilingService::GenerateStaticId(const std::string& str) +{ + return IProfilingService::GetStaticId(str); +} + +} // namespace pipe +} // namespace arm diff --git a/src/profiling/IProfilingService.hpp b/src/profiling/IProfilingService.hpp index c2e824e6f5..31d9b8d1e3 100644 --- a/src/profiling/IProfilingService.hpp +++ b/src/profiling/IProfilingService.hpp @@ -7,9 +7,16 @@ #include "CounterIdMap.hpp" #include "Holder.hpp" +#include "ICounterValues.hpp" +#include "ICounterRegistry.hpp" #include "IProfilingServiceStatus.hpp" #include "ISendCounterPacket.hpp" +#include "IReportStructure.hpp" +#include "ProfilingState.hpp" +#include +#include +#include #include namespace arm @@ -18,18 +25,44 @@ namespace arm namespace pipe { -class IProfilingService : public IProfilingGuidGenerator, public IProfilingServiceStatus +class IProfilingService : public IProfilingGuidGenerator, + public IProfilingServiceStatus, + public IReadWriteCounterValues { public: + static std::unique_ptr CreateProfilingService( + armnn::Optional reportStructure = armnn::EmptyOptional()); virtual ~IProfilingService() {}; virtual std::unique_ptr GetSendTimelinePacket() const = 0; virtual const ICounterMappings& GetCounterMappings() const = 0; virtual ISendCounterPacket& GetSendCounterPacket() = 0; virtual bool IsProfilingEnabled() const = 0; + virtual bool IsTimelineReportingEnabled() const = 0; virtual CaptureData GetCaptureData() = 0; + virtual ProfilingState GetCurrentState() const = 0; + // Resets the profiling options, optionally clears the profiling service entirely + virtual void ResetExternalProfilingOptions(const ProfilingOptions& options, + bool resetProfilingService = false) = 0; + virtual ProfilingState ConfigureProfilingService(const ProfilingOptions& options, + bool resetProfilingService = false) = 0; + // Store a profiling context returned from a backend that support profiling. + virtual void AddBackendProfilingContext(const armnn::BackendId backendId, + std::shared_ptr profilingContext) = 0; + virtual ICounterRegistry& GetCounterRegistry() = 0; + virtual IRegisterCounterMapping& GetCounterMappingRegistry() = 0; + // IProfilingGuidGenerator functions + /// Return the next random Guid in the sequence + ProfilingDynamicGuid NextGuid() override; + /// Create a ProfilingStaticGuid based on a hash of the string + ProfilingStaticGuid GenerateStaticId(const std::string& str) override; + static ProfilingDynamicGuid GetNextGuid(); + static ProfilingStaticGuid GetStaticId(const std::string& str); + void ResetGuidGenerator(); + +private: + static ProfilingGuidGenerator m_GuidGenerator; }; } // namespace pipe } // namespace arm - diff --git a/src/profiling/ProfilingService.cpp b/src/profiling/ProfilingService.cpp index cef8a6d9ea..2e67dc870d 100644 --- a/src/profiling/ProfilingService.cpp +++ b/src/profiling/ProfilingService.cpp @@ -21,23 +21,6 @@ namespace arm namespace pipe { -ProfilingGuidGenerator ProfilingService::m_GuidGenerator; - -ProfilingDynamicGuid ProfilingService::GetNextGuid() -{ - return m_GuidGenerator.NextGuid(); -} - -ProfilingStaticGuid ProfilingService::GetStaticId(const std::string& str) -{ - return m_GuidGenerator.GenerateStaticId(str); -} - -void ProfilingService::ResetGuidGenerator() -{ - m_GuidGenerator.Reset(); -} - void ProfilingService::ResetExternalProfilingOptions(const arm::pipe::ProfilingOptions& options, bool resetProfilingService) { @@ -316,16 +299,6 @@ uint32_t ProfilingService::IncrementCounterValue(uint16_t counterUid) return counterValuePtr->operator++(std::memory_order::memory_order_relaxed); } -ProfilingDynamicGuid ProfilingService::NextGuid() -{ - return ProfilingService::GetNextGuid(); -} - -ProfilingStaticGuid ProfilingService::GenerateStaticId(const std::string& str) -{ - return ProfilingService::GetStaticId(str); -} - std::unique_ptr ProfilingService::GetSendTimelinePacket() const { return m_TimelinePacketWriterFactory.GetSendTimelinePacket(); diff --git a/src/profiling/ProfilingService.hpp b/src/profiling/ProfilingService.hpp index ab71b0c768..a4b02c10ad 100644 --- a/src/profiling/ProfilingService.hpp +++ b/src/profiling/ProfilingService.hpp @@ -15,7 +15,6 @@ #include "ICounterRegistry.hpp" #include "ICounterValues.hpp" #include -#include #include "IProfilingService.hpp" #include "IReportStructure.hpp" #include "PeriodicCounterCapture.hpp" @@ -29,9 +28,9 @@ #include "SendTimelinePacket.hpp" #include "TimelinePacketWriterFactory.hpp" #include "INotifyBackends.hpp" +#include #include -#include #include @@ -40,15 +39,8 @@ namespace arm namespace pipe { -// Static constants describing ArmNN's counter UID's -static const uint16_t NETWORK_LOADS = 0; -static const uint16_t NETWORK_UNLOADS = 1; -static const uint16_t REGISTERED_BACKENDS = 2; -static const uint16_t UNREGISTERED_BACKENDS = 3; -static const uint16_t INFERENCES_RUN = 4; -static const uint16_t MAX_ARMNN_COUNTER = INFERENCES_RUN; - -class ProfilingService : public IReadWriteCounterValues, public IProfilingService, public INotifyBackends + +class ProfilingService : public IProfilingService, public INotifyBackends { public: using IProfilingConnectionFactoryPtr = std::unique_ptr; @@ -150,9 +142,9 @@ public: // Resets the profiling options, optionally clears the profiling service entirely void ResetExternalProfilingOptions(const ProfilingOptions& options, - bool resetProfilingService = false); + bool resetProfilingService = false) override; ProfilingState ConfigureProfilingService(const ProfilingOptions& options, - bool resetProfilingService = false); + bool resetProfilingService = false) override; // Updates the profiling service, making it transition to a new state if necessary @@ -163,21 +155,21 @@ public: // Store a profiling context returned from a backend that support profiling. void AddBackendProfilingContext(const armnn::BackendId backendId, - std::shared_ptr profilingContext); + std::shared_ptr profilingContext) override; // Enable the recording of timeline events and entities void NotifyBackendsForTimelineReporting() override; const ICounterDirectory& GetCounterDirectory() const; - ICounterRegistry& GetCounterRegistry(); - ProfilingState GetCurrentState() const; + ICounterRegistry& GetCounterRegistry() override; + ProfilingState GetCurrentState() const override; bool IsCounterRegistered(uint16_t counterUid) const override; uint32_t GetAbsoluteCounterValue(uint16_t counterUid) const override; uint32_t GetDeltaCounterValue(uint16_t counterUid) override; uint16_t GetCounterCount() const override; // counter global/backend mapping functions const ICounterMappings& GetCounterMappings() const override; - IRegisterCounterMapping& GetCounterMappingRegistry(); + IRegisterCounterMapping& GetCounterMappingRegistry() override; // Getters for the profiling service state bool IsProfilingEnabled() const override; @@ -193,13 +185,6 @@ public: uint32_t SubtractCounterValue(uint16_t counterUid, uint32_t value) override; uint32_t IncrementCounterValue(uint16_t counterUid) override; - // IProfilingGuidGenerator functions - /// Return the next random Guid in the sequence - ProfilingDynamicGuid NextGuid() override; - /// Create a ProfilingStaticGuid based on a hash of the string - ProfilingStaticGuid GenerateStaticId(const std::string& str) override; - - std::unique_ptr GetSendTimelinePacket() const override; ISendCounterPacket& GetSendCounterPacket() override @@ -207,13 +192,7 @@ public: return m_SendCounterPacket; } - static ProfilingDynamicGuid GetNextGuid(); - - static ProfilingStaticGuid GetStaticId(const std::string& str); - - void ResetGuidGenerator(); - - bool IsTimelineReportingEnabled() + bool IsTimelineReportingEnabled() const override { return m_TimelineReporting; } @@ -272,8 +251,6 @@ private: BackendProfilingContext m_BackendProfilingContexts; uint16_t m_MaxGlobalCounterId; - static ProfilingGuidGenerator m_GuidGenerator; - // Signalling to let external actors know when service is active or not std::mutex m_ServiceActiveMutex; std::condition_variable m_ServiceActiveConditionVariable; diff --git a/src/profiling/ProfilingState.hpp b/src/profiling/ProfilingState.hpp new file mode 100644 index 0000000000..0fc1903118 --- /dev/null +++ b/src/profiling/ProfilingState.hpp @@ -0,0 +1,24 @@ +// +// Copyright © 2022 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +namespace arm +{ + +namespace pipe +{ + +enum class ProfilingState +{ + Uninitialised, + NotConnected, + WaitingForAck, + Active +}; + +} // namespace pipe + +} // namespace arm diff --git a/src/profiling/ProfilingStateMachine.hpp b/src/profiling/ProfilingStateMachine.hpp index 2980556ca8..2648bcaba0 100644 --- a/src/profiling/ProfilingStateMachine.hpp +++ b/src/profiling/ProfilingStateMachine.hpp @@ -5,6 +5,8 @@ #pragma once +#include "ProfilingState.hpp" + #include #include @@ -15,14 +17,6 @@ namespace arm namespace pipe { -enum class ProfilingState -{ - Uninitialised, - NotConnected, - WaitingForAck, - Active -}; - class ProfilingStateMachine { public: @@ -71,4 +65,3 @@ constexpr char const* GetProfilingStateName(ProfilingState state) } // namespace pipe } // namespace arm - diff --git a/src/profiling/RegisterBackendCounters.hpp b/src/profiling/RegisterBackendCounters.hpp index f25feb5306..34f9f3a3eb 100644 --- a/src/profiling/RegisterBackendCounters.hpp +++ b/src/profiling/RegisterBackendCounters.hpp @@ -8,7 +8,7 @@ #include "armnn/backends/profiling/IBackendProfiling.hpp" #include "CounterIdMap.hpp" #include "CounterDirectory.hpp" -#include "ProfilingService.hpp" +#include "IProfilingService.hpp" namespace arm { @@ -21,7 +21,7 @@ class RegisterBackendCounters : public IRegisterBackendCounters public: RegisterBackendCounters( - uint16_t currentMaxGlobalCounterID, const armnn::BackendId& backendId, ProfilingService& profilingService) + uint16_t currentMaxGlobalCounterID, const armnn::BackendId& backendId, IProfilingService& profilingService) : m_CurrentMaxGlobalCounterID(currentMaxGlobalCounterID), m_BackendId(backendId), m_ProfilingService(profilingService), @@ -55,10 +55,10 @@ public: private: uint16_t m_CurrentMaxGlobalCounterID; const armnn::BackendId& m_BackendId; - ProfilingService& m_ProfilingService; + IProfilingService& m_ProfilingService; ICounterRegistry& m_CounterDirectory; }; } // namespace pipe -} // namespace arm \ No newline at end of file +} // namespace arm diff --git a/src/profiling/TimelineUtilityMethods.cpp b/src/profiling/TimelineUtilityMethods.cpp index bc8e7b6ce8..fea8ed7ae0 100644 --- a/src/profiling/TimelineUtilityMethods.cpp +++ b/src/profiling/TimelineUtilityMethods.cpp @@ -15,7 +15,7 @@ namespace arm namespace pipe { -std::unique_ptr TimelineUtilityMethods::GetTimelineUtils(ProfilingService& profilingService) +std::unique_ptr TimelineUtilityMethods::GetTimelineUtils(IProfilingService& profilingService) { if (profilingService.GetCurrentState() == ProfilingState::Active && profilingService.IsTimelineReportingEnabled()) { @@ -114,7 +114,7 @@ ProfilingDynamicGuid TimelineUtilityMethods::CreateNamedTypedEntity(const std::s } // Generate dynamic GUID of the entity - ProfilingDynamicGuid entityGuid = ProfilingService::GetNextGuid(); + ProfilingDynamicGuid entityGuid = IProfilingService::GetNextGuid(); CreateNamedTypedEntity(entityGuid, name, type); @@ -177,7 +177,7 @@ ProfilingStaticGuid TimelineUtilityMethods::DeclareLabel(const std::string& labe } // Generate a static GUID for the given label name - ProfilingStaticGuid labelGuid = ProfilingService::GetStaticId(labelName); + ProfilingStaticGuid labelGuid = IProfilingService::GetStaticId(labelName); // Send the new label to the external profiling service, this call throws in case of error m_SendTimelinePacket->SendTimelineLabelBinaryPacket(labelGuid, labelName); @@ -200,7 +200,7 @@ void TimelineUtilityMethods::MarkEntityWithLabel(ProfilingGuid entityGuid, ProfilingStaticGuid labelGuid = DeclareLabel(labelName); // Generate a GUID for the label relationship - ProfilingDynamicGuid relationshipGuid = ProfilingService::GetNextGuid(); + ProfilingDynamicGuid relationshipGuid = IProfilingService::GetNextGuid(); // Send the new label link to the external profiling service, this call throws in case of error m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, @@ -214,7 +214,7 @@ void TimelineUtilityMethods::MarkEntityWithType(ProfilingGuid entityGuid, ProfilingStaticGuid typeNameGuid) { // Generate a GUID for the label relationship - ProfilingDynamicGuid relationshipGuid = ProfilingService::GetNextGuid(); + ProfilingDynamicGuid relationshipGuid = IProfilingService::GetNextGuid(); // Send the new label link to the external profiling service, this call throws in case of error m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, @@ -256,7 +256,7 @@ ProfilingDynamicGuid TimelineUtilityMethods::CreateNamedTypedChildEntity(Profili ProfilingDynamicGuid childEntityGuid = CreateNamedTypedEntity(entityName, entityType); // Generate a GUID for the retention link relationship - ProfilingDynamicGuid retentionLinkGuid = ProfilingService::GetNextGuid(); + ProfilingDynamicGuid retentionLinkGuid = IProfilingService::GetNextGuid(); // Send the new retention link to the external profiling service, this call throws in case of error m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink, @@ -291,7 +291,7 @@ void TimelineUtilityMethods::CreateNamedTypedChildEntity(ProfilingGuid childEnti CreateNamedTypedEntity(childEntityGuid, entityName, entityType); // Generate a GUID for the retention link relationship - ProfilingDynamicGuid retentionLinkGuid = ProfilingService::GetNextGuid(); + ProfilingDynamicGuid retentionLinkGuid = IProfilingService::GetNextGuid(); // Send the new retention link to the external profiling service, this call throws in case of error m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink, @@ -317,7 +317,7 @@ void TimelineUtilityMethods::CreateNamedTypedChildEntity(ProfilingGuid childEnti CreateNamedTypedEntity(childEntityGuid, entityName, typeGuid); // Generate a GUID for the retention link relationship - ProfilingDynamicGuid retentionLinkGuid = ProfilingService::GetNextGuid(); + ProfilingDynamicGuid retentionLinkGuid = IProfilingService::GetNextGuid(); // Send the new retention link to the external profiling service, this call throws in case of error m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink, @@ -333,7 +333,7 @@ ProfilingDynamicGuid TimelineUtilityMethods::CreateRelationship(ProfilingRelatio ProfilingGuid relationshipCategory) { // Generate a GUID for the relationship - ProfilingDynamicGuid relationshipGuid = ProfilingService::GetNextGuid(); + ProfilingDynamicGuid relationshipGuid = IProfilingService::GetNextGuid(); // Send the new retention link to the external profiling service, this call throws in case of error m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType, @@ -349,7 +349,7 @@ ProfilingDynamicGuid TimelineUtilityMethods::CreateConnectionRelationship(Profil ProfilingGuid tailGuid) { // Generate a GUID for the relationship - ProfilingDynamicGuid relationshipGuid = ProfilingService::GetNextGuid(); + ProfilingDynamicGuid relationshipGuid = IProfilingService::GetNextGuid(); // Send the new retention link to the external profiling service, this call throws in case of error m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(relationshipType, @@ -378,13 +378,13 @@ ProfilingDynamicGuid TimelineUtilityMethods::RecordEvent(ProfilingGuid entityGui int threadId = armnnUtils::Threads::GetCurrentThreadId(); // Generate a GUID for the event - ProfilingDynamicGuid eventGuid = ProfilingService::GetNextGuid(); + ProfilingDynamicGuid eventGuid = IProfilingService::GetNextGuid(); // Send the new timeline event to the external profiling service, this call throws in case of error m_SendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventGuid); // Generate a GUID for the execution link - ProfilingDynamicGuid executionLinkId = ProfilingService::GetNextGuid(); + ProfilingDynamicGuid executionLinkId = IProfilingService::GetNextGuid(); // Send the new execution link to the external profiling service, this call throws in case of error m_SendTimelinePacket->SendTimelineRelationshipBinaryPacket(ProfilingRelationshipType::ExecutionLink, @@ -399,7 +399,7 @@ ProfilingDynamicGuid TimelineUtilityMethods::RecordEvent(ProfilingGuid entityGui ProfilingDynamicGuid TimelineUtilityMethods::RecordWorkloadInferenceAndStartOfLifeEvent(ProfilingGuid workloadGuid, ProfilingGuid inferenceGuid) { - ProfilingDynamicGuid workloadInferenceGuid = ProfilingService::GetNextGuid(); + ProfilingDynamicGuid workloadInferenceGuid = IProfilingService::GetNextGuid(); CreateTypedEntity(workloadInferenceGuid, LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID); CreateRelationship(ProfilingRelationshipType::RetentionLink, inferenceGuid, diff --git a/src/profiling/TimelineUtilityMethods.hpp b/src/profiling/TimelineUtilityMethods.hpp index d0c96587b4..fa25dc47b0 100644 --- a/src/profiling/TimelineUtilityMethods.hpp +++ b/src/profiling/TimelineUtilityMethods.hpp @@ -5,7 +5,7 @@ #pragma once -#include "ProfilingService.hpp" +#include "IProfilingService.hpp" #include "armnn/profiling/ISendTimelinePacket.hpp" #include @@ -22,7 +22,7 @@ public: // static factory method which will return a pointer to a timelie utility methods // object if profiling is enabled. Otherwise will return a null unique_ptr - static std::unique_ptr GetTimelineUtils(ProfilingService& profilingService); + static std::unique_ptr GetTimelineUtils(IProfilingService& profilingService); TimelineUtilityMethods( std::unique_ptr& sendTimelinePacket) diff --git a/src/profiling/backends/BackendProfiling.hpp b/src/profiling/backends/BackendProfiling.hpp index 82678a162f..545234db56 100644 --- a/src/profiling/backends/BackendProfiling.hpp +++ b/src/profiling/backends/BackendProfiling.hpp @@ -18,7 +18,7 @@ class BackendProfiling : public IBackendProfiling { public: BackendProfiling(const ProfilingOptions& options, - ProfilingService& profilingService, + IProfilingService& profilingService, const armnn::BackendId& backendId) : m_Options(options), m_ProfilingService(profilingService), @@ -44,7 +44,7 @@ public: private: ProfilingOptions m_Options; - ProfilingService& m_ProfilingService; + IProfilingService& m_ProfilingService; armnn::BackendId m_BackendId; }; diff --git a/src/profiling/test/ProfilingTestUtils.hpp b/src/profiling/test/ProfilingTestUtils.hpp index 810a34c3e2..16c6dde4ea 100644 --- a/src/profiling/test/ProfilingTestUtils.hpp +++ b/src/profiling/test/ProfilingTestUtils.hpp @@ -72,23 +72,22 @@ namespace pipe class ProfilingServiceRuntimeHelper : public ProfilingService { public: - ProfilingServiceRuntimeHelper(ProfilingService& profilingService) + ProfilingServiceRuntimeHelper(IProfilingService& profilingService) : m_ProfilingService(profilingService) {} ~ProfilingServiceRuntimeHelper() = default; BufferManager& GetProfilingBufferManager() { - return GetBufferManager(m_ProfilingService); + return GetBufferManager(static_cast(m_ProfilingService)); } - ProfilingService& m_ProfilingService; + IProfilingService& m_ProfilingService; void ForceTransitionToState(ProfilingState newState) { - TransitionToState(m_ProfilingService, newState); + TransitionToState(static_cast(m_ProfilingService), newState); } }; } // namespace pipe } // namespace arm - -- cgit v1.2.1