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 +++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 src/armnn/ArmNNProfilingServiceInitialiser.cpp (limited to 'src/armnn/ArmNNProfilingServiceInitialiser.cpp') 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 -- cgit v1.2.1