Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 1 | // |
Teresa Charlin | fbf0e5b | 2020-08-17 01:01:06 +0100 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 8 | #include <ResolveType.hpp> |
| 9 | |
Matteo Martincigh | e5b8eb9 | 2019-11-28 15:45:42 +0000 | [diff] [blame] | 10 | #include <armnn/backends/IBackendInternal.hpp> |
Colm Donelan | 0c47974 | 2021-12-10 12:43:54 +0000 | [diff] [blame] | 11 | #include <armnn/backends/WorkloadFactory.hpp> |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 12 | |
Sadik Armagan | a097d2a | 2021-11-24 15:47:28 +0000 | [diff] [blame] | 13 | #include <armnnTestUtils/LayerTestResult.hpp> |
| 14 | #include <armnnTestUtils/TensorCopyUtils.hpp> |
| 15 | #include <DataTypeUtils.hpp> |
| 16 | #include <TensorHelpers.hpp> |
Colm Donelan | 0c47974 | 2021-12-10 12:43:54 +0000 | [diff] [blame] | 17 | #include <armnnTestUtils/WorkloadTestUtils.hpp> |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 18 | |
| 19 | namespace |
| 20 | { |
| 21 | |
| 22 | template<armnn::DataType ArmnnType, |
| 23 | std::size_t InputDim, |
| 24 | std::size_t OutputDim, |
| 25 | typename T = armnn::ResolveType<ArmnnType>> |
| 26 | LayerTestResult<T, OutputDim> BatchToSpaceNdHelper( |
| 27 | armnn::IWorkloadFactory &workloadFactory, |
| 28 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 29 | const armnn::ITensorHandleFactory& tensorHandleFactory, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 30 | const armnn::DataLayout& dataLayout, |
| 31 | const unsigned int *inputShape, |
| 32 | const std::vector<float> &inputData, |
| 33 | const std::vector<unsigned int> &blockShape, |
| 34 | const std::vector<std::pair<unsigned int, unsigned int>> &crops, |
| 35 | const unsigned int *outputShape, |
| 36 | const std::vector<float> &outputData, |
| 37 | float scale = 1.0f, |
| 38 | int32_t offset = 0) |
| 39 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 40 | IgnoreUnused(memoryManager); |
Derek Lamberti | c374ff0 | 2019-12-10 21:57:35 +0000 | [diff] [blame] | 41 | |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 42 | armnn::TensorInfo inputTensorInfo(InputDim, inputShape, ArmnnType); |
| 43 | armnn::TensorInfo outputTensorInfo(OutputDim, outputShape, ArmnnType); |
| 44 | |
| 45 | inputTensorInfo.SetQuantizationScale(scale); |
| 46 | inputTensorInfo.SetQuantizationOffset(offset); |
| 47 | |
| 48 | outputTensorInfo.SetQuantizationScale(scale); |
| 49 | outputTensorInfo.SetQuantizationOffset(offset); |
| 50 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 51 | std::vector<T> input = ConvertToDataType<ArmnnType>(inputData, inputTensorInfo); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 52 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 53 | std::vector<T> actualOutput(outputTensorInfo.GetNumElements()); |
| 54 | std::vector<T> expectedOutput = ConvertToDataType<ArmnnType>(outputData, outputTensorInfo); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 55 | |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 56 | std::unique_ptr<armnn::ITensorHandle> inputHandle = tensorHandleFactory.CreateTensorHandle(inputTensorInfo); |
| 57 | std::unique_ptr<armnn::ITensorHandle> outputHandle = tensorHandleFactory.CreateTensorHandle(outputTensorInfo); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 58 | |
| 59 | armnn::BatchToSpaceNdQueueDescriptor data; |
| 60 | data.m_Parameters.m_DataLayout = dataLayout; |
| 61 | data.m_Parameters.m_BlockShape = blockShape; |
| 62 | data.m_Parameters.m_Crops = crops; |
| 63 | armnn::WorkloadInfo info; |
| 64 | AddInputToWorkload(data, info, inputTensorInfo, inputHandle.get()); |
| 65 | AddOutputToWorkload(data, info, outputTensorInfo, outputHandle.get()); |
| 66 | |
| 67 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreateBatchToSpaceNd(data, info); |
| 68 | |
| 69 | inputHandle->Allocate(); |
| 70 | outputHandle->Allocate(); |
| 71 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 72 | CopyDataToITensorHandle(inputHandle.get(), input.data()); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 73 | |
| 74 | workload->PostAllocationConfigure(); |
| 75 | workload->Execute(); |
| 76 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 77 | CopyDataFromITensorHandle(actualOutput.data(), outputHandle.get()); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 78 | |
Sadik Armagan | 483c811 | 2021-06-01 09:24:52 +0100 | [diff] [blame] | 79 | return LayerTestResult<T, OutputDim>(actualOutput, |
| 80 | expectedOutput, |
| 81 | outputHandle->GetShape(), |
| 82 | outputTensorInfo.GetShape()); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | } // anonymous namespace |
| 86 | |
| 87 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 88 | LayerTestResult<T, 4> BatchToSpaceNdNhwcTest1( |
| 89 | armnn::IWorkloadFactory& workloadFactory, |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 90 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 91 | const armnn::ITensorHandleFactory& tensorHandleFactory) |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 92 | { |
| 93 | const unsigned int inputShape[] = {4, 2, 2, 1}; |
| 94 | const unsigned int outputShape[] = {1, 4, 4, 1}; |
| 95 | |
| 96 | std::vector<float> input({ |
| 97 | // Batch 0, Height 0, Width (2) x Channel (1) |
| 98 | 1.0f, 3.0f, |
| 99 | // Batch 0, Height 1, Width (2) x Channel (1) |
| 100 | 9.0f, 11.0f, |
| 101 | |
| 102 | |
| 103 | // Batch 1, Height 0, Width (2) x Channel (1) |
| 104 | 2.0f, 4.0f, |
| 105 | // Batch 1, Height 1, Width (2) x Channel (1) |
| 106 | 10.0f, 12.0f, |
| 107 | |
| 108 | |
| 109 | // Batch 2, Height 0, Width (2) x Channel (1) |
| 110 | 5.0f, 7.0f, |
| 111 | // Batch 2, Height 1, Width (2) x Channel (1) |
| 112 | 13.0f, 15.0f, |
| 113 | |
| 114 | // Batch 3, Height 0, Width (2) x Channel (3) |
| 115 | 6.0f, 8.0f, |
| 116 | // Batch 3, Height 1, Width (2) x Channel (1) |
| 117 | 14.0f, 16.0f |
| 118 | }); |
| 119 | |
| 120 | std::vector<float> expectedOutput({ |
| 121 | 1.0f, 2.0f, 3.0f, 4.0f, |
| 122 | 5.0f, 6.0f, 7.0f, 8.0f, |
| 123 | 9.0f, 10.0f, 11.0f, 12.0f, |
| 124 | 13.0f, 14.0f, 15.0f, 16.0f |
| 125 | }); |
| 126 | |
| 127 | std::vector<unsigned int> blockShape {2, 2}; |
| 128 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 129 | |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 130 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 131 | armnn::DataLayout::NHWC, inputShape, input, blockShape, |
| 132 | crops, outputShape, expectedOutput); |
| 133 | } |
| 134 | |
| 135 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 136 | LayerTestResult<T, 4> BatchToSpaceNdNhwcTest2( |
| 137 | armnn::IWorkloadFactory& workloadFactory, |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 138 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 139 | const armnn::ITensorHandleFactory& tensorHandleFactory) |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 140 | { |
| 141 | const unsigned int inputShape[] = {4, 1, 1, 1}; |
| 142 | const unsigned int outputShape[] = {1, 2, 2, 1}; |
| 143 | |
| 144 | std::vector<float> input({ |
| 145 | // Batch 0, Height 0, Width (2) x Channel (1) |
| 146 | 1.0f, 2.0f, 3.0f, 4.0f |
| 147 | }); |
| 148 | |
| 149 | std::vector<float> expectedOutput({1.0f, 2.0f, 3.0f, 4.0f}); |
| 150 | |
| 151 | std::vector<unsigned int> blockShape({2, 2}); |
| 152 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 153 | |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 154 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 155 | armnn::DataLayout::NHWC, inputShape, input, blockShape, |
| 156 | crops, outputShape, expectedOutput); |
| 157 | } |
| 158 | |
| 159 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 160 | LayerTestResult<T, 4> BatchToSpaceNdNhwcTest3( |
| 161 | armnn::IWorkloadFactory& workloadFactory, |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 162 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 163 | const armnn::ITensorHandleFactory& tensorHandleFactory) |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 164 | { |
| 165 | const unsigned int inputShape[] = {4, 1, 1, 3}; |
| 166 | const unsigned int outputShape[] = {1, 2, 2, 3}; |
| 167 | |
| 168 | std::vector<float> input({1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f}); |
| 169 | |
| 170 | std::vector<float> expectedOutput({1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f}); |
| 171 | |
| 172 | std::vector<unsigned int> blockShape({2, 2}); |
| 173 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 174 | |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 175 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 176 | armnn::DataLayout::NHWC, inputShape, input, blockShape, |
| 177 | crops, outputShape, expectedOutput); |
| 178 | } |
| 179 | |
| 180 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 181 | LayerTestResult<T, 4> BatchToSpaceNdNhwcTest4( |
| 182 | armnn::IWorkloadFactory& workloadFactory, |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 183 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 184 | const armnn::ITensorHandleFactory& tensorHandleFactory) |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 185 | { |
| 186 | const unsigned int inputShape[] = {8, 1, 3, 1}; |
| 187 | const unsigned int outputShape[] = {2, 2, 4, 1}; |
| 188 | |
| 189 | std::vector<float> input({ |
| 190 | 0.0f, 1.0f, 3.0f, |
| 191 | 0.0f, 9.0f, 11.0f, |
| 192 | 0.0f, 2.0f, 4.0f, |
| 193 | 0.0f, 10.0f, 12.0f, |
| 194 | 0.0f, 5.0f, 7.0f, |
| 195 | 0.0f, 13.0f, 15.0f, |
| 196 | 0.0f, 6.0f, 8.0f, |
| 197 | 0.0f, 14.0f, 16.0f |
| 198 | }); |
| 199 | |
| 200 | std::vector<float> expectedOutput({ |
| 201 | 1.0f, 2.0f, 3.0f, 4.0f, |
| 202 | 5.0f, 6.0f, 7.0f, 8.0f, |
| 203 | 9.0f, 10.0f, 11.0f, 12.0f, |
| 204 | 13.0f, 14.0f, 15.0f, 16.0f |
| 205 | }); |
| 206 | |
| 207 | std::vector<unsigned int> blockShape({2, 2}); |
| 208 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {2, 0}}; |
| 209 | |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 210 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 211 | armnn::DataLayout::NHWC, inputShape, input, blockShape, |
| 212 | crops, outputShape, expectedOutput); |
| 213 | } |
| 214 | |
| 215 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 216 | LayerTestResult<T, 4> BatchToSpaceNdNhwcTest5( |
| 217 | armnn::IWorkloadFactory& workloadFactory, |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 218 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 219 | const armnn::ITensorHandleFactory& tensorHandleFactory) |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 220 | { |
| 221 | const unsigned int inputShape[] = {4, 2, 2, 1}; |
| 222 | const unsigned int outputShape[] = {1, 4, 4, 1}; |
| 223 | |
| 224 | std::vector<float> input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}); |
| 225 | std::vector<float> expectedOutput({1, 5, 2, 6, 9, 13, 10, 14, 3, 7, 4, 8, 11, 15, 12, 16}); |
| 226 | |
| 227 | std::vector<unsigned int> blockShape({2, 2}); |
| 228 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 229 | |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 230 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory, |
| 231 | armnn::DataLayout::NHWC, inputShape, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 232 | input, blockShape, crops, outputShape, expectedOutput); |
| 233 | } |
| 234 | |
| 235 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 236 | LayerTestResult<T, 4> BatchToSpaceNdNhwcTest6( |
| 237 | armnn::IWorkloadFactory& workloadFactory, |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 238 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 239 | const armnn::ITensorHandleFactory& tensorHandleFactory) |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 240 | { |
| 241 | const unsigned int inputShape[] = {4, 1, 1, 1}; |
| 242 | const unsigned int outputShape[] = {1, 2, 2, 1}; |
| 243 | |
| 244 | std::vector<float> input({ |
| 245 | // Batch 0, Height 0, Width (2) x Channel (1) |
| 246 | 1, 2, 3, 4 |
| 247 | }); |
| 248 | |
| 249 | std::vector<float> expectedOutput({1, 2, 3, 4}); |
| 250 | |
| 251 | std::vector<unsigned int> blockShape({2, 2}); |
| 252 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 253 | |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 254 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 255 | armnn::DataLayout::NHWC, inputShape, input, blockShape, |
| 256 | crops, outputShape, expectedOutput); |
| 257 | } |
| 258 | |
| 259 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 260 | LayerTestResult<T, 4> BatchToSpaceNdNhwcTest7( |
| 261 | armnn::IWorkloadFactory& workloadFactory, |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 262 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 263 | const armnn::ITensorHandleFactory& tensorHandleFactory) |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 264 | { |
| 265 | const unsigned int inputShape[] = {4, 1, 1, 3}; |
| 266 | const unsigned int outputShape[] = {1, 2, 2, 3}; |
| 267 | |
| 268 | std::vector<float> input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}); |
| 269 | |
| 270 | std::vector<float> expectedOutput({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}); |
| 271 | |
| 272 | std::vector<unsigned int> blockShape({2, 2}); |
| 273 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 274 | |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 275 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 276 | armnn::DataLayout::NHWC, inputShape, input, blockShape, |
| 277 | crops, outputShape, expectedOutput); |
| 278 | } |
| 279 | |
| 280 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 281 | LayerTestResult<T, 4> BatchToSpaceNdNchwTest1( |
| 282 | armnn::IWorkloadFactory &workloadFactory, |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 283 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 284 | const armnn::ITensorHandleFactory& tensorHandleFactory) |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 285 | { |
| 286 | const unsigned int inputShape[] = {4, 3, 1, 1}; |
| 287 | const unsigned int outputShape[] = {1, 3, 2, 2}; |
| 288 | |
| 289 | std::vector<float> input({1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f}); |
| 290 | |
| 291 | std::vector<float> expectedOutput({ |
| 292 | // Batch 0, Channel 0, Height (2) x Width (2) |
| 293 | 1.0f, 4.0f, |
| 294 | 7.0f, 10.0f, |
| 295 | |
| 296 | // Batch 0, Channel 1, Height (2) x Width (2) |
| 297 | 2.0f, 5.0f, |
| 298 | 8.0f, 11.0f, |
| 299 | |
| 300 | // Batch 0, Channel 2, Height (2) x Width (2) |
| 301 | 3.0f, 6.0f, |
| 302 | 9.0f, 12.0f, |
| 303 | }); |
| 304 | |
| 305 | std::vector<unsigned int> blockShape({2, 2}); |
| 306 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 307 | |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 308 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 309 | armnn::DataLayout::NCHW, inputShape, input, blockShape, |
| 310 | crops, outputShape, expectedOutput); |
| 311 | } |
| 312 | |
| 313 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 314 | LayerTestResult<T, 4> BatchToSpaceNdNchwTest2( |
| 315 | armnn::IWorkloadFactory& workloadFactory, |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 316 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 317 | const armnn::ITensorHandleFactory& tensorHandleFactory) |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 318 | { |
| 319 | const unsigned int inputShape[] = {4, 1, 1, 1}; |
| 320 | const unsigned int outputShape[] = {1, 1, 2, 2}; |
| 321 | |
| 322 | std::vector<float> input({ |
| 323 | // Batch 0, Height 0, Width (2) x Channel (1) |
| 324 | 1.0f, 2.0f, 3.0f, 4.0f |
| 325 | }); |
| 326 | |
| 327 | std::vector<float> expectedOutput({1.0f, 2.0f, 3.0f, 4.0f}); |
| 328 | |
| 329 | std::vector<unsigned int> blockShape({2, 2}); |
| 330 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 331 | |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 332 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 333 | armnn::DataLayout::NCHW, inputShape, input, blockShape, |
| 334 | crops, outputShape, expectedOutput); |
| 335 | } |
| 336 | |
| 337 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 338 | LayerTestResult<T, 4> BatchToSpaceNdNchwTest3( |
| 339 | armnn::IWorkloadFactory& workloadFactory, |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 340 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 341 | const armnn::ITensorHandleFactory& tensorHandleFactory) |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 342 | { |
| 343 | const unsigned int inputShape[] = {4, 3, 1, 1}; |
| 344 | const unsigned int outputShape[] = {1, 3, 2, 2}; |
| 345 | |
| 346 | std::vector<float> input({1.0f, 3.0f, 5.0f, 7.0f, 9.0f, 11.0f, 2.0f, 4.0f, 6.0f, 8.0f, 10.0f, 12.0f}); |
| 347 | |
| 348 | std::vector<float> expectedOutput({ |
| 349 | // Batch 0, Channel 0, Height (2) x Width (2) |
| 350 | 1.0f, 7.0f, |
| 351 | 2.0f, 8.0f, |
| 352 | |
| 353 | // Batch 0, Channel 1, Height (2) x Width (2) |
| 354 | 3.0f, 9.0f, |
| 355 | 4.0f, 10.0f, |
| 356 | |
| 357 | // Batch 0, Channel 2, Height (2) x Width (2) |
| 358 | 5.0f, 11.0f, |
| 359 | 6.0f, 12.0f, |
| 360 | }); |
| 361 | |
| 362 | std::vector<unsigned int> blockShape({2, 2}); |
| 363 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 364 | |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 365 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 366 | armnn::DataLayout::NCHW, inputShape, input, blockShape, |
| 367 | crops, outputShape, expectedOutput); |
| 368 | } |
| 369 | |
| 370 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 371 | LayerTestResult<T, 4> BatchToSpaceNdNchwTest4( |
| 372 | armnn::IWorkloadFactory &workloadFactory, |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 373 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 374 | const armnn::ITensorHandleFactory& tensorHandleFactory) |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 375 | { |
| 376 | const unsigned int inputShape[] = {4, 3, 1, 1}; |
| 377 | const unsigned int outputShape[] = {1, 3, 2, 2}; |
| 378 | |
| 379 | std::vector<float> input({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}); |
| 380 | |
| 381 | std::vector<float> expectedOutput({ |
| 382 | // Batch 0, Channel 0, Height (2) x Width (2) |
| 383 | 1, 4, |
| 384 | 7, 10, |
| 385 | |
| 386 | // Batch 0, Channel 1, Height (2) x Width (2) |
| 387 | 2, 5, |
| 388 | 8, 11, |
| 389 | |
| 390 | // Batch 0, Channel 2, Height (2) x Width (2) |
| 391 | 3, 6, |
| 392 | 9, 12, |
| 393 | }); |
| 394 | |
| 395 | std::vector<unsigned int> blockShape({2, 2}); |
| 396 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 397 | |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 398 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 399 | armnn::DataLayout::NCHW, inputShape, input, blockShape, |
| 400 | crops, outputShape, expectedOutput); |
| 401 | } |
| 402 | |
| 403 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 404 | LayerTestResult<T, 4> BatchToSpaceNdNchwTest5( |
| 405 | armnn::IWorkloadFactory& workloadFactory, |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 406 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 407 | const armnn::ITensorHandleFactory& tensorHandleFactory) |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 408 | { |
| 409 | const unsigned int inputShape[] = {4, 1, 1, 1}; |
| 410 | const unsigned int outputShape[] = {1, 1, 2, 2}; |
| 411 | |
| 412 | std::vector<float> input({ |
| 413 | // Batch 0, Height 0, Width (2) x Channel (1) |
| 414 | 1, 2, 3, 4 |
| 415 | }); |
| 416 | |
| 417 | std::vector<float> expectedOutput({1, 2, 3, 4}); |
| 418 | |
| 419 | std::vector<unsigned int> blockShape({2, 2}); |
| 420 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 421 | |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 422 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 423 | armnn::DataLayout::NCHW, inputShape, input, blockShape, |
| 424 | crops, outputShape, expectedOutput); |
| 425 | } |
| 426 | |
| 427 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 428 | LayerTestResult<T, 4> BatchToSpaceNdNchwTest6( |
| 429 | armnn::IWorkloadFactory& workloadFactory, |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 430 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 431 | const armnn::ITensorHandleFactory& tensorHandleFactory) |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 432 | { |
| 433 | const unsigned int inputShape[] = {4, 3, 1, 1}; |
| 434 | const unsigned int outputShape[] = {1, 3, 2, 2}; |
| 435 | |
| 436 | std::vector<float> input({1, 3, 5, 7, 9, 11, 2, 4, 6, 8, 10, 12}); |
| 437 | |
| 438 | std::vector<float> expectedOutput({ |
| 439 | // Batch 0, Channel 0, Height (2) x Width (2) |
| 440 | 1, 7, |
| 441 | 2, 8, |
| 442 | |
| 443 | // Batch 0, Channel 1, Height (2) x Width (2) |
| 444 | 3, 9, |
| 445 | 4, 10, |
| 446 | |
| 447 | // Batch 0, Channel 2, Height (2) x Width (2) |
| 448 | 5, 11, |
| 449 | 6, 12, |
| 450 | }); |
| 451 | |
| 452 | std::vector<unsigned int> blockShape({2, 2}); |
| 453 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {0, 0}}; |
| 454 | |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 455 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 456 | armnn::DataLayout::NCHW, inputShape, input, blockShape, |
| 457 | crops, outputShape, expectedOutput); |
| 458 | } |
| 459 | |
| 460 | template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>> |
| 461 | LayerTestResult<T, 4> BatchToSpaceNdNchwTest7( |
| 462 | armnn::IWorkloadFactory& workloadFactory, |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 463 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 464 | const armnn::ITensorHandleFactory& tensorHandleFactory) |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 465 | { |
| 466 | const unsigned int inputShape[] = {8, 1, 1, 3}; |
| 467 | const unsigned int outputShape[] = {2, 1, 2, 4}; |
| 468 | |
| 469 | std::vector<float> input({ |
| 470 | 0, 1, 3, 0, 9, 11, |
| 471 | 0, 2, 4, 0, 10, 12, |
| 472 | 0, 5, 7, 0, 13, 15, |
| 473 | 0, 6, 8, 0, 14, 16 |
| 474 | }); |
| 475 | |
| 476 | std::vector<float> expectedOutput({ |
| 477 | 1, 2, 3, 4, |
| 478 | 5, 6, 7, 8, |
| 479 | 9, 10, 11, 12, |
| 480 | 13, 14, 15, 16 |
| 481 | }); |
| 482 | |
| 483 | std::vector<unsigned int> blockShape({2, 2}); |
| 484 | std::vector<std::pair<unsigned int, unsigned int>> crops = {{0, 0}, {2, 0}}; |
| 485 | |
Keith Davis | 33a626f | 2020-08-27 15:38:12 +0100 | [diff] [blame] | 486 | return BatchToSpaceNdHelper<ArmnnType, 4, 4>(workloadFactory, memoryManager, tensorHandleFactory, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 487 | armnn::DataLayout::NCHW, inputShape, input, blockShape, |
| 488 | crops, outputShape, expectedOutput); |
| 489 | } |