blob: 472716c97cc8c3b5e4909da7ae82468ee356b2c1 [file] [log] [blame]
Matteo Martincighf02e6cd2019-05-17 12:15:30 +01001//
Sadik Armagana097d2a2021-11-24 15:47:28 +00002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
Matteo Martincighf02e6cd2019-05-17 12:15:30 +01003// SPDX-License-Identifier: MIT
4//
5
6#include "CommonTestUtils.hpp"
7
Matteo Martincighe5b8eb92019-11-28 15:45:42 +00008#include <armnn/backends/IBackendInternal.hpp>
Matteo Martincighf02e6cd2019-05-17 12:15:30 +01009
10using namespace armnn;
11
Keith Davisb4dd5cc2022-04-07 11:32:00 +010012SubgraphView::InputSlots CreateInputsFrom(Layer* layer,
13 std::vector<unsigned int> ignoreSlots)
Matteo Martincighf02e6cd2019-05-17 12:15:30 +010014{
15 SubgraphView::InputSlots result;
Keith Davisb4dd5cc2022-04-07 11:32:00 +010016 for (auto&& it = layer->BeginInputSlots(); it != layer->EndInputSlots(); ++it)
17 {
18 if (std::find(ignoreSlots.begin(), ignoreSlots.end(), it->GetSlotIndex()) != ignoreSlots.end())
19 {
20 continue;
21 }
22 else
23 {
24 result.push_back(&(*it));
25 }
26 }
27 return result;
28}
29
30// ignoreSlots assumes you want to ignore the same slots all on layers within the vector
31SubgraphView::InputSlots CreateInputsFrom(const std::vector<Layer*>& layers,
32 std::vector<unsigned int> ignoreSlots)
33{
34 SubgraphView::InputSlots result;
35 for (auto&& layer: layers)
Matteo Martincighf02e6cd2019-05-17 12:15:30 +010036 {
37 for (auto&& it = layer->BeginInputSlots(); it != layer->EndInputSlots(); ++it)
38 {
Keith Davisb4dd5cc2022-04-07 11:32:00 +010039 if (std::find(ignoreSlots.begin(), ignoreSlots.end(), it->GetSlotIndex()) != ignoreSlots.end())
40 {
41 continue;
42 }
43 else
44 {
45 result.push_back(&(*it));
46 }
Matteo Martincighf02e6cd2019-05-17 12:15:30 +010047 }
48 }
49 return result;
50}
51
52SubgraphView::OutputSlots CreateOutputsFrom(const std::vector<Layer*>& layers)
53{
54 SubgraphView::OutputSlots result;
55 for (auto && layer : layers)
56 {
57 for (auto&& it = layer->BeginOutputSlots(); it != layer->EndOutputSlots(); ++it)
58 {
59 result.push_back(&(*it));
60 }
61 }
62 return result;
63}
64
65SubgraphView::SubgraphViewPtr CreateSubgraphViewFrom(SubgraphView::InputSlots&& inputs,
66 SubgraphView::OutputSlots&& outputs,
67 SubgraphView::Layers&& layers)
68{
69 return std::make_unique<SubgraphView>(std::move(inputs), std::move(outputs), std::move(layers));
70}
71
72armnn::IBackendInternalUniquePtr CreateBackendObject(const armnn::BackendId& backendId)
73{
74 auto& backendRegistry = BackendRegistryInstance();
75 auto backendFactory = backendRegistry.GetFactory(backendId);
76 auto backendObjPtr = backendFactory();
77
78 return backendObjPtr;
79}
Aron Virginas-Tar735a4502019-06-26 15:02:47 +010080
81armnn::TensorShape MakeTensorShape(unsigned int batches,
82 unsigned int channels,
83 unsigned int height,
84 unsigned int width,
85 armnn::DataLayout layout)
86{
87 using namespace armnn;
88 switch (layout)
89 {
90 case DataLayout::NCHW:
91 return TensorShape{ batches, channels, height, width };
92 case DataLayout::NHWC:
93 return TensorShape{ batches, height, width, channels };
94 default:
95 throw InvalidArgumentException(std::string("Unsupported data layout: ") + GetDataLayoutName(layout));
96 }
97}