Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "PadTestImpl.hpp" |
| 7 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 8 | #include <QuantizeHelper.hpp> |
| 9 | |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 10 | #include <backendsCommon/test/TensorCopyUtils.hpp> |
| 11 | #include <backendsCommon/test/WorkloadTestUtils.hpp> |
| 12 | |
| 13 | #include <test/TensorHelpers.hpp> |
| 14 | |
| 15 | // |
| 16 | // Implementation templates |
| 17 | // |
| 18 | |
| 19 | template<armnn::DataType ArmnnType, typename T> |
| 20 | LayerTestResult<T, 2> Pad2dTestCommon( |
| 21 | armnn::IWorkloadFactory& workloadFactory, |
| 22 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 23 | float qScale, |
| 24 | int32_t qOffset, |
| 25 | const float customPaddingValue) |
| 26 | { |
| 27 | const armnn::TensorShape inputShape{ 3, 3 }; |
| 28 | const armnn::TensorShape outputShape{ 7, 7 }; |
| 29 | |
| 30 | const armnn::TensorInfo inputTensorInfo(inputShape, ArmnnType, qScale, qOffset); |
| 31 | const armnn::TensorInfo outputTensorInfo(outputShape, ArmnnType, qScale, qOffset); |
| 32 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 33 | std::vector<T> inputValues = armnnUtils::QuantizedVector<T>( |
| 34 | { |
| 35 | // Height (3) x Width (3) |
| 36 | 4, 8, 6, |
| 37 | 7, 4, 4, |
| 38 | 3, 2, 4 |
| 39 | }, |
| 40 | qScale, qOffset); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 41 | |
| 42 | auto p = customPaddingValue; |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 43 | std::vector<T> expectedOutputValues = armnnUtils::QuantizedVector<T>( |
| 44 | { |
| 45 | p, p, p, p, p, p, p, |
| 46 | p, p, p, p, p, p, p, |
| 47 | p, p, 4, 8, 6, p, p, |
| 48 | p, p, 7, 4, 4, p, p, |
| 49 | p, p, 3, 2, 4, p, p, |
| 50 | p, p, p, p, p, p, p, |
| 51 | p, p, p, p, p, p, p |
| 52 | }, |
| 53 | qScale, qOffset); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 54 | |
| 55 | auto inputTensor = MakeTensor<T, 2>(inputTensorInfo, std::vector<T>(inputValues)); |
| 56 | |
| 57 | LayerTestResult<T, 2> result(outputTensorInfo); |
| 58 | result.outputExpected = MakeTensor<T, 2>(outputTensorInfo, std::vector<T>(expectedOutputValues)); |
| 59 | |
| 60 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 61 | std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); |
| 62 | |
| 63 | armnn::PadQueueDescriptor descriptor; |
| 64 | |
| 65 | std::vector<std::pair<unsigned int, unsigned int>> padList; |
| 66 | padList.push_back(std::pair<unsigned int, unsigned int>(2,2)); |
| 67 | padList.push_back(std::pair<unsigned int, unsigned int>(2,2)); |
| 68 | |
| 69 | descriptor.m_Parameters.m_PadList = padList; |
| 70 | descriptor.m_Parameters.m_PadValue = customPaddingValue; |
| 71 | armnn::WorkloadInfo info; |
| 72 | |
| 73 | AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get()); |
| 74 | AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get()); |
| 75 | |
| 76 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreatePad(descriptor, info); |
| 77 | |
| 78 | inputHandle->Allocate(); |
| 79 | outputHandle->Allocate(); |
| 80 | |
| 81 | CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0]); |
| 82 | |
| 83 | workload->PostAllocationConfigure(); |
| 84 | workload->Execute(); |
| 85 | |
| 86 | CopyDataFromITensorHandle(&result.output[0][0], outputHandle.get()); |
| 87 | |
| 88 | return result; |
| 89 | } |
| 90 | |
| 91 | template<armnn::DataType ArmnnType, typename T> |
| 92 | LayerTestResult<T, 3> Pad3dTestCommon( |
| 93 | armnn::IWorkloadFactory& workloadFactory, |
| 94 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 95 | float qScale, |
| 96 | int32_t qOffset) |
| 97 | { |
| 98 | const armnn::TensorShape inputShape{ 2, 2, 2 }; |
| 99 | const armnn::TensorShape outputShape{ 3, 5, 6 }; |
| 100 | |
| 101 | const armnn::TensorInfo inputTensorInfo(inputShape, ArmnnType, qScale, qOffset); |
| 102 | const armnn::TensorInfo outputTensorInfo(outputShape, ArmnnType, qScale, qOffset); |
| 103 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 104 | std::vector<T> inputValues = armnnUtils::QuantizedVector<T>( |
| 105 | { |
| 106 | // Channel 0, Height (2) x Width (2) |
| 107 | 0, 4, |
| 108 | 2, 5, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 109 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 110 | // Channel 1, Height (2) x Width (2) |
| 111 | 6, 1, |
| 112 | 5, 2 |
| 113 | }, |
| 114 | qScale, qOffset); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 115 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 116 | std::vector<T> expectedOutputValues = armnnUtils::QuantizedVector<T>( |
| 117 | { |
| 118 | 0, 0, 0, 0, 0, 0, |
| 119 | 0, 0, 0, 0, 0, 0, |
| 120 | 0, 0, 0, 4, 0, 0, |
| 121 | 0, 0, 2, 5, 0, 0, |
| 122 | 0, 0, 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 123 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 124 | 0, 0, 0, 0, 0, 0, |
| 125 | 0, 0, 0, 0, 0, 0, |
| 126 | 0, 0, 6, 1, 0, 0, |
| 127 | 0, 0, 5, 2, 0, 0, |
| 128 | 0, 0, 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 129 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 130 | 0, 0, 0, 0, 0, 0, |
| 131 | 0, 0, 0, 0, 0, 0, |
| 132 | 0, 0, 0, 0, 0, 0, |
| 133 | 0, 0, 0, 0, 0, 0, |
| 134 | 0, 0, 0, 0, 0, 0 |
| 135 | }, |
| 136 | qScale, qOffset); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 137 | |
| 138 | auto inputTensor = MakeTensor<T, 3>(inputTensorInfo, std::vector<T>(inputValues)); |
| 139 | |
| 140 | LayerTestResult<T, 3> result(outputTensorInfo); |
| 141 | result.outputExpected = MakeTensor<T, 3>(outputTensorInfo, std::vector<T>(expectedOutputValues)); |
| 142 | |
| 143 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 144 | std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); |
| 145 | |
| 146 | armnn::PadQueueDescriptor descriptor; |
| 147 | |
| 148 | std::vector<std::pair<unsigned int, unsigned int>> PadList; |
| 149 | PadList.push_back(std::pair<unsigned int, unsigned int>(0,1)); |
| 150 | PadList.push_back(std::pair<unsigned int, unsigned int>(2,1)); |
| 151 | PadList.push_back(std::pair<unsigned int, unsigned int>(2,2)); |
| 152 | |
| 153 | descriptor.m_Parameters.m_PadList = PadList; |
| 154 | armnn::WorkloadInfo info; |
| 155 | |
| 156 | AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get()); |
| 157 | AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get()); |
| 158 | |
| 159 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreatePad(descriptor, info); |
| 160 | |
| 161 | inputHandle->Allocate(); |
| 162 | outputHandle->Allocate(); |
| 163 | |
| 164 | CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0][0]); |
| 165 | |
| 166 | workload->PostAllocationConfigure(); |
| 167 | workload->Execute(); |
| 168 | |
| 169 | CopyDataFromITensorHandle(&result.output[0][0][0], outputHandle.get()); |
| 170 | |
| 171 | return result; |
| 172 | } |
| 173 | |
| 174 | template<armnn::DataType ArmnnType, typename T> |
| 175 | LayerTestResult<T, 4> Pad4dTestCommon( |
| 176 | armnn::IWorkloadFactory& workloadFactory, |
| 177 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 178 | float qScale, |
| 179 | int32_t qOffset) |
| 180 | { |
| 181 | const armnn::TensorShape inputShape{ 2, 2, 3, 2 }; |
| 182 | const armnn::TensorShape outputShape{ 4, 5, 7, 4 }; |
| 183 | |
| 184 | const armnn::TensorInfo inputTensorInfo(inputShape, ArmnnType, qScale, qOffset); |
| 185 | const armnn::TensorInfo outputTensorInfo(outputShape, ArmnnType, qScale, qOffset); |
| 186 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 187 | std::vector<T> inputValues = armnnUtils::QuantizedVector<T>( |
| 188 | { |
| 189 | // Batch 0, Channel 0, Height (3) x Width (2) |
| 190 | 0, 1, |
| 191 | 2, 3, |
| 192 | 4, 5, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 193 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 194 | // Batch 0, Channel 1, Height (3) x Width (2) |
| 195 | 6, 7, |
| 196 | 8, 9, |
| 197 | 10, 11, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 198 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 199 | // Batch 1, Channel 0, Height (3) x Width (2) |
| 200 | 12, 13, |
| 201 | 14, 15, |
| 202 | 16, 17, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 203 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 204 | // Batch 1, Channel 1, Height (3) x Width (2) |
| 205 | 18, 19, |
| 206 | 20, 21, |
| 207 | 22, 23 |
| 208 | }, |
| 209 | qScale, qOffset); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 210 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 211 | std::vector<T> expectedOutputValues = armnnUtils::QuantizedVector<T>( |
| 212 | { |
| 213 | 0, 0, 0, 0, |
| 214 | 0, 0, 0, 0, |
| 215 | 0, 0, 0, 0, |
| 216 | 0, 0, 0, 0, |
| 217 | 0, 0, 0, 0, |
| 218 | 0, 0, 0, 0, |
| 219 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 220 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 221 | 0, 0, 0, 0, |
| 222 | 0, 0, 0, 0, |
| 223 | 0, 0, 0, 0, |
| 224 | 0, 0, 0, 0, |
| 225 | 0, 0, 0, 0, |
| 226 | 0, 0, 0, 0, |
| 227 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 228 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 229 | 0, 0, 0, 0, |
| 230 | 0, 0, 0, 0, |
| 231 | 0, 0, 0, 0, |
| 232 | 0, 0, 0, 0, |
| 233 | 0, 0, 0, 0, |
| 234 | 0, 0, 0, 0, |
| 235 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 236 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 237 | 0, 0, 0, 0, |
| 238 | 0, 0, 0, 0, |
| 239 | 0, 0, 0, 0, |
| 240 | 0, 0, 0, 0, |
| 241 | 0, 0, 0, 0, |
| 242 | 0, 0, 0, 0, |
| 243 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 244 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 245 | 0, 0, 0, 0, |
| 246 | 0, 0, 0, 0, |
| 247 | 0, 0, 0, 0, |
| 248 | 0, 0, 0, 0, |
| 249 | 0, 0, 0, 0, |
| 250 | 0, 0, 0, 0, |
| 251 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 252 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 253 | 0, 0, 0, 0, |
| 254 | 0, 0, 0, 0, |
| 255 | 0, 0, 0, 0, |
| 256 | 0, 0, 0, 0, |
| 257 | 0, 0, 0, 0, |
| 258 | 0, 0, 0, 0, |
| 259 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 260 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 261 | 0, 0, 0, 0, |
| 262 | 0, 0, 0, 0, |
| 263 | 0, 0, 0, 0, |
| 264 | 0, 0, 0, 0, |
| 265 | 0, 0, 0, 0, |
| 266 | 0, 0, 0, 0, |
| 267 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 268 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 269 | 0, 0, 0, 0, |
| 270 | 0, 0, 0, 0, |
| 271 | 0, 0, 0, 0, |
| 272 | 0, 0, 1, 0, |
| 273 | 0, 2, 3, 0, |
| 274 | 0, 4, 5, 0, |
| 275 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 276 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 277 | 0, 0, 0, 0, |
| 278 | 0, 0, 0, 0, |
| 279 | 0, 0, 0, 0, |
| 280 | 0, 6, 7, 0, |
| 281 | 0, 8, 9, 0, |
| 282 | 0, 10, 11, 0, |
| 283 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 284 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 285 | 0, 0, 0, 0, |
| 286 | 0, 0, 0, 0, |
| 287 | 0, 0, 0, 0, |
| 288 | 0, 0, 0, 0, |
| 289 | 0, 0, 0, 0, |
| 290 | 0, 0, 0, 0, |
| 291 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 292 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 293 | 0, 0, 0, 0, |
| 294 | 0, 0, 0, 0, |
| 295 | 0, 0, 0, 0, |
| 296 | 0, 0, 0, 0, |
| 297 | 0, 0, 0, 0, |
| 298 | 0, 0, 0, 0, |
| 299 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 300 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 301 | 0, 0, 0, 0, |
| 302 | 0, 0, 0, 0, |
| 303 | 0, 0, 0, 0, |
| 304 | 0, 0, 0, 0, |
| 305 | 0, 0, 0, 0, |
| 306 | 0, 0, 0, 0, |
| 307 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 308 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 309 | 0, 0, 0, 0, |
| 310 | 0, 0, 0, 0, |
| 311 | 0, 0, 0, 0, |
| 312 | 0, 12, 13, 0, |
| 313 | 0, 14, 15, 0, |
| 314 | 0, 16, 17, 0, |
| 315 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 316 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 317 | 0, 0, 0, 0, |
| 318 | 0, 0, 0, 0, |
| 319 | 0, 0, 0, 0, |
| 320 | 0, 18, 19, 0, |
| 321 | 0, 20, 21, 0, |
| 322 | 0, 22, 23, 0, |
| 323 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 324 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 325 | 0, 0, 0, 0, |
| 326 | 0, 0, 0, 0, |
| 327 | 0, 0, 0, 0, |
| 328 | 0, 0, 0, 0, |
| 329 | 0, 0, 0, 0, |
| 330 | 0, 0, 0, 0, |
| 331 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 332 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 333 | 0, 0, 0, 0, |
| 334 | 0, 0, 0, 0, |
| 335 | 0, 0, 0, 0, |
| 336 | 0, 0, 0, 0, |
| 337 | 0, 0, 0, 0, |
| 338 | 0, 0, 0, 0, |
| 339 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 340 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 341 | 0, 0, 0, 0, |
| 342 | 0, 0, 0, 0, |
| 343 | 0, 0, 0, 0, |
| 344 | 0, 0, 0, 0, |
| 345 | 0, 0, 0, 0, |
| 346 | 0, 0, 0, 0, |
| 347 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 348 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 349 | 0, 0, 0, 0, |
| 350 | 0, 0, 0, 0, |
| 351 | 0, 0, 0, 0, |
| 352 | 0, 0, 0, 0, |
| 353 | 0, 0, 0, 0, |
| 354 | 0, 0, 0, 0, |
| 355 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 356 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 357 | 0, 0, 0, 0, |
| 358 | 0, 0, 0, 0, |
| 359 | 0, 0, 0, 0, |
| 360 | 0, 0, 0, 0, |
| 361 | 0, 0, 0, 0, |
| 362 | 0, 0, 0, 0, |
| 363 | 0, 0, 0, 0, |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 364 | |
Aron Virginas-Tar | 48623a0 | 2019-10-22 10:00:28 +0100 | [diff] [blame] | 365 | 0, 0, 0, 0, |
| 366 | 0, 0, 0, 0, |
| 367 | 0, 0, 0, 0, |
| 368 | 0, 0, 0, 0, |
| 369 | 0, 0, 0, 0, |
| 370 | 0, 0, 0, 0, |
| 371 | 0, 0, 0, 0 |
| 372 | }, |
| 373 | qScale, qOffset); |
Aron Virginas-Tar | 00d306e | 2019-08-28 18:08:46 +0100 | [diff] [blame] | 374 | |
| 375 | auto inputTensor = MakeTensor<T, 4>(inputTensorInfo, std::vector<T>(inputValues)); |
| 376 | |
| 377 | LayerTestResult<T, 4> result(outputTensorInfo); |
| 378 | result.outputExpected = MakeTensor<T, 4>(outputTensorInfo, std::vector<T>(expectedOutputValues)); |
| 379 | |
| 380 | std::unique_ptr<armnn::ITensorHandle> inputHandle = workloadFactory.CreateTensorHandle(inputTensorInfo); |
| 381 | std::unique_ptr<armnn::ITensorHandle> outputHandle = workloadFactory.CreateTensorHandle(outputTensorInfo); |
| 382 | |
| 383 | armnn::PadQueueDescriptor descriptor; |
| 384 | |
| 385 | std::vector<std::pair<unsigned int, unsigned int>> PadList; |
| 386 | PadList.push_back(std::pair<unsigned int, unsigned int>(1,1)); |
| 387 | PadList.push_back(std::pair<unsigned int, unsigned int>(2,1)); |
| 388 | PadList.push_back(std::pair<unsigned int, unsigned int>(3,1)); |
| 389 | PadList.push_back(std::pair<unsigned int, unsigned int>(1,1)); |
| 390 | |
| 391 | descriptor.m_Parameters.m_PadList = PadList; |
| 392 | armnn::WorkloadInfo info; |
| 393 | |
| 394 | AddInputToWorkload(descriptor, info, inputTensorInfo, inputHandle.get()); |
| 395 | AddOutputToWorkload(descriptor, info, outputTensorInfo, outputHandle.get()); |
| 396 | |
| 397 | std::unique_ptr<armnn::IWorkload> workload = workloadFactory.CreatePad(descriptor, info); |
| 398 | |
| 399 | inputHandle->Allocate(); |
| 400 | outputHandle->Allocate(); |
| 401 | |
| 402 | CopyDataToITensorHandle(inputHandle.get(), &inputTensor[0][0][0][0]); |
| 403 | |
| 404 | workload->PostAllocationConfigure(); |
| 405 | workload->Execute(); |
| 406 | |
| 407 | CopyDataFromITensorHandle(&result.output[0][0][0][0], outputHandle.get()); |
| 408 | |
| 409 | return result; |
| 410 | } |
| 411 | |
| 412 | // |
| 413 | // Explicit template specializations |
| 414 | // |
| 415 | |
| 416 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedSymm16>, 2> |
| 417 | Pad2dTestCommon<armnn::DataType::QuantisedSymm16>( |
| 418 | armnn::IWorkloadFactory& workloadFactory, |
| 419 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 420 | float qScale, |
| 421 | int32_t qOffset, |
| 422 | const float customPaddingValue); |
| 423 | |
| 424 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedSymm16>, 3> |
| 425 | Pad3dTestCommon<armnn::DataType::QuantisedSymm16>( |
| 426 | armnn::IWorkloadFactory& workloadFactory, |
| 427 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 428 | float qScale, |
| 429 | int32_t qOffset); |
| 430 | |
| 431 | template LayerTestResult<armnn::ResolveType<armnn::DataType::QuantisedSymm16>, 4> |
| 432 | Pad4dTestCommon<armnn::DataType::QuantisedSymm16>( |
| 433 | armnn::IWorkloadFactory& workloadFactory, |
| 434 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager, |
| 435 | float qScale, |
| 436 | int32_t qOffset); |
| 437 | |
| 438 | // |
| 439 | // Implementation functions |
| 440 | // |
| 441 | |
| 442 | LayerTestResult<uint8_t, 2> PadUint82dTest( |
| 443 | armnn::IWorkloadFactory& workloadFactory, |
| 444 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 445 | { |
| 446 | return Pad2dTestCommon<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager, 1.0f, 0); |
| 447 | } |
| 448 | |
| 449 | LayerTestResult<uint8_t, 2> PadUint82dCustomPaddingTest( |
| 450 | armnn::IWorkloadFactory& workloadFactory, |
| 451 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 452 | { |
| 453 | return Pad2dTestCommon<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager, 1.0f, 0, 1.0f); |
| 454 | } |
| 455 | |
| 456 | LayerTestResult<uint8_t, 3> PadUint83dTest( |
| 457 | armnn::IWorkloadFactory& workloadFactory, |
| 458 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 459 | { |
| 460 | return Pad3dTestCommon<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager, 1.0f, 0); |
| 461 | } |
| 462 | |
| 463 | LayerTestResult<uint8_t, 4> PadUint84dTest( |
| 464 | armnn::IWorkloadFactory& workloadFactory, |
| 465 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 466 | { |
| 467 | return Pad4dTestCommon<armnn::DataType::QuantisedAsymm8>(workloadFactory, memoryManager, 1.0f, 0); |
| 468 | } |
| 469 | |
| 470 | LayerTestResult<float, 2> PadFloat322dTest( |
| 471 | armnn::IWorkloadFactory& workloadFactory, |
| 472 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 473 | { |
| 474 | return Pad2dTestCommon<armnn::DataType::Float32>(workloadFactory, memoryManager, 0.0f, 0); |
| 475 | } |
| 476 | |
| 477 | LayerTestResult<float, 2> PadFloat322dCustomPaddingTest( |
| 478 | armnn::IWorkloadFactory& workloadFactory, |
| 479 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 480 | { |
| 481 | return Pad2dTestCommon<armnn::DataType::Float32>(workloadFactory, memoryManager, 0.0f, 0, 1.0f); |
| 482 | } |
| 483 | |
| 484 | LayerTestResult<float, 3> PadFloat323dTest( |
| 485 | armnn::IWorkloadFactory& workloadFactory, |
| 486 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 487 | { |
| 488 | return Pad3dTestCommon<armnn::DataType::Float32>(workloadFactory, memoryManager, 0.0f, 0); |
| 489 | } |
| 490 | |
| 491 | LayerTestResult<float, 4> PadFloat324dTest( |
| 492 | armnn::IWorkloadFactory& workloadFactory, |
| 493 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 494 | { |
| 495 | return Pad4dTestCommon<armnn::DataType::Float32>(workloadFactory, memoryManager, 0.0f, 0); |
| 496 | } |