Aron Virginas-Tar | e89ebad | 2019-08-27 18:14:26 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "DivisionTestImpl.hpp" |
| 7 | |
| 8 | #include "ElementwiseTestImpl.hpp" |
| 9 | |
| 10 | template<> |
| 11 | std::unique_ptr<armnn::IWorkload> CreateWorkload<armnn::DivisionQueueDescriptor>( |
| 12 | const armnn::IWorkloadFactory& workloadFactory, |
| 13 | const armnn::WorkloadInfo& info, |
| 14 | const armnn::DivisionQueueDescriptor& descriptor) |
| 15 | { |
| 16 | return workloadFactory.CreateDivision(descriptor, info); |
| 17 | } |
| 18 | |
| 19 | LayerTestResult<float, 4> DivisionByZeroTest( |
| 20 | armnn::IWorkloadFactory& workloadFactory, |
| 21 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 22 | { |
| 23 | const unsigned int width = 2u; |
| 24 | const unsigned int height = 2u; |
| 25 | const unsigned int channelCount = 2u; |
| 26 | const unsigned int batchSize = 2u; |
| 27 | |
| 28 | unsigned int shape[] = { batchSize, channelCount, height, width }; |
| 29 | |
| 30 | std::vector<float> input0 = |
| 31 | { |
| 32 | 1.f, 1.f, 1.f, 1.f, 0.f, 0.f, 0.f, 0.f, |
| 33 | -1.f, -1.f, -1.f, -1.f, 5.f, 5.f, 5.f, 5.f |
| 34 | }; |
| 35 | |
| 36 | std::vector<float> input1 = |
| 37 | { |
| 38 | 0.f, 0.f, -0.f, -0.f, 0.f, 0.f, -0.f, -0.f, |
| 39 | 0.f, 0.f, -0.f, -0.f, 5.f, 5.f, 5.f, 5.f |
| 40 | }; |
| 41 | |
| 42 | std::vector<float> output = |
| 43 | { |
| 44 | INFINITY, INFINITY, -INFINITY, -INFINITY, NAN, NAN, -NAN, -NAN, |
| 45 | -INFINITY, -INFINITY, INFINITY, INFINITY, 1, 1, 1, 1 |
| 46 | }; |
| 47 | |
| 48 | return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::Float32>( |
| 49 | workloadFactory, |
| 50 | memoryManager, |
| 51 | shape, |
| 52 | input0, |
| 53 | shape, |
| 54 | input1, |
| 55 | shape, |
| 56 | output); |
| 57 | } |
| 58 | |
| 59 | LayerTestResult<float, 4> DivisionTest( |
| 60 | armnn::IWorkloadFactory& workloadFactory, |
| 61 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 62 | { |
| 63 | const unsigned int width = 2u; |
| 64 | const unsigned int height = 2u; |
| 65 | const unsigned int channelCount = 2u; |
| 66 | const unsigned int batchSize = 2u; |
| 67 | |
| 68 | unsigned int shape[] = { batchSize, channelCount, height, width }; |
| 69 | |
| 70 | std::vector<float> input0 = |
| 71 | { |
| 72 | 2.f, 2.f, 2.f, 2.f, 3.f, 3.f, 3.f, 3.f, |
| 73 | 4.f, 4.f, 4.f, 4.f, 5.f, 5.f, 5.f, 5.f |
| 74 | }; |
| 75 | |
| 76 | std::vector<float> input1 = |
| 77 | { |
| 78 | 1.f, 1.f, 1.f, 1.f, 2.f, 2.f, 2.f, 2.f, |
| 79 | 4.f, 4.f, 4.f, 4.f, 4.f, 4.f, 4.f, 4.f |
| 80 | }; |
| 81 | |
| 82 | std::vector<float> output = |
| 83 | { |
| 84 | 2.f, 2.f, 2.f, 2.f, 1.50f, 1.50f, 1.50f, 1.50f, |
| 85 | 1.f, 1.f, 1.f, 1.f, 1.25f, 1.25f, 1.25f, 1.25f |
| 86 | }; |
| 87 | |
| 88 | return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::Float32>( |
| 89 | workloadFactory, |
| 90 | memoryManager, |
| 91 | shape, |
| 92 | input0, |
| 93 | shape, |
| 94 | input1, |
| 95 | shape, |
| 96 | output); |
| 97 | } |
| 98 | |
| 99 | LayerTestResult<float, 4> DivisionBroadcast1ElementTest( |
| 100 | armnn::IWorkloadFactory& workloadFactory, |
| 101 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 102 | { |
| 103 | unsigned int shape0[] = { 1, 2, 2, 2 }; |
| 104 | unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 105 | |
| 106 | std::vector<float> input0({ 2, 4, 6, 8, 10, 12, 14, 16}); |
| 107 | |
| 108 | std::vector<float> input1({ 2 }); |
| 109 | |
| 110 | std::vector<float> output({ 1, 2, 3, 4, 5, 6, 7, 8}); |
| 111 | |
| 112 | return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::Float32>( |
| 113 | workloadFactory, |
| 114 | memoryManager, |
| 115 | shape0, |
| 116 | input0, |
| 117 | shape1, |
| 118 | input1, |
| 119 | shape0, |
| 120 | output); |
| 121 | } |
| 122 | |
| 123 | LayerTestResult<float, 4> DivisionBroadcast1DVectorTest( |
| 124 | armnn::IWorkloadFactory& workloadFactory, |
| 125 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 126 | { |
| 127 | unsigned int shape0[] = { 1, 3, 3, 2 }; |
| 128 | unsigned int shape1[] = { 1, 1, 1, 2 }; |
| 129 | |
| 130 | std::vector<float> input0 = |
| 131 | { |
| 132 | 1.f, 4.f, 3.f, 8.f, 5.f, 12.f, |
| 133 | 7.f, 16.f, 9.f, 20.f, 11.f, 24.f, |
| 134 | 13.f, 28.f, 15.f, 32.f, 17.f, 36.f |
| 135 | }; |
| 136 | |
| 137 | std::vector<float> input1 = { 1.f, 2.f }; |
| 138 | |
| 139 | std::vector<float> output = |
| 140 | { |
| 141 | 1.f, 2.f, 3.f, 4.f, 5.f, 6.f, |
| 142 | 7.f, 8.f, 9.f, 10.f, 11.f, 12.f, |
| 143 | 13.f, 14.f, 15.f, 16.f, 17.f, 18.f |
| 144 | }; |
| 145 | |
| 146 | return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::Float32>( |
| 147 | workloadFactory, |
| 148 | memoryManager, |
| 149 | shape0, |
| 150 | input0, |
| 151 | shape1, |
| 152 | input1, |
| 153 | shape0, |
| 154 | output); |
| 155 | } |
| 156 | |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 157 | LayerTestResult<armnn::Half, 4> DivisionFloat16Test( |
| 158 | armnn::IWorkloadFactory& workloadFactory, |
| 159 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 160 | { |
| 161 | using namespace half_float::literal; |
| 162 | |
| 163 | const unsigned int width = 2u; |
| 164 | const unsigned int height = 2u; |
| 165 | const unsigned int channelCount = 2u; |
| 166 | const unsigned int batchSize = 2u; |
| 167 | |
| 168 | unsigned int shape[] = { batchSize, channelCount, height, width }; |
| 169 | |
| 170 | std::vector<armnn::Half> input0 = |
| 171 | { |
| 172 | 2._h, 2._h, 2._h, 2._h, 3._h, 3._h, 3._h, 3._h, |
| 173 | 4._h, 4._h, 4._h, 4._h, 5._h, 5._h, 5._h, 5._h |
| 174 | }; |
| 175 | |
| 176 | std::vector<armnn::Half> input1 = |
| 177 | { |
| 178 | 1._h, 1._h, 1._h, 1._h, 2._h, 2._h, 2._h, 2._h, |
| 179 | 4._h, 4._h, 4._h, 4._h, 4._h, 4._h, 4._h, 4._h |
| 180 | }; |
| 181 | |
| 182 | std::vector<armnn::Half> output = |
| 183 | { |
| 184 | 2._h, 2._h, 2._h, 2._h, 1.50_h, 1.50_h, 1.50_h, 1.50_h, |
| 185 | 1._h, 1._h, 1._h, 1._h, 1.25_h, 1.25_h, 1.25_h, 1.25_h |
| 186 | }; |
| 187 | |
| 188 | return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::Float16>( |
| 189 | workloadFactory, |
| 190 | memoryManager, |
| 191 | shape, |
| 192 | input0, |
| 193 | shape, |
| 194 | input1, |
| 195 | shape, |
| 196 | output); |
| 197 | } |
| 198 | |
| 199 | LayerTestResult<armnn::Half, 4> DivisionBroadcast1ElementFloat16Test( |
| 200 | armnn::IWorkloadFactory& workloadFactory, |
| 201 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 202 | { |
| 203 | using namespace half_float::literal; |
| 204 | |
| 205 | unsigned int shape0[] = { 1, 2, 2, 2 }; |
| 206 | unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 207 | |
| 208 | std::vector<armnn::Half> input0({ 2._h, 4._h, 6._h, 8._h, 10._h, 12._h, 14._h, 16._h}); |
| 209 | |
| 210 | std::vector<armnn::Half> input1({ 2._h }); |
| 211 | |
| 212 | std::vector<armnn::Half> output({ 1._h, 2._h, 3._h, 4._h, 5._h, 6._h, 7._h, 8._h}); |
| 213 | |
| 214 | return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::Float16>( |
| 215 | workloadFactory, |
| 216 | memoryManager, |
| 217 | shape0, |
| 218 | input0, |
| 219 | shape1, |
| 220 | input1, |
| 221 | shape0, |
| 222 | output); |
| 223 | } |
| 224 | |
| 225 | LayerTestResult<armnn::Half, 4> DivisionBroadcast1DVectorFloat16Test( |
| 226 | armnn::IWorkloadFactory& workloadFactory, |
| 227 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 228 | { |
| 229 | using namespace half_float::literal; |
| 230 | |
| 231 | unsigned int shape0[] = { 1, 3, 3, 2 }; |
| 232 | unsigned int shape1[] = { 1, 1, 1, 2 }; |
| 233 | |
| 234 | std::vector<armnn::Half> input0 = |
| 235 | { |
| 236 | 1._h, 4._h, 3._h, 8._h, 5._h, 12._h, |
| 237 | 7._h, 16._h, 9._h, 20._h, 11._h, 24._h, |
| 238 | 13._h, 28._h, 15._h, 32._h, 17._h, 36._h |
| 239 | }; |
| 240 | |
| 241 | std::vector<armnn::Half> input1 = { 1._h, 2._h }; |
| 242 | |
| 243 | std::vector<armnn::Half> output = |
| 244 | { |
| 245 | 1._h, 2._h, 3._h, 4._h, 5._h, 6._h, |
| 246 | 7._h, 8._h, 9._h, 10._h, 11._h, 12._h, |
| 247 | 13._h, 14._h, 15._h, 16._h, 17._h, 18._h |
| 248 | }; |
| 249 | |
| 250 | return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::Float16>( |
| 251 | workloadFactory, |
| 252 | memoryManager, |
| 253 | shape0, |
| 254 | input0, |
| 255 | shape1, |
| 256 | input1, |
| 257 | shape0, |
| 258 | output); |
| 259 | } |
| 260 | |
Aron Virginas-Tar | e89ebad | 2019-08-27 18:14:26 +0100 | [diff] [blame] | 261 | LayerTestResult<uint8_t, 4> DivisionUint8Test( |
| 262 | armnn::IWorkloadFactory& workloadFactory, |
| 263 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 264 | { |
| 265 | const unsigned int width = 2u; |
| 266 | const unsigned int height = 2u; |
| 267 | const unsigned int channelCount = 2u; |
| 268 | const unsigned int batchSize = 2u; |
| 269 | |
| 270 | unsigned int shape[] = { batchSize, channelCount, height, width }; |
| 271 | |
| 272 | std::vector<uint8_t> input0 = |
| 273 | { |
| 274 | 2, 2, 2, 2, 3, 3, 3, 3, |
| 275 | 4, 4, 4, 4, 5, 5, 5, 5 |
| 276 | }; |
| 277 | |
| 278 | std::vector<uint8_t> input1 = |
| 279 | { |
| 280 | 1, 1, 1, 1, 2, 2, 2, 2, |
| 281 | 4, 4, 4, 4, 4, 4, 4, 4 |
| 282 | }; |
| 283 | |
| 284 | std::vector<uint8_t> output = |
| 285 | { |
| 286 | 8, 8, 8, 8, 6, 6, 6, 6, |
| 287 | 4, 4, 4, 4, 5, 5, 5, 5 |
| 288 | }; |
| 289 | |
| 290 | return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::QuantisedAsymm8>( |
| 291 | workloadFactory, |
| 292 | memoryManager, |
| 293 | shape, |
| 294 | input0, |
| 295 | shape, |
| 296 | input1, |
| 297 | shape, |
| 298 | output, |
| 299 | 0.25f, |
| 300 | 0); |
| 301 | } |
| 302 | |
| 303 | LayerTestResult<uint8_t, 4> DivisionBroadcast1ElementUint8Test( |
| 304 | armnn::IWorkloadFactory& workloadFactory, |
| 305 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 306 | { |
| 307 | unsigned int shape0[] = { 1, 2, 2, 2 }; |
| 308 | unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 309 | |
| 310 | std::vector<uint8_t> input0 = { 2, 4, 6, 8, 10, 12, 14, 16}; |
| 311 | |
| 312 | std::vector<uint8_t> input1 = { 2 }; |
| 313 | |
| 314 | std::vector<uint8_t> output = { 1, 2, 3, 4, 5, 6, 7, 8}; |
| 315 | |
| 316 | return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::QuantisedAsymm8>( |
| 317 | workloadFactory, |
| 318 | memoryManager, |
| 319 | shape0, |
| 320 | input0, |
| 321 | shape1, |
| 322 | input1, |
| 323 | shape0, |
| 324 | output); |
| 325 | } |
| 326 | |
| 327 | LayerTestResult<uint8_t, 4> DivisionBroadcast1DVectorUint8Test( |
| 328 | armnn::IWorkloadFactory& workloadFactory, |
| 329 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 330 | { |
| 331 | unsigned int shape0[] = { 1, 3, 3, 2 }; |
| 332 | unsigned int shape1[] = { 1, 1, 1, 2 }; |
| 333 | |
| 334 | std::vector<uint8_t> input0 = |
| 335 | { |
| 336 | 1, 4, 3, 8, 5, 12, |
| 337 | 7, 16, 9, 20, 11, 24, |
| 338 | 13, 28, 15, 32, 17, 36 |
| 339 | }; |
| 340 | |
| 341 | std::vector<uint8_t> input1 = { 1, 2 }; |
| 342 | |
| 343 | std::vector<uint8_t> output = |
| 344 | { |
| 345 | 1, 2, 3, 4, 5, 6, |
| 346 | 7, 8, 9, 10, 11, 12, |
| 347 | 13, 14, 15, 16, 17, 18 |
| 348 | }; |
| 349 | |
| 350 | return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::QuantisedAsymm8>( |
| 351 | workloadFactory, |
| 352 | memoryManager, |
| 353 | shape0, |
| 354 | input0, |
| 355 | shape1, |
| 356 | input1, |
| 357 | shape0, |
| 358 | output); |
| 359 | } |
| 360 | |
| 361 | LayerTestResult<int16_t,4> DivisionInt16Test( |
| 362 | armnn::IWorkloadFactory& workloadFactory, |
| 363 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 364 | { |
| 365 | unsigned int shape[] = { 2, 2, 2, 2 }; |
| 366 | |
| 367 | std::vector<int16_t> input0 = |
| 368 | { |
| 369 | 2, 2, 2, 2, 3, 3, 3, 3, |
| 370 | 4, 4, 4, 4, 5, 5, 5, 5 |
| 371 | }; |
| 372 | |
| 373 | std::vector<int16_t> input1 = |
| 374 | { |
| 375 | 1, 1, 1, 1, 2, 2, 2, 2, |
| 376 | 4, 4, 4, 4, 4, 4, 4, 4 |
| 377 | }; |
| 378 | |
| 379 | std::vector<int16_t> output = |
| 380 | { |
| 381 | 8, 8, 8, 8, 6, 6, 6, 6, |
| 382 | 4, 4, 4, 4, 5, 5, 5, 5 |
| 383 | }; |
| 384 | |
| 385 | return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::QuantisedSymm16>( |
| 386 | workloadFactory, |
| 387 | memoryManager, |
| 388 | shape, |
| 389 | input0, |
| 390 | shape, |
| 391 | input1, |
| 392 | shape, |
| 393 | output, |
| 394 | 0.25f, |
| 395 | 0); |
| 396 | } |
| 397 | |
| 398 | LayerTestResult<int16_t, 4> DivisionBroadcast1ElementInt16Test( |
| 399 | armnn::IWorkloadFactory& workloadFactory, |
| 400 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 401 | { |
| 402 | unsigned int shape0[] = { 1, 2, 2, 2 }; |
| 403 | unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 404 | |
| 405 | std::vector<int16_t> input0 = { 2, 4, 6, 8, 10, 12, 14, 16}; |
| 406 | |
| 407 | std::vector<int16_t> input1 = { 2 }; |
| 408 | |
| 409 | std::vector<int16_t> output = { 1, 2, 3, 4, 5, 6, 7, 8}; |
| 410 | |
| 411 | return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::QuantisedSymm16>( |
| 412 | workloadFactory, |
| 413 | memoryManager, |
| 414 | shape0, |
| 415 | input0, |
| 416 | shape1, |
| 417 | input1, |
| 418 | shape0, |
| 419 | output); |
| 420 | } |
| 421 | |
| 422 | LayerTestResult<int16_t, 4> DivisionBroadcast1DVectorInt16Test( |
| 423 | armnn::IWorkloadFactory& workloadFactory, |
| 424 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 425 | { |
| 426 | unsigned int shape0[] = { 1, 3, 3, 2 }; |
| 427 | unsigned int shape1[] = { 1, 1, 1, 2 }; |
| 428 | |
| 429 | std::vector<int16_t> input0 = |
| 430 | { |
| 431 | 1, 4, 3, 8, 5, 12, |
| 432 | 7, 16, 9, 20, 11, 24, |
| 433 | 13, 28, 15, 32, 17, 36 |
| 434 | }; |
| 435 | |
| 436 | std::vector<int16_t> input1 = { 1, 2 }; |
| 437 | |
| 438 | std::vector<int16_t> output = |
| 439 | { |
| 440 | 1, 2, 3, 4, 5, 6, |
| 441 | 7, 8, 9, 10, 11, 12, |
| 442 | 13, 14, 15, 16, 17, 18 |
| 443 | }; |
| 444 | |
| 445 | return ElementwiseTestHelper<4, armnn::DivisionQueueDescriptor, armnn::DataType::QuantisedSymm16>( |
| 446 | workloadFactory, |
| 447 | memoryManager, |
| 448 | shape0, |
| 449 | input0, |
| 450 | shape1, |
| 451 | input1, |
| 452 | shape0, |
| 453 | output); |
| 454 | } |