blob: c7259ab041759666bd32892f0a8a508566f95889 [file] [log] [blame]
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001//
2// Copyright © 2019 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
8#include <string>
9#include <vector>
10#include <memory>
11#include <unordered_set>
12#include <unordered_map>
13
14#include <boost/numeric/conversion/cast.hpp>
15
16namespace armnn
17{
18
19namespace profiling
20{
21
22// Forward declarations
23class Category;
24class Device;
25class CounterSet;
26class Counter;
27
28// Profiling objects smart pointer types
29using CategoryPtr = std::unique_ptr<Category>;
30using DevicePtr = std::unique_ptr<Device>;
31using CounterSetPtr = std::unique_ptr<CounterSet>;
32using CounterPtr = std::shared_ptr<Counter>;
33
34// Profiling objects collection types
35using Categories = std::unordered_set<CategoryPtr>;
36using Devices = std::unordered_map<uint16_t, DevicePtr>;
37using CounterSets = std::unordered_map<uint16_t, CounterSetPtr>;
38using Counters = std::unordered_map<uint16_t, CounterPtr>;
39
40// Profiling objects collection iterator types
41using CategoriesIt = Categories::const_iterator;
42using DevicesIt = Devices::const_iterator;
43using CounterSetsIt = CounterSets::const_iterator;
44using CountersIt = Counters::const_iterator;
45
46class Category final
47{
48public:
49 // Constructors
50 Category(const std::string& name, uint16_t deviceUid, uint16_t counterSetUid)
51 : m_Name(name)
52 , m_DeviceUid(deviceUid)
53 , m_CounterSetUid(counterSetUid)
54 {}
55
56 // Fields
57 std::string m_Name;
58
59 // Connections
60 std::vector<uint16_t> m_Counters; // The UIDs of the counters associated with this category
61 uint16_t m_DeviceUid; // Optional, set to zero if the counter is not associated with a device
62 uint16_t m_CounterSetUid; // Optional, set to zero if the counter is not associated with a counter set
63};
64
65class Device final
66{
67public:
68 // Constructors
69 Device(uint16_t deviceUid, const std::string& name, uint16_t cores)
70 : m_Uid(deviceUid)
71 , m_Name(name)
72 , m_Cores(cores)
73 {}
74
75 // Fields
76 uint16_t m_Uid;
77 std::string m_Name;
78 uint16_t m_Cores;
79};
80
81class CounterSet final
82{
83public:
84 // Constructors
85 CounterSet(uint16_t counterSetUid, const std::string& name, uint16_t count)
86 : m_Uid(counterSetUid)
87 , m_Name(name)
88 , m_Count(count)
89 {}
90
91 // Fields
92 uint16_t m_Uid;
93 std::string m_Name;
94 uint16_t m_Count;
95};
96
97class Counter final
98{
99public:
100 // Constructors
101 Counter(uint16_t counterUid,
102 uint16_t maxCounterUid,
103 uint16_t counterClass,
104 uint16_t interpolation,
105 double multiplier,
106 const std::string& name,
107 const std::string& description,
108 const std::string& units,
109 uint16_t deviceUid,
110 uint16_t counterSetUid)
111 : m_Uid(counterUid)
112 , m_MaxCounterUid(maxCounterUid)
113 , m_Class(counterClass)
114 , m_Interpolation(interpolation)
115 , m_Multiplier(multiplier)
116 , m_Name(name)
117 , m_Description(description)
118 , m_Units(units)
119 , m_DeviceUid(deviceUid)
120 , m_CounterSetUid(counterSetUid)
121 {}
122
123 // Fields
124 uint16_t m_Uid;
125 uint16_t m_MaxCounterUid;
126 uint16_t m_Class;
127 uint16_t m_Interpolation;
128 double m_Multiplier;
129 std::string m_Name;
130 std::string m_Description;
131 std::string m_Units; // Optional, leave empty if the counter does not need units
132
133 // Connections
134 uint16_t m_DeviceUid; // Optional, set to zero if the counter is not associated with a device
135 uint16_t m_CounterSetUid; // Optional, set to zero if the counter is not associated with a counter set
136};
137
138class ICounterDirectory
139{
140public:
141 virtual ~ICounterDirectory() {}
142
143 // Getters for counts
144 virtual uint16_t GetCategoryCount() const = 0;
145 virtual uint16_t GetDeviceCount() const = 0;
146 virtual uint16_t GetCounterSetCount() const = 0;
147 virtual uint16_t GetCounterCount() const = 0;
148
149 // Getters for collections
150 virtual const Categories& GetCategories() const = 0;
151 virtual const Devices& GetDevices() const = 0;
152 virtual const CounterSets& GetCounterSets() const = 0;
153 virtual const Counters& GetCounters() const = 0;
154
155 // Getters for profiling objects
156 virtual const Category* GetCategory(const std::string& name) const = 0;
157 virtual const Device* GetDevice(uint16_t uid) const = 0;
158 virtual const CounterSet* GetCounterSet(uint16_t uid) const = 0;
159 virtual const Counter* GetCounter(uint16_t uid) const = 0;
160};
161
162} // namespace profiling
163
164} // namespace armnn