blob: 7ca3fc1bd8fdff5abb6dfe3d5693bede1715c5d8 [file] [log] [blame]
Jim Flynn34430252022-03-04 15:03:58 +00001//
Declan-ARM7c75e332024-03-12 16:40:25 +00002// Copyright © 2022,2024 Arm Ltd. All rights reserved.
Jim Flynn34430252022-03-04 15:03:58 +00003// SPDX-License-Identifier: MIT
4//
5
6#include "ArmNNProfilingServiceInitialiser.hpp"
7
8#include <armnn/BackendRegistry.hpp>
9#include <armnn/profiling/ArmNNProfiling.hpp>
Jim Flynn75c14f42022-03-10 22:05:42 +000010#include <armnn/utility/Assert.hpp>
11
Jim Flynnc454ac92022-03-16 18:43:18 +000012#include <common/include/Counter.hpp>
Jim Flynn34430252022-03-04 15:03:58 +000013
14namespace armnn
15{
16
17void 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-ARM7c75e332024-03-12 16:40:25 +000043 if (!loadedNetworksCounter)
44 {
45 throw armnn::NullPointerException("loadedNetworksCounter must not be null.");
46 }
47
Jim Flynn34430252022-03-04 15:03:58 +000048 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-ARM7c75e332024-03-12 16:40:25 +000064
Jim Flynn34430252022-03-04 15:03:58 +000065 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-ARM7c75e332024-03-12 16:40:25 +000082
Jim Flynn34430252022-03-04 15:03:58 +000083 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-ARM7c75e332024-03-12 16:40:25 +0000104
Jim Flynn34430252022-03-04 15:03:58 +0000105 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-ARM7c75e332024-03-12 16:40:25 +0000122
Jim Flynn34430252022-03-04 15:03:58 +0000123 profilingService.InitializeCounterValue(inferencesRunCounter->m_Uid);
124 }
125}
126
127} // namespace armnn