telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd and Contributors. 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 | |
Jim Flynn | 68db06f | 2020-10-06 10:14:50 +0100 | [diff] [blame] | 9 | #include <backendsCommon/MapWorkload.hpp> |
Jim Flynn | 3a40ea5 | 2020-10-08 11:42:30 +0100 | [diff] [blame] | 10 | #include <backendsCommon/UnmapWorkload.hpp> |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 11 | #include <backendsCommon/WorkloadFactory.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 12 | |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 13 | #include <armnn/utility/IgnoreUnused.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 14 | |
| 15 | namespace |
| 16 | { |
| 17 | armnn::Graph dummyGraph; |
| 18 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 19 | // Make a dummy TensorInfo object. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 20 | template<armnn::DataType DataType> |
| 21 | armnn::TensorInfo MakeDummyTensorInfo() |
| 22 | { |
Teresa Charlin | 33d5827 | 2020-01-28 12:24:34 +0000 | [diff] [blame] | 23 | return armnn::TensorInfo({2,2,2,2}, DataType, 1.0, 0); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | |
| 27 | // Make a dummy WorkloadInfo using a dummy TensorInfo. |
| 28 | template<armnn::DataType DataType> |
| 29 | armnn::WorkloadInfo MakeDummyWorkloadInfo(unsigned int numInputs, unsigned int numOutputs) |
| 30 | { |
| 31 | armnn::WorkloadInfo info; |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 32 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 33 | for (unsigned int i=0; i < numInputs; i++) |
| 34 | { |
| 35 | info.m_InputTensorInfos.push_back(MakeDummyTensorInfo<DataType>()); |
| 36 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 37 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 38 | for (unsigned int o=0; o < numOutputs; o++) |
| 39 | { |
| 40 | info.m_OutputTensorInfos.push_back(MakeDummyTensorInfo<DataType>()); |
| 41 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 42 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 43 | return info; |
| 44 | } |
| 45 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 46 | // Template class to create a dummy layer (2 parameters). |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 47 | template<typename LayerType, typename DescType = typename LayerType::DescriptorType> |
| 48 | struct DummyLayer |
| 49 | { |
| 50 | DummyLayer() |
| 51 | { |
| 52 | m_Layer = dummyGraph.AddLayer<LayerType>(DescType(), ""); |
| 53 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 54 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 55 | ~DummyLayer() |
| 56 | { |
| 57 | dummyGraph.EraseLayer(m_Layer); |
| 58 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 59 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 60 | LayerType* m_Layer; |
| 61 | }; |
| 62 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 63 | // Template class to create a dummy layer (1 parameter). |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 64 | template<typename LayerType> |
| 65 | struct DummyLayer<LayerType, void> |
| 66 | { |
| 67 | DummyLayer() |
| 68 | { |
| 69 | m_Layer = dummyGraph.AddLayer<LayerType>(""); |
| 70 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 71 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 72 | ~DummyLayer() |
| 73 | { |
| 74 | dummyGraph.EraseLayer(m_Layer); |
| 75 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 76 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 77 | LayerType* m_Layer; |
| 78 | }; |
| 79 | |
| 80 | template<> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 81 | struct DummyLayer<armnn::BatchNormalizationLayer> |
| 82 | { |
| 83 | DummyLayer() |
| 84 | { |
| 85 | m_Layer = dummyGraph.AddLayer<armnn::BatchNormalizationLayer>(armnn::BatchNormalizationDescriptor(), ""); |
| 86 | m_Layer->m_Mean = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 87 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 88 | m_Layer->m_Variance = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 89 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 90 | m_Layer->m_Beta = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 91 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 92 | m_Layer->m_Gamma = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 93 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 94 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 95 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 96 | ~DummyLayer() |
| 97 | { |
| 98 | dummyGraph.EraseLayer(m_Layer); |
| 99 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 100 | |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 101 | armnn::BatchNormalizationLayer* m_Layer; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | template<> |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 105 | struct DummyLayer<armnn::BatchToSpaceNdLayer> |
| 106 | { |
| 107 | DummyLayer() |
| 108 | { |
| 109 | m_Layer = dummyGraph.AddLayer<armnn::BatchToSpaceNdLayer>(armnn::BatchToSpaceNdDescriptor(), ""); |
| 110 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 111 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 112 | ~DummyLayer() |
| 113 | { |
| 114 | dummyGraph.EraseLayer(m_Layer); |
| 115 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 116 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 117 | armnn::BatchToSpaceNdLayer* m_Layer; |
| 118 | }; |
| 119 | |
| 120 | template<> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 121 | struct DummyLayer<armnn::ConstantLayer, void> |
| 122 | { |
| 123 | DummyLayer() |
| 124 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 125 | m_Layer = dummyGraph.AddLayer<armnn::ConstantLayer>(""); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 126 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 127 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 128 | ~DummyLayer() |
| 129 | { |
| 130 | dummyGraph.EraseLayer(m_Layer); |
| 131 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 132 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 133 | armnn::ConstantLayer* m_Layer; |
| 134 | }; |
| 135 | |
| 136 | template<> |
| 137 | struct DummyLayer<armnn::InputLayer, armnn::LayerBindingId> |
| 138 | { |
| 139 | DummyLayer() |
| 140 | { |
| 141 | m_Layer = dummyGraph.AddLayer<armnn::InputLayer>(armnn::LayerBindingId(), ""); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 142 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 143 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 144 | ~DummyLayer() |
| 145 | { |
| 146 | dummyGraph.EraseLayer(m_Layer); |
| 147 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 148 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 149 | armnn::InputLayer* m_Layer; |
| 150 | }; |
| 151 | |
| 152 | template<> |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 153 | struct DummyLayer<armnn::ConcatLayer> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 154 | { |
| 155 | DummyLayer() |
| 156 | { |
| 157 | armnn::OriginsDescriptor desc(2); |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 158 | m_Layer = dummyGraph.AddLayer<armnn::ConcatLayer>(desc, ""); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 159 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 160 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 161 | ~DummyLayer() |
| 162 | { |
| 163 | dummyGraph.EraseLayer(m_Layer); |
| 164 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 165 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 166 | armnn::ConcatLayer* m_Layer; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | template<> |
Jim Flynn | 68db06f | 2020-10-06 10:14:50 +0100 | [diff] [blame] | 170 | struct DummyLayer<armnn::MapLayer, void> |
| 171 | { |
| 172 | DummyLayer() |
| 173 | { |
| 174 | m_Layer = dummyGraph.AddLayer<armnn::MapLayer>(""); |
| 175 | } |
| 176 | |
| 177 | ~DummyLayer() |
| 178 | { |
| 179 | dummyGraph.EraseLayer(m_Layer); |
| 180 | } |
| 181 | |
| 182 | armnn::MapLayer* m_Layer; |
| 183 | }; |
| 184 | |
| 185 | template<> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 186 | struct DummyLayer<armnn::OutputLayer, armnn::LayerBindingId> |
| 187 | { |
| 188 | DummyLayer() |
| 189 | { |
| 190 | m_Layer = dummyGraph.AddLayer<armnn::OutputLayer>(armnn::LayerBindingId(), ""); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 191 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 192 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 193 | ~DummyLayer() |
| 194 | { |
| 195 | dummyGraph.EraseLayer(m_Layer); |
| 196 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 197 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 198 | armnn::OutputLayer* m_Layer; |
| 199 | }; |
| 200 | |
| 201 | template<> |
| 202 | struct DummyLayer<armnn::SplitterLayer> |
| 203 | { |
| 204 | DummyLayer() |
| 205 | { |
| 206 | armnn::ViewsDescriptor desc(1); |
| 207 | m_Layer = dummyGraph.AddLayer<armnn::SplitterLayer>(desc, ""); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 208 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 209 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 210 | ~DummyLayer() |
| 211 | { |
| 212 | dummyGraph.EraseLayer(m_Layer); |
| 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 | armnn::SplitterLayer* m_Layer; |
| 216 | }; |
| 217 | |
Jim Flynn | 3a40ea5 | 2020-10-08 11:42:30 +0100 | [diff] [blame] | 218 | template<> |
| 219 | struct DummyLayer<armnn::UnmapLayer, void> |
| 220 | { |
| 221 | DummyLayer() |
| 222 | { |
| 223 | m_Layer = dummyGraph.AddLayer<armnn::UnmapLayer>(""); |
| 224 | } |
| 225 | |
| 226 | ~DummyLayer() |
| 227 | { |
| 228 | dummyGraph.EraseLayer(m_Layer); |
| 229 | } |
| 230 | |
| 231 | armnn::UnmapLayer* m_Layer; |
| 232 | }; |
| 233 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 234 | template <typename ConvolutionLayerType> |
| 235 | struct DummyConvolutionLayer |
| 236 | { |
| 237 | DummyConvolutionLayer() |
| 238 | { |
| 239 | typename ConvolutionLayerType::DescriptorType desc; |
James Conroy | 663c184 | 2019-11-01 15:21:48 +0000 | [diff] [blame] | 240 | desc.m_StrideX = 1; |
| 241 | desc.m_StrideY = 1; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 242 | m_Layer = dummyGraph.AddLayer<ConvolutionLayerType>(desc, ""); |
| 243 | m_Layer->m_Weight = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 244 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 245 | m_Layer->m_Bias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 246 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 247 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 248 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 249 | ~DummyConvolutionLayer() |
| 250 | { |
| 251 | dummyGraph.EraseLayer(m_Layer); |
| 252 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 253 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 254 | ConvolutionLayerType* m_Layer; |
| 255 | }; |
| 256 | |
| 257 | template<> |
| 258 | struct DummyLayer<armnn::Convolution2dLayer> |
| 259 | : public DummyConvolutionLayer<armnn::Convolution2dLayer> |
| 260 | { |
| 261 | }; |
| 262 | |
| 263 | template<> |
| 264 | struct DummyLayer<armnn::DepthwiseConvolution2dLayer> |
| 265 | : public DummyConvolutionLayer<armnn::DepthwiseConvolution2dLayer> |
| 266 | { |
| 267 | }; |
| 268 | |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 269 | template<> |
| 270 | struct DummyLayer<armnn::TransposeConvolution2dLayer> |
| 271 | : public DummyConvolutionLayer<armnn::TransposeConvolution2dLayer> |
| 272 | { |
| 273 | }; |
| 274 | |
Derek Lamberti | 6a5e5e8 | 2019-12-05 14:41:20 +0000 | [diff] [blame] | 275 | template<> |
| 276 | struct DummyLayer<armnn::DetectionPostProcessLayer> |
| 277 | { |
| 278 | DummyLayer() |
| 279 | { |
| 280 | m_Layer = dummyGraph.AddLayer<armnn::DetectionPostProcessLayer>(armnn::DetectionPostProcessDescriptor(), ""); |
| 281 | m_Layer->m_Anchors = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 282 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 283 | } |
| 284 | |
| 285 | ~DummyLayer() |
| 286 | { |
| 287 | dummyGraph.EraseLayer(m_Layer); |
| 288 | } |
| 289 | |
| 290 | armnn::DetectionPostProcessLayer* m_Layer; |
| 291 | }; |
| 292 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 293 | template <typename LstmLayerType> |
| 294 | struct DummyLstmLayer |
| 295 | { |
| 296 | DummyLstmLayer() |
| 297 | { |
| 298 | typename LstmLayerType::DescriptorType desc; |
| 299 | desc.m_CifgEnabled = false; |
| 300 | |
| 301 | m_Layer = dummyGraph.AddLayer<LstmLayerType>(armnn::LstmDescriptor(), ""); |
| 302 | m_Layer->m_BasicParameters.m_InputToForgetWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 303 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 304 | m_Layer->m_BasicParameters.m_InputToCellWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 305 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 306 | m_Layer->m_BasicParameters.m_InputToOutputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 307 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 308 | m_Layer->m_BasicParameters.m_RecurrentToForgetWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 309 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 310 | m_Layer->m_BasicParameters.m_RecurrentToCellWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 311 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 312 | m_Layer->m_BasicParameters.m_RecurrentToOutputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 313 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 314 | m_Layer->m_BasicParameters.m_ForgetGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 315 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 316 | m_Layer->m_BasicParameters.m_CellBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 317 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 318 | m_Layer->m_BasicParameters.m_OutputGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 319 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 320 | |
| 321 | m_Layer->m_CifgParameters.m_InputToInputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 322 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 323 | m_Layer->m_CifgParameters.m_RecurrentToInputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 324 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 325 | m_Layer->m_CifgParameters.m_InputGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 326 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 327 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 328 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 329 | ~DummyLstmLayer() |
| 330 | { |
| 331 | dummyGraph.EraseLayer(m_Layer); |
| 332 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 333 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 334 | armnn::LstmLayer* m_Layer; |
| 335 | }; |
| 336 | |
| 337 | template<> |
| 338 | struct DummyLayer<armnn::LstmLayer> |
| 339 | : public DummyLstmLayer<armnn::LstmLayer> |
| 340 | { |
| 341 | }; |
| 342 | |
James Conroy | 586a9aa | 2020-03-20 08:49:33 +0000 | [diff] [blame] | 343 | template <typename QLstmLayerType> |
| 344 | struct DummyQLstmLayer |
| 345 | { |
| 346 | DummyQLstmLayer() |
| 347 | { |
| 348 | typename QLstmLayerType::DescriptorType desc; |
| 349 | desc.m_CifgEnabled = false; |
| 350 | desc.m_PeepholeEnabled = true; |
| 351 | desc.m_ProjectionEnabled = true; |
| 352 | desc.m_LayerNormEnabled = true; |
| 353 | |
| 354 | m_Layer = dummyGraph.AddLayer<QLstmLayerType>(armnn::QLstmDescriptor(), "qLstm"); |
| 355 | |
| 356 | // Basic params |
| 357 | m_Layer->m_BasicParameters.m_InputToForgetWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 358 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8)); |
| 359 | m_Layer->m_BasicParameters.m_InputToCellWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 360 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8)); |
| 361 | m_Layer->m_BasicParameters.m_InputToOutputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 362 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8)); |
| 363 | |
| 364 | m_Layer->m_BasicParameters.m_RecurrentToForgetWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 365 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8)); |
| 366 | m_Layer->m_BasicParameters.m_RecurrentToCellWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 367 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8)); |
| 368 | m_Layer->m_BasicParameters.m_RecurrentToOutputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 369 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8)); |
| 370 | |
| 371 | m_Layer->m_BasicParameters.m_ForgetGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 372 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32)); |
| 373 | m_Layer->m_BasicParameters.m_CellBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 374 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32)); |
| 375 | m_Layer->m_BasicParameters.m_OutputGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 376 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32)); |
| 377 | |
| 378 | // CIFG optional params |
| 379 | m_Layer->m_CifgParameters.m_InputToInputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 380 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8)); |
| 381 | m_Layer->m_CifgParameters.m_RecurrentToInputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 382 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8)); |
| 383 | m_Layer->m_CifgParameters.m_InputGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 384 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32)); |
| 385 | |
| 386 | // Projection optional params |
| 387 | m_Layer->m_ProjectionParameters.m_ProjectionWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 388 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS8)); |
| 389 | m_Layer->m_ProjectionParameters.m_ProjectionBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 390 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32)); |
| 391 | |
| 392 | // Peephole optional params |
| 393 | m_Layer->m_PeepholeParameters.m_CellToInputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 394 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16)); |
| 395 | m_Layer->m_PeepholeParameters.m_CellToForgetWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 396 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16)); |
| 397 | m_Layer->m_PeepholeParameters.m_CellToOutputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 398 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16)); |
| 399 | |
| 400 | // Layer normalization optional params |
| 401 | m_Layer->m_LayerNormParameters.m_InputLayerNormWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 402 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16)); |
| 403 | m_Layer->m_LayerNormParameters.m_ForgetLayerNormWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 404 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16)); |
| 405 | m_Layer->m_LayerNormParameters.m_CellLayerNormWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 406 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16)); |
| 407 | m_Layer->m_LayerNormParameters.m_OutputLayerNormWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 408 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QSymmS16)); |
| 409 | } |
| 410 | |
| 411 | ~DummyQLstmLayer() |
| 412 | { |
| 413 | dummyGraph.EraseLayer(m_Layer); |
| 414 | } |
| 415 | |
| 416 | armnn::QLstmLayer* m_Layer; |
| 417 | }; |
| 418 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 419 | template<> |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 420 | struct DummyLayer<armnn::QuantizedLstmLayer, void> |
| 421 | { |
| 422 | DummyLayer() |
| 423 | { |
| 424 | m_Layer = dummyGraph.AddLayer<armnn::QuantizedLstmLayer>(""); |
| 425 | |
| 426 | m_Layer->m_QuantizedLstmParameters.m_InputToInputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 427 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8)); |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 428 | m_Layer->m_QuantizedLstmParameters.m_InputToForgetWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 429 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8)); |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 430 | m_Layer->m_QuantizedLstmParameters.m_InputToCellWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 431 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8)); |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 432 | m_Layer->m_QuantizedLstmParameters.m_InputToOutputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 433 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8)); |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 434 | |
| 435 | m_Layer->m_QuantizedLstmParameters.m_RecurrentToInputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 436 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8)); |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 437 | m_Layer->m_QuantizedLstmParameters.m_RecurrentToForgetWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 438 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8)); |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 439 | m_Layer->m_QuantizedLstmParameters.m_RecurrentToCellWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 440 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8)); |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 441 | m_Layer->m_QuantizedLstmParameters.m_RecurrentToOutputWeights = std::make_unique<armnn::ScopedCpuTensorHandle>( |
Derek Lamberti | f90c56d | 2020-01-10 17:14:08 +0000 | [diff] [blame] | 442 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::QAsymmU8)); |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 443 | |
| 444 | m_Layer->m_QuantizedLstmParameters.m_InputGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 445 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32)); |
| 446 | m_Layer->m_QuantizedLstmParameters.m_ForgetGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 447 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32)); |
| 448 | m_Layer->m_QuantizedLstmParameters.m_CellBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 449 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32)); |
| 450 | m_Layer->m_QuantizedLstmParameters.m_OutputGateBias = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 451 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Signed32)); |
| 452 | } |
| 453 | |
| 454 | ~DummyLayer() |
| 455 | { |
| 456 | dummyGraph.EraseLayer(m_Layer); |
| 457 | } |
| 458 | |
| 459 | armnn::QuantizedLstmLayer* m_Layer; |
| 460 | }; |
| 461 | |
| 462 | template<> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 463 | struct DummyLayer<armnn::FullyConnectedLayer> |
| 464 | { |
| 465 | DummyLayer() |
| 466 | { |
| 467 | armnn::FullyConnectedLayer::DescriptorType desc; |
| 468 | m_Layer = dummyGraph.AddLayer<armnn::FullyConnectedLayer>(desc, ""); |
| 469 | m_Layer->m_Weight = std::make_unique<armnn::ScopedCpuTensorHandle>( |
| 470 | armnn::TensorInfo(armnn::TensorShape({1,1,1,1}), armnn::DataType::Float32)); |
| 471 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 472 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 473 | ~DummyLayer() |
| 474 | { |
| 475 | dummyGraph.EraseLayer(m_Layer); |
| 476 | } |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 477 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 478 | armnn::FullyConnectedLayer* m_Layer; |
| 479 | }; |
| 480 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 481 | // Tag for giving LayerType entries a unique strong type each. |
| 482 | template<armnn::LayerType> |
| 483 | struct Tag{}; |
| 484 | |
| 485 | #define DECLARE_LAYER_POLICY_CUSTOM_PARAM(name, descType) \ |
| 486 | template<armnn::DataType DataType> \ |
| 487 | struct LayerTypePolicy<armnn::LayerType::name, DataType> \ |
| 488 | { \ |
| 489 | using Type = armnn::name##Layer; \ |
| 490 | using Desc = descType; \ |
| 491 | using QueueDesc = armnn::name##QueueDescriptor; \ |
| 492 | constexpr static const char* NameStr = #name; \ |
Derek Lamberti | e606b7c | 2019-10-21 16:51:11 +0100 | [diff] [blame] | 493 | constexpr static const bool IsException = false; \ |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 494 | \ |
| 495 | static std::unique_ptr<armnn::IWorkload> MakeDummyWorkload(armnn::IWorkloadFactory *factory, \ |
| 496 | unsigned int nIn, unsigned int nOut) \ |
| 497 | { \ |
| 498 | QueueDesc desc; \ |
| 499 | armnn::WorkloadInfo info = MakeDummyWorkloadInfo<DataType>(nIn, nOut); \ |
| 500 | return factory->Create##name(desc, info); \ |
| 501 | } \ |
| 502 | }; |
| 503 | |
Jim Flynn | 68db06f | 2020-10-06 10:14:50 +0100 | [diff] [blame] | 504 | #define DECLARE_LAYER_POLICY_MAP_PARAM(name, descType) \ |
| 505 | template<armnn::DataType DataType> \ |
| 506 | struct LayerTypePolicy<armnn::LayerType::name, DataType> \ |
| 507 | { \ |
| 508 | using Type = armnn::name##Layer; \ |
| 509 | using Desc = descType; \ |
| 510 | using QueueDesc = armnn::name##QueueDescriptor; \ |
| 511 | using Workload = armnn::name##Workload; \ |
| 512 | constexpr static const char* NameStr = #name; \ |
| 513 | constexpr static const bool IsException = false; \ |
| 514 | \ |
| 515 | static std::unique_ptr<armnn::IWorkload> MakeDummyWorkload(armnn::IWorkloadFactory* factory, \ |
| 516 | unsigned int nIn, unsigned int nOut) \ |
| 517 | { \ |
| 518 | IgnoreUnused(factory); \ |
| 519 | QueueDesc desc; \ |
| 520 | armnn::WorkloadInfo info = MakeDummyWorkloadInfo<DataType>(nIn, nOut); \ |
| 521 | return std::make_unique<armnn::name##Workload>(desc, info); \ |
| 522 | } \ |
| 523 | }; |
| 524 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 525 | // Define a layer policy specialization for use with the IsLayerSupported tests. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 526 | // Use this version for layers whose constructor takes 1 parameter(name). |
| 527 | #define DECLARE_LAYER_POLICY_1_PARAM(name) DECLARE_LAYER_POLICY_CUSTOM_PARAM(name, void) |
| 528 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 529 | // Define a layer policy specialization for use with the IsLayerSupported tests. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 530 | // Use this version for layers whose constructor takes 2 parameters(descriptor and name). |
| 531 | #define DECLARE_LAYER_POLICY_2_PARAM(name) DECLARE_LAYER_POLICY_CUSTOM_PARAM(name, armnn::name##Descriptor) |
| 532 | |
Derek Lamberti | 013c390 | 2019-10-21 10:46:16 +0100 | [diff] [blame] | 533 | |
| 534 | #define DECLARE_LAYER_POLICY_EXCEPTION(name, descType) \ |
| 535 | template<armnn::DataType DataType> \ |
| 536 | struct LayerTypePolicy<armnn::LayerType::name, DataType> \ |
| 537 | { \ |
| 538 | using Type = armnn::name##Layer; \ |
| 539 | using Desc = descType; \ |
| 540 | constexpr static const char* NameStr = #name; \ |
Derek Lamberti | b99ef39 | 2019-10-21 14:10:38 +0100 | [diff] [blame] | 541 | constexpr static const bool IsException = true; \ |
Derek Lamberti | 013c390 | 2019-10-21 10:46:16 +0100 | [diff] [blame] | 542 | \ |
| 543 | static std::unique_ptr<armnn::IWorkload> MakeDummyWorkload(armnn::IWorkloadFactory *factory, \ |
| 544 | unsigned int nIn, unsigned int nOut) \ |
| 545 | { \ |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 546 | IgnoreUnused(factory, nIn, nOut); \ |
Derek Lamberti | 013c390 | 2019-10-21 10:46:16 +0100 | [diff] [blame] | 547 | return std::unique_ptr<armnn::IWorkload>(); \ |
| 548 | } \ |
| 549 | }; |
| 550 | |
| 551 | #define DECLARE_LAYER_POLICY_EXCEPTION_1_PARAM(name) DECLARE_LAYER_POLICY_EXCEPTION(name, void) |
| 552 | #define DECLARE_LAYER_POLICY_EXCEPTION_2_PARAM(name) DECLARE_LAYER_POLICY_EXCEPTION(name, armnn::name##Descriptor) |
| 553 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 554 | // Layer policy template. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 555 | template<armnn::LayerType Type, armnn::DataType DataType> |
| 556 | struct LayerTypePolicy; |
| 557 | |
| 558 | // Every entry in the armnn::LayerType enum must be accounted for below. |
| 559 | DECLARE_LAYER_POLICY_2_PARAM(Activation) |
| 560 | |
| 561 | DECLARE_LAYER_POLICY_1_PARAM(Addition) |
| 562 | |
Nikhil Raj | ee391d5 | 2019-09-05 17:50:44 +0100 | [diff] [blame] | 563 | DECLARE_LAYER_POLICY_2_PARAM(ArgMinMax) |
| 564 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 565 | DECLARE_LAYER_POLICY_2_PARAM(BatchNormalization) |
| 566 | |
Éanna Ó Catháin | 4e1e136 | 2018-11-12 11:36:34 +0000 | [diff] [blame] | 567 | DECLARE_LAYER_POLICY_2_PARAM(BatchToSpaceNd) |
| 568 | |
Aron Virginas-Tar | 77bfb5e | 2019-10-16 17:45:38 +0100 | [diff] [blame] | 569 | DECLARE_LAYER_POLICY_2_PARAM(Comparison) |
| 570 | |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 571 | DECLARE_LAYER_POLICY_2_PARAM(Concat) |
| 572 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 573 | DECLARE_LAYER_POLICY_1_PARAM(Constant) |
| 574 | |
Narumol Prangnawarat | 7ddbbae | 2020-03-13 10:26:05 +0000 | [diff] [blame] | 575 | DECLARE_LAYER_POLICY_1_PARAM(ConvertBf16ToFp32) |
| 576 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 577 | DECLARE_LAYER_POLICY_1_PARAM(ConvertFp16ToFp32) |
| 578 | |
Narumol Prangnawarat | ea54a01 | 2020-03-16 16:36:10 +0000 | [diff] [blame] | 579 | DECLARE_LAYER_POLICY_1_PARAM(ConvertFp32ToBf16) |
| 580 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 581 | DECLARE_LAYER_POLICY_1_PARAM(ConvertFp32ToFp16) |
| 582 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 583 | DECLARE_LAYER_POLICY_2_PARAM(Convolution2d) |
| 584 | |
| 585 | DECLARE_LAYER_POLICY_1_PARAM(MemCopy) |
| 586 | |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 587 | DECLARE_LAYER_POLICY_1_PARAM(MemImport) |
| 588 | |
Nattapat Chaimanowong | 964e955 | 2019-03-26 11:03:26 +0000 | [diff] [blame] | 589 | DECLARE_LAYER_POLICY_1_PARAM(Debug) |
Nattapat Chaimanowong | a9a1cf1 | 2018-12-03 16:06:49 +0000 | [diff] [blame] | 590 | |
Aron Virginas-Tar | dd6247f | 2019-09-19 14:31:17 +0100 | [diff] [blame] | 591 | DECLARE_LAYER_POLICY_2_PARAM(DepthToSpace) |
| 592 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 593 | DECLARE_LAYER_POLICY_2_PARAM(DepthwiseConvolution2d) |
| 594 | |
Nattapat Chaimanowong | e4294fd | 2019-03-28 09:56:53 +0000 | [diff] [blame] | 595 | DECLARE_LAYER_POLICY_1_PARAM(Dequantize) |
| 596 | |
Narumol Prangnawarat | 94dd5d8 | 2019-01-23 18:06:26 +0000 | [diff] [blame] | 597 | DECLARE_LAYER_POLICY_2_PARAM(DetectionPostProcess) |
| 598 | |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 599 | DECLARE_LAYER_POLICY_2_PARAM(ElementwiseUnary) |
| 600 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 601 | DECLARE_LAYER_POLICY_2_PARAM(FakeQuantization) |
| 602 | |
Ryan OShea | ec6c680 | 2020-06-05 17:17:06 +0100 | [diff] [blame] | 603 | DECLARE_LAYER_POLICY_2_PARAM(Fill) |
| 604 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 605 | DECLARE_LAYER_POLICY_1_PARAM(Floor) |
| 606 | |
| 607 | DECLARE_LAYER_POLICY_2_PARAM(FullyConnected) |
| 608 | |
Teresa Charlin | 5266473 | 2020-06-29 16:27:03 +0100 | [diff] [blame] | 609 | DECLARE_LAYER_POLICY_2_PARAM(Gather) |
narpra01 | b89b05f | 2019-01-16 09:53:09 +0000 | [diff] [blame] | 610 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 611 | DECLARE_LAYER_POLICY_CUSTOM_PARAM(Input, armnn::LayerBindingId) |
| 612 | |
Kevin May | ce5045a | 2019-10-02 14:07:47 +0100 | [diff] [blame] | 613 | DECLARE_LAYER_POLICY_2_PARAM(InstanceNormalization) |
| 614 | |
Matteo Martincigh | bcd3c85 | 2018-09-28 14:14:12 +0100 | [diff] [blame] | 615 | DECLARE_LAYER_POLICY_2_PARAM(L2Normalization) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 616 | |
James Conroy | aba90cd | 2020-11-06 16:28:18 +0000 | [diff] [blame] | 617 | DECLARE_LAYER_POLICY_2_PARAM(LogicalBinary) |
| 618 | |
Aron Virginas-Tar | f982dea | 2019-10-11 14:07:53 +0100 | [diff] [blame] | 619 | DECLARE_LAYER_POLICY_2_PARAM(LogSoftmax) |
| 620 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 621 | DECLARE_LAYER_POLICY_2_PARAM(Lstm) |
| 622 | |
Jim Flynn | 68db06f | 2020-10-06 10:14:50 +0100 | [diff] [blame] | 623 | DECLARE_LAYER_POLICY_MAP_PARAM(Map, void) |
| 624 | |
Nattapat Chaimanowong | 5a4304a | 2018-11-28 10:44:37 +0000 | [diff] [blame] | 625 | DECLARE_LAYER_POLICY_1_PARAM(Maximum) |
| 626 | |
narpra01 | 32b9046 | 2018-09-13 11:07:48 +0100 | [diff] [blame] | 627 | DECLARE_LAYER_POLICY_2_PARAM(Mean) |
| 628 | |
Nattapat Chaimanowong | 1f88630 | 2019-04-05 13:37:19 +0100 | [diff] [blame] | 629 | DECLARE_LAYER_POLICY_1_PARAM(Merge) |
| 630 | |
kevmay01 | 9053969 | 2018-11-29 08:40:19 +0000 | [diff] [blame] | 631 | DECLARE_LAYER_POLICY_1_PARAM(Minimum) |
| 632 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 633 | DECLARE_LAYER_POLICY_1_PARAM(Multiplication) |
| 634 | |
| 635 | DECLARE_LAYER_POLICY_2_PARAM(Normalization) |
| 636 | |
| 637 | DECLARE_LAYER_POLICY_CUSTOM_PARAM(Output, armnn::LayerBindingId) |
| 638 | |
Mohamed Nour Abouelseoud | 5662c20 | 2018-09-24 13:30:09 +0100 | [diff] [blame] | 639 | DECLARE_LAYER_POLICY_2_PARAM(Pad) |
| 640 | |
Derek Lamberti | a9cca6a | 2019-03-25 15:41:58 +0000 | [diff] [blame] | 641 | DECLARE_LAYER_POLICY_1_PARAM(Quantize) |
| 642 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 643 | DECLARE_LAYER_POLICY_2_PARAM(Permute) |
| 644 | |
| 645 | DECLARE_LAYER_POLICY_2_PARAM(Pooling2d) |
| 646 | |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 647 | DECLARE_LAYER_POLICY_2_PARAM(PreCompiled) |
| 648 | |
Matteo Martincigh | 0e406ee | 2019-06-12 15:42:18 +0100 | [diff] [blame] | 649 | DECLARE_LAYER_POLICY_1_PARAM(Prelu) |
James Conroy | 586a9aa | 2020-03-20 08:49:33 +0000 | [diff] [blame] | 650 | DECLARE_LAYER_POLICY_2_PARAM(QLstm) |
| 651 | |
James Conroy | ee18dc8 | 2019-07-17 11:27:46 +0100 | [diff] [blame] | 652 | DECLARE_LAYER_POLICY_1_PARAM(QuantizedLstm) |
| 653 | |
Francis Murtagh | e7a86a4 | 2018-08-29 12:42:10 +0100 | [diff] [blame] | 654 | DECLARE_LAYER_POLICY_1_PARAM(Division) |
| 655 | |
Finn Williams | 2605b23 | 2020-06-10 15:53:46 +0100 | [diff] [blame] | 656 | DECLARE_LAYER_POLICY_1_PARAM(Rank) |
| 657 | |
Teresa Charlin | a9075df | 2019-06-27 15:41:57 +0100 | [diff] [blame] | 658 | DECLARE_LAYER_POLICY_2_PARAM(Resize) |
| 659 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 660 | DECLARE_LAYER_POLICY_2_PARAM(Reshape) |
| 661 | |
Aron Virginas-Tar | 636ab40 | 2019-09-16 14:27:45 +0100 | [diff] [blame] | 662 | DECLARE_LAYER_POLICY_2_PARAM(Slice) |
| 663 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 664 | DECLARE_LAYER_POLICY_2_PARAM(Softmax) |
| 665 | |
Nattapat Chaimanowong | 207ef9a | 2018-11-02 10:57:25 +0000 | [diff] [blame] | 666 | DECLARE_LAYER_POLICY_2_PARAM(SpaceToBatchNd) |
| 667 | |
Aron Virginas-Tar | 972af15 | 2019-06-11 14:14:03 +0100 | [diff] [blame] | 668 | DECLARE_LAYER_POLICY_2_PARAM(SpaceToDepth) |
| 669 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 670 | DECLARE_LAYER_POLICY_2_PARAM(Splitter) |
| 671 | |
Matthew Jackson | 2b8c1da | 2019-07-04 14:59:16 +0100 | [diff] [blame] | 672 | DECLARE_LAYER_POLICY_2_PARAM(Stack) |
| 673 | |
Derek Lamberti | 013c390 | 2019-10-21 10:46:16 +0100 | [diff] [blame] | 674 | DECLARE_LAYER_POLICY_EXCEPTION_2_PARAM(StandIn) |
| 675 | |
Conor Kennedy | 430b5d8 | 2018-11-14 15:28:28 +0000 | [diff] [blame] | 676 | DECLARE_LAYER_POLICY_2_PARAM(StridedSlice) |
| 677 | |
David Beck | c2044fe | 2018-09-05 15:00:38 +0100 | [diff] [blame] | 678 | DECLARE_LAYER_POLICY_1_PARAM(Subtraction) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 679 | |
Sadik Armagan | 0c3ea5b | 2021-02-03 09:29:30 +0000 | [diff] [blame] | 680 | DECLARE_LAYER_POLICY_2_PARAM(Reduce) |
| 681 | |
Sadik Armagan | eff363d | 2019-04-05 15:25:46 +0100 | [diff] [blame] | 682 | DECLARE_LAYER_POLICY_1_PARAM(Switch) |
| 683 | |
Mike Kelly | c9ea45a | 2020-02-28 18:11:58 +0000 | [diff] [blame] | 684 | DECLARE_LAYER_POLICY_2_PARAM(Transpose) |
| 685 | |
Aron Virginas-Tar | 639fb04 | 2019-06-20 14:28:19 +0100 | [diff] [blame] | 686 | DECLARE_LAYER_POLICY_2_PARAM(TransposeConvolution2d) |
| 687 | |
Jim Flynn | 3a40ea5 | 2020-10-08 11:42:30 +0100 | [diff] [blame] | 688 | DECLARE_LAYER_POLICY_MAP_PARAM(Unmap, void) |
| 689 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 690 | |
| 691 | // Generic implementation to get the number of input slots for a given layer type; |
| 692 | template<armnn::LayerType Type> |
| 693 | unsigned int GetNumInputs(const armnn::Layer& layer) |
| 694 | { |
| 695 | return layer.GetNumInputSlots(); |
| 696 | } |
| 697 | |
| 698 | // Generic implementation to get the number of output slots for a given layer type; |
| 699 | template<armnn::LayerType Type> |
| 700 | unsigned int GetNumOutputs(const armnn::Layer& layer) |
| 701 | { |
| 702 | return layer.GetNumOutputSlots(); |
| 703 | } |
| 704 | |
| 705 | template<> |
Jim Flynn | e242f2d | 2019-05-22 14:24:13 +0100 | [diff] [blame] | 706 | unsigned int GetNumInputs<armnn::LayerType::Concat>(const armnn::Layer& layer) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 707 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 708 | IgnoreUnused(layer); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 709 | return 2; |
| 710 | } |
| 711 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 712 | // Tests that the IsLayerSupported() function returns the correct value. |
| 713 | // 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] | 714 | // Returns true if expectations are met, otherwise returns false. |
| 715 | template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type> |
| 716 | bool IsLayerSupportedTest(FactoryType *factory, Tag<Type>) |
| 717 | { |
| 718 | using LayerPolicy = LayerTypePolicy<Type, DataType>; |
| 719 | using LayerType = typename LayerPolicy::Type; |
| 720 | using LayerDesc = typename LayerPolicy::Desc; |
| 721 | DummyLayer<LayerType, LayerDesc> layer; |
| 722 | |
Derek Lamberti | b99ef39 | 2019-10-21 14:10:38 +0100 | [diff] [blame] | 723 | if (LayerPolicy::IsException) //Don't test exceptions to the rule. |
| 724 | { |
| 725 | return true; |
| 726 | } |
| 727 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 728 | unsigned int numIn = GetNumInputs<Type>(*layer.m_Layer); |
| 729 | unsigned int numOut = GetNumOutputs<Type>(*layer.m_Layer); |
| 730 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 731 | // Make another dummy layer just to make IsLayerSupported have valid inputs. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 732 | DummyLayer<armnn::ConstantLayer, void> previousLayer; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 733 | // Set output of the previous layer to a dummy tensor. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 734 | armnn::TensorInfo output = MakeDummyTensorInfo<DataType>(); |
| 735 | previousLayer.m_Layer->GetOutputSlot(0).SetTensorInfo(output); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 736 | // Connect all outputs of the previous layer to inputs of tested layer. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 737 | for (unsigned int i = 0; i < numIn; i++) |
| 738 | { |
| 739 | armnn::IOutputSlot& previousLayerOutputSlot = previousLayer.m_Layer->GetOutputSlot(0); |
| 740 | armnn::IInputSlot& layerInputSlot = layer.m_Layer->GetInputSlot(i); |
| 741 | previousLayerOutputSlot.Connect(layerInputSlot); |
| 742 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 743 | // Set outputs of tested layer to a dummy tensor. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 744 | for (unsigned int i = 0; i < numOut; i++) |
| 745 | { |
| 746 | layer.m_Layer->GetOutputSlot(0).SetTensorInfo(output); |
| 747 | } |
| 748 | |
| 749 | std::string layerName = LayerPolicy::NameStr; |
| 750 | std::string reasonIfUnsupported; |
| 751 | if (FactoryType::IsLayerSupported(*layer.m_Layer, DataType, reasonIfUnsupported)) |
| 752 | { |
| 753 | std::string errorMsg = " layer expected support but found none."; |
| 754 | try |
| 755 | { |
| 756 | bool retVal = LayerPolicy::MakeDummyWorkload(factory, numIn, numOut).get() != nullptr; |
Matteo Martincigh | fbebcbd | 2018-10-16 09:45:08 +0100 | [diff] [blame] | 757 | BOOST_CHECK_MESSAGE(retVal, layerName << errorMsg); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 758 | return retVal; |
| 759 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 760 | catch(const armnn::InvalidArgumentException& e) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 761 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 762 | IgnoreUnused(e); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 763 | // This is ok since we throw InvalidArgumentException when creating the dummy workload. |
| 764 | return true; |
| 765 | } |
| 766 | catch(const std::exception& e) |
| 767 | { |
| 768 | errorMsg = e.what(); |
| 769 | BOOST_TEST_ERROR(layerName << ": " << errorMsg); |
| 770 | return false; |
| 771 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 772 | catch(...) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 773 | { |
| 774 | errorMsg = "Unexpected error while testing support for "; |
| 775 | BOOST_TEST_ERROR(errorMsg << layerName); |
| 776 | return false; |
| 777 | } |
| 778 | } |
| 779 | else |
| 780 | { |
| 781 | std::string errorMsg = "layer expected no support (giving reason: " + reasonIfUnsupported + ") but found some."; |
| 782 | try |
| 783 | { |
| 784 | bool retVal = LayerPolicy::MakeDummyWorkload(factory, numIn, numOut).get() == nullptr; |
| 785 | BOOST_CHECK_MESSAGE(retVal, layerName << errorMsg); |
| 786 | return retVal; |
| 787 | } |
| 788 | // These two exceptions are ok: For workloads that are partially supported, attempting to instantiate them |
| 789 | // using parameters that make IsLayerSupported() return false should throw an |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 790 | // InvalidArgumentException or UnimplementedException. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 791 | catch(const armnn::InvalidArgumentException& e) |
| 792 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 793 | IgnoreUnused(e); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 794 | return true; |
| 795 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 796 | catch(const armnn::UnimplementedException& e) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 797 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 798 | IgnoreUnused(e); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 799 | return true; |
| 800 | } |
| 801 | catch(const std::exception& e) |
| 802 | { |
| 803 | errorMsg = e.what(); |
| 804 | BOOST_TEST_ERROR(layerName << ": " << errorMsg); |
| 805 | return false; |
| 806 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 807 | catch(...) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 808 | { |
| 809 | errorMsg = "Unexpected error while testing support for "; |
| 810 | BOOST_TEST_ERROR(errorMsg << layerName); |
| 811 | return false; |
| 812 | } |
| 813 | } |
| 814 | } |
| 815 | |
Jim Flynn | 68db06f | 2020-10-06 10:14:50 +0100 | [diff] [blame] | 816 | template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type> |
| 817 | bool IsLayerSupportedTest(FactoryType *factory, Tag<armnn::LayerType::Map>) |
| 818 | { |
| 819 | IgnoreUnused(factory); |
| 820 | return true; |
| 821 | } |
| 822 | |
Jim Flynn | 3a40ea5 | 2020-10-08 11:42:30 +0100 | [diff] [blame] | 823 | template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type> |
| 824 | bool IsLayerSupportedTest(FactoryType *factory, Tag<armnn::LayerType::Unmap>) |
| 825 | { |
| 826 | IgnoreUnused(factory); |
| 827 | return true; |
| 828 | } |
| 829 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 830 | // Helper function to compute the next type in the LayerType enum. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 831 | constexpr armnn::LayerType NextType(armnn::LayerType type) |
| 832 | { |
| 833 | return static_cast<armnn::LayerType>(static_cast<int>(type)+1); |
| 834 | } |
| 835 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 836 | // Termination function for determining the end of the LayerType enumeration. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 837 | template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type> |
| 838 | bool IsLayerSupportedTestsImpl(FactoryType *factory, Tag<armnn::LayerType::LastLayer>) |
| 839 | { |
| 840 | return IsLayerSupportedTest<FactoryType, DataType, Type>(factory, Tag<Type>()); |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 841 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 842 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 843 | // 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] | 844 | template<typename FactoryType, armnn::DataType DataType, armnn::LayerType Type> |
| 845 | bool IsLayerSupportedTestsImpl(FactoryType *factory, Tag<Type>) |
| 846 | { |
| 847 | bool v = IsLayerSupportedTest<FactoryType, DataType, Type>(factory, Tag<Type>()); |
| 848 | |
| 849 | return v && |
| 850 | IsLayerSupportedTestsImpl<FactoryType, DataType, NextType(Type)> |
| 851 | (factory, Tag<NextType(Type)>()); |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 852 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 853 | |
| 854 | // Helper function to pass through to the test framework. |
| 855 | template<typename FactoryType, armnn::DataType DataType> |
| 856 | bool IsLayerSupportedTests(FactoryType *factory) |
| 857 | { |
| 858 | return IsLayerSupportedTestsImpl<FactoryType, DataType>(factory, Tag<armnn::LayerType::FirstLayer>()); |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 859 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 860 | |
| 861 | template<armnn::LayerType Type> |
| 862 | bool TestLayerTypeMatches() |
| 863 | { |
| 864 | using LayerPolicy = LayerTypePolicy<Type, armnn::DataType::Float32>; |
| 865 | using LayerType = typename LayerPolicy::Type; |
| 866 | using LayerDesc = typename LayerPolicy::Desc; |
| 867 | DummyLayer<LayerType, LayerDesc> layer; |
| 868 | |
| 869 | std::stringstream ss; |
| 870 | ss << LayerPolicy::NameStr << " layer type mismatches expected layer type value."; |
| 871 | bool v = Type == layer.m_Layer->GetType(); |
| 872 | BOOST_CHECK_MESSAGE(v, ss.str()); |
| 873 | return v; |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 874 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 875 | |
| 876 | template<armnn::LayerType Type> |
| 877 | bool LayerTypeMatchesTestImpl(Tag<armnn::LayerType::LastLayer>) |
| 878 | { |
| 879 | return TestLayerTypeMatches<Type>(); |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 880 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 881 | |
| 882 | template<armnn::LayerType Type> |
| 883 | bool LayerTypeMatchesTestImpl(Tag<Type>) |
| 884 | { |
| 885 | return TestLayerTypeMatches<Type>() && |
| 886 | LayerTypeMatchesTestImpl<NextType(Type)>(Tag<NextType(Type)>()); |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 887 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 888 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 889 | template<typename FactoryType, typename LayerType, armnn::DataType InputDataType , armnn::DataType OutputDataType> |
| 890 | bool IsConvertLayerSupportedTests(std::string& reasonIfUnsupported) |
| 891 | { |
| 892 | armnn::Graph graph; |
| 893 | LayerType* const layer = graph.AddLayer<LayerType>("LayerName"); |
| 894 | |
| 895 | armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input"); |
| 896 | armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output"); |
| 897 | |
| 898 | armnn::TensorInfo inputTensorInfo({1, 3, 2, 3}, InputDataType); |
| 899 | armnn::TensorInfo outputTensorInfo({1, 3, 2, 3}, OutputDataType); |
| 900 | |
| 901 | input->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); |
| 902 | input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo); |
| 903 | layer->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 904 | layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo); |
| 905 | |
| 906 | bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported); |
| 907 | |
| 908 | return result; |
Matteo Martincigh | 59a950c | 2018-12-13 12:48:25 +0000 | [diff] [blame] | 909 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 910 | |
Matthew Bentham | 1f0ff35 | 2019-01-02 13:26:31 +0000 | [diff] [blame] | 911 | template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType> |
James Conroy | 177df1e | 2020-11-13 10:18:51 +0000 | [diff] [blame] | 912 | bool IsLogicalBinaryLayerSupportedTests(std::string& reasonIfUnsupported) |
| 913 | { |
| 914 | armnn::Graph graph; |
| 915 | armnn::LogicalBinaryDescriptor desc(armnn::LogicalBinaryOperation::LogicalOr); |
| 916 | |
| 917 | armnn::Layer* const input0 = graph.AddLayer<armnn::InputLayer>(0, "input0"); |
| 918 | armnn::Layer* const input1 = graph.AddLayer<armnn::InputLayer>(1, "input1"); |
| 919 | |
| 920 | armnn::Layer* const layer = graph.AddLayer<armnn::LogicalBinaryLayer>(desc, "logicalOrLayer"); |
| 921 | |
| 922 | armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output1"); |
| 923 | |
| 924 | armnn::TensorInfo inputTensorInfo0({1, 1, 1, 4}, InputDataType); |
| 925 | armnn::TensorInfo inputTensorInfo1({1, 1, 1, 4}, InputDataType); |
| 926 | |
| 927 | armnn::TensorInfo outputTensorInfo({1, 1, 1, 4}, OutputDataType); |
| 928 | |
| 929 | input0->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); |
| 930 | input1->GetOutputSlot(0).Connect(layer->GetInputSlot(1)); |
| 931 | |
| 932 | input0->GetOutputHandler(0).SetTensorInfo(inputTensorInfo0); |
| 933 | input1->GetOutputHandler(0).SetTensorInfo(inputTensorInfo1); |
| 934 | |
| 935 | layer->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 936 | layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo); |
| 937 | |
| 938 | bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported); |
| 939 | |
| 940 | return result; |
| 941 | } |
| 942 | |
| 943 | template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType> |
| 944 | bool IsLogicalBinaryLayerBroadcastSupportedTests(std::string& reasonIfUnsupported) |
| 945 | { |
| 946 | armnn::Graph graph; |
| 947 | armnn::LogicalBinaryDescriptor desc(armnn::LogicalBinaryOperation::LogicalAnd); |
| 948 | |
| 949 | armnn::Layer* const input0 = graph.AddLayer<armnn::InputLayer>(0, "input0"); |
| 950 | armnn::Layer* const input1 = graph.AddLayer<armnn::InputLayer>(1, "input1"); |
| 951 | |
| 952 | armnn::Layer* const layer = graph.AddLayer<armnn::LogicalBinaryLayer>(desc, "logicalAndLayer"); |
| 953 | |
| 954 | armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output2"); |
| 955 | |
| 956 | armnn::TensorInfo inputTensorInfo0({1, 1, 1, 4}, InputDataType); |
| 957 | armnn::TensorInfo inputTensorInfo1({1, 1, 1, 1}, InputDataType); |
| 958 | |
| 959 | armnn::TensorInfo outputTensorInfo({1, 1, 1, 4}, OutputDataType); |
| 960 | |
| 961 | input0->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); |
| 962 | input1->GetOutputSlot(0).Connect(layer->GetInputSlot(1)); |
| 963 | |
| 964 | input0->GetOutputHandler(0).SetTensorInfo(inputTensorInfo0); |
| 965 | input1->GetOutputHandler(0).SetTensorInfo(inputTensorInfo1); |
| 966 | |
| 967 | layer->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 968 | layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo); |
| 969 | |
| 970 | bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported); |
| 971 | |
| 972 | return result; |
| 973 | } |
| 974 | |
| 975 | template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType> |
Matthew Bentham | 1f0ff35 | 2019-01-02 13:26:31 +0000 | [diff] [blame] | 976 | bool IsMeanLayerSupportedTests(std::string& reasonIfUnsupported) |
| 977 | { |
| 978 | armnn::Graph graph; |
| 979 | static const std::vector<unsigned> axes = {1, 0}; |
| 980 | armnn::MeanDescriptor desc(axes, false); |
| 981 | |
| 982 | armnn::Layer* const layer = graph.AddLayer<armnn::MeanLayer>(desc, "LayerName"); |
| 983 | |
| 984 | armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input"); |
| 985 | armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output"); |
| 986 | |
| 987 | armnn::TensorInfo inputTensorInfo({4, 3, 2}, InputDataType); |
| 988 | armnn::TensorInfo outputTensorInfo({2}, OutputDataType); |
| 989 | |
| 990 | input->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); |
| 991 | input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo); |
| 992 | layer->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 993 | layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo); |
| 994 | |
| 995 | bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported); |
| 996 | |
| 997 | return result; |
| 998 | } |
| 999 | |
James Conroy | 4d1ff58 | 2019-06-10 17:06:39 +0100 | [diff] [blame] | 1000 | // Tests that IsMeanSupported fails when input tensor dimensions |
| 1001 | // do not match output tensor dimensions when keepDims == true |
| 1002 | template<typename FactoryType, armnn::DataType InputDataType , armnn::DataType OutputDataType> |
| 1003 | bool IsMeanLayerNotSupportedTests(std::string& reasonIfUnsupported) |
| 1004 | { |
| 1005 | armnn::Graph graph; |
| 1006 | static const std::vector<unsigned> axes = {}; |
| 1007 | // Set keepDims == true |
| 1008 | armnn::MeanDescriptor desc(axes, true); |
| 1009 | |
| 1010 | armnn::Layer* const layer = graph.AddLayer<armnn::MeanLayer>(desc, "LayerName"); |
| 1011 | |
| 1012 | armnn::Layer* const input = graph.AddLayer<armnn::InputLayer>(0, "input"); |
| 1013 | armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "output"); |
| 1014 | |
| 1015 | // Mismatching number of tensor dimensions |
| 1016 | armnn::TensorInfo inputTensorInfo({1, 1, 1, 1}, InputDataType); |
| 1017 | armnn::TensorInfo outputTensorInfo({1, 1}, OutputDataType); |
| 1018 | |
| 1019 | input->GetOutputSlot(0).Connect(layer->GetInputSlot(0)); |
| 1020 | input->GetOutputHandler(0).SetTensorInfo(inputTensorInfo); |
| 1021 | layer->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 1022 | layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo); |
| 1023 | |
| 1024 | bool result = FactoryType::IsLayerSupported(*layer, InputDataType, reasonIfUnsupported); |
| 1025 | |
| 1026 | return result; |
| 1027 | } |
| 1028 | |
Mike Kelly | 0886ac4 | 2020-04-27 09:55:40 +0100 | [diff] [blame] | 1029 | template<typename FactoryType, armnn::DataType OutputDataType> |
| 1030 | bool IsConstantLayerSupportedTests(std::string& reasonIfUnsupported) |
| 1031 | { |
| 1032 | armnn::Graph graph; |
| 1033 | |
| 1034 | armnn::Layer* const layer = graph.AddLayer<armnn::ConstantLayer>("ConstantLayerName"); |
| 1035 | armnn::Layer* const output = graph.AddLayer<armnn::OutputLayer>(0, "OutputLayerName"); |
| 1036 | |
| 1037 | armnn::TensorInfo outputTensorInfo({1, 1}, OutputDataType); |
| 1038 | |
| 1039 | layer->GetOutputSlot(0).Connect(output->GetInputSlot(0)); |
| 1040 | layer->GetOutputHandler(0).SetTensorInfo(outputTensorInfo); |
| 1041 | |
| 1042 | bool result = FactoryType::IsLayerSupported(*layer, OutputDataType, reasonIfUnsupported); |
| 1043 | |
| 1044 | return result; |
| 1045 | } |
Matthew Bentham | 1f0ff35 | 2019-01-02 13:26:31 +0000 | [diff] [blame] | 1046 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1047 | } //namespace |