From f02e6cd728a0bceea221120ec039a4b66436d51d Mon Sep 17 00:00:00 2001 From: Matteo Martincigh Date: Fri, 17 May 2019 12:15:30 +0100 Subject: IVGCVSW-3030 Add unit testing for the Optimization API * Added OptimizeSubgraphViewTests file covering a number of use cases for the Optimization API * Fixed a bug in the sub-graph selector algorithm that skipped the first layer in a sub-graph if it wasn't an input layer * Changed the graph splitting logic to make use of maps instead of unordered_maps to keep the split sub-graphs in consistent order between executions * Added more common unit test utils * Minor fixes to comply to the include file conventions Change-Id: Iad464eaedd004109e5ef41aa487cea3ad86177d3 Signed-off-by: Matteo Martincigh --- .../backendsCommon/test/CommonTestUtils.hpp | 64 +++++++++++++++++++--- 1 file changed, 57 insertions(+), 7 deletions(-) (limited to 'src/backends/backendsCommon/test/CommonTestUtils.hpp') diff --git a/src/backends/backendsCommon/test/CommonTestUtils.hpp b/src/backends/backendsCommon/test/CommonTestUtils.hpp index 68180fb289..5da0228842 100644 --- a/src/backends/backendsCommon/test/CommonTestUtils.hpp +++ b/src/backends/backendsCommon/test/CommonTestUtils.hpp @@ -2,21 +2,71 @@ // Copyright © 2017 Arm Ltd. All rights reserved. // SPDX-License-Identifier: MIT // + #pragma once #include +#include +#include + +#include +#include -using namespace armnn; +#include -namespace +// Connects two layers +void Connect(armnn::IConnectableLayer* from, armnn::IConnectableLayer* to, const armnn::TensorInfo& tensorInfo, + unsigned int fromIndex = 0, unsigned int toIndex = 0); + +// Checks that two collections have the exact same contents (in any order) +// The given collections do not have to contain duplicates +// Cannot use std::sort here because std lists have their own std::list::sort method +template +bool AreEqual(const CollectionType& lhs, const CollectionType& rhs) { + if (lhs.size() != rhs.size()) + { + return false; + } + + auto lhs_it = std::find_if(lhs.begin(), lhs.end(), [&rhs](auto& item) + { + return std::find(rhs.begin(), rhs.end(), item) == rhs.end(); + }); -// Connects two layers. -void Connect(IConnectableLayer* from, IConnectableLayer* to, const TensorInfo& tensorInfo, - unsigned int fromIndex = 0, unsigned int toIndex = 0) + return lhs_it == lhs.end(); +} + +// Checks that the given collection contains the specified item +template +bool Contains(const CollectionType& collection, const typename CollectionType::value_type& item) { - from->GetOutputSlot(fromIndex).Connect(to->GetInputSlot(toIndex)); - from->GetOutputSlot(fromIndex).SetTensorInfo(tensorInfo); + return std::find(collection.begin(), collection.end(), item) != collection.end(); } +// Checks that the given map contains the specified key +template +bool Contains(const MapType& map, const typename MapType::key_type& key) +{ + return map.find(key) != map.end(); } + +template +void SetWeightAndBias(ConvolutionLayer* layer, const armnn::TensorInfo& weightInfo, const armnn::TensorInfo& biasInfo) +{ + layer->m_Weight = std::make_unique(weightInfo); + layer->m_Bias = std::make_unique(biasInfo); + + layer->m_Weight->Allocate(); + layer->m_Bias->Allocate(); +} + +armnn::SubgraphView::InputSlots CreateInputsFrom(const std::vector& layers); + +armnn::SubgraphView::OutputSlots CreateOutputsFrom(const std::vector& layers); + +armnn::SubgraphView::SubgraphViewPtr CreateSubgraphViewFrom(armnn::SubgraphView::InputSlots&& inputs, + armnn::SubgraphView::OutputSlots&& outputs, + armnn::SubgraphView::Layers&& layers); + +armnn::IBackendInternalUniquePtr CreateBackendObject(const armnn::BackendId& backendId); -- cgit v1.2.1