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