IVGCVSW-2918 Implement ExecutionFrame.
authorTeresa Charlin <teresa.charlinreyes@arm.com>
Wed, 10 Apr 2019 12:59:49 +0000 (13:59 +0100)
committerteresa.charlinreyes <teresa.charlinreyes@arm.com>
Tue, 23 Apr 2019 09:56:18 +0000 (09:56 +0000)
*Add interface IExecutionFrame.
*Add basic implementation ExecutionFrame.
*Add Unit Test

Change-Id: I960ac84a05c0c9b03735ec5e9c63f6f8f95b57b5
Signed-off-by: Kevin May <kevin.may@arm.com>
Signed-off-by: Teresa Charlin <teresa.charlinreyes@arm.com>
Signed-off-by: Aron Virginas-Tar <Aron.Virginas-Tar@arm.com>
CMakeLists.txt
src/armnn/ExecutionFrame.cpp [new file with mode: 0644]
src/armnn/ExecutionFrame.hpp [new file with mode: 0644]
src/armnn/test/ExecutionFrameTest.cpp [new file with mode: 0644]

index fed4e9b..233ef3c 100644 (file)
@@ -286,6 +286,8 @@ list(APPEND armnn_sources
     src/armnn/Descriptors.cpp
     src/armnn/DeviceSpec.hpp
     src/armnn/Exceptions.cpp
+    src/armnn/ExecutionFrame.cpp
+    src/armnn/ExecutionFrame.hpp
     src/armnn/Graph.cpp
     src/armnn/Graph.hpp
     src/armnn/IGraphObservable.hpp
@@ -417,6 +419,7 @@ if(BUILD_UNIT_TESTS)
         src/armnn/test/CsvReaderTest.cpp
         src/armnn/test/DebugCallbackTest.cpp
         src/armnn/test/EndToEndTest.cpp
+        src/armnn/test/ExecutionFrameTest.cpp
         src/armnn/test/FloatingPointConverterTest.cpp
         src/armnn/test/GraphTests.cpp
         src/armnn/test/GraphUtils.cpp
diff --git a/src/armnn/ExecutionFrame.cpp b/src/armnn/ExecutionFrame.cpp
new file mode 100644 (file)
index 0000000..4d952b2
--- /dev/null
@@ -0,0 +1,49 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "ExecutionFrame.hpp"
+
+using namespace std;
+
+namespace armnn
+{
+ExecutionFrame::ExecutionFrame() {}
+
+IExecutionFrame* ExecutionFrame::ExecuteWorkloads(IExecutionFrame* previousFrame)
+{
+    for (auto& workload: m_WorkloadQueue)
+    {
+        workload->Execute();
+    }
+    return m_NextExecutionFrame;
+}
+
+void ExecutionFrame::PostAllocationConfigure()
+{
+    for (auto&& workloadPtr: m_WorkloadQueue)
+    {
+        workloadPtr.get()->PostAllocationConfigure();
+    }
+}
+
+void ExecutionFrame::RegisterDebugCallback(const DebugCallbackFunction& func)
+{
+    for (auto&& workloadPtr: m_WorkloadQueue)
+    {
+        workloadPtr.get()->RegisterDebugCallback(func);
+    }
+}
+
+void ExecutionFrame::AddWorkloadToQueue(std::unique_ptr<IWorkload> workload)
+{
+    m_WorkloadQueue.push_back(move(workload));
+}
+
+void ExecutionFrame::SetNextExecutionFrame(IExecutionFrame* nextExecutionFrame)
+{
+    m_NextExecutionFrame = nextExecutionFrame;
+}
+
+}
\ No newline at end of file
diff --git a/src/armnn/ExecutionFrame.hpp b/src/armnn/ExecutionFrame.hpp
new file mode 100644 (file)
index 0000000..c7e7780
--- /dev/null
@@ -0,0 +1,42 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <backendsCommon/Workload.hpp>
+
+namespace armnn
+{
+
+using WorkloadQueue = std::vector< std::unique_ptr<IWorkload> >;
+
+/// ExecutionFrame interface to enqueue a workload computation.
+class IExecutionFrame
+{
+
+public:
+    ~IExecutionFrame() {}
+
+    virtual IExecutionFrame* ExecuteWorkloads(IExecutionFrame* previousFrame) = 0;
+    virtual void PostAllocationConfigure() {};
+    virtual void RegisterDebugCallback(const DebugCallbackFunction& func) {};
+};
+
+class ExecutionFrame: public IExecutionFrame
+{
+public:
+    ExecutionFrame();
+
+    IExecutionFrame* ExecuteWorkloads(IExecutionFrame* previousFrame) override ;
+    void PostAllocationConfigure() override;
+    void RegisterDebugCallback(const DebugCallbackFunction& func) override ;
+    void AddWorkloadToQueue(std::unique_ptr<IWorkload> workload);
+    void SetNextExecutionFrame(IExecutionFrame* nextExecutionFrame);
+private:
+    WorkloadQueue m_WorkloadQueue;
+    IExecutionFrame* m_NextExecutionFrame = nullptr;
+};
+
+}
\ No newline at end of file
diff --git a/src/armnn/test/ExecutionFrameTest.cpp b/src/armnn/test/ExecutionFrameTest.cpp
new file mode 100644 (file)
index 0000000..c348021
--- /dev/null
@@ -0,0 +1,38 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include <boost/test/unit_test.hpp>
+
+#include <ExecutionFrame.hpp>
+
+// Test that the values set in m_NextExecutionFrame are correct.
+// The execution order is given by the m_NextExecutionFrame in each ExecutionFrame.
+// A
+// |
+// B
+// |
+// C
+BOOST_AUTO_TEST_CASE(NextExecutionFrameTest)
+{
+    armnn::ExecutionFrame executionFrameA;
+    armnn::ExecutionFrame executionFrameB;
+    armnn::ExecutionFrame executionFrameC;
+
+    executionFrameA.SetNextExecutionFrame(&executionFrameB);
+    executionFrameB.SetNextExecutionFrame(&executionFrameC);
+    //not setting C to check that the default setting is nullptr.
+
+    auto nextExecutionFrameA = executionFrameA.ExecuteWorkloads(nullptr);
+    auto nextExecutionFrameB = executionFrameB.ExecuteWorkloads(&executionFrameA);
+    auto nextExecutionFrameC = executionFrameC.ExecuteWorkloads(&executionFrameB);
+
+    BOOST_CHECK_EQUAL(nextExecutionFrameA, &executionFrameB);
+    BOOST_CHECK_EQUAL(nextExecutionFrameB, &executionFrameC);
+
+    BOOST_CHECK(!nextExecutionFrameC);
+
+    BOOST_CHECK_NE(nextExecutionFrameA, &executionFrameC);
+}
+