telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [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 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 7 | #include <Graph.hpp> |
| 8 | |
| 9 | #include <backendsCommon/WorkloadFactory.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 10 | |
| 11 | #include <boost/core/ignore_unused.hpp> |
| 12 | |
| 13 | namespace |
| 14 | { |
| 15 | armnn::Graph dummyGraph; |
| 16 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 17 | // Make a dummy TensorInfo object. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 18 | template<armnn::DataType DataType> |
| 19 | armnn::TensorInfo MakeDummyTensorInfo() |
| 20 | { |
| 21 | return armnn::TensorInfo({2,2,2,2}, DataType); |
| 22 | } |
| 23 | |
| 24 | |
| 25 | // Make a dummy WorkloadInfo using a dummy TensorInfo. |
| 26 | template<armnn::DataType DataType> |
| 27 | armnn::WorkloadInfo MakeDummyWorkloadInfo(unsigned int numInputs, unsigned int numOutputs) |
| 28 | { |
| 29 | armnn::WorkloadInfo info; |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 30 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 31 | for (unsigned int i=0; i < numInputs; i++) |
| 32 | { |
| 33 | info.m_InputTensorInfos.push_back(MakeDummyTensorInfo<DataType>()); |
| 34 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 35 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 36 | for (unsigned int o=0; o < numOutputs; o++) |
| 37 | { |
| 38 | info.m_OutputTensorInfos.push_back(MakeDummyTensorInfo<DataType>()); |
| 39 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 40 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 41 | return info; |
| 42 | } |
| 43 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 44 | // Template class to create a dummy layer (2 parameters). |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 45 | template<typename LayerType, typename DescType = typename LayerType::DescriptorType> |
| 46 | struct DummyLayer |
| 47 | { |
| 48 | DummyLayer() |
| 49 | { |
| 50 | m_Layer = dummyGraph.AddLayer<LayerType>(DescType(), ""); |
| 51 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 52 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 53 | ~DummyLayer() |
| 54 | { |
| 55 | dummyGraph.EraseLayer(m_Layer); |
| 56 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 57 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 58 | LayerType* m_Layer; |
| 59 | }; |
| 60 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 61 | // Template class to create a dummy layer (1 parameter). |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 62 | template<typename LayerType> |
| 63 | struct DummyLayer<LayerType, void> |
| 64 | { |
| 65 | DummyLayer() |
| 66 | { |
| 67 | m_Layer = dummyGraph.AddLayer<LayerType>(""); |
| 68 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 69 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 70 | ~DummyLayer() |
| 71 | { |
| 72 | dummyGraph.EraseLayer(m_Layer); |
| 73 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 74 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 75 | LayerType* m_Layer; |
| 76 | }; |
| 77 | |
| 78 | template<> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 79 | struct DummyLayer<armnn::BatchNormalizationLayer> |
| 80 | { |
| 81 | DummyLayer() |
| 82 | { |
| 83 | m_Layer = dummyGraph.AddLayer<armnn::BatchNormalizationLayer>(armnn::BatchNormalizationDescriptor(), ""); |
| 84 | m_Layer->m_Mean = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 85 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 86 | m_Layer->m_Variance = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 87 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 88 | m_Layer->m_Beta = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 89 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 90 | m_Layer->m_Gamma = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 91 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 92 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 93 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 94 | ~DummyLayer() |
| 95 | { |
| 96 | dummyGraph.EraseLayer(m_Layer); |
| 97 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 98 | |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 99 | armnn::BatchNormalizationLayer* m_Layer; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | template<> |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 103 | struct DummyLayer<armnn::BatchToSpaceNdLayer> |
| 104 | { |
| 105 | DummyLayer() |
| 106 | { |
| 107 | m_Layer = dummyGraph.AddLayer<armnn::BatchToSpaceNdLayer>(armnn::BatchToSpaceNdDescriptor(), ""); |
| 108 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 109 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 110 | ~DummyLayer() |
| 111 | { |
| 112 | dummyGraph.EraseLayer(m_Layer); |
| 113 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 114 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 115 | armnn::BatchToSpaceNdLayer* m_Layer; |
| 116 | }; |
| 117 | |
| 118 | template<> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 119 | struct DummyLayer<armnn::ConstantLayer, void> |
| 120 | { |
| 121 | DummyLayer() |
| 122 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 123 | m_Layer = dummyGraph.AddLayer<armnn::ConstantLayer>(""); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 124 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 125 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 126 | ~DummyLayer() |
| 127 | { |
| 128 | dummyGraph.EraseLayer(m_Layer); |
| 129 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 130 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 131 | armnn::ConstantLayer* m_Layer; |
| 132 | }; |
| 133 | |
| 134 | template<> |
| 135 | struct DummyLayer<armnn::InputLayer, armnn::LayerBindingId> |
| 136 | { |
| 137 | DummyLayer() |
| 138 | { |
| 139 | m_Layer = dummyGraph.AddLayer<armnn::InputLayer>(armnn::LayerBindingId(), ""); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 140 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 141 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 142 | ~DummyLayer() |
| 143 | { |
| 144 | dummyGraph.EraseLayer(m_Layer); |
| 145 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 146 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 147 | armnn::InputLayer* m_Layer; |
| 148 | }; |
| 149 | |
| 150 | template<> |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 151 | struct DummyLayer<armnn::ConcatLayer> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 152 | { |
| 153 | DummyLayer() |
| 154 | { |
| 155 | armnn::OriginsDescriptor desc(2); |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 156 | m_Layer = dummyGraph.AddLayer<armnn::ConcatLayer>(desc, ""); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 157 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 158 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 159 | ~DummyLayer() |
| 160 | { |
| 161 | dummyGraph.EraseLayer(m_Layer); |
| 162 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 163 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 164 | armnn::ConcatLayer* m_Layer; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | template<> |
| 168 | struct DummyLayer<armnn::OutputLayer, armnn::LayerBindingId> |
| 169 | { |
| 170 | DummyLayer() |
| 171 | { |
| 172 | m_Layer = dummyGraph.AddLayer<armnn::OutputLayer>(armnn::LayerBindingId(), ""); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 173 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 174 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 175 | ~DummyLayer() |
| 176 | { |
| 177 | dummyGraph.EraseLayer(m_Layer); |
| 178 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 179 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 180 | armnn::OutputLayer* m_Layer; |
| 181 | }; |
| 182 | |
| 183 | template<> |
| 184 | struct DummyLayer<armnn::SplitterLayer> |
| 185 | { |
| 186 | DummyLayer() |
| 187 | { |
| 188 | armnn::ViewsDescriptor desc(1); |
| 189 | m_Layer = dummyGraph.AddLayer<armnn::SplitterLayer>(desc, ""); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 190 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 191 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 192 | ~DummyLayer() |
| 193 | { |
| 194 | dummyGraph.EraseLayer(m_Layer); |
| 195 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 196 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 197 | armnn::SplitterLayer* m_Layer; |
| 198 | }; |
| 199 | |
| 200 | template <typename ConvolutionLayerType> |
| 201 | struct DummyConvolutionLayer |
| 202 | { |
| 203 | DummyConvolutionLayer() |
| 204 | { |
| 205 | typename ConvolutionLayerType::DescriptorType desc; |
James Conroy | 663c184 | 2019-11-01 15:21:48 +0000 | [diff] [blame] | 206 | desc.m_StrideX = 1; |
| 207 | desc.m_StrideY = 1; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 208 | m_Layer = dummyGraph.AddLayer<ConvolutionLayerType>(desc, ""); |
| 209 | m_Layer->m_Weight = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 210 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 211 | m_Layer->m_Bias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 212 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 213 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 214 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 215 | ~DummyConvolutionLayer() |
| 216 | { |
| 217 | dummyGraph.EraseLayer(m_Layer); |
| 218 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 219 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 220 | ConvolutionLayerType* m_Layer; |
| 221 | }; |
| 222 | |
| 223 | template<> |
| 224 | struct DummyLayer<armnn::Convolution2dLayer> |
| 225 | : public DummyConvolutionLayer<armnn::Convolution2dLayer> |
| 226 | { |
| 227 | }; |
| 228 | |
| 229 | template<> |
| 230 | struct DummyLayer<armnn::DepthwiseConvolution2dLayer> |
| 231 | : public DummyConvolutionLayer<armnn::DepthwiseConvolution2dLayer> |
| 232 | { |
| 233 | }; |
| 234 | |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 235 | template<> |
| 236 | struct DummyLayer<armnn::TransposeConvolution2dLayer> |
| 237 | : public DummyConvolutionLayer<armnn::TransposeConvolution2dLayer> |
| 238 | { |
| 239 | }; |
| 240 | |
Derek Lamberti | 6a5e5e8 | 2019-12-05 14:41:20 +0000 | [diff] [blame] | 241 | template<> |
| 242 | struct DummyLayer<armnn::DetectionPostProcessLayer> |
| 243 | { |
| 244 | DummyLayer() |
| 245 | { |
| 246 | m_Layer = dummyGraph.AddLayer<armnn::DetectionPostProcessLayer>(armnn::DetectionPostProcessDescriptor(), ""); |
| 247 | m_Layer->m_Anchors = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 248 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 249 | } |
| 250 | |
| 251 | ~DummyLayer() |
| 252 | { |
| 253 | dummyGraph.EraseLayer(m_Layer); |
| 254 | } |
| 255 | |
| 256 | armnn::DetectionPostProcessLayer* m_Layer; |
| 257 | }; |
| 258 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 259 | template <typename LstmLayerType> |
| 260 | struct DummyLstmLayer |
| 261 | { |
| 262 | DummyLstmLayer() |
| 263 | { |
| 264 | typename LstmLayerType::DescriptorType desc; |
| 265 | desc.m_CifgEnabled = false; |
| 266 | |
| 267 | m_Layer = dummyGraph.AddLayer<LstmLayerType>(armnn::LstmDescriptor(), ""); |
| 268 | m_Layer->m_BasicParameters.m_InputToForgetWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 269 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 270 | m_Layer->m_BasicParameters.m_InputToCellWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 271 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 272 | m_Layer->m_BasicParameters.m_InputToOutputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 273 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 274 | m_Layer->m_BasicParameters.m_RecurrentToForgetWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 275 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 276 | m_Layer->m_BasicParameters.m_RecurrentToCellWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 277 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 278 | m_Layer->m_BasicParameters.m_RecurrentToOutputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 279 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 280 | m_Layer->m_BasicParameters.m_ForgetGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 281 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 282 | m_Layer->m_BasicParameters.m_CellBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 283 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 284 | m_Layer->m_BasicParameters.m_OutputGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 285 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 286 | |
| 287 | m_Layer->m_CifgParameters.m_InputToInputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 288 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 289 | m_Layer->m_CifgParameters.m_RecurrentToInputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 290 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 291 | m_Layer->m_CifgParameters.m_CellToInputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 292 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 293 | m_Layer->m_CifgParameters.m_InputGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 294 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 295 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 296 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 297 | ~DummyLstmLayer() |
| 298 | { |
| 299 | dummyGraph.EraseLayer(m_Layer); |
| 300 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 301 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 302 | armnn::LstmLayer* m_Layer; |
| 303 | }; |
| 304 | |
| 305 | template<> |
| 306 | struct DummyLayer<armnn::LstmLayer> |
| 307 | : public DummyLstmLayer<armnn::LstmLayer> |
| 308 | { |
| 309 | }; |
| 310 | |
| 311 | template<> |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 312 | struct DummyLayer<armnn::QuantizedLstmLayer, void> |
| 313 | { |
| 314 | DummyLayer() |
| 315 | { |
| 316 | m_Layer = dummyGraph.AddLayer<armnn::QuantizedLstmLayer>(""); |
| 317 | |
| 318 | m_Layer->m_QuantizedLstmParameters.m_InputToInputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 319 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QuantisedAsymm8)); |
| 320 | m_Layer->m_QuantizedLstmParameters.m_InputToForgetWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 321 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QuantisedAsymm8)); |
| 322 | m_Layer->m_QuantizedLstmParameters.m_InputToCellWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 323 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QuantisedAsymm8)); |
| 324 | m_Layer->m_QuantizedLstmParameters.m_InputToOutputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 325 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QuantisedAsymm8)); |
| 326 | |
| 327 | m_Layer->m_QuantizedLstmParameters.m_RecurrentToInputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 328 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QuantisedAsymm8)); |
| 329 | m_Layer->m_QuantizedLstmParameters.m_RecurrentToForgetWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 330 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QuantisedAsymm8)); |
| 331 | m_Layer->m_QuantizedLstmParameters.m_RecurrentToCellWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 332 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QuantisedAsymm8)); |
| 333 | m_Layer->m_QuantizedLstmParameters.m_RecurrentToOutputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 334 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QuantisedAsymm8)); |
| 335 | |
| 336 | m_Layer->m_QuantizedLstmParameters.m_InputGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 337 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32)); |
| 338 | m_Layer->m_QuantizedLstmParameters.m_ForgetGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 339 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32)); |
| 340 | m_Layer->m_QuantizedLstmParameters.m_CellBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 341 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32)); |
| 342 | m_Layer->m_QuantizedLstmParameters.m_OutputGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 343 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32)); |
| 344 | } |
| 345 | |
| 346 | ~DummyLayer() |
| 347 | { |
| 348 | dummyGraph.EraseLayer(m_Layer); |
| 349 | } |
| 350 | |
| 351 | armnn::QuantizedLstmLayer* m_Layer; |
| 352 | }; |
| 353 | |
| 354 | template<> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 355 | struct DummyLayer<armnn::FullyConnectedLayer> |
| 356 | { |
| 357 | DummyLayer() |
| 358 | { |
| 359 | armnn::FullyConnectedLayer::DescriptorType desc; |
| 360 | m_Layer = dummyGraph.AddLayer<armnn::FullyConnectedLayer>(desc, ""); |
| 361 | m_Layer->m_Weight = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 362 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 363 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 364 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 365 | ~DummyLayer() |
| 366 | { |
| 367 | dummyGraph.EraseLayer(m_Layer); |
| 368 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 369 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 370 | armnn::FullyConnectedLayer* m_Layer; |
| 371 | }; |
| 372 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 373 | // Tag for giving LayerType entries a unique strong type each. |
| 374 | template<armnn::LayerType> |
| 375 | struct Tag{}; |
| 376 | |
| 377 | #define DECLARE_LAYER_POLICY_CUSTOM_PARAM(name, descType) \ |
| 378 | template<armnn::DataType DataType> \ |
| 379 | struct LayerTypePolicy<armnn::LayerType::name, DataType> \ |
| 380 | { \ |
| 381 | using Type = armnn::name##Layer; \ |
| 382 | using Desc = descType; \ |
| 383 | using QueueDesc = armnn::name##QueueDescriptor; \ |
| 384 | constexpr static const char* NameStr = #name; \ |
Derek Lamberti | e606b7c | 2019-10-21 16:51:11 +0100 | [diff] [blame] | 385 | constexpr static const bool IsException = false; \ |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 386 | \ |
| 387 | static std::unique_ptr<armnn::IWorkload> MakeDummyWorkload(armnn::IWorkloadFactory *factory, \ |
| 388 | unsigned int nIn, unsigned int nOut) \ |
| 389 | { \ |
| 390 | QueueDesc desc; \ |
| 391 | armnn::WorkloadInfo info = MakeDummyWorkloadInfo<DataType>(nIn, nOut); \ |
| 392 | return factory->Create##name(desc, info); \ |
| 393 | } \ |
| 394 | }; |
| 395 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 396 | // Define a layer policy specialization for use with the IsLayerSupported tests. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 397 | // Use this version for layers whose constructor takes 1 parameter(name). |
| 398 | #define DECLARE_LAYER_POLICY_1_PARAM(name) DECLARE_LAYER_POLICY_CUSTOM_PARAM(name, void) |
| 399 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 400 | // Define a layer policy specialization for use with the IsLayerSupported tests. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 401 | // Use this version for layers whose constructor takes 2 parameters(descriptor and name). |
| 402 | #define DECLARE_LAYER_POLICY_2_PARAM(name) DECLARE_LAYER_POLICY_CUSTOM_PARAM(name, armnn::name##Descriptor) |
| 403 | |
Derek Lamberti | 013c390 | 2019-10-21 10:46:16 +0100 | [diff] [blame] | 404 | |
| 405 | #define DECLARE_LAYER_POLICY_EXCEPTION(name, descType) \ |
| 406 | template<armnn::DataType DataType> \ |
| 407 | struct LayerTypePolicy<armnn::LayerType::name, DataType> \ |
| 408 | { \ |
| 409 | using Type = armnn::name##Layer; \ |
| 410 | using Desc = descType; \ |
| 411 | constexpr static const char* NameStr = #name; \ |
Derek Lamberti | b99ef39 | 2019-10-21 14:10:38 +0100 | [diff] [blame] | 412 | constexpr static const bool IsException = true; \ |
Derek Lamberti | 013c390 | 2019-10-21 10:46:16 +0100 | [diff] [blame] | 413 | \ |
| 414 | static std::unique_ptr<armnn::IWorkload> MakeDummyWorkload(armnn::IWorkloadFactory *factory, \ |
| 415 | unsigned int nIn, unsigned int nOut) \ |
| 416 | { \ |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame^] | 417 | boost::ignore_unused(factory, nIn, nOut); \ |
Derek Lamberti | 013c390 | 2019-10-21 10:46:16 +0100 | [diff] [blame] | 418 | return std::unique_ptr<armnn::IWorkload>(); \ |
| 419 | } \ |
| 420 | }; |
| 421 | |
| 422 | #define DECLARE_LAYER_POLICY_EXCEPTION_1_PARAM(name) DECLARE_LAYER_POLICY_EXCEPTION(name, void) |
| 423 | #define DECLARE_LAYER_POLICY_EXCEPTION_2_PARAM(name) DECLARE_LAYER_POLICY_EXCEPTION(name, armnn::name##Descriptor) |
| 424 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 425 | // Layer policy template. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 426 | template<armnn::LayerType Type, armnn::DataType DataType> |
| 427 | struct LayerTypePolicy; |
| 428 | |
| 429 | // Every entry in the armnn::LayerType enum must be accounted for below. |
Kevin May | 868eb14 | 2019-09-04 17:29:31 +0100 | [diff] [blame] | 430 | DECLARE_LAYER_POLICY_1_PARAM(Abs) |
| 431 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 432 | DECLARE_LAYER_POLICY_2_PARAM(Activation) |
| 433 | |
| 434 | DECLARE_LAYER_POLICY_1_PARAM(Addition) |
| 435 | |
Nikhil Raj | ee391d5 | 2019-09-05 17:50:44 +0100 | [diff] [blame] | 436 | DECLARE_LAYER_POLICY_2_PARAM(ArgMinMax) |
| 437 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 438 | DECLARE_LAYER_POLICY_2_PARAM(BatchNormalization) |
| 439 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 440 | DECLARE_LAYER_POLICY_2_PARAM(BatchToSpaceNd) |
| 441 | |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 442 | DECLARE_LAYER_POLICY_2_PARAM(Comparison) |
| 443 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 444 | DECLARE_LAYER_POLICY_2_PARAM(Concat) |
| 445 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 446 | DECLARE_LAYER_POLICY_1_PARAM(Constant) |
| 447 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 448 | DECLARE_LAYER_POLICY_1_PARAM(ConvertFp16ToFp32) |
| 449 | |
| 450 | DECLARE_LAYER_POLICY_1_PARAM(ConvertFp32ToFp16) |
| 451 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 452 | DECLARE_LAYER_POLICY_2_PARAM(Convolution2d) |
| 453 | |
| 454 | DECLARE_LAYER_POLICY_1_PARAM(MemCopy) |
| 455 | |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 456 | DECLARE_LAYER_POLICY_1_PARAM(MemImport) |
| 457 | |
Nattapat Chaimanowong | 964e955 | 2019-03-26 11:03:26 +0000 | [diff] [blame] | 458 | DECLARE_LAYER_POLICY_1_PARAM(Debug) |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 459 | |
Aron Virginas-Tar | dd6247f | 2019-09-19 14:31:17 +0100 | [diff] [blame] | 460 | DECLARE_LAYER_POLICY_2_PARAM(DepthToSpace) |
| 461 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 462 | DECLARE_LAYER_POLICY_2_PARAM(DepthwiseConvolution2d) |
| 463 | |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 464 | DECLARE_LAYER_POLICY_1_PARAM(Dequantize) |
| 465 | |
Narumol Prangnawarat | 94dd5d8 | 2019-01-23 18:06:26 +0000 | [diff] [blame] | 466 | DECLARE_LAYER_POLICY_2_PARAM(DetectionPostProcess) |
| 467 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 468 | DECLARE_LAYER_POLICY_2_PARAM(FakeQuantization) |
| 469 | |
| 470 | DECLARE_LAYER_POLICY_1_PARAM(Floor) |
| 471 | |
| 472 | DECLARE_LAYER_POLICY_2_PARAM(FullyConnected) |
| 473 | |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 474 | DECLARE_LAYER_POLICY_1_PARAM(Gather) |
| 475 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 476 | DECLARE_LAYER_POLICY_CUSTOM_PARAM(Input, armnn::LayerBindingId) |
| 477 | |
Kevin May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 478 | DECLARE_LAYER_POLICY_2_PARAM(InstanceNormalization) |
| 479 | |
Matteo Martincigh | bcd3c85 | 2018-09-28 14:14:12 +0100 | [diff] [blame] | 480 | DECLARE_LAYER_POLICY_2_PARAM(L2Normalization) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 481 | |
Aron Virginas-Tar | f982dea | 2019-10-11 14:07:53 +0100 | [diff] [blame] | 482 | DECLARE_LAYER_POLICY_2_PARAM(LogSoftmax) |
| 483 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 484 | DECLARE_LAYER_POLICY_2_PARAM(Lstm) |
| 485 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 486 | DECLARE_LAYER_POLICY_1_PARAM(Maximum) |
| 487 | |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 488 | DECLARE_LAYER_POLICY_2_PARAM(Mean) |
| 489 | |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 490 | DECLARE_LAYER_POLICY_1_PARAM(Merge) |
| 491 | |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 492 | DECLARE_LAYER_POLICY_1_PARAM(Minimum) |
| 493 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 494 | DECLARE_LAYER_POLICY_1_PARAM(Multiplication) |
| 495 | |
| 496 | DECLARE_LAYER_POLICY_2_PARAM(Normalization) |
| 497 | |
| 498 | DECLARE_LAYER_POLICY_CUSTOM_PARAM(Output, armnn::LayerBindingId) |
| 499 | |
Mohamed Nour Abouelseoud | 5662c20 | 2018-09-24 13:30:09 +0100 | [diff] [blame] | 500 | DECLARE_LAYER_POLICY_2_PARAM(Pad) |
| 501 | |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 502 | DECLARE_LAYER_POLICY_1_PARAM(Quantize) |
| 503 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 504 | DECLARE_LAYER_POLICY_2_PARAM(Permute) |
| 505 | |
| 506 | DECLARE_LAYER_POLICY_2_PARAM(Pooling2d) |
| 507 | |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 508 | DECLARE_LAYER_POLICY_2_PARAM(PreCompiled) |
| 509 | |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 510 | DECLARE_LAYER_POLICY_1_PARAM(Prelu) |
| 511 | |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 512 | DECLARE_LAYER_POLICY_1_PARAM(QuantizedLstm) |
| 513 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 514 | DECLARE_LAYER_POLICY_1_PARAM(Division) |
| 515 | |
Teresa Charlin | a9075df | 2019-06-27 15:41:57 +0100 | [diff] [blame] | 516 | DECLARE_LAYER_POLICY_2_PARAM(Resize) |
| 517 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 518 | DECLARE_LAYER_POLICY_2_PARAM(Reshape) |
| 519 | |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 520 | DECLARE_LAYER_POLICY_1_PARAM(Rsqrt) |
| 521 | |
Aron Virginas-Tar | 636ab40 | 2019-09-16 14:27:45 +0100 | [diff] [blame] | 522 | DECLARE_LAYER_POLICY_2_PARAM(Slice) |
| 523 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 524 | DECLARE_LAYER_POLICY_2_PARAM(Softmax) |
| 525 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 526 | DECLARE_LAYER_POLICY_2_PARAM(SpaceToBatchNd) |
| 527 | |
Aron Virginas-Tar | 972af15 | 2019-06-11 14:14:03 +0100 | [diff] [blame] | 528 | DECLARE_LAYER_POLICY_2_PARAM(SpaceToDepth) |
| 529 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 530 | DECLARE_LAYER_POLICY_2_PARAM(Splitter) |
| 531 | |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 532 | DECLARE_LAYER_POLICY_2_PARAM(Stack) |
| 533 | |
Derek Lamberti | 013c390 | 2019-10-21 10:46:16 +0100 | [diff] [blame] | 534 | DECLARE_LAYER_POLICY_EXCEPTION_2_PARAM(StandIn) |
| 535 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 536 | DECLARE_LAYER_POLICY_2_PARAM(StridedSlice) |
| 537 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 538 | DECLARE_LAYER_POLICY_1_PARAM(Subtraction) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 539 | |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 540 | DECLARE_LAYER_POLICY_1_PARAM(Switch) |
| 541 | |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 542 | DECLARE_LAYER_POLICY_2_PARAM(TransposeConvolution2d) |
| 543 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 544 | |
| 545 | // Generic implementation to get the number of input slots for a given layer type; |
| 546 | template<armnn::LayerType Type> |
| 547 | unsigned int GetNumInputs(const armnn::Layer& layer) |
| 548 | { |
| 549 | return layer.GetNumInputSlots(); |
| 550 | } |
| 551 | |
| 552 | // Generic implementation to get the number of output slots for a given layer type; |
| 553 | template<armnn::LayerType Type> |
| 554 | unsigned int GetNumOutputs(const armnn::Layer& layer) |
| 555 | { |
| 556 | return layer.GetNumOutputSlots(); |
| 557 | } |
| 558 | |
| 559 | template<> |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 560 | unsigned int GetNumInputs<armnn::LayerType::Concat>(const armnn::Layer& layer) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 561 | { |
| 562 | boost::ignore_unused(layer); |
| 563 | return 2; |
| 564 | } |
| 565 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 566 | // Tests that the IsLayerSupported() function returns the correct value. |
| 567 | // We determined the correct value by *trying* to create the relevant workload and seeing if it matches what we expect. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 568 | // Returns true if expectations are met, otherwise returns false. |
| 569 | template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type> |
| 570 | bool IsLayerSupportedTest(FactoryType *factory, Tag<Type>) |
| 571 | { |
| 572 | using LayerPolicy = LayerTypePolicy<Type, DataType>; |
| 573 | using LayerType = typename LayerPolicy::Type; |
| 574 | using LayerDesc = typename LayerPolicy::Desc; |
| 575 | DummyLayer<LayerType, LayerDesc> layer; |
| 576 | |
Derek Lamberti | b99ef39 | 2019-10-21 14:10:38 +0100 | [diff] [blame] | 577 | if (LayerPolicy::IsException) //Don't test exceptions to the rule. |
| 578 | { |
| 579 | return true; |
| 580 | } |
| 581 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 582 | unsigned int numIn = GetNumInputs<Type>(*layer.m_Layer); |
| 583 | unsigned int numOut = GetNumOutputs<Type>(*layer.m_Layer); |
| 584 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 585 | // Make another dummy layer just to make IsLayerSupported have valid inputs. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 586 | DummyLayer<armnn::ConstantLayer, void> previousLayer; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 587 | // Set output of the previous layer to a dummy tensor. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 588 | armnn::TensorInfo output = MakeDummyTensorInfo<DataType>(); |
| 589 | previousLayer.m_Layer->GetOutputSlot(0).SetTensorInfo(output); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 590 | // Connect all outputs of the previous layer to inputs of tested layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 591 | for (unsigned int i = 0; i < numIn; i++) |
| 592 | { |
| 593 | armnn::IOutputSlot& previousLayerOutputSlot = previousLayer.m_Layer->GetOutputSlot(0); |
| 594 | armnn::IInputSlot& layerInputSlot = layer.m_Layer->GetInputSlot(i); |
| 595 | previousLayerOutputSlot.Connect(layerInputSlot); |
| 596 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 597 | // Set outputs of tested layer to a dummy tensor. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 598 | for (unsigned int i = 0; i < numOut; i++) |
| 599 | { |
| 600 | layer.m_Layer->GetOutputSlot(0).SetTensorInfo(output); |
| 601 | } |
| 602 | |
| 603 | std::string layerName = LayerPolicy::NameStr; |
| 604 | std::string reasonIfUnsupported; |
| 605 | if (FactoryType::IsLayerSupported(*layer.m_Layer, DataType, reasonIfUnsupported)) |
| 606 | { |
| 607 | std::string errorMsg = " layer expected support but found none."; |
| 608 | try |
| 609 | { |
| 610 | bool retVal = LayerPolicy::MakeDummyWorkload(factory, numIn, numOut).get() != nullptr; |
Matteo Martincigh | fbebcbd | 2018-10-16 09:45:08 +0100 | [diff] [blame] | 611 | BOOST_CHECK_MESSAGE(retVal, layerName << errorMsg); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 612 | return retVal; |
| 613 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 614 | catch(const armnn::InvalidArgumentException& e) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 615 | { |
| 616 | boost::ignore_unused(e); |
| 617 | // This is ok since we throw InvalidArgumentException when creating the dummy workload. |
| 618 | return true; |
| 619 | } |
| 620 | catch(const std::exception& e) |
| 621 | { |
| 622 | errorMsg = e.what(); |
| 623 | BOOST_TEST_ERROR(layerName << ": " << errorMsg); |
| 624 | return false; |
| 625 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 626 | catch(...) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 627 | { |
| 628 | errorMsg = "Unexpected error while testing support for "; |
| 629 | BOOST_TEST_ERROR(errorMsg << layerName); |
| 630 | return false; |
| 631 | } |
| 632 | } |
| 633 | else |
| 634 | { |
| 635 | std::string errorMsg = "layer expected no support (giving reason: " + reasonIfUnsupported + ") but found some."; |
| 636 | try |
| 637 | { |
| 638 | bool retVal = LayerPolicy::MakeDummyWorkload(factory, numIn, numOut).get() == nullptr; |
| 639 | BOOST_CHECK_MESSAGE(retVal, layerName << errorMsg); |
| 640 | return retVal; |
| 641 | } |
| 642 | // These two exceptions are ok: For workloads that are partially supported, attempting to instantiate them |
| 643 | // using parameters that make IsLayerSupported() return false should throw an |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 644 | // InvalidArgumentException or UnimplementedException. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 645 | catch(const armnn::InvalidArgumentException& e) |
| 646 | { |
| 647 | boost::ignore_unused(e); |
| 648 | return true; |
| 649 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 650 | catch(const armnn::UnimplementedException& e) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 651 | { |
| 652 | boost::ignore_unused(e); |
| 653 | return true; |
| 654 | } |
| 655 | catch(const std::exception& e) |
| 656 | { |
| 657 | errorMsg = e.what(); |
| 658 | BOOST_TEST_ERROR(layerName << ": " << errorMsg); |
| 659 | return false; |
| 660 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 661 | catch(...) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 662 | { |
| 663 | errorMsg = "Unexpected error while testing support for "; |
| 664 | BOOST_TEST_ERROR(errorMsg << layerName); |
| 665 | return false; |
| 666 | } |
| 667 | } |
| 668 | } |
| 669 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 670 | // Helper function to compute the next type in the LayerType enum. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 671 | constexpr armnn::LayerType NextType(armnn::LayerType type) |
| 672 | { |
| 673 | return static_cast<armnn::LayerType>(static_cast<int>(type)+1); |
| 674 | } |
| 675 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 676 | // Termination function for determining the end of the LayerType enumeration. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 677 | template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type> |
| 678 | bool IsLayerSupportedTestsImpl(FactoryType *factory, Tag<armnn::LayerType::LastLayer>) |
| 679 | { |
| 680 | return IsLayerSupportedTest<FactoryType, DataType, Type>(factory, Tag<Type>()); |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 681 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 682 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 683 | // Recursive function to test and enter in the LayerType enum and then iterate on the next entry. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 684 | template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type> |
| 685 | bool IsLayerSupportedTestsImpl(FactoryType *factory, Tag<Type>) |
| 686 | { |
| 687 | bool v = IsLayerSupportedTest<FactoryType, DataType, Type>(factory, Tag<Type>()); |
| 688 | |
| 689 | return v && |
| 690 | IsLayerSupportedTestsImpl<FactoryType, DataType, NextType(Type)> |
| 691 | (factory, Tag<NextType(Type)>()); |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 692 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 693 | |
| 694 | // Helper function to pass through to the test framework. |
| 695 | template<typename FactoryType, armnn::DataType DataType> |
| 696 | bool IsLayerSupportedTests(FactoryType *factory) |
| 697 | { |
| 698 | return IsLayerSupportedTestsImpl<FactoryType, DataType>(factory, Tag<armnn::LayerType::FirstLayer>()); |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 699 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 700 | |
| 701 | template<armnn::LayerType Type> |
| 702 | bool TestLayerTypeMatches() |
| 703 | { |
| 704 | using LayerPolicy = LayerTypePolicy<Type, armnn::DataType::Float32>; |
| 705 | using LayerType = typename LayerPolicy::Type; |
| 706 | using LayerDesc = typename LayerPolicy::Desc; |
| 707 | DummyLayer<LayerType, LayerDesc> layer; |
| 708 | |
| 709 | std::stringstream ss; |
| 710 | ss << LayerPolicy::NameStr << " layer type mismatches expected layer type value."; |
| 711 | bool v = Type == layer.m_Layer->GetType(); |
| 712 | BOOST_CHECK_MESSAGE(v, ss.str()); |
| 713 | return v; |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 714 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 715 | |
| 716 | template<armnn::LayerType Type> |
| 717 | bool LayerTypeMatchesTestImpl(Tag<armnn::LayerType::LastLayer>) |
| 718 | { |
| 719 | return TestLayerTypeMatches<Type>(); |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 720 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 721 | |
| 722 | template<armnn::LayerType Type> |
| 723 | bool LayerTypeMatchesTestImpl(Tag<Type>) |
| 724 | { |
| 725 | return TestLayerTypeMatches<Type>() && |
| 726 | LayerTypeMatchesTestImpl<NextType(Type)>(Tag<NextType(Type)>()); |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 727 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 728 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 729 | template<typename FactoryType, typename LayerType, armnn::DataType InputDataType , armnn::DataType OutputDataType> |
| 730 | bool IsConvertLayerSupportedTests(std::string& reasonIfUnsupported) |
| 731 | { |
| 732 | armnn::Graph graph; |
| 733 | LayerType* const layer = graph.AddLayer<LayerType>("LayerName"); |
| 734 | |
| 735 | armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input"); |
| 736 | armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output"); |
| 737 | |
| 738 | armnn::TensorInfo inputTensorInfo({1, 3, 2, 3}, InputDataType); |
| 739 | armnn::TensorInfo outputTensorInfo({1, 3, 2, 3}, OutputDataType); |
| 740 | |
| 741 | input->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); |
| 742 | input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo); |
| 743 | layer->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 744 | layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo); |
| 745 | |
| 746 | bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported); |
| 747 | |
| 748 | return result; |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 749 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 750 | |
Matthew Bentham | 1f0ff35 | 2019-01-02 13:26:31 +0000 | [diff] [blame] | 751 | template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType> |
| 752 | bool IsMeanLayerSupportedTests(std::string& reasonIfUnsupported) |
| 753 | { |
| 754 | armnn::Graph graph; |
| 755 | static const std::vector<unsigned> axes = {1, 0}; |
| 756 | armnn::MeanDescriptor desc(axes, false); |
| 757 | |
| 758 | armnn::Layer* const layer = graph.AddLayer<armnn::MeanLayer>(desc, "LayerName"); |
| 759 | |
| 760 | armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input"); |
| 761 | armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output"); |
| 762 | |
| 763 | armnn::TensorInfo inputTensorInfo({4, 3, 2}, InputDataType); |
| 764 | armnn::TensorInfo outputTensorInfo({2}, OutputDataType); |
| 765 | |
| 766 | input->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); |
| 767 | input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo); |
| 768 | layer->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 769 | layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo); |
| 770 | |
| 771 | bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported); |
| 772 | |
| 773 | return result; |
| 774 | } |
| 775 | |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 776 | // Tests that IsMeanSupported fails when input tensor dimensions |
| 777 | // do not match output tensor dimensions when keepDims == true |
| 778 | template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType> |
| 779 | bool IsMeanLayerNotSupportedTests(std::string& reasonIfUnsupported) |
| 780 | { |
| 781 | armnn::Graph graph; |
| 782 | static const std::vector<unsigned> axes = {}; |
| 783 | // Set keepDims == true |
| 784 | armnn::MeanDescriptor desc(axes, true); |
| 785 | |
| 786 | armnn::Layer* const layer = graph.AddLayer<armnn::MeanLayer>(desc, "LayerName"); |
| 787 | |
| 788 | armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input"); |
| 789 | armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output"); |
| 790 | |
| 791 | // Mismatching number of tensor dimensions |
| 792 | armnn::TensorInfo inputTensorInfo({1, 1, 1, 1}, InputDataType); |
| 793 | armnn::TensorInfo outputTensorInfo({1, 1}, OutputDataType); |
| 794 | |
| 795 | input->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); |
| 796 | input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo); |
| 797 | layer->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 798 | layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo); |
| 799 | |
| 800 | bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported); |
| 801 | |
| 802 | return result; |
| 803 | } |
| 804 | |
Matthew Bentham | 1f0ff35 | 2019-01-02 13:26:31 +0000 | [diff] [blame] | 805 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 806 | } //namespace |