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