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; |
| 206 | m_Layer = dummyGraph.AddLayer<ConvolutionLayerType>(desc, ""); |
| 207 | m_Layer->m_Weight = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 208 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 209 | m_Layer->m_Bias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 210 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 211 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 212 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 213 | ~DummyConvolutionLayer() |
| 214 | { |
| 215 | dummyGraph.EraseLayer(m_Layer); |
| 216 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 217 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 218 | ConvolutionLayerType* m_Layer; |
| 219 | }; |
| 220 | |
| 221 | template<> |
| 222 | struct DummyLayer<armnn::Convolution2dLayer> |
| 223 | : public DummyConvolutionLayer<armnn::Convolution2dLayer> |
| 224 | { |
| 225 | }; |
| 226 | |
| 227 | template<> |
| 228 | struct DummyLayer<armnn::DepthwiseConvolution2dLayer> |
| 229 | : public DummyConvolutionLayer<armnn::DepthwiseConvolution2dLayer> |
| 230 | { |
| 231 | }; |
| 232 | |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 233 | template<> |
| 234 | struct DummyLayer<armnn::TransposeConvolution2dLayer> |
| 235 | : public DummyConvolutionLayer<armnn::TransposeConvolution2dLayer> |
| 236 | { |
| 237 | }; |
| 238 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 239 | template <typename LstmLayerType> |
| 240 | struct DummyLstmLayer |
| 241 | { |
| 242 | DummyLstmLayer() |
| 243 | { |
| 244 | typename LstmLayerType::DescriptorType desc; |
| 245 | desc.m_CifgEnabled = false; |
| 246 | |
| 247 | m_Layer = dummyGraph.AddLayer<LstmLayerType>(armnn::LstmDescriptor(), ""); |
| 248 | m_Layer->m_BasicParameters.m_InputToForgetWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 249 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 250 | m_Layer->m_BasicParameters.m_InputToCellWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 251 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 252 | m_Layer->m_BasicParameters.m_InputToOutputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 253 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 254 | m_Layer->m_BasicParameters.m_RecurrentToForgetWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 255 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 256 | m_Layer->m_BasicParameters.m_RecurrentToCellWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 257 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 258 | m_Layer->m_BasicParameters.m_RecurrentToOutputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 259 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 260 | m_Layer->m_BasicParameters.m_ForgetGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 261 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 262 | m_Layer->m_BasicParameters.m_CellBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 263 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 264 | m_Layer->m_BasicParameters.m_OutputGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 265 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 266 | |
| 267 | m_Layer->m_CifgParameters.m_InputToInputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 268 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 269 | m_Layer->m_CifgParameters.m_RecurrentToInputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 270 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 271 | m_Layer->m_CifgParameters.m_CellToInputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 272 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 273 | m_Layer->m_CifgParameters.m_InputGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 274 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 275 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 276 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 277 | ~DummyLstmLayer() |
| 278 | { |
| 279 | dummyGraph.EraseLayer(m_Layer); |
| 280 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 281 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 282 | armnn::LstmLayer* m_Layer; |
| 283 | }; |
| 284 | |
| 285 | template<> |
| 286 | struct DummyLayer<armnn::LstmLayer> |
| 287 | : public DummyLstmLayer<armnn::LstmLayer> |
| 288 | { |
| 289 | }; |
| 290 | |
| 291 | template<> |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 292 | struct DummyLayer<armnn::QuantizedLstmLayer, void> |
| 293 | { |
| 294 | DummyLayer() |
| 295 | { |
| 296 | m_Layer = dummyGraph.AddLayer<armnn::QuantizedLstmLayer>(""); |
| 297 | |
| 298 | m_Layer->m_QuantizedLstmParameters.m_InputToInputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 299 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QuantisedAsymm8)); |
| 300 | m_Layer->m_QuantizedLstmParameters.m_InputToForgetWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 301 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QuantisedAsymm8)); |
| 302 | m_Layer->m_QuantizedLstmParameters.m_InputToCellWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 303 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QuantisedAsymm8)); |
| 304 | m_Layer->m_QuantizedLstmParameters.m_InputToOutputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 305 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QuantisedAsymm8)); |
| 306 | |
| 307 | m_Layer->m_QuantizedLstmParameters.m_RecurrentToInputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 308 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QuantisedAsymm8)); |
| 309 | m_Layer->m_QuantizedLstmParameters.m_RecurrentToForgetWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 310 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QuantisedAsymm8)); |
| 311 | m_Layer->m_QuantizedLstmParameters.m_RecurrentToCellWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 312 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QuantisedAsymm8)); |
| 313 | m_Layer->m_QuantizedLstmParameters.m_RecurrentToOutputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 314 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QuantisedAsymm8)); |
| 315 | |
| 316 | m_Layer->m_QuantizedLstmParameters.m_InputGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 317 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32)); |
| 318 | m_Layer->m_QuantizedLstmParameters.m_ForgetGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 319 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32)); |
| 320 | m_Layer->m_QuantizedLstmParameters.m_CellBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 321 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32)); |
| 322 | m_Layer->m_QuantizedLstmParameters.m_OutputGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 323 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32)); |
| 324 | } |
| 325 | |
| 326 | ~DummyLayer() |
| 327 | { |
| 328 | dummyGraph.EraseLayer(m_Layer); |
| 329 | } |
| 330 | |
| 331 | armnn::QuantizedLstmLayer* m_Layer; |
| 332 | }; |
| 333 | |
| 334 | template<> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 335 | struct DummyLayer<armnn::FullyConnectedLayer> |
| 336 | { |
| 337 | DummyLayer() |
| 338 | { |
| 339 | armnn::FullyConnectedLayer::DescriptorType desc; |
| 340 | m_Layer = dummyGraph.AddLayer<armnn::FullyConnectedLayer>(desc, ""); |
| 341 | m_Layer->m_Weight = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 342 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 343 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 344 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 345 | ~DummyLayer() |
| 346 | { |
| 347 | dummyGraph.EraseLayer(m_Layer); |
| 348 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 349 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 350 | armnn::FullyConnectedLayer* m_Layer; |
| 351 | }; |
| 352 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 353 | // Tag for giving LayerType entries a unique strong type each. |
| 354 | template<armnn::LayerType> |
| 355 | struct Tag{}; |
| 356 | |
| 357 | #define DECLARE_LAYER_POLICY_CUSTOM_PARAM(name, descType) \ |
| 358 | template<armnn::DataType DataType> \ |
| 359 | struct LayerTypePolicy<armnn::LayerType::name, DataType> \ |
| 360 | { \ |
| 361 | using Type = armnn::name##Layer; \ |
| 362 | using Desc = descType; \ |
| 363 | using QueueDesc = armnn::name##QueueDescriptor; \ |
| 364 | constexpr static const char* NameStr = #name; \ |
| 365 | \ |
| 366 | static std::unique_ptr<armnn::IWorkload> MakeDummyWorkload(armnn::IWorkloadFactory *factory, \ |
| 367 | unsigned int nIn, unsigned int nOut) \ |
| 368 | { \ |
| 369 | QueueDesc desc; \ |
| 370 | armnn::WorkloadInfo info = MakeDummyWorkloadInfo<DataType>(nIn, nOut); \ |
| 371 | return factory->Create##name(desc, info); \ |
| 372 | } \ |
| 373 | }; |
| 374 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 375 | // Define a layer policy specialization for use with the IsLayerSupported tests. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 376 | // Use this version for layers whose constructor takes 1 parameter(name). |
| 377 | #define DECLARE_LAYER_POLICY_1_PARAM(name) DECLARE_LAYER_POLICY_CUSTOM_PARAM(name, void) |
| 378 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 379 | // Define a layer policy specialization for use with the IsLayerSupported tests. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 380 | // Use this version for layers whose constructor takes 2 parameters(descriptor and name). |
| 381 | #define DECLARE_LAYER_POLICY_2_PARAM(name) DECLARE_LAYER_POLICY_CUSTOM_PARAM(name, armnn::name##Descriptor) |
| 382 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 383 | // Layer policy template. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 384 | template<armnn::LayerType Type, armnn::DataType DataType> |
| 385 | struct LayerTypePolicy; |
| 386 | |
| 387 | // Every entry in the armnn::LayerType enum must be accounted for below. |
| 388 | DECLARE_LAYER_POLICY_2_PARAM(Activation) |
| 389 | |
| 390 | DECLARE_LAYER_POLICY_1_PARAM(Addition) |
| 391 | |
| 392 | DECLARE_LAYER_POLICY_2_PARAM(BatchNormalization) |
| 393 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 394 | DECLARE_LAYER_POLICY_2_PARAM(BatchToSpaceNd) |
| 395 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 396 | DECLARE_LAYER_POLICY_2_PARAM(Concat) |
| 397 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 398 | DECLARE_LAYER_POLICY_1_PARAM(Constant) |
| 399 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 400 | DECLARE_LAYER_POLICY_1_PARAM(ConvertFp16ToFp32) |
| 401 | |
| 402 | DECLARE_LAYER_POLICY_1_PARAM(ConvertFp32ToFp16) |
| 403 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 404 | DECLARE_LAYER_POLICY_2_PARAM(Convolution2d) |
| 405 | |
| 406 | DECLARE_LAYER_POLICY_1_PARAM(MemCopy) |
| 407 | |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 408 | DECLARE_LAYER_POLICY_1_PARAM(MemImport) |
| 409 | |
Nattapat Chaimanowong | 964e955 | 2019-03-26 11:03:26 +0000 | [diff] [blame] | 410 | DECLARE_LAYER_POLICY_1_PARAM(Debug) |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 411 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 412 | DECLARE_LAYER_POLICY_2_PARAM(DepthwiseConvolution2d) |
| 413 | |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 414 | DECLARE_LAYER_POLICY_1_PARAM(Dequantize) |
| 415 | |
Narumol Prangnawarat | 94dd5d8 | 2019-01-23 18:06:26 +0000 | [diff] [blame] | 416 | DECLARE_LAYER_POLICY_2_PARAM(DetectionPostProcess) |
| 417 | |
FrancisMurtagh | 2099595 | 2018-12-17 12:11:36 +0000 | [diff] [blame] | 418 | DECLARE_LAYER_POLICY_1_PARAM(Equal) |
| 419 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 420 | DECLARE_LAYER_POLICY_2_PARAM(FakeQuantization) |
| 421 | |
| 422 | DECLARE_LAYER_POLICY_1_PARAM(Floor) |
| 423 | |
| 424 | DECLARE_LAYER_POLICY_2_PARAM(FullyConnected) |
| 425 | |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 426 | DECLARE_LAYER_POLICY_1_PARAM(Gather) |
| 427 | |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 428 | DECLARE_LAYER_POLICY_1_PARAM(Greater) |
| 429 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 430 | DECLARE_LAYER_POLICY_CUSTOM_PARAM(Input, armnn::LayerBindingId) |
| 431 | |
Matteo Martincigh | bcd3c85 | 2018-09-28 14:14:12 +0100 | [diff] [blame] | 432 | DECLARE_LAYER_POLICY_2_PARAM(L2Normalization) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 433 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 434 | DECLARE_LAYER_POLICY_2_PARAM(Lstm) |
| 435 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 436 | DECLARE_LAYER_POLICY_1_PARAM(Maximum) |
| 437 | |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 438 | DECLARE_LAYER_POLICY_2_PARAM(Mean) |
| 439 | |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 440 | DECLARE_LAYER_POLICY_1_PARAM(Merge) |
| 441 | |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 442 | DECLARE_LAYER_POLICY_1_PARAM(Minimum) |
| 443 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 444 | DECLARE_LAYER_POLICY_1_PARAM(Multiplication) |
| 445 | |
| 446 | DECLARE_LAYER_POLICY_2_PARAM(Normalization) |
| 447 | |
| 448 | DECLARE_LAYER_POLICY_CUSTOM_PARAM(Output, armnn::LayerBindingId) |
| 449 | |
Mohamed Nour Abouelseoud | 5662c20 | 2018-09-24 13:30:09 +0100 | [diff] [blame] | 450 | DECLARE_LAYER_POLICY_2_PARAM(Pad) |
| 451 | |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 452 | DECLARE_LAYER_POLICY_1_PARAM(Quantize) |
| 453 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 454 | DECLARE_LAYER_POLICY_2_PARAM(Permute) |
| 455 | |
| 456 | DECLARE_LAYER_POLICY_2_PARAM(Pooling2d) |
| 457 | |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 458 | DECLARE_LAYER_POLICY_2_PARAM(PreCompiled) |
| 459 | |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 460 | DECLARE_LAYER_POLICY_1_PARAM(Prelu) |
| 461 | |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 462 | DECLARE_LAYER_POLICY_1_PARAM(QuantizedLstm) |
| 463 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 464 | DECLARE_LAYER_POLICY_1_PARAM(Division) |
| 465 | |
Teresa Charlin | a9075df | 2019-06-27 15:41:57 +0100 | [diff] [blame] | 466 | DECLARE_LAYER_POLICY_2_PARAM(Resize) |
| 467 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 468 | DECLARE_LAYER_POLICY_2_PARAM(Reshape) |
| 469 | |
Mohamed Nour Abouelseoud | a1d3c6a | 2018-12-27 12:39:16 +0000 | [diff] [blame] | 470 | DECLARE_LAYER_POLICY_1_PARAM(Rsqrt) |
| 471 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 472 | DECLARE_LAYER_POLICY_2_PARAM(Softmax) |
| 473 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 474 | DECLARE_LAYER_POLICY_2_PARAM(SpaceToBatchNd) |
| 475 | |
Aron Virginas-Tar | 972af15 | 2019-06-11 14:14:03 +0100 | [diff] [blame] | 476 | DECLARE_LAYER_POLICY_2_PARAM(SpaceToDepth) |
| 477 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 478 | DECLARE_LAYER_POLICY_2_PARAM(Splitter) |
| 479 | |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 480 | DECLARE_LAYER_POLICY_2_PARAM(Stack) |
| 481 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 482 | DECLARE_LAYER_POLICY_2_PARAM(StridedSlice) |
| 483 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 484 | DECLARE_LAYER_POLICY_1_PARAM(Subtraction) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 485 | |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 486 | DECLARE_LAYER_POLICY_1_PARAM(Switch) |
| 487 | |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 488 | DECLARE_LAYER_POLICY_2_PARAM(TransposeConvolution2d) |
| 489 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 490 | |
| 491 | // Generic implementation to get the number of input slots for a given layer type; |
| 492 | template<armnn::LayerType Type> |
| 493 | unsigned int GetNumInputs(const armnn::Layer& layer) |
| 494 | { |
| 495 | return layer.GetNumInputSlots(); |
| 496 | } |
| 497 | |
| 498 | // Generic implementation to get the number of output slots for a given layer type; |
| 499 | template<armnn::LayerType Type> |
| 500 | unsigned int GetNumOutputs(const armnn::Layer& layer) |
| 501 | { |
| 502 | return layer.GetNumOutputSlots(); |
| 503 | } |
| 504 | |
| 505 | template<> |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 506 | unsigned int GetNumInputs<armnn::LayerType::Concat>(const armnn::Layer& layer) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 507 | { |
| 508 | boost::ignore_unused(layer); |
| 509 | return 2; |
| 510 | } |
| 511 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 512 | // Tests that the IsLayerSupported() function returns the correct value. |
| 513 | // 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] | 514 | // Returns true if expectations are met, otherwise returns false. |
| 515 | template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type> |
| 516 | bool IsLayerSupportedTest(FactoryType *factory, Tag<Type>) |
| 517 | { |
| 518 | using LayerPolicy = LayerTypePolicy<Type, DataType>; |
| 519 | using LayerType = typename LayerPolicy::Type; |
| 520 | using LayerDesc = typename LayerPolicy::Desc; |
| 521 | DummyLayer<LayerType, LayerDesc> layer; |
| 522 | |
| 523 | unsigned int numIn = GetNumInputs<Type>(*layer.m_Layer); |
| 524 | unsigned int numOut = GetNumOutputs<Type>(*layer.m_Layer); |
| 525 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 526 | // Make another dummy layer just to make IsLayerSupported have valid inputs. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 527 | DummyLayer<armnn::ConstantLayer, void> previousLayer; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 528 | // Set output of the previous layer to a dummy tensor. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 529 | armnn::TensorInfo output = MakeDummyTensorInfo<DataType>(); |
| 530 | previousLayer.m_Layer->GetOutputSlot(0).SetTensorInfo(output); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 531 | // Connect all outputs of the previous layer to inputs of tested layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 532 | for (unsigned int i = 0; i < numIn; i++) |
| 533 | { |
| 534 | armnn::IOutputSlot& previousLayerOutputSlot = previousLayer.m_Layer->GetOutputSlot(0); |
| 535 | armnn::IInputSlot& layerInputSlot = layer.m_Layer->GetInputSlot(i); |
| 536 | previousLayerOutputSlot.Connect(layerInputSlot); |
| 537 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 538 | // Set outputs of tested layer to a dummy tensor. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 539 | for (unsigned int i = 0; i < numOut; i++) |
| 540 | { |
| 541 | layer.m_Layer->GetOutputSlot(0).SetTensorInfo(output); |
| 542 | } |
| 543 | |
| 544 | std::string layerName = LayerPolicy::NameStr; |
| 545 | std::string reasonIfUnsupported; |
| 546 | if (FactoryType::IsLayerSupported(*layer.m_Layer, DataType, reasonIfUnsupported)) |
| 547 | { |
| 548 | std::string errorMsg = " layer expected support but found none."; |
| 549 | try |
| 550 | { |
| 551 | bool retVal = LayerPolicy::MakeDummyWorkload(factory, numIn, numOut).get() != nullptr; |
Matteo Martincigh | fbebcbd | 2018-10-16 09:45:08 +0100 | [diff] [blame] | 552 | BOOST_CHECK_MESSAGE(retVal, layerName << errorMsg); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 553 | return retVal; |
| 554 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 555 | catch(const armnn::InvalidArgumentException& e) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 556 | { |
| 557 | boost::ignore_unused(e); |
| 558 | // This is ok since we throw InvalidArgumentException when creating the dummy workload. |
| 559 | return true; |
| 560 | } |
| 561 | catch(const std::exception& e) |
| 562 | { |
| 563 | errorMsg = e.what(); |
| 564 | BOOST_TEST_ERROR(layerName << ": " << errorMsg); |
| 565 | return false; |
| 566 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 567 | catch(...) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 568 | { |
| 569 | errorMsg = "Unexpected error while testing support for "; |
| 570 | BOOST_TEST_ERROR(errorMsg << layerName); |
| 571 | return false; |
| 572 | } |
| 573 | } |
| 574 | else |
| 575 | { |
| 576 | std::string errorMsg = "layer expected no support (giving reason: " + reasonIfUnsupported + ") but found some."; |
| 577 | try |
| 578 | { |
| 579 | bool retVal = LayerPolicy::MakeDummyWorkload(factory, numIn, numOut).get() == nullptr; |
| 580 | BOOST_CHECK_MESSAGE(retVal, layerName << errorMsg); |
| 581 | return retVal; |
| 582 | } |
| 583 | // These two exceptions are ok: For workloads that are partially supported, attempting to instantiate them |
| 584 | // using parameters that make IsLayerSupported() return false should throw an |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 585 | // InvalidArgumentException or UnimplementedException. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 586 | catch(const armnn::InvalidArgumentException& e) |
| 587 | { |
| 588 | boost::ignore_unused(e); |
| 589 | return true; |
| 590 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 591 | catch(const armnn::UnimplementedException& e) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 592 | { |
| 593 | boost::ignore_unused(e); |
| 594 | return true; |
| 595 | } |
| 596 | catch(const std::exception& e) |
| 597 | { |
| 598 | errorMsg = e.what(); |
| 599 | BOOST_TEST_ERROR(layerName << ": " << errorMsg); |
| 600 | return false; |
| 601 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 602 | catch(...) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 603 | { |
| 604 | errorMsg = "Unexpected error while testing support for "; |
| 605 | BOOST_TEST_ERROR(errorMsg << layerName); |
| 606 | return false; |
| 607 | } |
| 608 | } |
| 609 | } |
| 610 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 611 | // Helper function to compute the next type in the LayerType enum. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 612 | constexpr armnn::LayerType NextType(armnn::LayerType type) |
| 613 | { |
| 614 | return static_cast<armnn::LayerType>(static_cast<int>(type)+1); |
| 615 | } |
| 616 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 617 | // Termination function for determining the end of the LayerType enumeration. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 618 | template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type> |
| 619 | bool IsLayerSupportedTestsImpl(FactoryType *factory, Tag<armnn::LayerType::LastLayer>) |
| 620 | { |
| 621 | return IsLayerSupportedTest<FactoryType, DataType, Type>(factory, Tag<Type>()); |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 622 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 623 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 624 | // 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] | 625 | template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type> |
| 626 | bool IsLayerSupportedTestsImpl(FactoryType *factory, Tag<Type>) |
| 627 | { |
| 628 | bool v = IsLayerSupportedTest<FactoryType, DataType, Type>(factory, Tag<Type>()); |
| 629 | |
| 630 | return v && |
| 631 | IsLayerSupportedTestsImpl<FactoryType, DataType, NextType(Type)> |
| 632 | (factory, Tag<NextType(Type)>()); |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 633 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 634 | |
| 635 | // Helper function to pass through to the test framework. |
| 636 | template<typename FactoryType, armnn::DataType DataType> |
| 637 | bool IsLayerSupportedTests(FactoryType *factory) |
| 638 | { |
| 639 | return IsLayerSupportedTestsImpl<FactoryType, DataType>(factory, Tag<armnn::LayerType::FirstLayer>()); |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 640 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 641 | |
| 642 | template<armnn::LayerType Type> |
| 643 | bool TestLayerTypeMatches() |
| 644 | { |
| 645 | using LayerPolicy = LayerTypePolicy<Type, armnn::DataType::Float32>; |
| 646 | using LayerType = typename LayerPolicy::Type; |
| 647 | using LayerDesc = typename LayerPolicy::Desc; |
| 648 | DummyLayer<LayerType, LayerDesc> layer; |
| 649 | |
| 650 | std::stringstream ss; |
| 651 | ss << LayerPolicy::NameStr << " layer type mismatches expected layer type value."; |
| 652 | bool v = Type == layer.m_Layer->GetType(); |
| 653 | BOOST_CHECK_MESSAGE(v, ss.str()); |
| 654 | return v; |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 655 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 656 | |
| 657 | template<armnn::LayerType Type> |
| 658 | bool LayerTypeMatchesTestImpl(Tag<armnn::LayerType::LastLayer>) |
| 659 | { |
| 660 | return TestLayerTypeMatches<Type>(); |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 661 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 662 | |
| 663 | template<armnn::LayerType Type> |
| 664 | bool LayerTypeMatchesTestImpl(Tag<Type>) |
| 665 | { |
| 666 | return TestLayerTypeMatches<Type>() && |
| 667 | LayerTypeMatchesTestImpl<NextType(Type)>(Tag<NextType(Type)>()); |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 668 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 669 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 670 | template<typename FactoryType, typename LayerType, armnn::DataType InputDataType , armnn::DataType OutputDataType> |
| 671 | bool IsConvertLayerSupportedTests(std::string& reasonIfUnsupported) |
| 672 | { |
| 673 | armnn::Graph graph; |
| 674 | LayerType* const layer = graph.AddLayer<LayerType>("LayerName"); |
| 675 | |
| 676 | armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input"); |
| 677 | armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output"); |
| 678 | |
| 679 | armnn::TensorInfo inputTensorInfo({1, 3, 2, 3}, InputDataType); |
| 680 | armnn::TensorInfo outputTensorInfo({1, 3, 2, 3}, OutputDataType); |
| 681 | |
| 682 | input->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); |
| 683 | input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo); |
| 684 | layer->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 685 | layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo); |
| 686 | |
| 687 | bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported); |
| 688 | |
| 689 | return result; |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 690 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 691 | |
Matthew Bentham | 1f0ff35 | 2019-01-02 13:26:31 +0000 | [diff] [blame] | 692 | template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType> |
| 693 | bool IsMeanLayerSupportedTests(std::string& reasonIfUnsupported) |
| 694 | { |
| 695 | armnn::Graph graph; |
| 696 | static const std::vector<unsigned> axes = {1, 0}; |
| 697 | armnn::MeanDescriptor desc(axes, false); |
| 698 | |
| 699 | armnn::Layer* const layer = graph.AddLayer<armnn::MeanLayer>(desc, "LayerName"); |
| 700 | |
| 701 | armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input"); |
| 702 | armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output"); |
| 703 | |
| 704 | armnn::TensorInfo inputTensorInfo({4, 3, 2}, InputDataType); |
| 705 | armnn::TensorInfo outputTensorInfo({2}, OutputDataType); |
| 706 | |
| 707 | input->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); |
| 708 | input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo); |
| 709 | layer->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 710 | layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo); |
| 711 | |
| 712 | bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported); |
| 713 | |
| 714 | return result; |
| 715 | } |
| 716 | |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 717 | // Tests that IsMeanSupported fails when input tensor dimensions |
| 718 | // do not match output tensor dimensions when keepDims == true |
| 719 | template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType> |
| 720 | bool IsMeanLayerNotSupportedTests(std::string& reasonIfUnsupported) |
| 721 | { |
| 722 | armnn::Graph graph; |
| 723 | static const std::vector<unsigned> axes = {}; |
| 724 | // Set keepDims == true |
| 725 | armnn::MeanDescriptor desc(axes, true); |
| 726 | |
| 727 | armnn::Layer* const layer = graph.AddLayer<armnn::MeanLayer>(desc, "LayerName"); |
| 728 | |
| 729 | armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input"); |
| 730 | armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output"); |
| 731 | |
| 732 | // Mismatching number of tensor dimensions |
| 733 | armnn::TensorInfo inputTensorInfo({1, 1, 1, 1}, InputDataType); |
| 734 | armnn::TensorInfo outputTensorInfo({1, 1}, OutputDataType); |
| 735 | |
| 736 | input->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); |
| 737 | input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo); |
| 738 | layer->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 739 | layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo); |
| 740 | |
| 741 | bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported); |
| 742 | |
| 743 | return result; |
| 744 | } |
| 745 | |
Matthew Bentham | 1f0ff35 | 2019-01-02 13:26:31 +0000 | [diff] [blame] | 746 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 747 | } //namespace |