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