From 84da38b0f11ca3db0a439e510514be780f3933ff Mon Sep 17 00:00:00 2001 From: Derek Lamberti Date: Thu, 13 Jun 2019 11:40:08 +0100 Subject: IVGCVSW-3277 Refactor TensorHandle factory API * Added backend support for multiple types of TensorHandle factories * Refactored the backend API to enable new tensor strategies * Added mechanism to determine memory strategies during optimization * Perform mem-copy only when Direct access is not found * Explicitly deleted the copy-constructor from OutputSlot to prevent accidental local copies that would cause the DisconnectAll to be called by the destructor Change-Id: I7e812c8e5e6c1c20db1c5932749ac70fd93db7f8 Signed-off-by: Derek Lamberti Signed-off-by: Matteo Martincigh --- src/armnn/test/GraphTests.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/armnn/test/GraphTests.cpp') diff --git a/src/armnn/test/GraphTests.cpp b/src/armnn/test/GraphTests.cpp index 44cfa2eaec..ae5ff2232b 100644 --- a/src/armnn/test/GraphTests.cpp +++ b/src/armnn/test/GraphTests.cpp @@ -14,6 +14,8 @@ #include #include +#include +#include /// Checks that first comes before second in the order. @@ -477,10 +479,21 @@ struct CopyLayersFixture outputLayer->SetBackendId(armnn::Compute::CpuRef); softmaxLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); + + // Set the memory strategies + inputLayer->GetOutputSlot(0).SetMemoryStrategy(0, MemoryStrategy::DirectCompatibility); + convLayer1->GetOutputSlot(0).SetMemoryStrategy(0, MemoryStrategy::DirectCompatibility); + convLayer1->GetOutputSlot(0).SetMemoryStrategy(1, MemoryStrategy::DirectCompatibility); + convLayer2->GetOutputSlot(0).SetMemoryStrategy(0, MemoryStrategy::DirectCompatibility); + concatLayer->GetOutputSlot(0).SetMemoryStrategy(0, MemoryStrategy::DirectCompatibility); + actLayer->GetOutputSlot(0).SetMemoryStrategy(0, MemoryStrategy::DirectCompatibility); + softmaxLayer->GetOutputSlot(0).SetMemoryStrategy(0, MemoryStrategy::DirectCompatibility); } armnn::TensorInfo m_TensorDesc; armnn::Graph m_Graph; + std::map> m_Backends; + armnn::TensorHandleFactoryRegistry m_FactoryRegistry; private: @@ -501,26 +514,26 @@ private: BOOST_FIXTURE_TEST_CASE(AddCopyLayers, CopyLayersFixture) { const armnn::Graph origGraph(m_Graph); - m_Graph.AddCopyLayers(); + m_Graph.AddCopyLayers(m_Backends, m_FactoryRegistry); TestGraphAfterAddingCopyLayers(m_Graph, origGraph); } BOOST_FIXTURE_TEST_CASE(AddCopyLayersSeveralTimes, CopyLayersFixture) { - m_Graph.AddCopyLayers(); + m_Graph.AddCopyLayers(m_Backends, m_FactoryRegistry); // Calling AddCopyLayers() several times should not change the connections. const std::vector edges = GetEdgeList(m_Graph); for (int i = 0; i < 4; ++i) { - m_Graph.AddCopyLayers(); + m_Graph.AddCopyLayers(m_Backends, m_FactoryRegistry); const std::vector otherEdges = GetEdgeList(m_Graph); BOOST_TEST((edges == otherEdges)); } } -BOOST_AUTO_TEST_CASE(CopyLayersAddedBetweenSameLayersHaveDifferentNames) +BOOST_FIXTURE_TEST_CASE(CopyLayersAddedBetweenSameLayersHaveDifferentNames, CopyLayersFixture) { armnn::Graph graph; @@ -542,7 +555,12 @@ BOOST_AUTO_TEST_CASE(CopyLayersAddedBetweenSameLayersHaveDifferentNames) splitterLayer->GetOutputSlot(1).Connect(additionLayer->GetInputSlot(1)); additionLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); - graph.AddCopyLayers(); + inputLayer->GetOutputSlot(0).SetMemoryStrategy(0, armnn::MemoryStrategy::DirectCompatibility); + splitterLayer->GetOutputSlot(0).SetMemoryStrategy(0, armnn::MemoryStrategy::CopyToTarget); + splitterLayer->GetOutputSlot(1).SetMemoryStrategy(0, armnn::MemoryStrategy::CopyToTarget); + additionLayer->GetOutputSlot(0).SetMemoryStrategy(0, armnn::MemoryStrategy::DirectCompatibility); + + graph.AddCopyLayers(m_Backends, m_FactoryRegistry); std::vector edges = GetEdgeList(graph); BOOST_CHECK(edges.size() == 6u); -- cgit v1.2.1