aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/ArmNNProfilingServiceInitialiser.cpp
blob: 7ca3fc1bd8fdff5abb6dfe3d5693bede1715c5d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// Copyright © 2022,2024 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "ArmNNProfilingServiceInitialiser.hpp"

#include <armnn/BackendRegistry.hpp>
#include <armnn/profiling/ArmNNProfiling.hpp>
#include <armnn/utility/Assert.hpp>

#include <common/include/Counter.hpp>

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);
        if (!loadedNetworksCounter)
        {
            throw armnn::NullPointerException("loadedNetworksCounter must not be null.");
        }

        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);

        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);

        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<uint32_t>(
            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);

        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);

        profilingService.InitializeCounterValue(inferencesRunCounter->m_Uid);
    }
}

} // namespace armnn