diff options
author | Derek Lamberti <derek.lamberti@arm.com> | 2019-08-01 15:56:25 +0100 |
---|---|---|
committer | Áron Virginás-Tar <aron.virginas-tar@arm.com> | 2019-08-05 13:51:42 +0000 |
commit | f674aa0fd2809126debdaaeb8067067790d86907 (patch) | |
tree | d86d0261c7a25149217918986043c76d0823ee44 /src/armnn/test | |
parent | 737d9ff58b348b11234b6c2363390607d576177d (diff) | |
download | armnn-f674aa0fd2809126debdaaeb8067067790d86907.tar.gz |
IVGCVSW-3277 Mem export/import suppor for Tensors
* Rename MemoryStrategy to EdgeStrategy
* Add MemImportLayer
* Import memory rather than copy when possible
Change-Id: I1d3a9414f2cbe517dc2aae9bbd4fdd92712b38ef
Signed-off-by: Derek Lamberti <derek.lamberti@arm.com>
Diffstat (limited to 'src/armnn/test')
-rw-r--r-- | src/armnn/test/GraphTests.cpp | 34 | ||||
-rw-r--r-- | src/armnn/test/TensorHandleStrategyTest.cpp | 119 |
2 files changed, 123 insertions, 30 deletions
diff --git a/src/armnn/test/GraphTests.cpp b/src/armnn/test/GraphTests.cpp index 7950ec49f4..7bd6aac98b 100644 --- a/src/armnn/test/GraphTests.cpp +++ b/src/armnn/test/GraphTests.cpp @@ -495,13 +495,13 @@ struct CopyLayersFixture // Set the memory strategies - for this test should be DirectCompatibility for same backends, // and CopyToTarget for different backends - inputLayer->GetOutputSlot(0).SetMemoryStrategy(0, MemoryStrategy::DirectCompatibility); - convLayer1->GetOutputSlot(0).SetMemoryStrategy(0, MemoryStrategy::CopyToTarget); - convLayer1->GetOutputSlot(0).SetMemoryStrategy(1, MemoryStrategy::DirectCompatibility); - convLayer2->GetOutputSlot(0).SetMemoryStrategy(0, MemoryStrategy::CopyToTarget); - concatLayer->GetOutputSlot(0).SetMemoryStrategy(0, MemoryStrategy::DirectCompatibility); - actLayer->GetOutputSlot(0).SetMemoryStrategy(0, MemoryStrategy::DirectCompatibility); - softmaxLayer->GetOutputSlot(0).SetMemoryStrategy(0, MemoryStrategy::CopyToTarget); + inputLayer->GetOutputSlot(0).SetEdgeStrategy(0, EdgeStrategy::DirectCompatibility); + convLayer1->GetOutputSlot(0).SetEdgeStrategy(0, EdgeStrategy::CopyToTarget); + convLayer1->GetOutputSlot(0).SetEdgeStrategy(1, EdgeStrategy::DirectCompatibility); + convLayer2->GetOutputSlot(0).SetEdgeStrategy(0, EdgeStrategy::CopyToTarget); + concatLayer->GetOutputSlot(0).SetEdgeStrategy(0, EdgeStrategy::DirectCompatibility); + actLayer->GetOutputSlot(0).SetEdgeStrategy(0, EdgeStrategy::DirectCompatibility); + softmaxLayer->GetOutputSlot(0).SetEdgeStrategy(0, EdgeStrategy::CopyToTarget); } armnn::TensorInfo m_TensorDesc; @@ -529,7 +529,7 @@ BOOST_FIXTURE_TEST_CASE(AddCopyLayers, CopyLayersFixture) { InitialiseTestGraph(); const armnn::Graph origGraph(m_Graph); - m_Graph.AddCopyLayers(m_Backends, m_FactoryRegistry); + m_Graph.AddCompatibilityLayers(m_Backends, m_FactoryRegistry); TestGraphAfterAddingCopyLayers(m_Graph, origGraph); } @@ -537,13 +537,13 @@ BOOST_FIXTURE_TEST_CASE(AddCopyLayers, CopyLayersFixture) BOOST_FIXTURE_TEST_CASE(AddCopyLayersSeveralTimes, CopyLayersFixture) { InitialiseTestGraph(); - m_Graph.AddCopyLayers(m_Backends, m_FactoryRegistry); + m_Graph.AddCompatibilityLayers(m_Backends, m_FactoryRegistry); - // Calling AddCopyLayers() several times should not change the connections. + // Calling AddCompatibilityLayers() several times should not change the connections. const std::vector<Edge> edges = GetEdgeList(m_Graph); for (int i = 0; i < 4; ++i) { - m_Graph.AddCopyLayers(m_Backends, m_FactoryRegistry); + m_Graph.AddCompatibilityLayers(m_Backends, m_FactoryRegistry); const std::vector<Edge> otherEdges = GetEdgeList(m_Graph); BOOST_TEST((edges == otherEdges)); } @@ -571,18 +571,18 @@ BOOST_FIXTURE_TEST_CASE(CopyLayersAddedBetweenSameLayersHaveDifferentNames, Copy splitterLayer->GetOutputSlot(1).Connect(additionLayer->GetInputSlot(1)); additionLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); - 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); + inputLayer->GetOutputSlot(0).SetEdgeStrategy(0, armnn::EdgeStrategy::DirectCompatibility); + splitterLayer->GetOutputSlot(0).SetEdgeStrategy(0, armnn::EdgeStrategy::CopyToTarget); + splitterLayer->GetOutputSlot(1).SetEdgeStrategy(0, armnn::EdgeStrategy::CopyToTarget); + additionLayer->GetOutputSlot(0).SetEdgeStrategy(0, armnn::EdgeStrategy::DirectCompatibility); - graph.AddCopyLayers(m_Backends, m_FactoryRegistry); + graph.AddCompatibilityLayers(m_Backends, m_FactoryRegistry); std::vector<Edge> edges = GetEdgeList(graph); BOOST_CHECK(edges.size() == 6u); std::sort(edges.begin(), edges.end()); auto last = std::unique(edges.begin(), edges.end()); - BOOST_CHECK_MESSAGE(last == edges.end(), "Found duplicated edges after AddCopyLayers()"); + BOOST_CHECK_MESSAGE(last == edges.end(), "Found duplicated edges after AddCompatibilityLayers()"); } BOOST_AUTO_TEST_CASE(DuplicateLayerNames) diff --git a/src/armnn/test/TensorHandleStrategyTest.cpp b/src/armnn/test/TensorHandleStrategyTest.cpp index 3bb1c68169..c391b04d97 100644 --- a/src/armnn/test/TensorHandleStrategyTest.cpp +++ b/src/armnn/test/TensorHandleStrategyTest.cpp @@ -50,9 +50,11 @@ public: return nullptr; } - virtual const FactoryId GetId() const override { return m_Id; } + const FactoryId GetId() const override { return m_Id; } - virtual bool SupportsSubTensors() const override { return true; } + bool SupportsSubTensors() const override { return true; } + + MemorySourceFlags GetExportFlags() const override { return 1; } private: FactoryId m_Id = "UninitializedId"; @@ -60,6 +62,38 @@ private: std::weak_ptr<IMemoryManager> m_MemMgr; }; +class TestFactoryImport : public ITensorHandleFactory +{ +public: + TestFactoryImport(std::weak_ptr<IMemoryManager> mgr, ITensorHandleFactory::FactoryId id) + : m_Id(id) + , m_MemMgr(mgr) + {} + + std::unique_ptr<ITensorHandle> CreateSubTensorHandle(ITensorHandle& parent, + TensorShape const& subTensorShape, + unsigned int const* subTensorOrigin) const override + { + return nullptr; + } + + std::unique_ptr<ITensorHandle> CreateTensorHandle(const TensorInfo& tensorInfo) const override + { + return nullptr; + } + + const FactoryId GetId() const override { return m_Id; } + + bool SupportsSubTensors() const override { return true; } + + MemorySourceFlags GetImportFlags() const override { return 1; } + +private: + FactoryId m_Id = "ImporterId"; + + std::weak_ptr<IMemoryManager> m_MemMgr; +}; + class TestBackendA : public IBackendInternal { public: @@ -173,6 +207,42 @@ private: BackendId m_Id = "BackendC"; }; +class TestBackendD : public IBackendInternal +{ +public: + TestBackendD() = default; + + const BackendId& GetId() const override { return m_Id; } + + IWorkloadFactoryPtr CreateWorkloadFactory(const IMemoryManagerSharedPtr& memoryManager = nullptr) const override + { + return IWorkloadFactoryPtr{}; + } + + IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override + { + return ILayerSupportSharedPtr{}; + } + + std::vector<ITensorHandleFactory::FactoryId> GetHandleFactoryPreferences() const override + { + return std::vector<ITensorHandleFactory::FactoryId>{ + "TestHandleFactoryD1" + }; + } + + void RegisterTensorHandleFactories(TensorHandleFactoryRegistry& registry) override + { + auto mgr = std::make_shared<TestMemMgr>(); + + registry.RegisterMemoryManager(mgr); + registry.RegisterFactory(std::make_unique<TestFactoryImport>(mgr, "TestHandleFactoryD1")); + } + +private: + BackendId m_Id = "BackendD"; +}; + BOOST_AUTO_TEST_SUITE(TensorHandle) @@ -200,16 +270,19 @@ BOOST_AUTO_TEST_CASE(TensorHandleSelectionStrategy) auto backendA = std::make_unique<TestBackendA>(); auto backendB = std::make_unique<TestBackendB>(); auto backendC = std::make_unique<TestBackendC>(); + auto backendD = std::make_unique<TestBackendD>(); TensorHandleFactoryRegistry registry; backendA->RegisterTensorHandleFactories(registry); backendB->RegisterTensorHandleFactories(registry); backendC->RegisterTensorHandleFactories(registry); + backendD->RegisterTensorHandleFactories(registry); BackendsMap backends; backends["BackendA"] = std::move(backendA); backends["BackendB"] = std::move(backendB); backends["BackendC"] = std::move(backendC); + backends["BackendD"] = std::move(backendD); armnn::Graph graph; @@ -226,13 +299,17 @@ BOOST_AUTO_TEST_CASE(TensorHandleSelectionStrategy) armnn::SoftmaxLayer* const softmaxLayer3 = graph.AddLayer<armnn::SoftmaxLayer>(smDesc, "softmax3"); softmaxLayer3->SetBackendId("BackendC"); + armnn::SoftmaxLayer* const softmaxLayer4 = graph.AddLayer<armnn::SoftmaxLayer>(smDesc, "softmax4"); + softmaxLayer4->SetBackendId("BackendD"); + armnn::OutputLayer* const outputLayer = graph.AddLayer<armnn::OutputLayer>(0, "output"); outputLayer->SetBackendId("BackendA"); inputLayer->GetOutputSlot(0).Connect(softmaxLayer1->GetInputSlot(0)); softmaxLayer1->GetOutputSlot(0).Connect(softmaxLayer2->GetInputSlot(0)); softmaxLayer2->GetOutputSlot(0).Connect(softmaxLayer3->GetInputSlot(0)); - softmaxLayer3->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); + softmaxLayer3->GetOutputSlot(0).Connect(softmaxLayer4->GetInputSlot(0)); + softmaxLayer4->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); graph.TopologicalSort(); @@ -246,29 +323,45 @@ BOOST_AUTO_TEST_CASE(TensorHandleSelectionStrategy) OutputSlot& softmaxLayer1Out = softmaxLayer1->GetOutputSlot(0); OutputSlot& softmaxLayer2Out = softmaxLayer2->GetOutputSlot(0); OutputSlot& softmaxLayer3Out = softmaxLayer3->GetOutputSlot(0); + OutputSlot& softmaxLayer4Out = softmaxLayer4->GetOutputSlot(0); // Check that the correct factory was selected BOOST_TEST(inputLayerOut.GetTensorHandleFactoryId() == "TestHandleFactoryA1"); BOOST_TEST(softmaxLayer1Out.GetTensorHandleFactoryId() == "TestHandleFactoryB1"); BOOST_TEST(softmaxLayer2Out.GetTensorHandleFactoryId() == "TestHandleFactoryB1"); BOOST_TEST(softmaxLayer3Out.GetTensorHandleFactoryId() == "TestHandleFactoryC1"); + BOOST_TEST(softmaxLayer4Out.GetTensorHandleFactoryId() == "TestHandleFactoryD1"); // Check that the correct strategy was selected - BOOST_TEST((inputLayerOut.GetMemoryStrategyForConnection(0) == MemoryStrategy::DirectCompatibility)); - BOOST_TEST((softmaxLayer1Out.GetMemoryStrategyForConnection(0) == MemoryStrategy::DirectCompatibility)); - BOOST_TEST((softmaxLayer2Out.GetMemoryStrategyForConnection(0) == MemoryStrategy::CopyToTarget)); - BOOST_TEST((softmaxLayer3Out.GetMemoryStrategyForConnection(0) == MemoryStrategy::DirectCompatibility)); - - graph.AddCopyLayers(backends, registry); - int count= 0; - graph.ForEachLayer([&count](Layer* layer) + BOOST_TEST((inputLayerOut.GetEdgeStrategyForConnection(0) == EdgeStrategy::DirectCompatibility)); + BOOST_TEST((softmaxLayer1Out.GetEdgeStrategyForConnection(0) == EdgeStrategy::DirectCompatibility)); + BOOST_TEST((softmaxLayer2Out.GetEdgeStrategyForConnection(0) == EdgeStrategy::CopyToTarget)); + BOOST_TEST((softmaxLayer3Out.GetEdgeStrategyForConnection(0) == EdgeStrategy::ExportToTarget)); + BOOST_TEST((softmaxLayer4Out.GetEdgeStrategyForConnection(0) == EdgeStrategy::DirectCompatibility)); + + graph.AddCompatibilityLayers(backends, registry); + + // Test for copy layers + int copyCount= 0; + graph.ForEachLayer([©Count](Layer* layer) { if (layer->GetType() == LayerType::MemCopy) { - count++; + copyCount++; + } + }); + BOOST_TEST(copyCount == 1); + + // Test for import layers + int importCount= 0; + graph.ForEachLayer([&importCount](Layer *layer) + { + if (layer->GetType() == LayerType::MemImport) + { + importCount++; } }); - BOOST_TEST(count == 1); + BOOST_TEST(importCount == 1); } BOOST_AUTO_TEST_SUITE_END() |