Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 8 | #include <armnn/BackendId.hpp> |
| 9 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 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, uint16_t deviceUid, uint16_t counterSetUid) |
| 53 | : m_Name(name) |
| 54 | , m_DeviceUid(deviceUid) |
| 55 | , m_CounterSetUid(counterSetUid) |
| 56 | {} |
| 57 | |
| 58 | // Fields |
| 59 | std::string m_Name; |
| 60 | |
| 61 | // Connections |
| 62 | std::vector<uint16_t> m_Counters; // The UIDs of the counters associated with this category |
| 63 | uint16_t m_DeviceUid; // Optional, set to zero if the counter is not associated with a device |
| 64 | uint16_t m_CounterSetUid; // Optional, set to zero if the counter is not associated with a counter set |
| 65 | }; |
| 66 | |
| 67 | class Device final |
| 68 | { |
| 69 | public: |
| 70 | // Constructors |
| 71 | Device(uint16_t deviceUid, const std::string& name, uint16_t cores) |
| 72 | : m_Uid(deviceUid) |
| 73 | , m_Name(name) |
| 74 | , m_Cores(cores) |
| 75 | {} |
| 76 | |
| 77 | // Fields |
| 78 | uint16_t m_Uid; |
| 79 | std::string m_Name; |
| 80 | uint16_t m_Cores; |
| 81 | }; |
| 82 | |
| 83 | class CounterSet final |
| 84 | { |
| 85 | public: |
| 86 | // Constructors |
| 87 | CounterSet(uint16_t counterSetUid, const std::string& name, uint16_t count) |
| 88 | : m_Uid(counterSetUid) |
| 89 | , m_Name(name) |
| 90 | , m_Count(count) |
| 91 | {} |
| 92 | |
| 93 | // Fields |
| 94 | uint16_t m_Uid; |
| 95 | std::string m_Name; |
| 96 | uint16_t m_Count; |
| 97 | }; |
| 98 | |
| 99 | class Counter final |
| 100 | { |
| 101 | public: |
| 102 | // Constructors |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 103 | Counter(BackendId backendId, |
| 104 | uint16_t counterUid, |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 105 | uint16_t maxCounterUid, |
| 106 | uint16_t counterClass, |
| 107 | uint16_t interpolation, |
| 108 | double multiplier, |
| 109 | const std::string& name, |
| 110 | const std::string& description, |
| 111 | const std::string& units, |
| 112 | uint16_t deviceUid, |
| 113 | uint16_t counterSetUid) |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 114 | : m_BackendId(backendId) |
| 115 | , m_Uid(counterUid) |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 116 | , m_MaxCounterUid(maxCounterUid) |
| 117 | , m_Class(counterClass) |
| 118 | , m_Interpolation(interpolation) |
| 119 | , m_Multiplier(multiplier) |
| 120 | , m_Name(name) |
| 121 | , m_Description(description) |
| 122 | , m_Units(units) |
| 123 | , m_DeviceUid(deviceUid) |
| 124 | , m_CounterSetUid(counterSetUid) |
| 125 | {} |
| 126 | |
| 127 | // Fields |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 128 | BackendId m_BackendId; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 129 | uint16_t m_Uid; |
| 130 | uint16_t m_MaxCounterUid; |
| 131 | uint16_t m_Class; |
| 132 | uint16_t m_Interpolation; |
| 133 | double m_Multiplier; |
| 134 | std::string m_Name; |
| 135 | std::string m_Description; |
| 136 | std::string m_Units; // Optional, leave empty if the counter does not need units |
| 137 | |
| 138 | // Connections |
| 139 | uint16_t m_DeviceUid; // Optional, set to zero if the counter is not associated with a device |
| 140 | uint16_t m_CounterSetUid; // Optional, set to zero if the counter is not associated with a counter set |
| 141 | }; |
| 142 | |
| 143 | class ICounterDirectory |
| 144 | { |
| 145 | public: |
| 146 | virtual ~ICounterDirectory() {} |
| 147 | |
| 148 | // Getters for counts |
| 149 | virtual uint16_t GetCategoryCount() const = 0; |
| 150 | virtual uint16_t GetDeviceCount() const = 0; |
| 151 | virtual uint16_t GetCounterSetCount() const = 0; |
| 152 | virtual uint16_t GetCounterCount() const = 0; |
| 153 | |
| 154 | // Getters for collections |
| 155 | virtual const Categories& GetCategories() const = 0; |
| 156 | virtual const Devices& GetDevices() const = 0; |
| 157 | virtual const CounterSets& GetCounterSets() const = 0; |
| 158 | virtual const Counters& GetCounters() const = 0; |
| 159 | |
| 160 | // Getters for profiling objects |
| 161 | virtual const Category* GetCategory(const std::string& name) const = 0; |
| 162 | virtual const Device* GetDevice(uint16_t uid) const = 0; |
| 163 | virtual const CounterSet* GetCounterSet(uint16_t uid) const = 0; |
| 164 | virtual const Counter* GetCounter(uint16_t uid) const = 0; |
| 165 | }; |
| 166 | |
| 167 | } // namespace profiling |
| 168 | |
| 169 | } // namespace armnn |