ArmNN
 24.05
ArmNNProfilingServiceInitialiser.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2022,2024 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
10 #include <armnn/utility/Assert.hpp>
11 
12 #include <common/include/Counter.hpp>
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);
43  if (!loadedNetworksCounter)
44  {
45  throw armnn::NullPointerException("loadedNetworksCounter must not be null.");
46  }
47 
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);
64 
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);
82 
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>(
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);
104 
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);
122 
123  profilingService.InitializeCounterValue(inferencesRunCounter->m_Uid);
124  }
125 }
126 
127 } // namespace armnn
BackendRegistry.hpp
Assert.hpp
ArmNNProfilingServiceInitialiser.hpp
armnn::BackendRegistryInstance
BackendRegistry & BackendRegistryInstance()
Definition: BackendRegistry.cpp:15
ArmNNProfiling.hpp
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::ArmNNProfilingServiceInitialiser::InitialiseProfilingService
void InitialiseProfilingService(arm::pipe::IProfilingService &profilingService) override
Definition: ArmNNProfilingServiceInitialiser.cpp:17
armnn::NullPointerException
Definition: Exceptions.hpp:146