From 6db5f20ade72896ebf0f6513a4832b8f2e917aa0 Mon Sep 17 00:00:00 2001 From: Matteo Martincigh Date: Thu, 5 Sep 2019 12:02:04 +0100 Subject: IVGCVSW-3691 Rework the CounterDirectory class to take into consideration the connections between components * Added constructors and connections to the profiling classes * Used hash table to keep track of the profiling objects by UID * Added register methods * Added find/check helper methods * Updated the makefile to include the profiling directory * Added unit tests for the CounterDirectory class * Added ICounterDirectory interface class for read-only use * Added custom macro to locally disable conversion warnings Change-Id: I3f53a68663ee77b8d03ac0ef7dc01e90c6893511 Signed-off-by: Matteo Martincigh --- src/profiling/ICounterDirectory.hpp | 164 ++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 src/profiling/ICounterDirectory.hpp (limited to 'src/profiling/ICounterDirectory.hpp') diff --git a/src/profiling/ICounterDirectory.hpp b/src/profiling/ICounterDirectory.hpp new file mode 100644 index 0000000000..c7259ab041 --- /dev/null +++ b/src/profiling/ICounterDirectory.hpp @@ -0,0 +1,164 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include +#include +#include +#include +#include + +#include + +namespace armnn +{ + +namespace profiling +{ + +// Forward declarations +class Category; +class Device; +class CounterSet; +class Counter; + +// Profiling objects smart pointer types +using CategoryPtr = std::unique_ptr; +using DevicePtr = std::unique_ptr; +using CounterSetPtr = std::unique_ptr; +using CounterPtr = std::shared_ptr; + +// Profiling objects collection types +using Categories = std::unordered_set; +using Devices = std::unordered_map; +using CounterSets = std::unordered_map; +using Counters = std::unordered_map; + +// Profiling objects collection iterator types +using CategoriesIt = Categories::const_iterator; +using DevicesIt = Devices::const_iterator; +using CounterSetsIt = CounterSets::const_iterator; +using CountersIt = Counters::const_iterator; + +class Category final +{ +public: + // Constructors + Category(const std::string& name, uint16_t deviceUid, uint16_t counterSetUid) + : m_Name(name) + , m_DeviceUid(deviceUid) + , m_CounterSetUid(counterSetUid) + {} + + // Fields + std::string m_Name; + + // Connections + std::vector m_Counters; // The UIDs of the counters associated with this category + uint16_t m_DeviceUid; // Optional, set to zero if the counter is not associated with a device + uint16_t m_CounterSetUid; // Optional, set to zero if the counter is not associated with a counter set +}; + +class Device final +{ +public: + // Constructors + Device(uint16_t deviceUid, const std::string& name, uint16_t cores) + : m_Uid(deviceUid) + , m_Name(name) + , m_Cores(cores) + {} + + // Fields + uint16_t m_Uid; + std::string m_Name; + uint16_t m_Cores; +}; + +class CounterSet final +{ +public: + // Constructors + CounterSet(uint16_t counterSetUid, const std::string& name, uint16_t count) + : m_Uid(counterSetUid) + , m_Name(name) + , m_Count(count) + {} + + // Fields + uint16_t m_Uid; + std::string m_Name; + uint16_t m_Count; +}; + +class Counter final +{ +public: + // Constructors + Counter(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) + : m_Uid(counterUid) + , m_MaxCounterUid(maxCounterUid) + , m_Class(counterClass) + , m_Interpolation(interpolation) + , m_Multiplier(multiplier) + , m_Name(name) + , m_Description(description) + , m_Units(units) + , m_DeviceUid(deviceUid) + , m_CounterSetUid(counterSetUid) + {} + + // Fields + uint16_t m_Uid; + uint16_t m_MaxCounterUid; + uint16_t m_Class; + uint16_t m_Interpolation; + double m_Multiplier; + std::string m_Name; + std::string m_Description; + std::string m_Units; // Optional, leave empty if the counter does not need units + + // Connections + uint16_t m_DeviceUid; // Optional, set to zero if the counter is not associated with a device + uint16_t m_CounterSetUid; // Optional, set to zero if the counter is not associated with a counter set +}; + +class ICounterDirectory +{ +public: + virtual ~ICounterDirectory() {} + + // Getters for counts + virtual uint16_t GetCategoryCount() const = 0; + virtual uint16_t GetDeviceCount() const = 0; + virtual uint16_t GetCounterSetCount() const = 0; + virtual uint16_t GetCounterCount() const = 0; + + // Getters for collections + virtual const Categories& GetCategories() const = 0; + virtual const Devices& GetDevices() const = 0; + virtual const CounterSets& GetCounterSets() const = 0; + virtual const Counters& GetCounters() const = 0; + + // Getters for profiling objects + virtual const Category* GetCategory(const std::string& name) const = 0; + virtual const Device* GetDevice(uint16_t uid) const = 0; + virtual const CounterSet* GetCounterSet(uint16_t uid) const = 0; + virtual const Counter* GetCounter(uint16_t uid) const = 0; +}; + +} // namespace profiling + +} // namespace armnn -- cgit v1.2.1