IVGCVSW-3416 Create Command Handler Key class
authorFrancis Murtagh <francis.murtagh@arm.com>
Wed, 14 Aug 2019 08:49:34 +0000 (09:49 +0100)
committerFrancis Murtagh <francis.murtagh@arm.com>
Wed, 14 Aug 2019 08:49:34 +0000 (09:49 +0100)
 * Add CommandHandlerKey class with all comparison operators
 * Add UnitTests to check key sorting in collection

Change-Id: Icbd493d1e51e681cbe22a9e70ab9428a8a2ad107
Signed-off-by: Francis Murtagh <francis.murtagh@arm.com>
CMakeLists.txt
src/profiling/CommandHandlerKey.cpp [new file with mode: 0644]
src/profiling/CommandHandlerKey.hpp [new file with mode: 0644]
src/profiling/test/ProfilingTests.cpp [new file with mode: 0644]

index 08c693d..66b8cf4 100644 (file)
@@ -411,6 +411,8 @@ list(APPEND armnn_sources
     src/armnn/optimizations/OptimizeInversePermutes.hpp
     src/armnn/optimizations/PermuteAsReshape.hpp
     src/armnn/optimizations/SquashEqualSiblings.hpp
+    src/profiling/CommandHandlerKey.cpp
+    src/profiling/CommandHandlerKey.hpp
     third-party/half/half.hpp
     )
 
@@ -517,6 +519,7 @@ if(BUILD_UNIT_TESTS)
         src/armnn/test/UtilsTests.cpp
         src/armnnUtils/test/PrototxtConversionsTest.cpp
         src/armnnUtils/test/ParserHelperTest.cpp
+        src/profiling/test/ProfilingTests.cpp
         )
 
     if(BUILD_TF_PARSER)
diff --git a/src/profiling/CommandHandlerKey.cpp b/src/profiling/CommandHandlerKey.cpp
new file mode 100644 (file)
index 0000000..6ce7344
--- /dev/null
@@ -0,0 +1,57 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "CommandHandlerKey.hpp"
+
+uint32_t CommandHandlerKey::GetPacketId() const
+{
+    return m_PacketId;
+}
+
+uint32_t CommandHandlerKey::GetVersion() const
+{
+    return m_Version;
+}
+
+bool CommandHandlerKey::operator<(const CommandHandlerKey& rhs) const
+{
+    bool result = true;
+
+    if (m_PacketId == rhs.m_PacketId)
+    {
+        result = m_Version < rhs.m_Version;
+    }
+    else if (m_PacketId > rhs.m_PacketId)
+    {
+        result = false;
+    }
+
+    return result;
+}
+
+bool CommandHandlerKey::operator>(const CommandHandlerKey& rhs) const
+{
+    return rhs < *this;
+}
+
+bool CommandHandlerKey::operator<=(const CommandHandlerKey& rhs) const
+{
+    return !(*this > rhs);
+}
+
+bool CommandHandlerKey::operator>=(const CommandHandlerKey& rhs) const
+{
+    return !(*this < rhs);
+}
+
+bool CommandHandlerKey::operator==(const CommandHandlerKey& rhs) const
+{
+    return m_PacketId == rhs.m_PacketId && m_Version == rhs.m_Version;
+}
+
+bool CommandHandlerKey::operator!=(const CommandHandlerKey& rhs) const
+{
+    return !(*this == rhs);
+}
diff --git a/src/profiling/CommandHandlerKey.hpp b/src/profiling/CommandHandlerKey.hpp
new file mode 100644 (file)
index 0000000..12bafbe
--- /dev/null
@@ -0,0 +1,28 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <cstdint>
+
+class CommandHandlerKey
+{
+public:
+    CommandHandlerKey(uint32_t packetId, uint32_t version) : m_PacketId(packetId), m_Version(version) {};
+
+    uint32_t GetPacketId() const;
+    uint32_t GetVersion()  const;
+
+    bool operator< (const CommandHandlerKey& rhs) const;
+    bool operator> (const CommandHandlerKey& rhs) const;
+    bool operator<=(const CommandHandlerKey& rhs) const;
+    bool operator>=(const CommandHandlerKey& rhs) const;
+    bool operator==(const CommandHandlerKey& rhs) const;
+    bool operator!=(const CommandHandlerKey& rhs) const;
+
+private:
+    uint32_t m_PacketId;
+    uint32_t m_Version;
+};
diff --git a/src/profiling/test/ProfilingTests.cpp b/src/profiling/test/ProfilingTests.cpp
new file mode 100644 (file)
index 0000000..5abab2f
--- /dev/null
@@ -0,0 +1,59 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "../CommandHandlerKey.hpp"
+
+#include <boost/test/unit_test.hpp>
+
+BOOST_AUTO_TEST_SUITE(ExternalProfiling)
+
+BOOST_AUTO_TEST_CASE(CheckCommandHandlerKeyComparisons)
+{
+    CommandHandlerKey testKey0(1, 1);
+    CommandHandlerKey testKey1(1, 1);
+    CommandHandlerKey testKey2(1, 1);
+    CommandHandlerKey testKey3(0, 0);
+    CommandHandlerKey testKey4(2, 2);
+    CommandHandlerKey testKey5(0, 2);
+
+    BOOST_CHECK(testKey1<testKey4);
+    BOOST_CHECK(testKey1>testKey3);
+    BOOST_CHECK(testKey1<=testKey4);
+    BOOST_CHECK(testKey1>=testKey3);
+    BOOST_CHECK(testKey1<=testKey2);
+    BOOST_CHECK(testKey1>=testKey2);
+    BOOST_CHECK(testKey1==testKey2);
+    BOOST_CHECK(testKey1==testKey1);
+
+    BOOST_CHECK(!(testKey1==testKey5));
+    BOOST_CHECK(!(testKey1!=testKey1));
+    BOOST_CHECK(testKey1!=testKey5);
+
+    BOOST_CHECK(testKey1==testKey2 && testKey2==testKey1);
+    BOOST_CHECK(testKey0==testKey1 && testKey1==testKey2 && testKey0==testKey2);
+
+    BOOST_CHECK(testKey1.GetPacketId()==1);
+    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)
+        };
+
+    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)
+        };
+
+    BOOST_CHECK(vect == expectedVect);
+}
+
+BOOST_AUTO_TEST_SUITE_END()