blob: bbed43ae4cfec37b0ccca1cd3da1254181ac973f [file] [log] [blame]
Jim Flynn34430252022-03-04 15:03:58 +00001//
2// Copyright © 2022 Arm Ltd. All rights reserved.
3// 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);
43 ARMNN_ASSERT(loadedNetworksCounter);
44 profilingService.InitializeCounterValue(loadedNetworksCounter->m_Uid);
45 }
46 // Register a counter for the number of unloaded networks
47 std::string networkUnloads("Network unloads");
48 if (!profilingService.IsCounterRegistered(networkUnloads))
49 {
50 const arm::pipe::Counter* unloadedNetworksCounter =
51 profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(),
52 arm::pipe::NETWORK_UNLOADS,
53 ArmNN_Runtime,
54 ZERO,
55 ZERO,
56 ONE,
57 networkUnloads,
58 "The number of networks unloaded at runtime",
59 networks);
60 ARMNN_ASSERT(unloadedNetworksCounter);
61 profilingService.InitializeCounterValue(unloadedNetworksCounter->m_Uid);
62 }
63 std::string backends("backends");
64 // Register a counter for the number of registered backends
65 std::string backendsRegistered("Backends registered");
66 if (!profilingService.IsCounterRegistered(backendsRegistered))
67 {
68 const arm::pipe::Counter* registeredBackendsCounter =
69 profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(),
70 arm::pipe::REGISTERED_BACKENDS,
71 ArmNN_Runtime,
72 ZERO,
73 ZERO,
74 ONE,
75 backendsRegistered,
76 "The number of registered backends",
77 backends);
78 ARMNN_ASSERT(registeredBackendsCounter);
79 profilingService.InitializeCounterValue(registeredBackendsCounter->m_Uid);
80
81 // Due to backends being registered before the profiling service becomes active,
82 // we need to set the counter to the correct value here
83 profilingService.SetCounterValue(arm::pipe::REGISTERED_BACKENDS, static_cast<uint32_t>(
84 armnn::BackendRegistryInstance().Size()));
85 }
86 // Register a counter for the number of registered backends
87 std::string backendsUnregistered("Backends unregistered");
88 if (!profilingService.IsCounterRegistered(backendsUnregistered))
89 {
90 const arm::pipe::Counter* unregisteredBackendsCounter =
91 profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(),
92 arm::pipe::UNREGISTERED_BACKENDS,
93 ArmNN_Runtime,
94 ZERO,
95 ZERO,
96 ONE,
97 backendsUnregistered,
98 "The number of unregistered backends",
99 backends);
100 ARMNN_ASSERT(unregisteredBackendsCounter);
101 profilingService.InitializeCounterValue(unregisteredBackendsCounter->m_Uid);
102 }
103 // Register a counter for the number of inferences run
104 std::string inferences("inferences");
105 std::string inferencesRun("Inferences run");
106 if (!profilingService.IsCounterRegistered(inferencesRun))
107 {
108 const arm::pipe::Counter* inferencesRunCounter =
109 profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(),
110 arm::pipe::INFERENCES_RUN,
111 ArmNN_Runtime,
112 ZERO,
113 ZERO,
114 ONE,
115 inferencesRun,
116 "The number of inferences run",
117 inferences);
118 ARMNN_ASSERT(inferencesRunCounter);
119 profilingService.InitializeCounterValue(inferencesRunCounter->m_Uid);
120 }
121}
122
123} // namespace armnn