From 344302581b66677a748a456f370752db75adde21 Mon Sep 17 00:00:00 2001 From: Jim Flynn Date: Fri, 4 Mar 2022 15:03:58 +0000 Subject: IVGCVSW-6816 Inject counter registration into ProfilingService Change-Id: I87ce3a1306eced9fc347cc383d9c7bc8994f0b0c Signed-off-by: Jim Flynn --- src/armnn/ArmNNProfilingServiceInitialiser.cpp | 121 +++++++++++++++++++++++++ src/armnn/ArmNNProfilingServiceInitialiser.hpp | 20 ++++ src/armnn/Runtime.cpp | 17 +++- src/armnn/Runtime.hpp | 8 +- src/armnn/test/RuntimeTests.cpp | 10 +- 5 files changed, 170 insertions(+), 6 deletions(-) create mode 100644 src/armnn/ArmNNProfilingServiceInitialiser.cpp create mode 100644 src/armnn/ArmNNProfilingServiceInitialiser.hpp (limited to 'src/armnn') diff --git a/src/armnn/ArmNNProfilingServiceInitialiser.cpp b/src/armnn/ArmNNProfilingServiceInitialiser.cpp new file mode 100644 index 0000000000..d23cce5634 --- /dev/null +++ b/src/armnn/ArmNNProfilingServiceInitialiser.cpp @@ -0,0 +1,121 @@ +// +// Copyright © 2022 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "ArmNNProfilingServiceInitialiser.hpp" + +#include +#include +#include + +namespace armnn +{ + +void ArmNNProfilingServiceInitialiser::InitialiseProfilingService(arm::pipe::IProfilingService& profilingService) +{ + uint16_t ZERO = 0; + double ONE = 1.0; + std::string ArmNN_Runtime("ArmNN_Runtime"); + // Register a category for the basic runtime counters + if (!profilingService.IsCategoryRegistered(ArmNN_Runtime)) + { + profilingService.GetCounterRegistry().RegisterCategory(ArmNN_Runtime); + } + + std::string networks("networks"); + std::string networkLoads("Network loads"); + // Register a counter for the number of Network loads + if (!profilingService.IsCounterRegistered(networkLoads)) + { + const arm::pipe::Counter* loadedNetworksCounter = + profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(), + arm::pipe::NETWORK_LOADS, + ArmNN_Runtime, + ZERO, + ZERO, + ONE, + networkLoads, + "The number of networks loaded at runtime", + networks); + ARMNN_ASSERT(loadedNetworksCounter); + profilingService.InitializeCounterValue(loadedNetworksCounter->m_Uid); + } + // Register a counter for the number of unloaded networks + std::string networkUnloads("Network unloads"); + if (!profilingService.IsCounterRegistered(networkUnloads)) + { + const arm::pipe::Counter* unloadedNetworksCounter = + profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(), + arm::pipe::NETWORK_UNLOADS, + ArmNN_Runtime, + ZERO, + ZERO, + ONE, + networkUnloads, + "The number of networks unloaded at runtime", + networks); + ARMNN_ASSERT(unloadedNetworksCounter); + profilingService.InitializeCounterValue(unloadedNetworksCounter->m_Uid); + } + std::string backends("backends"); + // Register a counter for the number of registered backends + std::string backendsRegistered("Backends registered"); + if (!profilingService.IsCounterRegistered(backendsRegistered)) + { + const arm::pipe::Counter* registeredBackendsCounter = + profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(), + arm::pipe::REGISTERED_BACKENDS, + ArmNN_Runtime, + ZERO, + ZERO, + ONE, + backendsRegistered, + "The number of registered backends", + backends); + ARMNN_ASSERT(registeredBackendsCounter); + profilingService.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 + profilingService.SetCounterValue(arm::pipe::REGISTERED_BACKENDS, static_cast( + armnn::BackendRegistryInstance().Size())); + } + // Register a counter for the number of registered backends + std::string backendsUnregistered("Backends unregistered"); + if (!profilingService.IsCounterRegistered(backendsUnregistered)) + { + const arm::pipe::Counter* unregisteredBackendsCounter = + profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(), + arm::pipe::UNREGISTERED_BACKENDS, + ArmNN_Runtime, + ZERO, + ZERO, + ONE, + backendsUnregistered, + "The number of unregistered backends", + backends); + ARMNN_ASSERT(unregisteredBackendsCounter); + profilingService.InitializeCounterValue(unregisteredBackendsCounter->m_Uid); + } + // Register a counter for the number of inferences run + std::string inferences("inferences"); + std::string inferencesRun("Inferences run"); + if (!profilingService.IsCounterRegistered(inferencesRun)) + { + const arm::pipe::Counter* inferencesRunCounter = + profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(), + arm::pipe::INFERENCES_RUN, + ArmNN_Runtime, + ZERO, + ZERO, + ONE, + inferencesRun, + "The number of inferences run", + inferences); + ARMNN_ASSERT(inferencesRunCounter); + profilingService.InitializeCounterValue(inferencesRunCounter->m_Uid); + } +} + +} // namespace armnn diff --git a/src/armnn/ArmNNProfilingServiceInitialiser.hpp b/src/armnn/ArmNNProfilingServiceInitialiser.hpp new file mode 100644 index 0000000000..e8a0ae0649 --- /dev/null +++ b/src/armnn/ArmNNProfilingServiceInitialiser.hpp @@ -0,0 +1,20 @@ +// +// Copyright © 2022 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include +#include + +namespace armnn +{ + +class ArmNNProfilingServiceInitialiser : public arm::pipe::IInitialiseProfilingService +{ +public: + void InitialiseProfilingService(arm::pipe::IProfilingService& profilingService) override; +}; + +} // namespace armnn diff --git a/src/armnn/Runtime.cpp b/src/armnn/Runtime.cpp index 4cc34ff6ac..af257e1be5 100644 --- a/src/armnn/Runtime.cpp +++ b/src/armnn/Runtime.cpp @@ -2,6 +2,8 @@ // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // + +#include "ArmNNProfilingServiceInitialiser.hpp" #include "Runtime.hpp" #include @@ -115,7 +117,11 @@ Status IRuntime::Execute(IWorkingMemHandle& workingMemHandle, std::vector preImportedInputs, std::vector preImportedOutputs) { - return pRuntimeImpl->Execute(workingMemHandle, inputTensors, outputTensors, preImportedInputs, preImportedOutputs); + return pRuntimeImpl->Execute(workingMemHandle, + inputTensors, + outputTensors, + preImportedInputs, + preImportedOutputs); } Status IRuntime::UnloadNetwork(NetworkId networkId) @@ -295,10 +301,17 @@ void RuntimeImpl::ReportStructure() // arm::pipe::IProfilingService& profilingSe } } +void RuntimeImpl::InitialiseProfilingService(arm::pipe::IProfilingService& profilingService) +{ + ArmNNProfilingServiceInitialiser initialiser; + initialiser.InitialiseProfilingService(profilingService); +} + RuntimeImpl::RuntimeImpl(const IRuntime::CreationOptions& options) : m_NetworkIdCounter(0) { - m_ProfilingService = arm::pipe::IProfilingService::CreateProfilingService(*this); + m_ProfilingService = arm::pipe::IProfilingService::CreateProfilingService( + arm::pipe::MAX_ARMNN_COUNTER, *this, *this); const auto start_time = armnn::GetTimeNow(); ARMNN_LOG(info) << "ArmNN v" << ARMNN_VERSION; if ( options.m_ProfilingOptions.m_TimelineEnabled && !options.m_ProfilingOptions.m_EnableProfiling ) diff --git a/src/armnn/Runtime.hpp b/src/armnn/Runtime.hpp index a8fa5fd5c5..f2462b15d2 100644 --- a/src/armnn/Runtime.hpp +++ b/src/armnn/Runtime.hpp @@ -14,6 +14,7 @@ #include +#include #include #include @@ -24,8 +25,9 @@ namespace armnn { using LoadedNetworks = std::unordered_map>; using IReportStructure = arm::pipe::IReportStructure; + using IInitialiseProfilingService = arm::pipe::IInitialiseProfilingService; -struct RuntimeImpl final : public IReportStructure +struct RuntimeImpl final : public IReportStructure, public IInitialiseProfilingService { public: /// Loads a complete network into the Runtime. @@ -108,7 +110,9 @@ public: //NOTE: we won't need the profiling service reference but it is good to pass the service // in this way to facilitate other implementations down the road - void ReportStructure(); + void ReportStructure() override; + + void InitialiseProfilingService(arm::pipe::IProfilingService& profilingService) override; private: friend void RuntimeLoadedNetworksReserve(RuntimeImpl* runtime); // See RuntimeTests.cpp diff --git a/src/armnn/test/RuntimeTests.cpp b/src/armnn/test/RuntimeTests.cpp index 73e36eaf56..afe4bc7ea0 100644 --- a/src/armnn/test/RuntimeTests.cpp +++ b/src/armnn/test/RuntimeTests.cpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include #include #include @@ -627,7 +629,9 @@ TEST_CASE("ProfilingDisable") armnn::NetworkId netId; CHECK(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success); - ProfilingServiceRuntimeHelper profilingServiceHelper(GetProfilingService(&runtime)); + armnn::ArmNNProfilingServiceInitialiser initialiser; + ProfilingServiceRuntimeHelper profilingServiceHelper( + arm::pipe::MAX_ARMNN_COUNTER, initialiser, GetProfilingService(&runtime)); BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager(); auto readableBuffer = bufferManager.GetReadableBuffer(); @@ -649,7 +653,9 @@ TEST_CASE("ProfilingEnableCpuRef") GetProfilingService(&runtime).ResetExternalProfilingOptions( ConvertExternalProfilingOptions(options.m_ProfilingOptions), false); - ProfilingServiceRuntimeHelper profilingServiceHelper(GetProfilingService(&runtime)); + armnn::ArmNNProfilingServiceInitialiser initialiser; + ProfilingServiceRuntimeHelper profilingServiceHelper( + arm::pipe::MAX_ARMNN_COUNTER, initialiser, GetProfilingService(&runtime)); profilingServiceHelper.ForceTransitionToState(ProfilingState::NotConnected); profilingServiceHelper.ForceTransitionToState(ProfilingState::WaitingForAck); profilingServiceHelper.ForceTransitionToState(ProfilingState::Active); -- cgit v1.2.1