From ab84575629b4836ce592ea77831225ce5bbe676f Mon Sep 17 00:00:00 2001 From: Jim Flynn Date: Fri, 25 Oct 2019 13:17:30 +0100 Subject: IVGCVSW-4031 Provide well known profiling GUIDs Change-Id: Ibf99b025f51503e8937012b655aad74698f32e38 Signed-off-by: Jim Flynn Signed-off-by: Matteo Martincigh --- src/profiling/IProfilingGuidGenerator.hpp | 2 ++ src/profiling/LabelsAndEventClasses.cpp | 36 ++++++++++++++++++++ src/profiling/LabelsAndEventClasses.hpp | 38 +++++++++++++++++++++ src/profiling/ProfilingGuidGenerator.hpp | 21 ++++++++++-- src/profiling/test/SendTimelinePacketTests.cpp | 46 ++++++++++++++++++++++---- 5 files changed, 134 insertions(+), 9 deletions(-) create mode 100644 src/profiling/LabelsAndEventClasses.cpp create mode 100644 src/profiling/LabelsAndEventClasses.hpp (limited to 'src') diff --git a/src/profiling/IProfilingGuidGenerator.hpp b/src/profiling/IProfilingGuidGenerator.hpp index 96e1792146..34ee9673b5 100644 --- a/src/profiling/IProfilingGuidGenerator.hpp +++ b/src/profiling/IProfilingGuidGenerator.hpp @@ -7,6 +7,8 @@ #include "ProfilingGuid.hpp" +#include + namespace armnn { diff --git a/src/profiling/LabelsAndEventClasses.cpp b/src/profiling/LabelsAndEventClasses.cpp new file mode 100644 index 0000000000..a00562db9c --- /dev/null +++ b/src/profiling/LabelsAndEventClasses.cpp @@ -0,0 +1,36 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "LabelsAndEventClasses.hpp" + +namespace armnn +{ + +namespace profiling +{ + +ProfilingGuidGenerator LabelsAndEventClasses::m_GuidGenerator; + +// Labels (string value + GUID) +std::string LabelsAndEventClasses::NAME_LABEL("name"); +std::string LabelsAndEventClasses::TYPE_LABEL("type"); +std::string LabelsAndEventClasses::INDEX_LABEL("index"); + +ProfilingStaticGuid LabelsAndEventClasses::NAME_GUID( + m_GuidGenerator.GenerateStaticId(LabelsAndEventClasses::NAME_LABEL)); +ProfilingStaticGuid LabelsAndEventClasses::TYPE_GUID( + m_GuidGenerator.GenerateStaticId(LabelsAndEventClasses::TYPE_LABEL)); +ProfilingStaticGuid LabelsAndEventClasses::INDEX_GUID( + m_GuidGenerator.GenerateStaticId(LabelsAndEventClasses::INDEX_LABEL)); + +// Event Class GUIDs +ProfilingStaticGuid LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS( + m_GuidGenerator.GenerateStaticId("ARMNN_PROFILING_SOL")); +ProfilingStaticGuid LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS( + m_GuidGenerator.GenerateStaticId("ARMNN_PROFILING_EOL")); + +} // namespace profiling + +} // namespace armnn diff --git a/src/profiling/LabelsAndEventClasses.hpp b/src/profiling/LabelsAndEventClasses.hpp new file mode 100644 index 0000000000..07aeb81099 --- /dev/null +++ b/src/profiling/LabelsAndEventClasses.hpp @@ -0,0 +1,38 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include "ProfilingGuid.hpp" +#include "ProfilingGuidGenerator.hpp" + +namespace armnn +{ + +namespace profiling +{ + +class LabelsAndEventClasses +{ +public: + // Labels (string value + GUID) + static std::string NAME_LABEL; + static std::string TYPE_LABEL; + static std::string INDEX_LABEL; + static ProfilingStaticGuid NAME_GUID; + static ProfilingStaticGuid TYPE_GUID; + static ProfilingStaticGuid INDEX_GUID; + + // Event Class GUIDs + static ProfilingStaticGuid ARMNN_PROFILING_SOL_EVENT_CLASS; + static ProfilingStaticGuid ARMNN_PROFILING_EOL_EVENT_CLASS; + +private: + static ProfilingGuidGenerator m_GuidGenerator; +}; + +} // namespace profiling + +} // namespace armnn diff --git a/src/profiling/ProfilingGuidGenerator.hpp b/src/profiling/ProfilingGuidGenerator.hpp index 38816faf3e..81997e10a7 100644 --- a/src/profiling/ProfilingGuidGenerator.hpp +++ b/src/profiling/ProfilingGuidGenerator.hpp @@ -7,6 +7,8 @@ #include "IProfilingGuidGenerator.hpp" +#include + namespace armnn { @@ -17,15 +19,28 @@ class ProfilingGuidGenerator : public IProfilingGuidGenerator { public: /// Construct a generator with the default address space static/dynamic partitioning - ProfilingGuidGenerator() {} + ProfilingGuidGenerator() : m_Sequence(0) {} /// Return the next random Guid in the sequence // NOTE: dummy implementation for the moment - inline ProfilingDynamicGuid NextGuid() override { return ProfilingDynamicGuid(0); } + inline ProfilingDynamicGuid NextGuid() override + { + ProfilingDynamicGuid guid(m_Sequence); + m_Sequence++; + return guid; + } /// 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); } + inline ProfilingStaticGuid GenerateStaticId(const std::string& str) override + { + uint64_t guid = static_cast(m_StringHasher(str)); + return guid; + } + +private: + std::hash m_StringHasher; + uint64_t m_Sequence; }; } // namespace profiling diff --git a/src/profiling/test/SendTimelinePacketTests.cpp b/src/profiling/test/SendTimelinePacketTests.cpp index 9b144bb3d3..53e52b5b5b 100644 --- a/src/profiling/test/SendTimelinePacketTests.cpp +++ b/src/profiling/test/SendTimelinePacketTests.cpp @@ -12,6 +12,9 @@ #include #include +#include + +#include using namespace armnn::profiling; @@ -392,14 +395,16 @@ BOOST_AUTO_TEST_CASE(GetGuidsFromProfilingService) 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); + // TODO this will change again... + std::hash hasher; + uint64_t hash = static_cast(hasher("dummy")); + ProfilingStaticGuid expectedStaticValue(hash); 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); + uint64_t dynamicGuidValue = static_cast(dynamicGuid); + ++dynamicGuidValue; + ProfilingDynamicGuid expectedDynamicValue(dynamicGuidValue); + dynamicGuid = profilingService.NextGuid(); BOOST_CHECK(dynamicGuid == expectedDynamicValue); } @@ -414,4 +419,33 @@ BOOST_AUTO_TEST_CASE(GetTimelinePackerWriterFromProfilingService) BOOST_CHECK(writer != nullptr); } +BOOST_AUTO_TEST_CASE(CheckStaticGuidsAndEvents) +{ + BOOST_CHECK("name" == LabelsAndEventClasses::NAME_LABEL); + BOOST_CHECK("type" == LabelsAndEventClasses::TYPE_LABEL); + BOOST_CHECK("index" == LabelsAndEventClasses::INDEX_LABEL); + + std::hash hasher; + + uint64_t hash = static_cast(hasher(LabelsAndEventClasses::NAME_LABEL)); + ProfilingStaticGuid expectedNameGuid(hash); + BOOST_CHECK(LabelsAndEventClasses::NAME_GUID == expectedNameGuid); + + hash = static_cast(hasher(LabelsAndEventClasses::TYPE_LABEL)); + ProfilingStaticGuid expectedTypeGuid(hash); + BOOST_CHECK(LabelsAndEventClasses::TYPE_GUID == expectedTypeGuid); + + hash = static_cast(hasher(LabelsAndEventClasses::INDEX_LABEL)); + ProfilingStaticGuid expectedIndexGuid(hash); + BOOST_CHECK(LabelsAndEventClasses::INDEX_GUID == expectedIndexGuid); + + hash = static_cast(hasher("ARMNN_PROFILING_SOL")); + ProfilingStaticGuid expectedSol(hash); + BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS == expectedSol); + + hash = static_cast(hasher("ARMNN_PROFILING_EOL")); + ProfilingStaticGuid expectedEol(hash); + BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS == expectedEol); +} + BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.1