blob: 58bd6b197fdcc6fcd215faeca1538f48d921bdad [file] [log] [blame]
narpra01b9546cf2018-11-20 15:21:28 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
Matteo Martincighf02e6cd2019-05-17 12:15:30 +01005
narpra01b9546cf2018-11-20 15:21:28 +00006#pragma once
7
8#include <Graph.hpp>
Matteo Martincighf02e6cd2019-05-17 12:15:30 +01009#include <SubgraphView.hpp>
10#include <SubgraphViewSelector.hpp>
narpra01b9546cf2018-11-20 15:21:28 +000011
Matteo Martincighf02e6cd2019-05-17 12:15:30 +010012#include <backendsCommon/CpuTensorHandle.hpp>
13#include <backendsCommon/BackendRegistry.hpp>
narpra01b9546cf2018-11-20 15:21:28 +000014
Matteo Martincighbf0e7222019-06-20 17:17:45 +010015#include <test/TestUtils.hpp>
Matteo Martincighf02e6cd2019-05-17 12:15:30 +010016
Matteo Martincighbf0e7222019-06-20 17:17:45 +010017#include <algorithm>
Matteo Martincighf02e6cd2019-05-17 12:15:30 +010018
19// Checks that two collections have the exact same contents (in any order)
20// The given collections do not have to contain duplicates
21// Cannot use std::sort here because std lists have their own std::list::sort method
22template <typename CollectionType>
23bool AreEqual(const CollectionType& lhs, const CollectionType& rhs)
narpra01b9546cf2018-11-20 15:21:28 +000024{
Matteo Martincighf02e6cd2019-05-17 12:15:30 +010025 if (lhs.size() != rhs.size())
26 {
27 return false;
28 }
narpra01b9546cf2018-11-20 15:21:28 +000029
Matteo Martincighf02e6cd2019-05-17 12:15:30 +010030 auto lhs_it = std::find_if(lhs.begin(), lhs.end(), [&rhs](auto& item)
31 {
32 return std::find(rhs.begin(), rhs.end(), item) == rhs.end();
33 });
34
35 return lhs_it == lhs.end();
narpra01b9546cf2018-11-20 15:21:28 +000036}
37
Matteo Martincighf02e6cd2019-05-17 12:15:30 +010038// Checks that the given collection contains the specified item
39template <typename CollectionType>
40bool Contains(const CollectionType& collection, const typename CollectionType::value_type& item)
41{
42 return std::find(collection.begin(), collection.end(), item) != collection.end();
narpra01b9546cf2018-11-20 15:21:28 +000043}
Matteo Martincighf02e6cd2019-05-17 12:15:30 +010044
45// Checks that the given map contains the specified key
46template <typename MapType>
47bool Contains(const MapType& map, const typename MapType::key_type& key)
48{
49 return map.find(key) != map.end();
50}
51
52template <typename ConvolutionLayer>
53void SetWeightAndBias(ConvolutionLayer* layer, const armnn::TensorInfo& weightInfo, const armnn::TensorInfo& biasInfo)
54{
55 layer->m_Weight = std::make_unique<armnn::ScopedCpuTensorHandle>(weightInfo);
56 layer->m_Bias = std::make_unique<armnn::ScopedCpuTensorHandle>(biasInfo);
57
58 layer->m_Weight->Allocate();
59 layer->m_Bias->Allocate();
60}
61
62armnn::SubgraphView::InputSlots CreateInputsFrom(const std::vector<armnn::Layer*>& layers);
63
64armnn::SubgraphView::OutputSlots CreateOutputsFrom(const std::vector<armnn::Layer*>& layers);
65
66armnn::SubgraphView::SubgraphViewPtr CreateSubgraphViewFrom(armnn::SubgraphView::InputSlots&& inputs,
67 armnn::SubgraphView::OutputSlots&& outputs,
68 armnn::SubgraphView::Layers&& layers);
69
70armnn::IBackendInternalUniquePtr CreateBackendObject(const armnn::BackendId& backendId);
Aron Virginas-Tar735a4502019-06-26 15:02:47 +010071
72armnn::TensorShape MakeTensorShape(unsigned int batches,
73 unsigned int channels,
74 unsigned int height,
75 unsigned int width,
76 armnn::DataLayout layout);