diff options
author | Matthew Bentham <matthew.bentham@arm.com> | 2019-07-30 08:24:12 +0000 |
---|---|---|
committer | Matteo Martincigh <matteo.martincigh@arm.com> | 2019-07-30 15:58:30 +0000 |
commit | 0cf01dce414db3ce9595a438cf3c3f10dd938450 (patch) | |
tree | 900e14259365c2998a9ad75f3edd18b375c11fd6 /src/armnn/Graph.cpp | |
parent | bc2e210785a63e8360839e4ded5d2c15c2dffaf5 (diff) | |
download | armnn-0cf01dce414db3ce9595a438cf3c3f10dd938450.tar.gz |
IVGCVSW-3581 Fix AddCopyLayers and associated tests
Take a copy of the MemoryStrategies for a layer before inserting
new connections. Use the copy when looking up the original MemoryStrategies
during the graph transformation.
Fix the unit tests for AddCopyLayers to have cases where copies are needed.
Fix the validation for clarity and correctness - was previously comparing
Layers by pointer when it should have been by name (as it was comparing
with a cloned graph).
Change-Id: Ie282dc11913e977b8151ce1ad8bfba5e11617d40
Signed-off-by: Matthew Bentham <Matthew.Bentham@arm.com>
Diffstat (limited to 'src/armnn/Graph.cpp')
-rw-r--r-- | src/armnn/Graph.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/armnn/Graph.cpp b/src/armnn/Graph.cpp index e521623737..9e00f5ec01 100644 --- a/src/armnn/Graph.cpp +++ b/src/armnn/Graph.cpp @@ -285,12 +285,13 @@ void Graph::AddCopyLayers(std::map<BackendId, std::unique_ptr<IBackendInternal>> { OutputSlot& srcOutputSlot = srcLayer->GetOutputSlot(srcOutputIndex); const std::vector<InputSlot*> srcConnections = srcOutputSlot.GetConnections(); + const std::vector<MemoryStrategy> srcMemoryStrategies = srcOutputSlot.GetMemoryStrategies(); for (unsigned int srcConnectionIndex = 0; srcConnectionIndex < srcConnections.size(); srcConnectionIndex++) { InputSlot* dstInputSlot = srcConnections[srcConnectionIndex]; BOOST_ASSERT(dstInputSlot); - auto strategy = srcOutputSlot.GetMemoryStrategyForConnection(srcConnectionIndex); + MemoryStrategy strategy = srcMemoryStrategies[srcConnectionIndex]; BOOST_ASSERT_MSG(strategy != MemoryStrategy::Undefined, "Undefined memory strategy found while adding copy layers for compatibility"); @@ -339,8 +340,19 @@ void Graph::AddCopyLayers(std::map<BackendId, std::unique_ptr<IBackendInternal>> copyOutputSlot.SetTensorHandleFactory(ITensorHandleFactory::LegacyFactoryId); } + // The output strategy of a copy layer is always DirectCompatibility. copyOutputSlot.SetMemoryStrategy(0, MemoryStrategy::DirectCompatibility); - srcOutputSlot.SetMemoryStrategy(srcConnectionIndex, MemoryStrategy::DirectCompatibility); + + // Recalculate the connection index on the previous layer as we have just inserted into it. + const std::vector<InputSlot*>& newSourceConnections = srcOutputSlot.GetConnections(); + long newSrcConnectionIndex = std::distance(newSourceConnections.begin(), + std::find(newSourceConnections.begin(), + newSourceConnections.end(), + ©Layer->GetInputSlot(0))); + + // The input strategy of a copy layer is always DirectCompatibilty. + srcOutputSlot.SetMemoryStrategy(boost::numeric_cast<unsigned int>(newSrcConnectionIndex), + MemoryStrategy::DirectCompatibility); } } } |