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