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