blob: 0c68838cd603bdb63810dc935069afd2cb54a4d3 [file] [log] [blame]
Jim Flynn97897022020-02-02 12:52:59 +00001//
2// Copyright © 2020 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "RegisterBackendCounters.hpp"
7
8namespace armnn
9{
10
11namespace profiling
12{
13
14void RegisterBackendCounters::RegisterCategory(const std::string& categoryName,
15 const Optional<uint16_t>& deviceUid,
16 const Optional<uint16_t>& counterSetUid)
17{
18 m_CounterDirectory.RegisterCategory(categoryName, deviceUid, counterSetUid);
19}
20
21uint16_t RegisterBackendCounters::RegisterDevice(const std::string& deviceName,
22 uint16_t cores,
23 const Optional<std::string>& parentCategoryName)
24{
25 const Device* devicePtr = m_CounterDirectory.RegisterDevice(deviceName, cores, parentCategoryName);
26 return devicePtr->m_Uid;
27}
28
29uint16_t RegisterBackendCounters::RegisterCounterSet(const std::string& counterSetName,
30 uint16_t count,
31 const Optional<std::string>& parentCategoryName)
32{
33 const CounterSet* counterSetPtr = m_CounterDirectory.RegisterCounterSet(counterSetName, count, parentCategoryName);
34 return counterSetPtr->m_Uid;
35}
36
37uint16_t RegisterBackendCounters::RegisterCounter(const uint16_t uid,
38 const std::string& parentCategoryName,
39 uint16_t counterClass,
40 uint16_t interpolation,
41 double multiplier,
42 const std::string& name,
43 const std::string& description,
44 const Optional<std::string>& units,
45 const Optional<uint16_t>& numberOfCores,
46 const Optional<uint16_t>& deviceUid,
47 const Optional<uint16_t>& counterSetUid)
48{
49 ++m_CurrentMaxGlobalCounterID;
50 const Counter* counterPtr = m_CounterDirectory.RegisterCounter(m_BackendId,
51 m_CurrentMaxGlobalCounterID,
52 parentCategoryName,
53 counterClass,
54 interpolation,
55 multiplier,
56 name,
57 description,
58 units,
59 numberOfCores,
60 deviceUid,
61 counterSetUid);
62 m_CurrentMaxGlobalCounterID = counterPtr->m_MaxCounterUid;
63 // register mappings
64 IRegisterCounterMapping& counterIdMap = ProfilingService::Instance().GetCounterMappingRegistry();
65 uint16_t globalCounterId = counterPtr->m_Uid;
66 if (globalCounterId == counterPtr->m_MaxCounterUid)
67 {
68 counterIdMap.RegisterMapping(globalCounterId, uid, m_BackendId);
69 }
70 else
71 {
72 uint16_t backendCounterId = uid;
73 while (globalCounterId <= counterPtr->m_MaxCounterUid)
74 {
75 // register mapping
76 // globalCounterId -> backendCounterId, m_BackendId
77 counterIdMap.RegisterMapping(globalCounterId, backendCounterId, m_BackendId);
78 ++globalCounterId;
79 ++backendCounterId;
80 }
81 }
82 return m_CurrentMaxGlobalCounterID;
83}
84
85} // namespace profiling
86
87} // namespace armnn