aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikhil Raj <nikhil.raj@arm.com>2019-08-19 10:04:23 +0100
committerNikhil Raj <nikhil.raj@arm.com>2019-08-19 10:04:23 +0100
commitd88e47c3a334447b964649518c088bf32054ed79 (patch)
tree6943c202d85f04778382d7123a6e3c05e49ad1a6
parent94d7915bef33ad59d1bdfa791490268c682c5359 (diff)
downloadarmnn-d88e47c3a334447b964649518c088bf32054ed79.tar.gz
IVGCVSW-3429 Add a utility Version class
Change-Id: Id429f7d9176c775953c1261c5a3e9f1d565927c1 Signed-off-by: Nikhil Raj <nikhil.raj@arm.com>
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/profiling/EncodeVersion.hpp56
-rw-r--r--src/profiling/test/ProfilingTests.cpp31
3 files changed, 88 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index df4b742cda..05dd0ec16d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -417,6 +417,7 @@ list(APPEND armnn_sources
src/profiling/CommandHandlerKey.hpp
src/profiling/CommandHandlerRegistry.cpp
src/profiling/CommandHandlerRegistry.hpp
+ src/profiling/EncodeVersion.hpp
src/profiling/Packet.cpp
src/profiling/Packet.hpp
third-party/half/half.hpp
diff --git a/src/profiling/EncodeVersion.hpp b/src/profiling/EncodeVersion.hpp
new file mode 100644
index 0000000000..257393329a
--- /dev/null
+++ b/src/profiling/EncodeVersion.hpp
@@ -0,0 +1,56 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+#pragma once
+
+#include <cstddef>
+
+namespace mlutil
+{
+
+namespace Impl
+{
+
+ constexpr uint32_t EncodeVersion(uint32_t major, uint32_t minor, uint32_t patch)
+ {
+ return (major << 22) | (minor << 12) | patch;
+ }
+
+} // namespace Impl
+
+// Encodes a semantic version https://semver.org/ into a 32 bit integer in the following fashion
+//
+// bits 22:31 major: Unsigned 10-bit integer. Major component of the schema version number.
+// bits 12:21 minor: Unsigned 10-bit integer. Minor component of the schema version number.
+// bits 0:11 patch: Unsigned 12-bit integer. Patch component of the schema version number.
+//
+class Version
+{
+public:
+ Version(uint32_t encodedValue)
+ {
+ m_Major = (encodedValue >> 22) & 1023;
+ m_Minor = (encodedValue >> 12) & 1023;
+ m_Patch = encodedValue & 4095;
+ }
+
+ 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);
+ }
+
+ uint32_t GetMajor() {return m_Major;}
+ uint32_t GetMinor() {return m_Minor;}
+ uint32_t GetPatch() {return m_Patch;}
+
+private:
+ uint32_t m_Major;
+ uint32_t m_Minor;
+ uint32_t m_Patch;
+};
+
+} // namespace mlutil
diff --git a/src/profiling/test/ProfilingTests.cpp b/src/profiling/test/ProfilingTests.cpp
index a8ec0277d2..8a2f2bd88e 100644
--- a/src/profiling/test/ProfilingTests.cpp
+++ b/src/profiling/test/ProfilingTests.cpp
@@ -6,6 +6,7 @@
#include "../CommandHandlerKey.hpp"
#include "../CommandHandlerFunctor.hpp"
#include "../CommandHandlerRegistry.hpp"
+#include "../EncodeVersion.hpp"
#include "../Packet.hpp"
#include <cstdint>
@@ -62,6 +63,36 @@ BOOST_AUTO_TEST_CASE(CheckCommandHandlerKeyComparisons)
BOOST_CHECK(vect == expectedVect);
}
+BOOST_AUTO_TEST_CASE(CheckEncodeVersion)
+{
+ mlutil::Version version1(12);
+
+ BOOST_CHECK(version1.GetMajor() == 0);
+ BOOST_CHECK(version1.GetMinor() == 0);
+ BOOST_CHECK(version1.GetPatch() == 12);
+
+ mlutil::Version version2(4108);
+
+ BOOST_CHECK(version2.GetMajor() == 0);
+ BOOST_CHECK(version2.GetMinor() == 1);
+ BOOST_CHECK(version2.GetPatch() == 12);
+
+ mlutil::Version version3(4198412);
+
+ BOOST_CHECK(version3.GetMajor() == 1);
+ BOOST_CHECK(version3.GetMinor() == 1);
+ BOOST_CHECK(version3.GetPatch() == 12);
+
+ mlutil::Version version4(0);
+
+ BOOST_CHECK(version4.GetMajor() == 0);
+ BOOST_CHECK(version4.GetMinor() == 0);
+ BOOST_CHECK(version4.GetPatch() == 0);
+
+ mlutil::Version version5(1,0,0);
+ BOOST_CHECK(version5.GetEncodedValue() == 4194304);
+}
+
BOOST_AUTO_TEST_CASE(CheckPacketClass)
{
const char* data = "test";