telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 4 | // |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 5 | |
Sadik Armagan | a097d2a | 2021-11-24 15:47:28 +0000 | [diff] [blame] | 6 | #include <GraphUtils.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 7 | |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 8 | #include <armnn/LayerVisitorBase.hpp> |
Matthew Bentham | ff130e2 | 2020-01-17 11:47:42 +0000 | [diff] [blame] | 9 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 10 | #include <Network.hpp> |
Aron Virginas-Tar | 7010400 | 2018-10-24 15:33:28 +0100 | [diff] [blame] | 11 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 12 | #include <doctest/doctest.h> |
Aron Virginas-Tar | 7010400 | 2018-10-24 15:33:28 +0100 | [diff] [blame] | 13 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 14 | namespace |
| 15 | { |
| 16 | |
| 17 | bool AreAllLayerInputSlotsConnected(const armnn::IConnectableLayer& layer) |
| 18 | { |
| 19 | bool allConnected = true; |
| 20 | for (unsigned int i = 0; i < layer.GetNumInputSlots(); ++i) |
| 21 | { |
| 22 | const bool inputConnected = layer.GetInputSlot(i).GetConnection() != nullptr; |
| 23 | allConnected &= inputConnected; |
| 24 | } |
| 25 | return allConnected; |
| 26 | } |
| 27 | |
| 28 | } |
| 29 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 30 | TEST_SUITE("Network") |
| 31 | { |
| 32 | TEST_CASE("LayerGuids") |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 33 | { |
Francis Murtagh | 3d2b4b2 | 2021-02-15 18:23:17 +0000 | [diff] [blame] | 34 | armnn::NetworkImpl net; |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame^] | 35 | LayerGuid inputId = net.AddInputLayer(0)->GetGuid(); |
| 36 | LayerGuid addId = net.AddAdditionLayer()->GetGuid(); |
| 37 | LayerGuid outputId = net.AddOutputLayer(0)->GetGuid(); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 38 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 39 | CHECK(inputId != addId); |
| 40 | CHECK(addId != outputId); |
| 41 | CHECK(inputId != outputId); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 42 | } |
| 43 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 44 | TEST_CASE("NetworkBasic") |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 45 | { |
Francis Murtagh | 3d2b4b2 | 2021-02-15 18:23:17 +0000 | [diff] [blame] | 46 | armnn::NetworkImpl net; |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 47 | CHECK(net.PrintGraph() == armnn::Status::Success); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 48 | } |
| 49 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 50 | TEST_CASE("LayerNamesAreOptionalForINetwork") |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 51 | { |
Francis Murtagh | 3d2b4b2 | 2021-02-15 18:23:17 +0000 | [diff] [blame] | 52 | armnn::INetworkPtr inet(armnn::INetwork::Create()); |
| 53 | inet->AddInputLayer(0); |
| 54 | inet->AddAdditionLayer(); |
| 55 | inet->AddActivationLayer(armnn::ActivationDescriptor()); |
| 56 | inet->AddOutputLayer(0); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 57 | } |
| 58 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 59 | TEST_CASE("LayerNamesAreOptionalForNetwork") |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 60 | { |
Francis Murtagh | 3d2b4b2 | 2021-02-15 18:23:17 +0000 | [diff] [blame] | 61 | armnn::NetworkImpl net; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 62 | net.AddInputLayer(0); |
| 63 | net.AddAdditionLayer(); |
| 64 | net.AddActivationLayer(armnn::ActivationDescriptor()); |
| 65 | net.AddOutputLayer(0); |
| 66 | } |
| 67 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 68 | TEST_CASE("NetworkModification") |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 69 | { |
Francis Murtagh | 3d2b4b2 | 2021-02-15 18:23:17 +0000 | [diff] [blame] | 70 | armnn::NetworkImpl net; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 71 | |
| 72 | armnn::IConnectableLayer* const inputLayer = net.AddInputLayer(0, "input layer"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 73 | CHECK(inputLayer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 74 | |
| 75 | unsigned int dims[] = { 10,1,1,1 }; |
| 76 | std::vector<float> convWeightsData(10); |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 77 | armnn::ConstTensor weights(armnn::TensorInfo(4, dims, armnn::DataType::Float32, 0.0f, 0, true), convWeightsData); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 78 | |
| 79 | armnn::Convolution2dDescriptor convDesc2d; |
Matteo Martincigh | fc598e1 | 2019-05-14 10:36:13 +0100 | [diff] [blame] | 80 | armnn::IConnectableLayer* const convLayer = net.AddConvolution2dLayer(convDesc2d, |
| 81 | weights, |
| 82 | armnn::EmptyOptional(), |
| 83 | "conv layer"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 84 | CHECK(convLayer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 85 | |
| 86 | inputLayer->GetOutputSlot(0).Connect(convLayer->GetInputSlot(0)); |
| 87 | |
| 88 | armnn::FullyConnectedDescriptor fullyConnectedDesc; |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 89 | |
| 90 | // Constant layer that now holds weights data for FullyConnected |
| 91 | armnn::IConnectableLayer* const constantWeightsLayer = net.AddConstantLayer(weights, "const weights"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 92 | armnn::IConnectableLayer* const fullyConnectedLayer = net.AddFullyConnectedLayer(fullyConnectedDesc, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 93 | "fully connected"); |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 94 | CHECK(constantWeightsLayer); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 95 | CHECK(fullyConnectedLayer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 96 | |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 97 | constantWeightsLayer->GetOutputSlot(0).Connect(fullyConnectedLayer->GetInputSlot(1)); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 98 | convLayer->GetOutputSlot(0).Connect(fullyConnectedLayer->GetInputSlot(0)); |
| 99 | |
| 100 | armnn::Pooling2dDescriptor pooling2dDesc; |
| 101 | armnn::IConnectableLayer* const poolingLayer = net.AddPooling2dLayer(pooling2dDesc, "pooling2d"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 102 | CHECK(poolingLayer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 103 | |
| 104 | fullyConnectedLayer->GetOutputSlot(0).Connect(poolingLayer->GetInputSlot(0)); |
| 105 | |
| 106 | armnn::ActivationDescriptor activationDesc; |
| 107 | armnn::IConnectableLayer* const activationLayer = net.AddActivationLayer(activationDesc, "activation"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 108 | CHECK(activationLayer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 109 | |
| 110 | poolingLayer->GetOutputSlot(0).Connect(activationLayer->GetInputSlot(0)); |
| 111 | |
| 112 | armnn::NormalizationDescriptor normalizationDesc; |
| 113 | armnn::IConnectableLayer* const normalizationLayer = net.AddNormalizationLayer(normalizationDesc, "normalization"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 114 | CHECK(normalizationLayer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 115 | |
| 116 | activationLayer->GetOutputSlot(0).Connect(normalizationLayer->GetInputSlot(0)); |
| 117 | |
| 118 | armnn::SoftmaxDescriptor softmaxDesc; |
| 119 | armnn::IConnectableLayer* const softmaxLayer = net.AddSoftmaxLayer(softmaxDesc, "softmax"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 120 | CHECK(softmaxLayer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 121 | |
| 122 | normalizationLayer->GetOutputSlot(0).Connect(softmaxLayer->GetInputSlot(0)); |
| 123 | |
| 124 | armnn::BatchNormalizationDescriptor batchNormDesc; |
| 125 | |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 126 | armnn::TensorInfo tensorInfo({ 1 }, armnn::DataType::Float32, 0.0f, 0, true); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 127 | std::vector<float> data(tensorInfo.GetNumBytes() / sizeof(float)); |
| 128 | armnn::ConstTensor invalidTensor(tensorInfo, data); |
| 129 | |
| 130 | armnn::IConnectableLayer* const batchNormalizationLayer = net.AddBatchNormalizationLayer(batchNormDesc, |
| 131 | invalidTensor, |
| 132 | invalidTensor, |
| 133 | invalidTensor, |
| 134 | invalidTensor, |
| 135 | "batch norm"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 136 | CHECK(batchNormalizationLayer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 137 | |
| 138 | softmaxLayer->GetOutputSlot(0).Connect(batchNormalizationLayer->GetInputSlot(0)); |
| 139 | |
| 140 | armnn::IConnectableLayer* const additionLayer = net.AddAdditionLayer("addition"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 141 | CHECK(additionLayer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 142 | |
| 143 | batchNormalizationLayer->GetOutputSlot(0).Connect(additionLayer->GetInputSlot(0)); |
| 144 | batchNormalizationLayer->GetOutputSlot(0).Connect(additionLayer->GetInputSlot(1)); |
| 145 | |
| 146 | armnn::IConnectableLayer* const multiplicationLayer = net.AddMultiplicationLayer("multiplication"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 147 | CHECK(multiplicationLayer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 148 | |
| 149 | additionLayer->GetOutputSlot(0).Connect(multiplicationLayer->GetInputSlot(0)); |
| 150 | additionLayer->GetOutputSlot(0).Connect(multiplicationLayer->GetInputSlot(1)); |
| 151 | |
| 152 | armnn::IConnectableLayer* const outputLayer = net.AddOutputLayer(0, "output layer"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 153 | CHECK(outputLayer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 154 | |
| 155 | multiplicationLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
| 156 | |
| 157 | //Tests that all layers are present in the graph. |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 158 | CHECK(net.GetGraph().GetNumLayers() == 12); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 159 | |
| 160 | //Tests that the vertices exist and have correct names. |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 161 | CHECK(GraphHasNamedLayer(net.GetGraph(), "input layer")); |
| 162 | CHECK(GraphHasNamedLayer(net.GetGraph(), "conv layer")); |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 163 | CHECK(GraphHasNamedLayer(net.GetGraph(), "const weights")); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 164 | CHECK(GraphHasNamedLayer(net.GetGraph(), "fully connected")); |
| 165 | CHECK(GraphHasNamedLayer(net.GetGraph(), "pooling2d")); |
| 166 | CHECK(GraphHasNamedLayer(net.GetGraph(), "activation")); |
| 167 | CHECK(GraphHasNamedLayer(net.GetGraph(), "normalization")); |
| 168 | CHECK(GraphHasNamedLayer(net.GetGraph(), "softmax")); |
| 169 | CHECK(GraphHasNamedLayer(net.GetGraph(), "batch norm")); |
| 170 | CHECK(GraphHasNamedLayer(net.GetGraph(), "addition")); |
| 171 | CHECK(GraphHasNamedLayer(net.GetGraph(), "multiplication")); |
| 172 | CHECK(GraphHasNamedLayer(net.GetGraph(), "output layer")); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 173 | |
| 174 | auto checkOneOutputToOneInputConnection = [] |
| 175 | (const armnn::IConnectableLayer* const srcLayer, |
| 176 | const armnn::IConnectableLayer* const tgtLayer, |
| 177 | int expectedSrcNumInputs = 1, |
| 178 | int expectedDstNumOutputs = 1) |
| 179 | { |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 180 | CHECK(srcLayer->GetNumInputSlots() == expectedSrcNumInputs); |
| 181 | CHECK(srcLayer->GetNumOutputSlots() == 1); |
| 182 | CHECK(tgtLayer->GetNumInputSlots() == 1); |
| 183 | CHECK(tgtLayer->GetNumOutputSlots() == expectedDstNumOutputs); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 184 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 185 | CHECK(srcLayer->GetOutputSlot(0).GetNumConnections() == 1); |
| 186 | CHECK(srcLayer->GetOutputSlot(0).GetConnection(0) == &tgtLayer->GetInputSlot(0)); |
| 187 | CHECK(&srcLayer->GetOutputSlot(0) == tgtLayer->GetInputSlot(0).GetConnection()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 188 | }; |
| 189 | auto checkOneOutputToTwoInputsConnections = [] |
| 190 | (const armnn::IConnectableLayer* const srcLayer, |
| 191 | const armnn::IConnectableLayer* const tgtLayer, |
| 192 | int expectedSrcNumInputs, |
| 193 | int expectedDstNumOutputs = 1) |
| 194 | { |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 195 | CHECK(srcLayer->GetNumInputSlots() == expectedSrcNumInputs); |
| 196 | CHECK(srcLayer->GetNumOutputSlots() == 1); |
| 197 | CHECK(tgtLayer->GetNumInputSlots() == 2); |
| 198 | CHECK(tgtLayer->GetNumOutputSlots() == expectedDstNumOutputs); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 199 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 200 | CHECK(srcLayer->GetOutputSlot(0).GetNumConnections() == 2); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 201 | for (unsigned int i = 0; i < srcLayer->GetOutputSlot(0).GetNumConnections(); ++i) |
| 202 | { |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 203 | CHECK(srcLayer->GetOutputSlot(0).GetConnection(i) == &tgtLayer->GetInputSlot(i)); |
| 204 | CHECK(&srcLayer->GetOutputSlot(0) == tgtLayer->GetInputSlot(i).GetConnection()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 205 | } |
| 206 | }; |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 207 | auto checkOneOutputToTwoInputConnectionForTwoDifferentLayers = [] |
| 208 | (const armnn::IConnectableLayer* const srcLayer1, |
| 209 | const armnn::IConnectableLayer* const srcLayer2, |
| 210 | const armnn::IConnectableLayer* const tgtLayer, |
| 211 | int expectedSrcNumInputs1 = 1, |
| 212 | int expectedSrcNumInputs2 = 1, |
| 213 | int expectedDstNumOutputs = 1) |
| 214 | { |
| 215 | CHECK(srcLayer1->GetNumInputSlots() == expectedSrcNumInputs1); |
| 216 | CHECK(srcLayer1->GetNumOutputSlots() == 1); |
| 217 | CHECK(srcLayer2->GetNumInputSlots() == expectedSrcNumInputs2); |
| 218 | CHECK(srcLayer2->GetNumOutputSlots() == 1); |
| 219 | CHECK(tgtLayer->GetNumInputSlots() == 2); |
| 220 | CHECK(tgtLayer->GetNumOutputSlots() == expectedDstNumOutputs); |
| 221 | |
| 222 | CHECK(srcLayer1->GetOutputSlot(0).GetNumConnections() == 1); |
| 223 | CHECK(srcLayer2->GetOutputSlot(0).GetNumConnections() == 1); |
| 224 | CHECK(srcLayer1->GetOutputSlot(0).GetConnection(0) == &tgtLayer->GetInputSlot(0)); |
| 225 | CHECK(srcLayer2->GetOutputSlot(0).GetConnection(0) == &tgtLayer->GetInputSlot(1)); |
| 226 | CHECK(&srcLayer1->GetOutputSlot(0) == tgtLayer->GetInputSlot(0).GetConnection()); |
| 227 | CHECK(&srcLayer2->GetOutputSlot(0) == tgtLayer->GetInputSlot(1).GetConnection()); |
| 228 | }; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 229 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 230 | CHECK(AreAllLayerInputSlotsConnected(*convLayer)); |
| 231 | CHECK(AreAllLayerInputSlotsConnected(*fullyConnectedLayer)); |
| 232 | CHECK(AreAllLayerInputSlotsConnected(*poolingLayer)); |
| 233 | CHECK(AreAllLayerInputSlotsConnected(*activationLayer)); |
| 234 | CHECK(AreAllLayerInputSlotsConnected(*normalizationLayer)); |
| 235 | CHECK(AreAllLayerInputSlotsConnected(*softmaxLayer)); |
| 236 | CHECK(AreAllLayerInputSlotsConnected(*batchNormalizationLayer)); |
| 237 | CHECK(AreAllLayerInputSlotsConnected(*additionLayer)); |
| 238 | CHECK(AreAllLayerInputSlotsConnected(*multiplicationLayer)); |
| 239 | CHECK(AreAllLayerInputSlotsConnected(*outputLayer)); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 240 | |
| 241 | // Checks connectivity. |
| 242 | checkOneOutputToOneInputConnection(inputLayer, convLayer, 0); |
Matthew Sloyan | 81beae3 | 2021-07-13 19:46:11 +0100 | [diff] [blame] | 243 | checkOneOutputToTwoInputConnectionForTwoDifferentLayers(convLayer, constantWeightsLayer, fullyConnectedLayer, 1, 0); |
| 244 | checkOneOutputToOneInputConnection(fullyConnectedLayer, poolingLayer, 2, 1); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 245 | checkOneOutputToOneInputConnection(poolingLayer, activationLayer); |
| 246 | checkOneOutputToOneInputConnection(activationLayer, normalizationLayer); |
| 247 | checkOneOutputToOneInputConnection(normalizationLayer, softmaxLayer); |
| 248 | checkOneOutputToOneInputConnection(softmaxLayer, batchNormalizationLayer); |
| 249 | checkOneOutputToTwoInputsConnections(batchNormalizationLayer, additionLayer, 1); |
| 250 | checkOneOutputToTwoInputsConnections(additionLayer, multiplicationLayer, 2); |
| 251 | checkOneOutputToOneInputConnection(multiplicationLayer, outputLayer, 2, 0); |
| 252 | } |
| 253 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 254 | TEST_CASE("NetworkModification_SplitterConcat") |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 255 | { |
Francis Murtagh | 3d2b4b2 | 2021-02-15 18:23:17 +0000 | [diff] [blame] | 256 | armnn::NetworkImpl net; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 257 | |
| 258 | // Adds an input layer and an input tensor descriptor. |
| 259 | armnn::IConnectableLayer* inputLayer = net.AddInputLayer(0, "input layer"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 260 | CHECK(inputLayer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 261 | |
| 262 | // Adds a splitter layer. |
| 263 | armnn::ViewsDescriptor splitterDesc(2,4); |
| 264 | |
| 265 | armnn::IConnectableLayer* splitterLayer = net.AddSplitterLayer(splitterDesc, "splitter layer"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 266 | CHECK(splitterLayer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 267 | |
| 268 | inputLayer->GetOutputSlot(0).Connect(splitterLayer->GetInputSlot(0)); |
| 269 | |
| 270 | // Adds a softmax layer 1. |
| 271 | armnn::SoftmaxDescriptor softmaxDescriptor; |
| 272 | armnn::IConnectableLayer* softmaxLayer1 = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_1"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 273 | CHECK(softmaxLayer1); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 274 | |
| 275 | splitterLayer->GetOutputSlot(0).Connect(softmaxLayer1->GetInputSlot(0)); |
| 276 | |
| 277 | // Adds a softmax layer 2. |
| 278 | armnn::IConnectableLayer* softmaxLayer2 = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_2"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 279 | CHECK(softmaxLayer2); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 280 | |
| 281 | splitterLayer->GetOutputSlot(1).Connect(softmaxLayer2->GetInputSlot(0)); |
| 282 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 283 | // Adds a concat layer. |
| 284 | armnn::OriginsDescriptor concatDesc(2, 4); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 285 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 286 | armnn::IConnectableLayer* concatLayer = net.AddConcatLayer(concatDesc, "concat layer"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 287 | CHECK(concatLayer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 288 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 289 | softmaxLayer1->GetOutputSlot(0).Connect(concatLayer->GetInputSlot(0)); |
| 290 | softmaxLayer2->GetOutputSlot(0).Connect(concatLayer->GetInputSlot(1)); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 291 | |
| 292 | // Adds an output layer. |
| 293 | armnn::IConnectableLayer* outputLayer = net.AddOutputLayer(0, "output layer"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 294 | CHECK(outputLayer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 295 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 296 | concatLayer->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 297 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 298 | CHECK(splitterLayer->GetNumOutputSlots() == 2); |
| 299 | CHECK(splitterLayer->GetOutputSlot(0).GetConnection(0) == &softmaxLayer1->GetInputSlot(0)); |
| 300 | CHECK(&splitterLayer->GetOutputSlot(0) == softmaxLayer1->GetInputSlot(0).GetConnection()); |
| 301 | CHECK(splitterLayer->GetOutputSlot(1).GetConnection(0) == &softmaxLayer2->GetInputSlot(0)); |
| 302 | CHECK(&splitterLayer->GetOutputSlot(1) == softmaxLayer2->GetInputSlot(0).GetConnection()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 303 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 304 | CHECK(concatLayer->GetNumInputSlots() == 2); |
| 305 | CHECK(softmaxLayer1->GetOutputSlot(0).GetConnection(0) == &concatLayer->GetInputSlot(0)); |
| 306 | CHECK(&softmaxLayer1->GetOutputSlot(0) == concatLayer->GetInputSlot(0).GetConnection()); |
| 307 | CHECK(softmaxLayer2->GetOutputSlot(0).GetConnection(0) == &concatLayer->GetInputSlot(1)); |
| 308 | CHECK(&softmaxLayer2->GetOutputSlot(0) == concatLayer->GetInputSlot(1).GetConnection()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 309 | } |
| 310 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 311 | TEST_CASE("NetworkModification_SplitterAddition") |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 312 | { |
Francis Murtagh | 3d2b4b2 | 2021-02-15 18:23:17 +0000 | [diff] [blame] | 313 | armnn::NetworkImpl net; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 314 | |
| 315 | // Adds an input layer and an input tensor descriptor. |
| 316 | armnn::IConnectableLayer* layer = net.AddInputLayer(0, "input layer"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 317 | CHECK(layer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 318 | |
| 319 | // Adds a splitter layer. |
| 320 | armnn::ViewsDescriptor splitterDesc(2,4); |
| 321 | |
| 322 | armnn::IConnectableLayer* const splitterLayer = net.AddSplitterLayer(splitterDesc, "splitter layer"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 323 | CHECK(splitterLayer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 324 | |
| 325 | layer->GetOutputSlot(0).Connect(splitterLayer->GetInputSlot(0)); |
| 326 | |
| 327 | // Adds a softmax layer 1. |
| 328 | armnn::SoftmaxDescriptor softmaxDescriptor; |
| 329 | armnn::IConnectableLayer* const softmax1Layer = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_1"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 330 | CHECK(softmax1Layer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 331 | |
| 332 | splitterLayer->GetOutputSlot(0).Connect(softmax1Layer->GetInputSlot(0)); |
| 333 | |
| 334 | // Adds a softmax layer 2. |
| 335 | armnn::IConnectableLayer* const softmax2Layer = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_2"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 336 | CHECK(softmax2Layer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 337 | |
| 338 | splitterLayer->GetOutputSlot(1).Connect(softmax2Layer->GetInputSlot(0)); |
| 339 | |
| 340 | // Adds addition layer. |
| 341 | layer = net.AddAdditionLayer("add layer"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 342 | CHECK(layer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 343 | |
| 344 | softmax1Layer->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); |
| 345 | softmax2Layer->GetOutputSlot(0).Connect(layer->GetInputSlot(1)); |
| 346 | |
| 347 | // Adds an output layer. |
| 348 | armnn::IConnectableLayer* prevLayer = layer; |
| 349 | layer = net.AddOutputLayer(0, "output layer"); |
| 350 | |
| 351 | prevLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); |
| 352 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 353 | CHECK(layer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 354 | } |
| 355 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 356 | TEST_CASE("NetworkModification_SplitterMultiplication") |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 357 | { |
Francis Murtagh | 3d2b4b2 | 2021-02-15 18:23:17 +0000 | [diff] [blame] | 358 | armnn::NetworkImpl net; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 359 | |
| 360 | // Adds an input layer and an input tensor descriptor. |
| 361 | armnn::IConnectableLayer* layer = net.AddInputLayer(0, "input layer"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 362 | CHECK(layer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 363 | |
| 364 | // Adds a splitter layer. |
| 365 | armnn::ViewsDescriptor splitterDesc(2,4); |
| 366 | armnn::IConnectableLayer* const splitterLayer = net.AddSplitterLayer(splitterDesc, "splitter layer"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 367 | CHECK(splitterLayer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 368 | |
| 369 | layer->GetOutputSlot(0).Connect(splitterLayer->GetInputSlot(0)); |
| 370 | |
| 371 | // Adds a softmax layer 1. |
| 372 | armnn::SoftmaxDescriptor softmaxDescriptor; |
| 373 | armnn::IConnectableLayer* const softmax1Layer = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_1"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 374 | CHECK(softmax1Layer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 375 | |
| 376 | splitterLayer->GetOutputSlot(0).Connect(softmax1Layer->GetInputSlot(0)); |
| 377 | |
| 378 | // Adds a softmax layer 2. |
| 379 | armnn::IConnectableLayer* const softmax2Layer = net.AddSoftmaxLayer(softmaxDescriptor, "softmax_2"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 380 | CHECK(softmax2Layer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 381 | |
| 382 | splitterLayer->GetOutputSlot(1).Connect(softmax2Layer->GetInputSlot(0)); |
| 383 | |
| 384 | // Adds multiplication layer. |
| 385 | layer = net.AddMultiplicationLayer("multiplication layer"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 386 | CHECK(layer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 387 | |
| 388 | softmax1Layer->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); |
| 389 | softmax2Layer->GetOutputSlot(0).Connect(layer->GetInputSlot(1)); |
| 390 | |
| 391 | // Adds an output layer. |
| 392 | armnn::IConnectableLayer* prevLayer = layer; |
| 393 | layer = net.AddOutputLayer(0, "output layer"); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 394 | CHECK(layer); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 395 | |
| 396 | prevLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); |
| 397 | } |
| 398 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 399 | TEST_CASE("Network_AddQuantize") |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 400 | { |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 401 | struct Test : public armnn::IStrategy |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 402 | { |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 403 | void ExecuteStrategy(const armnn::IConnectableLayer* layer, |
| 404 | const armnn::BaseDescriptor& descriptor, |
| 405 | const std::vector<armnn::ConstTensor>& constants, |
| 406 | const char* name, |
| 407 | const armnn::LayerBindingId id = 0) override |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 408 | { |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 409 | armnn::IgnoreUnused(descriptor, constants, id); |
| 410 | switch (layer->GetType()) |
| 411 | { |
| 412 | case armnn::LayerType::Input: break; |
| 413 | case armnn::LayerType::Output: break; |
| 414 | case armnn::LayerType::Quantize: |
| 415 | { |
| 416 | m_Visited = true; |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 417 | |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 418 | CHECK(layer); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 419 | |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 420 | std::string expectedName = std::string("quantize"); |
| 421 | CHECK(std::string(layer->GetName()) == expectedName); |
| 422 | CHECK(std::string(name) == expectedName); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 423 | |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 424 | CHECK(layer->GetNumInputSlots() == 1); |
| 425 | CHECK(layer->GetNumOutputSlots() == 1); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 426 | |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 427 | const armnn::TensorInfo& infoIn = layer->GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 428 | CHECK((infoIn.GetDataType() == armnn::DataType::Float32)); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 429 | |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 430 | const armnn::TensorInfo& infoOut = layer->GetOutputSlot(0).GetTensorInfo(); |
| 431 | CHECK((infoOut.GetDataType() == armnn::DataType::QAsymmU8)); |
| 432 | break; |
| 433 | } |
| 434 | default: |
| 435 | { |
| 436 | // nothing |
| 437 | } |
| 438 | } |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | bool m_Visited = false; |
| 442 | }; |
| 443 | |
| 444 | |
| 445 | auto graph = armnn::INetwork::Create(); |
| 446 | |
| 447 | auto input = graph->AddInputLayer(0, "input"); |
| 448 | auto quantize = graph->AddQuantizeLayer("quantize"); |
| 449 | auto output = graph->AddOutputLayer(1, "output"); |
| 450 | |
| 451 | input->GetOutputSlot(0).Connect(quantize->GetInputSlot(0)); |
| 452 | quantize->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 453 | |
| 454 | armnn::TensorInfo infoIn({3,1}, armnn::DataType::Float32); |
| 455 | input->GetOutputSlot(0).SetTensorInfo(infoIn); |
| 456 | |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 457 | armnn::TensorInfo infoOut({3,1}, armnn::DataType::QAsymmU8); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 458 | quantize->GetOutputSlot(0).SetTensorInfo(infoOut); |
| 459 | |
| 460 | Test testQuantize; |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 461 | graph->ExecuteStrategy(testQuantize); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 462 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 463 | CHECK(testQuantize.m_Visited == true); |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 464 | |
| 465 | } |
| 466 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 467 | TEST_CASE("Network_AddMerge") |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 468 | { |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 469 | struct Test : public armnn::IStrategy |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 470 | { |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 471 | void ExecuteStrategy(const armnn::IConnectableLayer* layer, |
| 472 | const armnn::BaseDescriptor& descriptor, |
| 473 | const std::vector<armnn::ConstTensor>& constants, |
| 474 | const char* name, |
| 475 | const armnn::LayerBindingId id = 0) override |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 476 | { |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 477 | armnn::IgnoreUnused(descriptor, constants, id); |
| 478 | switch (layer->GetType()) |
| 479 | { |
| 480 | case armnn::LayerType::Input: break; |
| 481 | case armnn::LayerType::Output: break; |
| 482 | case armnn::LayerType::Merge: |
| 483 | { |
| 484 | m_Visited = true; |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 485 | |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 486 | CHECK(layer); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 487 | |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 488 | std::string expectedName = std::string("merge"); |
| 489 | CHECK(std::string(layer->GetName()) == expectedName); |
| 490 | CHECK(std::string(name) == expectedName); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 491 | |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 492 | CHECK(layer->GetNumInputSlots() == 2); |
| 493 | CHECK(layer->GetNumOutputSlots() == 1); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 494 | |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 495 | const armnn::TensorInfo& infoIn0 = layer->GetInputSlot(0).GetConnection()->GetTensorInfo(); |
| 496 | CHECK((infoIn0.GetDataType() == armnn::DataType::Float32)); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 497 | |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 498 | const armnn::TensorInfo& infoIn1 = layer->GetInputSlot(1).GetConnection()->GetTensorInfo(); |
| 499 | CHECK((infoIn1.GetDataType() == armnn::DataType::Float32)); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 500 | |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 501 | const armnn::TensorInfo& infoOut = layer->GetOutputSlot(0).GetTensorInfo(); |
| 502 | CHECK((infoOut.GetDataType() == armnn::DataType::Float32)); |
| 503 | break; |
| 504 | } |
| 505 | default: |
| 506 | { |
| 507 | // nothing |
| 508 | } |
| 509 | } |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | bool m_Visited = false; |
| 513 | }; |
| 514 | |
| 515 | armnn::INetworkPtr network = armnn::INetwork::Create(); |
| 516 | |
| 517 | armnn::IConnectableLayer* input0 = network->AddInputLayer(0); |
| 518 | armnn::IConnectableLayer* input1 = network->AddInputLayer(1); |
| 519 | armnn::IConnectableLayer* merge = network->AddMergeLayer("merge"); |
| 520 | armnn::IConnectableLayer* output = network->AddOutputLayer(0); |
| 521 | |
| 522 | input0->GetOutputSlot(0).Connect(merge->GetInputSlot(0)); |
| 523 | input1->GetOutputSlot(0).Connect(merge->GetInputSlot(1)); |
| 524 | merge->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 525 | |
| 526 | const armnn::TensorInfo info({3,1}, armnn::DataType::Float32); |
| 527 | input0->GetOutputSlot(0).SetTensorInfo(info); |
| 528 | input1->GetOutputSlot(0).SetTensorInfo(info); |
| 529 | merge->GetOutputSlot(0).SetTensorInfo(info); |
| 530 | |
| 531 | Test testMerge; |
Jan Eilers | 1b2654f | 2021-09-24 15:45:46 +0100 | [diff] [blame] | 532 | network->ExecuteStrategy(testMerge); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 533 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 534 | CHECK(testMerge.m_Visited == true); |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 535 | } |
| 536 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 537 | TEST_CASE("StandInLayerNetworkTest") |
Colm Donelan | a876982 | 2019-10-23 14:18:56 +0100 | [diff] [blame] | 538 | { |
| 539 | // Create a simple network with a StandIn some place in it. |
Francis Murtagh | 3d2b4b2 | 2021-02-15 18:23:17 +0000 | [diff] [blame] | 540 | armnn::NetworkImpl net; |
Colm Donelan | a876982 | 2019-10-23 14:18:56 +0100 | [diff] [blame] | 541 | auto input = net.AddInputLayer(0); |
| 542 | |
| 543 | // Add some valid layer. |
| 544 | auto floor = net.AddFloorLayer("Floor"); |
| 545 | |
| 546 | // Add a standin layer |
| 547 | armnn::StandInDescriptor standInDescriptor; |
| 548 | standInDescriptor.m_NumInputs = 1; |
| 549 | standInDescriptor.m_NumOutputs = 1; |
| 550 | auto standIn = net.AddStandInLayer(standInDescriptor, "StandIn"); |
| 551 | |
| 552 | // Finally the output. |
| 553 | auto output = net.AddOutputLayer(0); |
| 554 | |
| 555 | // Connect up the layers |
| 556 | input->GetOutputSlot(0).Connect(floor->GetInputSlot(0)); |
| 557 | |
| 558 | floor->GetOutputSlot(0).Connect(standIn->GetInputSlot(0)); |
| 559 | |
| 560 | standIn->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 561 | |
| 562 | // Check that the layer is there. |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 563 | CHECK(GraphHasNamedLayer(net.GetGraph(), "StandIn")); |
Colm Donelan | a876982 | 2019-10-23 14:18:56 +0100 | [diff] [blame] | 564 | // Check that it is connected as expected. |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 565 | CHECK(input->GetOutputSlot(0).GetConnection(0) == &floor->GetInputSlot(0)); |
| 566 | CHECK(floor->GetOutputSlot(0).GetConnection(0) == &standIn->GetInputSlot(0)); |
| 567 | CHECK(standIn->GetOutputSlot(0).GetConnection(0) == &output->GetInputSlot(0)); |
Colm Donelan | a876982 | 2019-10-23 14:18:56 +0100 | [diff] [blame] | 568 | } |
| 569 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 570 | TEST_CASE("StandInLayerSingleInputMultipleOutputsNetworkTest") |
Colm Donelan | a876982 | 2019-10-23 14:18:56 +0100 | [diff] [blame] | 571 | { |
| 572 | // Another test with one input and two outputs on the StandIn layer. |
Francis Murtagh | 3d2b4b2 | 2021-02-15 18:23:17 +0000 | [diff] [blame] | 573 | armnn::NetworkImpl net; |
Colm Donelan | a876982 | 2019-10-23 14:18:56 +0100 | [diff] [blame] | 574 | |
| 575 | // Create the input. |
| 576 | auto input = net.AddInputLayer(0); |
| 577 | |
| 578 | // Add a standin layer |
| 579 | armnn::StandInDescriptor standInDescriptor; |
| 580 | standInDescriptor.m_NumInputs = 1; |
| 581 | standInDescriptor.m_NumOutputs = 2; |
| 582 | auto standIn = net.AddStandInLayer(standInDescriptor, "StandIn"); |
| 583 | |
| 584 | // Add two outputs. |
| 585 | auto output0 = net.AddOutputLayer(0); |
| 586 | auto output1 = net.AddOutputLayer(1); |
| 587 | |
| 588 | // Connect up the layers |
| 589 | input->GetOutputSlot(0).Connect(standIn->GetInputSlot(0)); |
| 590 | |
| 591 | // Connect the two outputs of the Standin to the two outputs. |
| 592 | standIn->GetOutputSlot(0).Connect(output0->GetInputSlot(0)); |
| 593 | standIn->GetOutputSlot(1).Connect(output1->GetInputSlot(0)); |
| 594 | |
| 595 | // Check that the layer is there. |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 596 | CHECK(GraphHasNamedLayer(net.GetGraph(), "StandIn")); |
Colm Donelan | a876982 | 2019-10-23 14:18:56 +0100 | [diff] [blame] | 597 | // Check that it is connected as expected. |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 598 | CHECK(input->GetOutputSlot(0).GetConnection(0) == &standIn->GetInputSlot(0)); |
| 599 | CHECK(standIn->GetOutputSlot(0).GetConnection(0) == &output0->GetInputSlot(0)); |
| 600 | CHECK(standIn->GetOutputSlot(1).GetConnection(0) == &output1->GetInputSlot(0)); |
Colm Donelan | a876982 | 2019-10-23 14:18:56 +0100 | [diff] [blame] | 601 | } |
| 602 | |
Jim Flynn | e466596 | 2022-01-31 16:08:53 +0000 | [diff] [blame] | 603 | TEST_CASE("ObtainConv2DDescriptorFromIConnectableLayer") |
| 604 | { |
| 605 | armnn::NetworkImpl net; |
| 606 | |
| 607 | unsigned int dims[] = { 10,1,1,1 }; |
| 608 | std::vector<float> convWeightsData(10); |
| 609 | armnn::ConstTensor weights(armnn::TensorInfo(4, dims, armnn::DataType::Float32, 0.0f, 0, true), convWeightsData); |
| 610 | |
| 611 | armnn::Convolution2dDescriptor convDesc2d; |
| 612 | convDesc2d.m_PadLeft = 2; |
| 613 | convDesc2d.m_PadRight = 3; |
| 614 | convDesc2d.m_PadTop = 4; |
| 615 | convDesc2d.m_PadBottom = 5; |
| 616 | convDesc2d.m_StrideX = 2; |
| 617 | convDesc2d.m_StrideY = 1; |
| 618 | convDesc2d.m_DilationX = 3; |
| 619 | convDesc2d.m_DilationY = 3; |
| 620 | convDesc2d.m_BiasEnabled = false; |
| 621 | convDesc2d.m_DataLayout = armnn::DataLayout::NCHW; |
| 622 | armnn::IConnectableLayer* const convLayer = net.AddConvolution2dLayer(convDesc2d, |
| 623 | weights, |
| 624 | armnn::EmptyOptional(), |
| 625 | "conv layer"); |
| 626 | CHECK(convLayer); |
| 627 | |
| 628 | const armnn::BaseDescriptor& descriptor = convLayer->GetParameters(); |
| 629 | CHECK(descriptor.IsNull() == false); |
| 630 | const armnn::Convolution2dDescriptor& originalDescriptor = |
| 631 | static_cast<const armnn::Convolution2dDescriptor&>(descriptor); |
| 632 | CHECK(originalDescriptor.m_PadLeft == 2); |
| 633 | CHECK(originalDescriptor.m_PadRight == 3); |
| 634 | CHECK(originalDescriptor.m_PadTop == 4); |
| 635 | CHECK(originalDescriptor.m_PadBottom == 5); |
| 636 | CHECK(originalDescriptor.m_StrideX == 2); |
| 637 | CHECK(originalDescriptor.m_StrideY == 1); |
| 638 | CHECK(originalDescriptor.m_DilationX == 3); |
| 639 | CHECK(originalDescriptor.m_DilationY == 3); |
| 640 | CHECK(originalDescriptor.m_BiasEnabled == false); |
| 641 | CHECK(originalDescriptor.m_DataLayout == armnn::DataLayout::NCHW); |
| 642 | } |
| 643 | |
| 644 | TEST_CASE("CheckNullDescriptor") |
| 645 | { |
| 646 | armnn::NetworkImpl net; |
| 647 | armnn::IConnectableLayer* const addLayer = net.AddAdditionLayer(); |
| 648 | |
| 649 | CHECK(addLayer); |
| 650 | |
| 651 | const armnn::BaseDescriptor& descriptor = addLayer->GetParameters(); |
| 652 | // additional layer has no descriptor so a NullDescriptor will be returned |
| 653 | CHECK(descriptor.IsNull() == true); |
| 654 | } |
| 655 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 656 | } |