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