narpra01 | b9546cf | 2018-11-20 15:21:28 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
Matteo Martincigh | f02e6cd | 2019-05-17 12:15:30 +0100 | [diff] [blame] | 5 | |
narpra01 | b9546cf | 2018-11-20 15:21:28 +0000 | [diff] [blame] | 6 | #pragma once |
| 7 | |
| 8 | #include <Graph.hpp> |
Matteo Martincigh | f02e6cd | 2019-05-17 12:15:30 +0100 | [diff] [blame] | 9 | #include <SubgraphView.hpp> |
| 10 | #include <SubgraphViewSelector.hpp> |
narpra01 | b9546cf | 2018-11-20 15:21:28 +0000 | [diff] [blame] | 11 | |
Matteo Martincigh | c601aa6 | 2019-10-29 15:03:22 +0000 | [diff] [blame] | 12 | #include <armnn/BackendRegistry.hpp> |
| 13 | |
Matteo Martincigh | f02e6cd | 2019-05-17 12:15:30 +0100 | [diff] [blame] | 14 | #include <backendsCommon/CpuTensorHandle.hpp> |
narpra01 | b9546cf | 2018-11-20 15:21:28 +0000 | [diff] [blame] | 15 | |
Matteo Martincigh | bf0e722 | 2019-06-20 17:17:45 +0100 | [diff] [blame] | 16 | #include <test/TestUtils.hpp> |
Matteo Martincigh | f02e6cd | 2019-05-17 12:15:30 +0100 | [diff] [blame] | 17 | |
Matteo Martincigh | bf0e722 | 2019-06-20 17:17:45 +0100 | [diff] [blame] | 18 | #include <algorithm> |
Matteo Martincigh | f02e6cd | 2019-05-17 12:15:30 +0100 | [diff] [blame] | 19 | |
| 20 | // Checks that two collections have the exact same contents (in any order) |
| 21 | // The given collections do not have to contain duplicates |
| 22 | // Cannot use std::sort here because std lists have their own std::list::sort method |
| 23 | template <typename CollectionType> |
| 24 | bool AreEqual(const CollectionType& lhs, const CollectionType& rhs) |
narpra01 | b9546cf | 2018-11-20 15:21:28 +0000 | [diff] [blame] | 25 | { |
Matteo Martincigh | f02e6cd | 2019-05-17 12:15:30 +0100 | [diff] [blame] | 26 | if (lhs.size() != rhs.size()) |
| 27 | { |
| 28 | return false; |
| 29 | } |
narpra01 | b9546cf | 2018-11-20 15:21:28 +0000 | [diff] [blame] | 30 | |
Matteo Martincigh | f02e6cd | 2019-05-17 12:15:30 +0100 | [diff] [blame] | 31 | auto lhs_it = std::find_if(lhs.begin(), lhs.end(), [&rhs](auto& item) |
| 32 | { |
| 33 | return std::find(rhs.begin(), rhs.end(), item) == rhs.end(); |
| 34 | }); |
| 35 | |
| 36 | return lhs_it == lhs.end(); |
narpra01 | b9546cf | 2018-11-20 15:21:28 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Matteo Martincigh | f02e6cd | 2019-05-17 12:15:30 +0100 | [diff] [blame] | 39 | // Checks that the given collection contains the specified item |
| 40 | template <typename CollectionType> |
| 41 | bool Contains(const CollectionType& collection, const typename CollectionType::value_type& item) |
| 42 | { |
| 43 | return std::find(collection.begin(), collection.end(), item) != collection.end(); |
narpra01 | b9546cf | 2018-11-20 15:21:28 +0000 | [diff] [blame] | 44 | } |
Matteo Martincigh | f02e6cd | 2019-05-17 12:15:30 +0100 | [diff] [blame] | 45 | |
| 46 | // Checks that the given map contains the specified key |
| 47 | template <typename MapType> |
| 48 | bool Contains(const MapType& map, const typename MapType::key_type& key) |
| 49 | { |
| 50 | return map.find(key) != map.end(); |
| 51 | } |
| 52 | |
| 53 | template <typename ConvolutionLayer> |
| 54 | void SetWeightAndBias(ConvolutionLayer* layer, const armnn::TensorInfo& weightInfo, const armnn::TensorInfo& biasInfo) |
| 55 | { |
| 56 | layer->m_Weight = std::make_unique<armnn::ScopedCpuTensorHandle>(weightInfo); |
| 57 | layer->m_Bias = std::make_unique<armnn::ScopedCpuTensorHandle>(biasInfo); |
| 58 | |
| 59 | layer->m_Weight->Allocate(); |
| 60 | layer->m_Bias->Allocate(); |
| 61 | } |
| 62 | |
| 63 | armnn::SubgraphView::InputSlots CreateInputsFrom(const std::vector<armnn::Layer*>& layers); |
| 64 | |
| 65 | armnn::SubgraphView::OutputSlots CreateOutputsFrom(const std::vector<armnn::Layer*>& layers); |
| 66 | |
| 67 | armnn::SubgraphView::SubgraphViewPtr CreateSubgraphViewFrom(armnn::SubgraphView::InputSlots&& inputs, |
| 68 | armnn::SubgraphView::OutputSlots&& outputs, |
| 69 | armnn::SubgraphView::Layers&& layers); |
| 70 | |
| 71 | armnn::IBackendInternalUniquePtr CreateBackendObject(const armnn::BackendId& backendId); |
Aron Virginas-Tar | 735a450 | 2019-06-26 15:02:47 +0100 | [diff] [blame] | 72 | |
| 73 | armnn::TensorShape MakeTensorShape(unsigned int batches, |
| 74 | unsigned int channels, |
| 75 | unsigned int height, |
| 76 | unsigned int width, |
Matteo Martincigh | c601aa6 | 2019-10-29 15:03:22 +0000 | [diff] [blame] | 77 | armnn::DataLayout layout); |