diff options
author | Aron Virginas-Tar <Aron.Virginas-Tar@arm.com> | 2019-08-22 18:10:52 +0100 |
---|---|---|
committer | Aron Virginas-Tar <Aron.Virginas-Tar@arm.com> | 2019-08-23 15:19:33 +0100 |
commit | 4e5fc1fb6c74fa6e4dcb24639db8fafd69a0a065 (patch) | |
tree | 17c793909c046e769d46fe65ddcaf59a51174acc | |
parent | 00dda4a66c10a56b02bdd534ba3b5fdb27527ebc (diff) | |
download | armnn-4e5fc1fb6c74fa6e4dcb24639db8fafd69a0a065.tar.gz |
IVGCVSW-3410 Create Counter Directory metadata classes
* Created classes Device, Counter, Category, CounterDirectory
Signed-off-by: Aron Virginas-Tar <Aron.Virginas-Tar@arm.com>
Change-Id: Iaec4b0e154d962983c60460714bafcc1fb16f47e
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/profiling/CounterDirectory.cpp | 163 | ||||
-rw-r--r-- | src/profiling/CounterDirectory.hpp | 104 |
3 files changed, 269 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 068768c7e5..0d587a7b67 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -417,6 +417,8 @@ list(APPEND armnn_sources src/profiling/CommandHandlerKey.hpp src/profiling/CommandHandlerRegistry.cpp src/profiling/CommandHandlerRegistry.hpp + src/profiling/CounterDirectory.cpp + src/profiling/CounterDirectory.hpp src/profiling/EncodeVersion.hpp src/profiling/Packet.cpp src/profiling/Packet.hpp diff --git a/src/profiling/CounterDirectory.cpp b/src/profiling/CounterDirectory.cpp new file mode 100644 index 0000000000..a84897995d --- /dev/null +++ b/src/profiling/CounterDirectory.cpp @@ -0,0 +1,163 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "CounterDirectory.hpp" + +#include <armnn/Exceptions.hpp> + +namespace armnn +{ + +namespace profiling +{ + +CounterDirectory::CounterDirectory(uint16_t uid, + const std::string& name, + uint16_t deviceCount, + uint16_t counterCount, + uint16_t categoryCount) + : m_Uid(uid) + , m_Name(name) + , m_DeviceCount(deviceCount) + , m_CounterCount(counterCount) + , m_CategoryCount(categoryCount) + , m_DeviceIds(deviceCount) + , m_CounterIds(counterCount) + , m_CategoryIds(categoryCount) + , m_DeviceObjects(deviceCount) + , m_CounterObjects(counterCount) + , m_CategoryObjects(categoryCount) +{} + +// Helper methods +void CounterDirectory::CheckDeviceIndex(uint16_t index) const +{ + if (index >= m_DeviceCount) + { + throw InvalidArgumentException("Invalid device index"); + } +} + +void CounterDirectory::CheckCounterIndex(uint16_t index) const +{ + if (index >= m_CounterCount) + { + throw InvalidArgumentException("Invalid counter index"); + } +} + +void CounterDirectory::CheckCategoryIndex(uint16_t index) const +{ + if (index >= m_CategoryCount) + { + throw InvalidArgumentException("Invalid category index"); + } +} + +// Getters for basic attributes +uint16_t CounterDirectory::GetUid() const +{ + return m_Uid; +} + +const std::string& CounterDirectory::GetName() const +{ + return m_Name; +} + +// Getters for counts +uint16_t CounterDirectory::GetDeviceCount() const +{ + return m_DeviceCount; +} + +uint16_t CounterDirectory::GetCounterCount() const +{ + return m_CounterCount; +} + +uint16_t CounterDirectory::GetCategoryCount() const +{ + return m_CategoryCount; +} + +// Getters and setters for devices +void CounterDirectory::GetDeviceValue(uint16_t index, uint32_t& value) const +{ + CheckDeviceIndex(index); + value = m_DeviceIds[index].load(); +} + +void CounterDirectory::SetDeviceValue(uint16_t index, uint32_t value) +{ + CheckDeviceIndex(index); + m_DeviceIds[index].store(value); +} + +void CounterDirectory::GetDeviceObject(uint16_t index, Device* device) const +{ + CheckDeviceIndex(index); + device = m_DeviceObjects[index].load(); +} + +void CounterDirectory::SetDeviceObject(uint16_t index, Device* device) +{ + CheckDeviceIndex(index); + m_DeviceObjects[index].store(device); +} + +// Getters and setters for counters +void CounterDirectory::GetCounterValue(uint16_t index, uint32_t& value) const +{ + CheckCounterIndex(index); + value = m_CounterIds[index].load(); +} + +void CounterDirectory::SetCounterValue(uint16_t index, uint32_t value) +{ + CheckCounterIndex(index); + m_CounterIds[index].store(value); +} + +void CounterDirectory::GetCounterObject(uint16_t index, Counter* counter) const +{ + CheckCounterIndex(index); + counter = m_CounterObjects[index].load(); +} + +void CounterDirectory::SetCounterObject(uint16_t index, Counter* counter) +{ + CheckCounterIndex(index); + m_CounterObjects[index].store(counter); +} + +// Getters and setters for categories +void CounterDirectory::GetCategoryValue(uint16_t index, uint32_t& value) const +{ + CheckCategoryIndex(index); + value = m_CategoryIds[index].load(); +} + +void CounterDirectory::SetCategoryValue(uint16_t index, uint32_t value) +{ + CheckCategoryIndex(index); + m_CategoryIds[index].store(value); +} + +void CounterDirectory::GetCategoryObject(uint16_t index, Category* category) const +{ + CheckCategoryIndex(index); + category = m_CategoryObjects[index].load(); +} + +void CounterDirectory::SetCategoryObject(uint16_t index, Category* category) +{ + CheckCategoryIndex(index); + m_CategoryObjects[index].store(category); +} + +} // namespace profiling + +} // namespace armnn diff --git a/src/profiling/CounterDirectory.hpp b/src/profiling/CounterDirectory.hpp new file mode 100644 index 0000000000..bbe7bcf6ef --- /dev/null +++ b/src/profiling/CounterDirectory.hpp @@ -0,0 +1,104 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include <atomic> +#include <string> +#include <vector> + +namespace armnn +{ + +namespace profiling +{ + +class Device +{ +public: + uint16_t m_Uid; + std::string m_Name; + uint16_t m_Cores; +}; + +class Counter +{ +public: + uint16_t m_Uid; + uint16_t m_MaxCounterUid; + uint16_t m_Class; + uint16_t m_Interpolation; + float m_Multiplier; + std::string m_Name; + std::string m_Description; + std::string m_Units; +}; + +class Category +{ +public: + std::string m_Name; +}; + +class CounterDirectory final +{ +public: + CounterDirectory(uint16_t uid, + const std::string& name, + uint16_t deviceCount, + uint16_t counterCount, + uint16_t categoryCount); + + ~CounterDirectory() = default; + + uint16_t GetUid() const; + const std::string& GetName() const; + + uint16_t GetDeviceCount() const; + uint16_t GetCounterCount() const; + uint16_t GetCategoryCount() const; + + void GetDeviceValue(uint16_t index, uint32_t& value) const; + void SetDeviceValue(uint16_t index, uint32_t value); + + void GetDeviceObject(uint16_t index, Device* counter) const; + void SetDeviceObject(uint16_t index, Device* counter); + + void GetCounterValue(uint16_t index, uint32_t& value) const; + void SetCounterValue(uint16_t index, uint32_t value); + + void GetCounterObject(uint16_t index, Counter* counter) const; + void SetCounterObject(uint16_t index, Counter* counter); + + void GetCategoryValue(uint16_t index, uint32_t& value) const; + void SetCategoryValue(uint16_t index, uint32_t value); + + void GetCategoryObject(uint16_t index, Category* counter) const; + void SetCategoryObject(uint16_t index, Category* counter); + +private: + uint16_t m_Uid; + std::string m_Name; + + uint16_t m_DeviceCount; + uint16_t m_CounterCount; + uint16_t m_CategoryCount; + + std::vector<std::atomic<uint32_t>> m_DeviceIds; + std::vector<std::atomic<uint32_t>> m_CounterIds; + std::vector<std::atomic<uint32_t>> m_CategoryIds; + + std::vector<std::atomic<Device*>> m_DeviceObjects; + std::vector<std::atomic<Counter*>> m_CounterObjects; + std::vector<std::atomic<Category*>> m_CategoryObjects; + + void CheckDeviceIndex(uint16_t index) const; + void CheckCounterIndex(uint16_t index) const; + void CheckCategoryIndex(uint16_t index) const; +}; + +} // namespace profiling + +} // namespace armnn |