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 "SubtractionTestImpl.hpp" |
| 7 | |
| 8 | #include "ElementwiseTestImpl.hpp" |
| 9 | |
| 10 | template<> |
| 11 | std::unique_ptr<armnn::IWorkload> CreateWorkload<armnn::SubtractionQueueDescriptor>( |
| 12 | const armnn::IWorkloadFactory& workloadFactory, |
| 13 | const armnn::WorkloadInfo& info, |
| 14 | const armnn::SubtractionQueueDescriptor& descriptor) |
| 15 | { |
| 16 | return workloadFactory.CreateSubtraction(descriptor, info); |
| 17 | } |
| 18 | |
| 19 | LayerTestResult<uint8_t, 4> SubtractionUint8Test( |
| 20 | armnn::IWorkloadFactory& workloadFactory, |
| 21 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 22 | { |
| 23 | const unsigned int shape0[] = { 1, 1, 2, 2 }; |
| 24 | const unsigned int shape1[] = { 1, 1, 2, 2 }; |
| 25 | |
| 26 | std::vector<uint8_t> input0 = { 10, 12, 14, 16 }; |
| 27 | std::vector<uint8_t> input1 = { 1, 2, 1, 2 }; |
| 28 | std::vector<uint8_t> output = { 3, 3, 5, 5 }; |
| 29 | |
| 30 | return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::QuantisedAsymm8>( |
| 31 | workloadFactory, |
| 32 | memoryManager, |
| 33 | shape0, |
| 34 | input0, |
| 35 | 0.5f, |
| 36 | 2, |
| 37 | shape1, |
| 38 | input1, |
| 39 | 1.0f, |
| 40 | 0, |
| 41 | shape0, |
| 42 | output, |
| 43 | 1.0f, |
| 44 | 0); |
| 45 | } |
| 46 | |
| 47 | LayerTestResult<uint8_t, 4> SubtractionBroadcast1ElementUint8Test( |
| 48 | armnn::IWorkloadFactory& workloadFactory, |
| 49 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 50 | { |
| 51 | const unsigned int shape0[] = { 1, 1, 2, 2 }; |
| 52 | const unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 53 | |
| 54 | std::vector<uint8_t> input0 = { 10, 12, 14, 16 }; |
| 55 | |
| 56 | std::vector<uint8_t> input1 = { 2 }; |
| 57 | |
| 58 | std::vector<uint8_t> output = { 5, 6, 7, 8 }; |
| 59 | |
| 60 | return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::QuantisedAsymm8>( |
| 61 | workloadFactory, |
| 62 | memoryManager, |
| 63 | shape0, |
| 64 | input0, |
| 65 | 0.5f, |
| 66 | 2, |
| 67 | shape1, |
| 68 | input1, |
| 69 | 1.0f, |
| 70 | 0, |
| 71 | shape0, |
| 72 | output, |
| 73 | 1.0f, |
| 74 | 3); |
| 75 | } |
| 76 | |
| 77 | LayerTestResult<uint8_t, 4> SubtractionBroadcastUint8Test( |
| 78 | armnn::IWorkloadFactory& workloadFactory, |
| 79 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 80 | { |
| 81 | const unsigned int shape0[] = { 1, 1, 2, 2 }; |
| 82 | const unsigned int shape1[] = { 1, 1, 2, 1 }; |
| 83 | |
| 84 | std::vector<uint8_t> input0 = { 10, 12, 14, 16 }; |
| 85 | |
| 86 | std::vector<uint8_t> input1 = { 2, 1 }; |
| 87 | |
| 88 | std::vector<uint8_t> output = { 8, 11, 12, 15 }; |
| 89 | |
| 90 | return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::QuantisedAsymm8>( |
| 91 | workloadFactory, |
| 92 | memoryManager, |
| 93 | shape0, |
| 94 | input0, |
| 95 | shape1, |
| 96 | input1, |
| 97 | shape0, |
| 98 | output); |
| 99 | } |
| 100 | |
| 101 | LayerTestResult<float, 4> SubtractionTest( |
| 102 | armnn::IWorkloadFactory& workloadFactory, |
| 103 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 104 | { |
| 105 | const unsigned int shape0[] = { 1, 1, 2, 2 }; |
| 106 | const unsigned int shape1[] = { 1, 1, 2, 2 }; |
| 107 | |
| 108 | std::vector<float> input0 = { 1, 2, 3, 4 }; |
| 109 | std::vector<float> input1 = { 1, -1, 0, 2 }; |
| 110 | std::vector<float> output = { 0, 3, 3, 2 }; |
| 111 | |
| 112 | return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, 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> SubtractionBroadcast1ElementTest( |
| 124 | armnn::IWorkloadFactory& workloadFactory, |
| 125 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 126 | { |
| 127 | const unsigned int shape0[] = { 1, 1, 2, 2 }; |
| 128 | const unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 129 | |
| 130 | std::vector<float> input0 = { 1, 2, 3, 4 }; |
| 131 | |
| 132 | std::vector<float> input1 = { 10 }; |
| 133 | |
| 134 | std::vector<float> output = { -9, -8, -7, -6 }; |
| 135 | |
| 136 | return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::Float32>( |
| 137 | workloadFactory, |
| 138 | memoryManager, |
| 139 | shape0, |
| 140 | input0, |
| 141 | shape1, |
| 142 | input1, |
| 143 | shape0, |
| 144 | output); |
| 145 | } |
| 146 | |
| 147 | LayerTestResult<float, 4> SubtractionBroadcastTest( |
| 148 | armnn::IWorkloadFactory& workloadFactory, |
| 149 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 150 | { |
| 151 | const unsigned int shape0[] = { 1, 1, 2, 2 }; |
| 152 | const unsigned int shape1[] = { 1, 1, 1, 2 }; |
| 153 | |
| 154 | std::vector<float> input0 = { 1, 2, 3, 4 }; |
| 155 | |
| 156 | std::vector<float> input1 = { 10, -5 }; |
| 157 | |
| 158 | std::vector<float> output = { -9, 7, -7, 9 }; |
| 159 | |
| 160 | return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::Float32>( |
| 161 | workloadFactory, |
| 162 | memoryManager, |
| 163 | shape0, |
| 164 | input0, |
| 165 | shape1, |
| 166 | input1, |
| 167 | shape0, |
| 168 | output); |
| 169 | } |
| 170 | |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 171 | LayerTestResult<armnn::Half, 4> SubtractionFloat16Test( |
| 172 | armnn::IWorkloadFactory& workloadFactory, |
| 173 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 174 | { |
| 175 | using namespace half_float::literal; |
| 176 | |
| 177 | const unsigned int shape0[] = { 1, 1, 2, 2 }; |
| 178 | const unsigned int shape1[] = { 1, 1, 2, 2 }; |
| 179 | |
| 180 | std::vector<armnn::Half> input0 = { 1._h, 2._h, 3._h, 4._h }; |
| 181 | std::vector<armnn::Half> input1 = { 1._h, -1._h, 0._h, 2._h }; |
| 182 | std::vector<armnn::Half> output = { 0._h, 3._h, 3._h, 2._h }; |
| 183 | |
| 184 | return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::Float16>( |
| 185 | workloadFactory, |
| 186 | memoryManager, |
| 187 | shape0, |
| 188 | input0, |
| 189 | shape1, |
| 190 | input1, |
| 191 | shape0, |
| 192 | output); |
| 193 | } |
| 194 | |
| 195 | LayerTestResult<armnn::Half, 4> SubtractionBroadcast1ElementFloat16Test( |
| 196 | armnn::IWorkloadFactory& workloadFactory, |
| 197 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 198 | { |
| 199 | using namespace half_float::literal; |
| 200 | |
| 201 | const unsigned int shape0[] = { 1, 1, 2, 2 }; |
| 202 | const unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 203 | |
| 204 | std::vector<armnn::Half> input0 = { 1._h, 2._h, 3._h, 4._h }; |
| 205 | |
| 206 | std::vector<armnn::Half> input1 = { 10._h }; |
| 207 | |
| 208 | std::vector<armnn::Half> output = { -9._h, -8._h, -7._h, -6._h }; |
| 209 | |
| 210 | return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::Float16>( |
| 211 | workloadFactory, |
| 212 | memoryManager, |
| 213 | shape0, |
| 214 | input0, |
| 215 | shape1, |
| 216 | input1, |
| 217 | shape0, |
| 218 | output); |
| 219 | } |
| 220 | |
| 221 | LayerTestResult<armnn::Half, 4> SubtractionBroadcastFloat16Test( |
| 222 | armnn::IWorkloadFactory& workloadFactory, |
| 223 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 224 | { |
| 225 | using namespace half_float::literal; |
| 226 | |
| 227 | const unsigned int shape0[] = { 1, 1, 2, 2 }; |
| 228 | const unsigned int shape1[] = { 1, 1, 1, 2 }; |
| 229 | |
| 230 | std::vector<armnn::Half> input0 = { 1._h, 2._h, 3._h, 4._h }; |
| 231 | |
| 232 | std::vector<armnn::Half> input1 = { 10._h, -5._h }; |
| 233 | |
| 234 | std::vector<armnn::Half> output = { -9._h, 7._h, -7._h, 9._h }; |
| 235 | |
| 236 | return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::Float16>( |
| 237 | workloadFactory, |
| 238 | memoryManager, |
| 239 | shape0, |
| 240 | input0, |
| 241 | shape1, |
| 242 | input1, |
| 243 | shape0, |
| 244 | output); |
| 245 | } |
| 246 | |
Aron Virginas-Tar | e89ebad | 2019-08-27 18:14:26 +0100 | [diff] [blame] | 247 | LayerTestResult<int16_t, 4> SubtractionInt16Test( |
| 248 | armnn::IWorkloadFactory& workloadFactory, |
| 249 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 250 | { |
| 251 | const unsigned int shape[] = { 1, 1, 2, 2 }; |
| 252 | |
| 253 | std::vector<int16_t> input0 = { 10, 12, 14, 16 }; |
| 254 | std::vector<int16_t> input1 = { 1, 2, 1, 2 }; |
| 255 | std::vector<int16_t> output = { 3, 3, 5, 5 }; |
| 256 | |
| 257 | return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::QuantisedSymm16>( |
| 258 | workloadFactory, |
| 259 | memoryManager, |
| 260 | shape, |
| 261 | input0, |
| 262 | 0.5f, |
| 263 | 0, |
| 264 | shape, |
| 265 | input1, |
| 266 | 1.0f, |
| 267 | 0, |
| 268 | shape, |
| 269 | output, |
| 270 | 1.0f, |
| 271 | 0); |
| 272 | } |
| 273 | |
| 274 | LayerTestResult<int16_t, 4> SubtractionBroadcast1ElementInt16Test( |
| 275 | armnn::IWorkloadFactory& workloadFactory, |
| 276 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 277 | { |
| 278 | const unsigned int shape0[] = { 1, 1, 2, 2 }; |
| 279 | const unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 280 | |
| 281 | std::vector<int16_t> input0 = { 10, 12, 14, 16 }; |
| 282 | |
| 283 | std::vector<int16_t> input1 = { 2 }; |
| 284 | |
| 285 | std::vector<int16_t> output = { 3, 4, 5, 6 }; |
| 286 | |
| 287 | return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::QuantisedSymm16>( |
| 288 | workloadFactory, |
| 289 | memoryManager, |
| 290 | shape0, |
| 291 | input0, |
| 292 | 0.5f, |
| 293 | 0, |
| 294 | shape1, |
| 295 | input1, |
| 296 | 1.0f, |
| 297 | 0, |
| 298 | shape0, |
| 299 | output, |
| 300 | 1.0f, |
| 301 | 0); |
| 302 | } |
| 303 | |
| 304 | LayerTestResult<int16_t, 4> SubtractionBroadcastInt16Test( |
| 305 | armnn::IWorkloadFactory& workloadFactory, |
| 306 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 307 | { |
| 308 | const unsigned int shape0[] = { 1, 1, 2, 2 }; |
| 309 | const unsigned int shape1[] = { 1, 1, 2, 1 }; |
| 310 | |
| 311 | std::vector<int16_t> input0 = { 10, 12, 14, 16 }; |
| 312 | |
| 313 | std::vector<int16_t> input1 = { 2, 1 }; |
| 314 | |
| 315 | std::vector<int16_t> output = { 8, 11, 12, 15 }; |
| 316 | |
| 317 | return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::QuantisedSymm16>( |
| 318 | workloadFactory, |
| 319 | memoryManager, |
| 320 | shape0, |
| 321 | input0, |
| 322 | shape1, |
| 323 | input1, |
| 324 | shape0, |
| 325 | output); |
| 326 | } |