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 |
Sadik Armagan | 4c99899 | 2020-02-25 12:44:44 +0000 | [diff] [blame] | 52 | Category(const std::string& name) |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 53 | : m_Name(name) |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 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 |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 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 |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 99 | Counter(BackendId backendId, |
| 100 | uint16_t counterUid, |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 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) |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 110 | : m_BackendId(backendId) |
| 111 | , m_Uid(counterUid) |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 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 |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 124 | BackendId m_BackendId; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 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 | |
| 139 | class ICounterDirectory |
| 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 |