Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 1 | // |
Declan-ARM | 7c75e33 | 2024-03-12 16:40:25 +0000 | [diff] [blame^] | 2 | // Copyright © 2022,2024 Arm Ltd. All rights reserved. |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ArmNNProfilingServiceInitialiser.hpp" |
| 7 | |
| 8 | #include <armnn/BackendRegistry.hpp> |
| 9 | #include <armnn/profiling/ArmNNProfiling.hpp> |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 10 | #include <armnn/utility/Assert.hpp> |
| 11 | |
Jim Flynn | c454ac9 | 2022-03-16 18:43:18 +0000 | [diff] [blame] | 12 | #include <common/include/Counter.hpp> |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 13 | |
| 14 | namespace armnn |
| 15 | { |
| 16 | |
| 17 | void ArmNNProfilingServiceInitialiser::InitialiseProfilingService(arm::pipe::IProfilingService& profilingService) |
| 18 | { |
| 19 | uint16_t ZERO = 0; |
| 20 | double ONE = 1.0; |
| 21 | std::string ArmNN_Runtime("ArmNN_Runtime"); |
| 22 | // Register a category for the basic runtime counters |
| 23 | if (!profilingService.IsCategoryRegistered(ArmNN_Runtime)) |
| 24 | { |
| 25 | profilingService.GetCounterRegistry().RegisterCategory(ArmNN_Runtime); |
| 26 | } |
| 27 | |
| 28 | std::string networks("networks"); |
| 29 | std::string networkLoads("Network loads"); |
| 30 | // Register a counter for the number of Network loads |
| 31 | if (!profilingService.IsCounterRegistered(networkLoads)) |
| 32 | { |
| 33 | const arm::pipe::Counter* loadedNetworksCounter = |
| 34 | profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(), |
| 35 | arm::pipe::NETWORK_LOADS, |
| 36 | ArmNN_Runtime, |
| 37 | ZERO, |
| 38 | ZERO, |
| 39 | ONE, |
| 40 | networkLoads, |
| 41 | "The number of networks loaded at runtime", |
| 42 | networks); |
Declan-ARM | 7c75e33 | 2024-03-12 16:40:25 +0000 | [diff] [blame^] | 43 | if (!loadedNetworksCounter) |
| 44 | { |
| 45 | throw armnn::NullPointerException("loadedNetworksCounter must not be null."); |
| 46 | } |
| 47 | |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 48 | profilingService.InitializeCounterValue(loadedNetworksCounter->m_Uid); |
| 49 | } |
| 50 | // Register a counter for the number of unloaded networks |
| 51 | std::string networkUnloads("Network unloads"); |
| 52 | if (!profilingService.IsCounterRegistered(networkUnloads)) |
| 53 | { |
| 54 | const arm::pipe::Counter* unloadedNetworksCounter = |
| 55 | profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(), |
| 56 | arm::pipe::NETWORK_UNLOADS, |
| 57 | ArmNN_Runtime, |
| 58 | ZERO, |
| 59 | ZERO, |
| 60 | ONE, |
| 61 | networkUnloads, |
| 62 | "The number of networks unloaded at runtime", |
| 63 | networks); |
Declan-ARM | 7c75e33 | 2024-03-12 16:40:25 +0000 | [diff] [blame^] | 64 | |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 65 | profilingService.InitializeCounterValue(unloadedNetworksCounter->m_Uid); |
| 66 | } |
| 67 | std::string backends("backends"); |
| 68 | // Register a counter for the number of registered backends |
| 69 | std::string backendsRegistered("Backends registered"); |
| 70 | if (!profilingService.IsCounterRegistered(backendsRegistered)) |
| 71 | { |
| 72 | const arm::pipe::Counter* registeredBackendsCounter = |
| 73 | profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(), |
| 74 | arm::pipe::REGISTERED_BACKENDS, |
| 75 | ArmNN_Runtime, |
| 76 | ZERO, |
| 77 | ZERO, |
| 78 | ONE, |
| 79 | backendsRegistered, |
| 80 | "The number of registered backends", |
| 81 | backends); |
Declan-ARM | 7c75e33 | 2024-03-12 16:40:25 +0000 | [diff] [blame^] | 82 | |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 83 | profilingService.InitializeCounterValue(registeredBackendsCounter->m_Uid); |
| 84 | |
| 85 | // Due to backends being registered before the profiling service becomes active, |
| 86 | // we need to set the counter to the correct value here |
| 87 | profilingService.SetCounterValue(arm::pipe::REGISTERED_BACKENDS, static_cast<uint32_t>( |
| 88 | armnn::BackendRegistryInstance().Size())); |
| 89 | } |
| 90 | // Register a counter for the number of registered backends |
| 91 | std::string backendsUnregistered("Backends unregistered"); |
| 92 | if (!profilingService.IsCounterRegistered(backendsUnregistered)) |
| 93 | { |
| 94 | const arm::pipe::Counter* unregisteredBackendsCounter = |
| 95 | profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(), |
| 96 | arm::pipe::UNREGISTERED_BACKENDS, |
| 97 | ArmNN_Runtime, |
| 98 | ZERO, |
| 99 | ZERO, |
| 100 | ONE, |
| 101 | backendsUnregistered, |
| 102 | "The number of unregistered backends", |
| 103 | backends); |
Declan-ARM | 7c75e33 | 2024-03-12 16:40:25 +0000 | [diff] [blame^] | 104 | |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 105 | profilingService.InitializeCounterValue(unregisteredBackendsCounter->m_Uid); |
| 106 | } |
| 107 | // Register a counter for the number of inferences run |
| 108 | std::string inferences("inferences"); |
| 109 | std::string inferencesRun("Inferences run"); |
| 110 | if (!profilingService.IsCounterRegistered(inferencesRun)) |
| 111 | { |
| 112 | const arm::pipe::Counter* inferencesRunCounter = |
| 113 | profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(), |
| 114 | arm::pipe::INFERENCES_RUN, |
| 115 | ArmNN_Runtime, |
| 116 | ZERO, |
| 117 | ZERO, |
| 118 | ONE, |
| 119 | inferencesRun, |
| 120 | "The number of inferences run", |
| 121 | inferences); |
Declan-ARM | 7c75e33 | 2024-03-12 16:40:25 +0000 | [diff] [blame^] | 122 | |
Jim Flynn | 3443025 | 2022-03-04 15:03:58 +0000 | [diff] [blame] | 123 | profilingService.InitializeCounterValue(inferencesRunCounter->m_Uid); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | } // namespace armnn |