aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAron Virginas-Tar <Aron.Virginas-Tar@arm.com>2019-08-22 12:56:34 +0100
committerAron Virginas-Tar <Aron.Virginas-Tar@arm.com>2019-08-23 11:16:39 +0100
commite898db9aaf07b4d0ea0242a1f3296f0192c42939 (patch)
tree017e040f9b18251f288f1f57ec270eac27ef85f6
parent91e1d89ad35ad081a4d5995d541791fbefdb3060 (diff)
downloadarmnn-e898db9aaf07b4d0ea0242a1f3296f0192c42939.tar.gz
IVGCVSW-3427 Create PacketVersionResolver class
* Create first version of PacketVersionResolver class * Add basic unit test * Move existing classes inside the armnn::profiling namespace * Add utility methods for Version Signed-off-by: Aron Virginas-Tar <Aron.Virginas-Tar@arm.com> Change-Id: If0ea0e1b9dea7fbfcd8b808e97b1e2aa91964dfa
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/profiling/CommandHandlerFunctor.cpp12
-rw-r--r--src/profiling/CommandHandlerFunctor.hpp12
-rw-r--r--src/profiling/CommandHandlerKey.cpp10
-rw-r--r--src/profiling/CommandHandlerKey.hpp10
-rw-r--r--src/profiling/CommandHandlerRegistry.cpp10
-rw-r--r--src/profiling/CommandHandlerRegistry.hpp13
-rw-r--r--src/profiling/EncodeVersion.hpp59
-rw-r--r--src/profiling/Packet.cpp12
-rw-r--r--src/profiling/Packet.hpp13
-rw-r--r--src/profiling/PacketVersionResolver.cpp22
-rw-r--r--src/profiling/PacketVersionResolver.hpp27
-rw-r--r--src/profiling/test/ProfilingTests.cpp62
13 files changed, 226 insertions, 38 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 420aabd365..068768c7e5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -420,6 +420,8 @@ list(APPEND armnn_sources
src/profiling/EncodeVersion.hpp
src/profiling/Packet.cpp
src/profiling/Packet.hpp
+ src/profiling/PacketVersionResolver.cpp
+ src/profiling/PacketVersionResolver.hpp
third-party/half/half.hpp
)
diff --git a/src/profiling/CommandHandlerFunctor.cpp b/src/profiling/CommandHandlerFunctor.cpp
index 7289221db8..894e2d440f 100644
--- a/src/profiling/CommandHandlerFunctor.cpp
+++ b/src/profiling/CommandHandlerFunctor.cpp
@@ -5,6 +5,12 @@
#include "CommandHandlerFunctor.hpp"
+namespace armnn
+{
+
+namespace profiling
+{
+
uint32_t CommandHandlerFunctor::GetPacketId() const
{
return m_PacketId;
@@ -13,4 +19,8 @@ uint32_t CommandHandlerFunctor::GetPacketId() const
uint32_t CommandHandlerFunctor::GetVersion() const
{
return m_Version;
-} \ No newline at end of file
+}
+
+} // namespace profiling
+
+} // namespace armnn
diff --git a/src/profiling/CommandHandlerFunctor.hpp b/src/profiling/CommandHandlerFunctor.hpp
index fce6e3f8bb..a9a59c145f 100644
--- a/src/profiling/CommandHandlerFunctor.hpp
+++ b/src/profiling/CommandHandlerFunctor.hpp
@@ -7,6 +7,12 @@
#include <cstdint>
+namespace armnn
+{
+
+namespace profiling
+{
+
#pragma once
class CommandHandlerFunctor
@@ -22,4 +28,8 @@ public:
private:
uint32_t m_PacketId;
uint32_t m_Version;
-}; \ No newline at end of file
+};
+
+} // namespace profiling
+
+} // namespace armnn
diff --git a/src/profiling/CommandHandlerKey.cpp b/src/profiling/CommandHandlerKey.cpp
index 6ce73440b8..66b20c57cc 100644
--- a/src/profiling/CommandHandlerKey.cpp
+++ b/src/profiling/CommandHandlerKey.cpp
@@ -5,6 +5,12 @@
#include "CommandHandlerKey.hpp"
+namespace armnn
+{
+
+namespace profiling
+{
+
uint32_t CommandHandlerKey::GetPacketId() const
{
return m_PacketId;
@@ -55,3 +61,7 @@ bool CommandHandlerKey::operator!=(const CommandHandlerKey& rhs) const
{
return !(*this == rhs);
}
+
+} // namespace profiling
+
+} // namespace armnn
diff --git a/src/profiling/CommandHandlerKey.hpp b/src/profiling/CommandHandlerKey.hpp
index 12bafbe49b..1ec5f5171f 100644
--- a/src/profiling/CommandHandlerKey.hpp
+++ b/src/profiling/CommandHandlerKey.hpp
@@ -7,6 +7,12 @@
#include <cstdint>
+namespace armnn
+{
+
+namespace profiling
+{
+
class CommandHandlerKey
{
public:
@@ -26,3 +32,7 @@ private:
uint32_t m_PacketId;
uint32_t m_Version;
};
+
+} // namespace profiling
+
+} // namespace armnn
diff --git a/src/profiling/CommandHandlerRegistry.cpp b/src/profiling/CommandHandlerRegistry.cpp
index d392db0534..97313475ff 100644
--- a/src/profiling/CommandHandlerRegistry.cpp
+++ b/src/profiling/CommandHandlerRegistry.cpp
@@ -8,6 +8,12 @@
#include <boost/assert.hpp>
#include <boost/log/trivial.hpp>
+namespace armnn
+{
+
+namespace profiling
+{
+
void CommandHandlerRegistry::RegisterFunctor(CommandHandlerFunctor* functor, uint32_t packetId, uint32_t version)
{
BOOST_ASSERT_MSG(functor, "Provided functor should not be a nullptr.");
@@ -27,3 +33,7 @@ CommandHandlerFunctor* CommandHandlerRegistry::GetFunctor(uint32_t packetId, uin
return registry.at(key);
}
+
+} // namespace profiling
+
+} // namespace armnn
diff --git a/src/profiling/CommandHandlerRegistry.hpp b/src/profiling/CommandHandlerRegistry.hpp
index ba81f1790f..61d45b0fd2 100644
--- a/src/profiling/CommandHandlerRegistry.hpp
+++ b/src/profiling/CommandHandlerRegistry.hpp
@@ -9,8 +9,15 @@
#include "CommandHandlerKey.hpp"
#include <boost/functional/hash.hpp>
+
#include <unordered_map>
+namespace armnn
+{
+
+namespace profiling
+{
+
struct CommandHandlerHash
{
std::size_t operator() (const CommandHandlerKey& commandHandlerKey) const
@@ -33,4 +40,8 @@ public:
private:
std::unordered_map<CommandHandlerKey, CommandHandlerFunctor*, CommandHandlerHash> registry;
-}; \ No newline at end of file
+};
+
+} // namespace profiling
+
+} // namespace armnn
diff --git a/src/profiling/EncodeVersion.hpp b/src/profiling/EncodeVersion.hpp
index 257393329a..f66f7278a5 100644
--- a/src/profiling/EncodeVersion.hpp
+++ b/src/profiling/EncodeVersion.hpp
@@ -4,20 +4,21 @@
//
#pragma once
-#include <cstddef>
+#include <cstdint>
+#include <string>
+#include <ostream>
+#include <sstream>
-namespace mlutil
+namespace armnn
{
-namespace Impl
+namespace profiling
{
- constexpr uint32_t EncodeVersion(uint32_t major, uint32_t minor, uint32_t patch)
- {
- return (major << 22) | (minor << 12) | patch;
- }
-
-} // namespace Impl
+constexpr inline uint32_t EncodeVersion(uint32_t major, uint32_t minor, uint32_t patch)
+{
+ return (major << 22) | (minor << 12) | patch;
+}
// Encodes a semantic version https://semver.org/ into a 32 bit integer in the following fashion
//
@@ -35,17 +36,35 @@ public:
m_Patch = encodedValue & 4095;
}
- Version(uint32_t major, uint32_t minor, uint32_t patch)
- : m_Major(major), m_Minor(minor), m_Patch(patch) {}
+ Version(uint32_t major, uint32_t minor, uint32_t patch) :
+ m_Major(major),
+ m_Minor(minor),
+ m_Patch(patch)
+ {}
uint32_t GetEncodedValue()
{
- return mlutil::Impl::EncodeVersion(m_Major, m_Minor, m_Patch);
+ return EncodeVersion(m_Major, m_Minor, m_Patch);
}
- uint32_t GetMajor() {return m_Major;}
- uint32_t GetMinor() {return m_Minor;}
- uint32_t GetPatch() {return m_Patch;}
+ uint32_t GetMajor() { return m_Major; }
+ uint32_t GetMinor() { return m_Minor; }
+ uint32_t GetPatch() { return m_Patch; }
+
+ bool operator==(const Version& other) const
+ {
+ return m_Major == other.m_Major && m_Minor == other.m_Minor && m_Patch == other.m_Patch;
+ }
+
+ std::string ToString() const
+ {
+ constexpr char separator = '.';
+
+ std::stringstream stringStream;
+ stringStream << m_Major << separator << m_Minor << separator << m_Patch;
+
+ return stringStream.str();
+ }
private:
uint32_t m_Major;
@@ -53,4 +72,12 @@ private:
uint32_t m_Patch;
};
-} // namespace mlutil
+inline std::ostream& operator<<(std::ostream& os, const Version& version)
+{
+ os << version.ToString();
+ return os;
+}
+
+} // namespace profiling
+
+} // namespace armnn
diff --git a/src/profiling/Packet.cpp b/src/profiling/Packet.cpp
index 97cb89b517..d0650a2aff 100644
--- a/src/profiling/Packet.cpp
+++ b/src/profiling/Packet.cpp
@@ -5,6 +5,12 @@
#include "Packet.hpp"
+namespace armnn
+{
+
+namespace profiling
+{
+
std::uint32_t Packet::GetHeader() const
{
return m_Header;
@@ -38,4 +44,8 @@ std::uint32_t Packet::GetPacketClass() const
std::uint32_t Packet::GetPacketType() const
{
return (m_PacketId & 7);
-} \ No newline at end of file
+}
+
+} // namespace profiling
+
+} // namespace armnn
diff --git a/src/profiling/Packet.hpp b/src/profiling/Packet.hpp
index 0d2ba42af5..ce378441f4 100644
--- a/src/profiling/Packet.hpp
+++ b/src/profiling/Packet.hpp
@@ -4,10 +4,15 @@
//
#pragma once
+#include <armnn/Exceptions.hpp>
#include <boost/log/trivial.hpp>
-#include <armnn/Exceptions.hpp>
+namespace armnn
+{
+
+namespace profiling
+{
class Packet
{
@@ -42,4 +47,8 @@ private:
uint32_t m_PacketId;
uint32_t m_Length;
const char* m_Data;
-}; \ No newline at end of file
+};
+
+} // namespace profiling
+
+} // namespace armnn
diff --git a/src/profiling/PacketVersionResolver.cpp b/src/profiling/PacketVersionResolver.cpp
new file mode 100644
index 0000000000..66e2b4d7ce
--- /dev/null
+++ b/src/profiling/PacketVersionResolver.cpp
@@ -0,0 +1,22 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "PacketVersionResolver.hpp"
+
+namespace armnn
+{
+
+namespace profiling
+{
+
+Version PacketVersionResolver::ResolvePacketVersion(uint32_t packetId) const
+{
+ // NOTE: For now every packet specification is at version 1.0.0
+ return Version(1, 0, 0);
+}
+
+} // namespace profiling
+
+} // namespace armnn
diff --git a/src/profiling/PacketVersionResolver.hpp b/src/profiling/PacketVersionResolver.hpp
new file mode 100644
index 0000000000..168a32ceb8
--- /dev/null
+++ b/src/profiling/PacketVersionResolver.hpp
@@ -0,0 +1,27 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include "EncodeVersion.hpp"
+
+namespace armnn
+{
+
+namespace profiling
+{
+
+class PacketVersionResolver final
+{
+public:
+ PacketVersionResolver() = default;
+ ~PacketVersionResolver() = default;
+
+ Version ResolvePacketVersion(uint32_t packetId) const;
+};
+
+} // namespace profiling
+
+} // namespace armnn
diff --git a/src/profiling/test/ProfilingTests.cpp b/src/profiling/test/ProfilingTests.cpp
index 8a2f2bd88e..3fd8d790a2 100644
--- a/src/profiling/test/ProfilingTests.cpp
+++ b/src/profiling/test/ProfilingTests.cpp
@@ -8,14 +8,20 @@
#include "../CommandHandlerRegistry.hpp"
#include "../EncodeVersion.hpp"
#include "../Packet.hpp"
+#include "../PacketVersionResolver.hpp"
+
+#include <boost/test/unit_test.hpp>
#include <cstdint>
#include <cstring>
-#include <boost/test/unit_test.hpp>
+#include <limits>
#include <map>
+#include <random>
BOOST_AUTO_TEST_SUITE(ExternalProfiling)
+using namespace armnn::profiling;
+
BOOST_AUTO_TEST_CASE(CheckCommandHandlerKeyComparisons)
{
CommandHandlerKey testKey0(1, 1);
@@ -45,51 +51,51 @@ BOOST_AUTO_TEST_CASE(CheckCommandHandlerKeyComparisons)
BOOST_CHECK(testKey1.GetVersion()==1);
std::vector<CommandHandlerKey> vect =
- {
- CommandHandlerKey(0,1), CommandHandlerKey(2,0), CommandHandlerKey(1,0),
- CommandHandlerKey(2,1), CommandHandlerKey(1,1), CommandHandlerKey(0,1),
- CommandHandlerKey(2,0), CommandHandlerKey(0,0)
- };
+ {
+ CommandHandlerKey(0,1), CommandHandlerKey(2,0), CommandHandlerKey(1,0),
+ CommandHandlerKey(2,1), CommandHandlerKey(1,1), CommandHandlerKey(0,1),
+ CommandHandlerKey(2,0), CommandHandlerKey(0,0)
+ };
std::sort(vect.begin(), vect.end());
std::vector<CommandHandlerKey> expectedVect =
- {
- CommandHandlerKey(0,0), CommandHandlerKey(0,1), CommandHandlerKey(0,1),
- CommandHandlerKey(1,0), CommandHandlerKey(1,1), CommandHandlerKey(2,0),
- CommandHandlerKey(2,0), CommandHandlerKey(2,1)
- };
+ {
+ CommandHandlerKey(0,0), CommandHandlerKey(0,1), CommandHandlerKey(0,1),
+ CommandHandlerKey(1,0), CommandHandlerKey(1,1), CommandHandlerKey(2,0),
+ CommandHandlerKey(2,0), CommandHandlerKey(2,1)
+ };
BOOST_CHECK(vect == expectedVect);
}
BOOST_AUTO_TEST_CASE(CheckEncodeVersion)
{
- mlutil::Version version1(12);
+ Version version1(12);
BOOST_CHECK(version1.GetMajor() == 0);
BOOST_CHECK(version1.GetMinor() == 0);
BOOST_CHECK(version1.GetPatch() == 12);
- mlutil::Version version2(4108);
+ Version version2(4108);
BOOST_CHECK(version2.GetMajor() == 0);
BOOST_CHECK(version2.GetMinor() == 1);
BOOST_CHECK(version2.GetPatch() == 12);
- mlutil::Version version3(4198412);
+ Version version3(4198412);
BOOST_CHECK(version3.GetMajor() == 1);
BOOST_CHECK(version3.GetMinor() == 1);
BOOST_CHECK(version3.GetPatch() == 12);
- mlutil::Version version4(0);
+ Version version4(0);
BOOST_CHECK(version4.GetMajor() == 0);
BOOST_CHECK(version4.GetMinor() == 0);
BOOST_CHECK(version4.GetPatch() == 0);
- mlutil::Version version5(1,0,0);
+ Version version5(1, 0, 0);
BOOST_CHECK(version5.GetEncodedValue() == 4194304);
}
@@ -236,4 +242,28 @@ BOOST_AUTO_TEST_CASE(CheckCommandHandlerRegistry)
BOOST_CHECK_THROW(registry.GetFunctor(0, 0), armnn::Exception);
}
+BOOST_AUTO_TEST_CASE(CheckPacketVersionResolver)
+{
+ // Set up random number generator for generating packetId values
+ std::random_device device;
+ std::mt19937 generator(device());
+ std::uniform_int_distribution<uint32_t> distribution(std::numeric_limits<uint32_t>::min(),
+ std::numeric_limits<uint32_t>::max());
+
+ // NOTE: Expected version is always 1.0.0, regardless of packetId
+ const Version expectedVersion(1, 0, 0);
+
+ PacketVersionResolver packetVersionResolver;
+
+ constexpr unsigned int numTests = 10u;
+
+ for (unsigned int i = 0u; i < numTests; ++i)
+ {
+ const uint32_t packetId = distribution(generator);
+ Version resolvedVersion = packetVersionResolver.ResolvePacketVersion(packetId);
+
+ BOOST_TEST(resolvedVersion == expectedVersion);
+ }
+}
+
BOOST_AUTO_TEST_SUITE_END()