blob: a84897995d1ca0533f40a6c271ca519c6bb9d246 [file] [log] [blame]
Aron Virginas-Tar4e5fc1f2019-08-22 18:10:52 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "CounterDirectory.hpp"
7
8#include <armnn/Exceptions.hpp>
9
10namespace armnn
11{
12
13namespace profiling
14{
15
16CounterDirectory::CounterDirectory(uint16_t uid,
17 const std::string& name,
18 uint16_t deviceCount,
19 uint16_t counterCount,
20 uint16_t categoryCount)
21 : m_Uid(uid)
22 , m_Name(name)
23 , m_DeviceCount(deviceCount)
24 , m_CounterCount(counterCount)
25 , m_CategoryCount(categoryCount)
26 , m_DeviceIds(deviceCount)
27 , m_CounterIds(counterCount)
28 , m_CategoryIds(categoryCount)
29 , m_DeviceObjects(deviceCount)
30 , m_CounterObjects(counterCount)
31 , m_CategoryObjects(categoryCount)
32{}
33
34// Helper methods
35void CounterDirectory::CheckDeviceIndex(uint16_t index) const
36{
37 if (index >= m_DeviceCount)
38 {
39 throw InvalidArgumentException("Invalid device index");
40 }
41}
42
43void CounterDirectory::CheckCounterIndex(uint16_t index) const
44{
45 if (index >= m_CounterCount)
46 {
47 throw InvalidArgumentException("Invalid counter index");
48 }
49}
50
51void CounterDirectory::CheckCategoryIndex(uint16_t index) const
52{
53 if (index >= m_CategoryCount)
54 {
55 throw InvalidArgumentException("Invalid category index");
56 }
57}
58
59// Getters for basic attributes
60uint16_t CounterDirectory::GetUid() const
61{
62 return m_Uid;
63}
64
65const std::string& CounterDirectory::GetName() const
66{
67 return m_Name;
68}
69
70// Getters for counts
71uint16_t CounterDirectory::GetDeviceCount() const
72{
73 return m_DeviceCount;
74}
75
76uint16_t CounterDirectory::GetCounterCount() const
77{
78 return m_CounterCount;
79}
80
81uint16_t CounterDirectory::GetCategoryCount() const
82{
83 return m_CategoryCount;
84}
85
86// Getters and setters for devices
87void CounterDirectory::GetDeviceValue(uint16_t index, uint32_t& value) const
88{
89 CheckDeviceIndex(index);
90 value = m_DeviceIds[index].load();
91}
92
93void CounterDirectory::SetDeviceValue(uint16_t index, uint32_t value)
94{
95 CheckDeviceIndex(index);
96 m_DeviceIds[index].store(value);
97}
98
99void CounterDirectory::GetDeviceObject(uint16_t index, Device* device) const
100{
101 CheckDeviceIndex(index);
102 device = m_DeviceObjects[index].load();
103}
104
105void CounterDirectory::SetDeviceObject(uint16_t index, Device* device)
106{
107 CheckDeviceIndex(index);
108 m_DeviceObjects[index].store(device);
109}
110
111// Getters and setters for counters
112void CounterDirectory::GetCounterValue(uint16_t index, uint32_t& value) const
113{
114 CheckCounterIndex(index);
115 value = m_CounterIds[index].load();
116}
117
118void CounterDirectory::SetCounterValue(uint16_t index, uint32_t value)
119{
120 CheckCounterIndex(index);
121 m_CounterIds[index].store(value);
122}
123
124void CounterDirectory::GetCounterObject(uint16_t index, Counter* counter) const
125{
126 CheckCounterIndex(index);
127 counter = m_CounterObjects[index].load();
128}
129
130void CounterDirectory::SetCounterObject(uint16_t index, Counter* counter)
131{
132 CheckCounterIndex(index);
133 m_CounterObjects[index].store(counter);
134}
135
136// Getters and setters for categories
137void CounterDirectory::GetCategoryValue(uint16_t index, uint32_t& value) const
138{
139 CheckCategoryIndex(index);
140 value = m_CategoryIds[index].load();
141}
142
143void CounterDirectory::SetCategoryValue(uint16_t index, uint32_t value)
144{
145 CheckCategoryIndex(index);
146 m_CategoryIds[index].store(value);
147}
148
149void CounterDirectory::GetCategoryObject(uint16_t index, Category* category) const
150{
151 CheckCategoryIndex(index);
152 category = m_CategoryObjects[index].load();
153}
154
155void CounterDirectory::SetCategoryObject(uint16_t index, Category* category)
156{
157 CheckCategoryIndex(index);
158 m_CategoryObjects[index].store(category);
159}
160
161} // namespace profiling
162
163} // namespace armnn