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 | |
| 114 | LayerTestResult<uint8_t, 4> MaximumUint8Test( |
| 115 | armnn::IWorkloadFactory& workloadFactory, |
| 116 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 117 | { |
| 118 | unsigned int shape[] = { 2, 2, 2, 2 }; |
| 119 | |
| 120 | // See dequantized values to the right. |
| 121 | std::vector<uint8_t> input0 = |
| 122 | { |
| 123 | 1, 1, 1, 1, 6, 6, 6, 6, |
| 124 | 3, 3, 3, 3, 4, 4, 4, 4 |
| 125 | }; |
| 126 | |
| 127 | std::vector<uint8_t> input1 = |
| 128 | { |
| 129 | 2, 2, 2, 2, 3, 3, 3, 3, |
| 130 | 4, 4, 4, 4, 5, 5, 5, 5 |
| 131 | }; |
| 132 | |
| 133 | std::vector<uint8_t> output = |
| 134 | { |
| 135 | 2, 2, 2, 2, 6, 6, 6, 6, |
| 136 | 4, 4, 4, 4, 5, 5, 5, 5 |
| 137 | }; |
| 138 | |
| 139 | return ElementwiseTestHelper<4, armnn::MaximumQueueDescriptor, armnn::DataType::QuantisedAsymm8>( |
| 140 | workloadFactory, |
| 141 | memoryManager, |
| 142 | shape, |
| 143 | input0, |
| 144 | shape, |
| 145 | input1, |
| 146 | shape, |
| 147 | output); |
| 148 | } |
| 149 | |
| 150 | LayerTestResult<uint8_t, 4> MaximumBroadcast1ElementUint8Test( |
| 151 | armnn::IWorkloadFactory& workloadFactory, |
| 152 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 153 | { |
| 154 | const unsigned int shape0[] = { 1, 2, 2, 3 }; |
| 155 | const unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 156 | |
| 157 | std::vector<uint8_t> input0 = |
| 158 | { |
| 159 | 1, 2, 3, 4, 5, 6, |
| 160 | 7, 8, 9, 10, 11, 12 |
| 161 | }; |
| 162 | |
| 163 | std::vector<uint8_t> input1 = { 2 }; |
| 164 | |
| 165 | std::vector<uint8_t> output = |
| 166 | { |
| 167 | 2, 2, 3, 4, 5, 6, |
| 168 | 7, 8, 9, 10, 11, 12 |
| 169 | }; |
| 170 | |
| 171 | return ElementwiseTestHelper<4, armnn::MaximumQueueDescriptor, armnn::DataType::QuantisedAsymm8>( |
| 172 | workloadFactory, |
| 173 | memoryManager, |
| 174 | shape0, |
| 175 | input0, |
| 176 | shape1, |
| 177 | input1, |
| 178 | shape0, |
| 179 | output); |
| 180 | } |
| 181 | |
| 182 | LayerTestResult<uint8_t, 4> MaximumBroadcast1DVectorUint8Test( |
| 183 | armnn::IWorkloadFactory& workloadFactory, |
| 184 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 185 | { |
| 186 | const unsigned int shape0[] = { 1, 2, 2, 3 }; |
| 187 | const unsigned int shape1[] = { 1, 1, 1, 3 }; |
| 188 | |
| 189 | std::vector<uint8_t> input0 = |
| 190 | { |
| 191 | 1, 2, 3, 4, 5, 6, |
| 192 | 7, 8, 9, 10, 11, 12 |
| 193 | }; |
| 194 | |
| 195 | std::vector<uint8_t> input1 = { 1, 10, 3 }; |
| 196 | |
| 197 | std::vector<uint8_t> output = { |
| 198 | 1, 10, 3, 4, 10, 6, |
| 199 | 7, 10, 9, 10, 11, 12 |
| 200 | }; |
| 201 | |
| 202 | return ElementwiseTestHelper<4, armnn::MaximumQueueDescriptor, armnn::DataType::QuantisedAsymm8>( |
| 203 | workloadFactory, |
| 204 | memoryManager, |
| 205 | shape0, |
| 206 | input0, |
| 207 | shape1, |
| 208 | input1, |
| 209 | shape0, |
| 210 | output); |
| 211 | } |
| 212 | |
| 213 | LayerTestResult<int16_t, 4> MaximumInt16Test( |
| 214 | armnn::IWorkloadFactory& workloadFactory, |
| 215 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 216 | { |
| 217 | unsigned int shape[] = { 2, 2, 2, 2 }; |
| 218 | |
| 219 | std::vector<int16_t> input0({ 1, 1, 1, 1, 6, 6, 6, 6, |
| 220 | 3, 3, 3, 3, 4, 4, 4, 4 }); |
| 221 | |
| 222 | std::vector<int16_t> input1({ 2, 2, 2, 2, 3, 3, 3, 3, |
| 223 | 4, 4, 4, 4, 5, 5, 5, 5 }); |
| 224 | |
| 225 | std::vector<int16_t> output({ 2, 2, 2, 2, 6, 6, 6, 6, |
| 226 | 4, 4, 4, 4, 5, 5, 5, 5 }); |
| 227 | |
| 228 | return ElementwiseTestHelper<4, armnn::MaximumQueueDescriptor, armnn::DataType::QuantisedSymm16>( |
| 229 | workloadFactory, |
| 230 | memoryManager, |
| 231 | shape, |
| 232 | input0, |
| 233 | shape, |
| 234 | input1, |
| 235 | shape, |
| 236 | output); |
| 237 | } |
| 238 | |
| 239 | LayerTestResult<int16_t, 4> MaximumBroadcast1ElementInt16Test( |
| 240 | armnn::IWorkloadFactory& workloadFactory, |
| 241 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 242 | { |
| 243 | const unsigned int shape0[] = { 1, 2, 2, 3 }; |
| 244 | const unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 245 | |
| 246 | std::vector<int16_t> input0 = |
| 247 | { |
| 248 | 1, 2, 3, 4, 5, 6, |
| 249 | 7, 8, 9, 10, 11, 12 |
| 250 | }; |
| 251 | |
| 252 | std::vector<int16_t> input1 = { 2 }; |
| 253 | |
| 254 | std::vector<int16_t> output = |
| 255 | { |
| 256 | 2, 2, 3, 4, 5, 6, |
| 257 | 7, 8, 9, 10, 11, 12 |
| 258 | }; |
| 259 | |
| 260 | return ElementwiseTestHelper<4, armnn::MaximumQueueDescriptor, armnn::DataType::QuantisedSymm16>( |
| 261 | workloadFactory, |
| 262 | memoryManager, |
| 263 | shape0, |
| 264 | input0, |
| 265 | shape1, |
| 266 | input1, |
| 267 | shape0, |
| 268 | output); |
| 269 | } |
| 270 | |
| 271 | LayerTestResult<int16_t, 4> MaximumBroadcast1DVectorInt16Test( |
| 272 | armnn::IWorkloadFactory& workloadFactory, |
| 273 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 274 | { |
| 275 | const unsigned int shape0[] = { 1, 2, 2, 3 }; |
| 276 | const unsigned int shape1[] = { 1, 1, 1, 3 }; |
| 277 | |
| 278 | std::vector<int16_t> input0 = |
| 279 | { |
| 280 | 1, 2, 3, 4, 5, 6, |
| 281 | 7, 8, 9, 10, 11, 12 |
| 282 | }; |
| 283 | |
| 284 | std::vector<int16_t> input1 = { 1, 10, 3 }; |
| 285 | |
| 286 | std::vector<int16_t> output = |
| 287 | { |
| 288 | 1, 10, 3, 4, 10, 6, |
| 289 | 7, 10, 9, 10, 11, 12 |
| 290 | }; |
| 291 | |
| 292 | return ElementwiseTestHelper<4, armnn::MaximumQueueDescriptor, armnn::DataType::QuantisedSymm16>( |
| 293 | workloadFactory, |
| 294 | memoryManager, |
| 295 | shape0, |
| 296 | input0, |
| 297 | shape1, |
| 298 | input1, |
| 299 | shape0, |
| 300 | output); |
| 301 | } |