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