From 00f3aaf282c53b47f4cebfa4b29d7039da883bc1 Mon Sep 17 00:00:00 2001 From: Jim Flynn Date: Thu, 24 Oct 2019 11:58:06 +0100 Subject: [PATCH] IVGCVSW-4027 Add the IProfilingGuidGenerator interface Change-Id: Idfb80d73171aa2b57d4dcf01dc137817cf19d2bd Signed-off-by: Jim Flynn --- CMakeLists.txt | 1 + src/profiling/IProfilingGuidGenerator.hpp | 30 ++++++++++++++++++++++++++ src/profiling/ProfilingGuidGenerator.hpp | 15 +++++++------ src/profiling/ProfilingService.cpp | 10 +++++++++ src/profiling/ProfilingService.hpp | 10 ++++++++- src/profiling/test/SendTimelinePacketTests.cpp | 19 ++++++++++++++++ 6 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 src/profiling/IProfilingGuidGenerator.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b451d9c..6edc57f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -460,6 +460,7 @@ list(APPEND armnn_sources src/profiling/IPeriodicCounterCapture.hpp src/profiling/IProfilingConnection.hpp src/profiling/IProfilingConnectionFactory.hpp + src/profiling/IProfilingGuidGenerator.hpp src/profiling/Packet.hpp src/profiling/PacketBuffer.cpp src/profiling/PacketBuffer.hpp diff --git a/src/profiling/IProfilingGuidGenerator.hpp b/src/profiling/IProfilingGuidGenerator.hpp new file mode 100644 index 0000000..96e1792 --- /dev/null +++ b/src/profiling/IProfilingGuidGenerator.hpp @@ -0,0 +1,30 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include "ProfilingGuid.hpp" + +namespace armnn +{ + +namespace profiling +{ + +class IProfilingGuidGenerator +{ +public: + /// Return the next random Guid in the sequence + virtual ProfilingDynamicGuid NextGuid() = 0; + + /// Create a ProfilingStaticGuid based on a hash of the string + virtual ProfilingStaticGuid GenerateStaticId(const std::string& str) = 0; + + virtual ~IProfilingGuidGenerator() {} +}; + +} // namespace profiling + +} // namespace armnn diff --git a/src/profiling/ProfilingGuidGenerator.hpp b/src/profiling/ProfilingGuidGenerator.hpp index 7c43cab..ff27c8e 100644 --- a/src/profiling/ProfilingGuidGenerator.hpp +++ b/src/profiling/ProfilingGuidGenerator.hpp @@ -5,7 +5,7 @@ #pragma once -#include "ProfilingGuid.hpp" +#include "IProfilingGuidGenerator.hpp" namespace armnn { @@ -13,20 +13,21 @@ namespace armnn namespace profiling { -class ProfilingGuidGenerator +class ProfilingGuidGenerator : public IProfilingGuidGenerator { public: /// Construct a generator with the default address space static/dynamic partitioning - ProfilingGuidGenerator() : m_Sequence(0) {} + ProfilingGuidGenerator() {} /// Return the next random Guid in the sequence - ProfilingDynamicGuid NextGuid(); + // NOTE: dummy implementation for the moment + inline ProfilingDynamicGuid NextGuid() override { return ProfilingDynamicGuid(0); } - /// Create a ProfilingStaticGuid based on a hash of the name - ProfilingStaticGuid GenerateStaticId(const char* name); + /// Create a ProfilingStaticGuid based on a hash of the string + // NOTE: dummy implementation for the moment + inline ProfilingStaticGuid GenerateStaticId(const std::string& str) override { return ProfilingStaticGuid(0); } private: - uint64_t m_Sequence; }; } // namespace profiling diff --git a/src/profiling/ProfilingService.cpp b/src/profiling/ProfilingService.cpp index 1cc9262..6122ed9 100644 --- a/src/profiling/ProfilingService.cpp +++ b/src/profiling/ProfilingService.cpp @@ -241,6 +241,16 @@ uint32_t ProfilingService::DecrementCounterValue(uint16_t counterUid) return counterValuePtr->operator--(std::memory_order::memory_order_relaxed); } +ProfilingDynamicGuid ProfilingService::NextGuid() +{ + return m_GuidGenerator.NextGuid(); +} + +ProfilingStaticGuid ProfilingService::GenerateStaticId(const std::string& str) +{ + return m_GuidGenerator.GenerateStaticId(str); +} + void ProfilingService::Initialize() { // Register a category for the basic runtime counters diff --git a/src/profiling/ProfilingService.hpp b/src/profiling/ProfilingService.hpp index f2c1783..c70c670 100644 --- a/src/profiling/ProfilingService.hpp +++ b/src/profiling/ProfilingService.hpp @@ -17,6 +17,7 @@ #include "RequestCounterDirectoryCommandHandler.hpp" #include "PeriodicCounterSelectionCommandHandler.hpp" #include "PerJobCounterSelectionCommandHandler.hpp" +#include "ProfilingGuidGenerator.hpp" namespace armnn { @@ -24,7 +25,7 @@ namespace armnn namespace profiling { -class ProfilingService : public IReadWriteCounterValues +class ProfilingService : public IReadWriteCounterValues, public IProfilingGuidGenerator { public: using ExternalProfilingOptions = Runtime::CreationOptions::ExternalProfilingOptions; @@ -66,6 +67,12 @@ public: uint32_t IncrementCounterValue(uint16_t counterUid) override; uint32_t DecrementCounterValue(uint16_t counterUid) override; + // IProfilingGuidGenerator functions + /// Return the next random Guid in the sequence + ProfilingDynamicGuid NextGuid() override; + /// Create a ProfilingStaticGuid based on a hash of the string + ProfilingStaticGuid GenerateStaticId(const std::string& str) override; + private: // Copy/move constructors/destructors and copy/move assignment operators are deleted ProfilingService(const ProfilingService&) = delete; @@ -101,6 +108,7 @@ private: RequestCounterDirectoryCommandHandler m_RequestCounterDirectoryCommandHandler; PeriodicCounterSelectionCommandHandler m_PeriodicCounterSelectionCommandHandler; PerJobCounterSelectionCommandHandler m_PerJobCounterSelectionCommandHandler; + ProfilingGuidGenerator m_GuidGenerator; protected: // Default constructor/destructor kept protected for testing diff --git a/src/profiling/test/SendTimelinePacketTests.cpp b/src/profiling/test/SendTimelinePacketTests.cpp index 6f90106..4045d26 100644 --- a/src/profiling/test/SendTimelinePacketTests.cpp +++ b/src/profiling/test/SendTimelinePacketTests.cpp @@ -6,6 +6,7 @@ #include "SendCounterPacketTests.hpp" #include +#include #include #include #include @@ -384,4 +385,22 @@ BOOST_AUTO_TEST_CASE(SendTimelinePacketTests3) armnn::RuntimeException); } +BOOST_AUTO_TEST_CASE(GetGuidsFromProfilingService) +{ + armnn::Runtime::CreationOptions::ExternalProfilingOptions options; + options.m_EnableProfiling = true; + ProfilingService& profilingService = ProfilingService::Instance(); + profilingService.ResetExternalProfilingOptions(options, true); + ProfilingStaticGuid staticGuid = profilingService.GenerateStaticId("dummy"); + // TODO when actual value gets generated verify its correctness + ProfilingStaticGuid expectedStaticValue(0); + BOOST_CHECK(staticGuid == expectedStaticValue); + ProfilingDynamicGuid dynamicGuid = profilingService.NextGuid(); + // TODO when actual value gets generated verify its correctness by verifying + // it is in the correct range i.e. > x and that if NextGuid is invoked + // again it is equal to the previous + 1 + ProfilingDynamicGuid expectedDynamicValue(0); + BOOST_CHECK(dynamicGuid == expectedDynamicValue); +} + BOOST_AUTO_TEST_SUITE_END() -- 2.7.4