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 | |
| 171 | LayerTestResult<int16_t, 4> SubtractionInt16Test( |
| 172 | armnn::IWorkloadFactory& workloadFactory, |
| 173 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 174 | { |
| 175 | const unsigned int shape[] = { 1, 1, 2, 2 }; |
| 176 | |
| 177 | std::vector<int16_t> input0 = { 10, 12, 14, 16 }; |
| 178 | std::vector<int16_t> input1 = { 1, 2, 1, 2 }; |
| 179 | std::vector<int16_t> output = { 3, 3, 5, 5 }; |
| 180 | |
| 181 | return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::QuantisedSymm16>( |
| 182 | workloadFactory, |
| 183 | memoryManager, |
| 184 | shape, |
| 185 | input0, |
| 186 | 0.5f, |
| 187 | 0, |
| 188 | shape, |
| 189 | input1, |
| 190 | 1.0f, |
| 191 | 0, |
| 192 | shape, |
| 193 | output, |
| 194 | 1.0f, |
| 195 | 0); |
| 196 | } |
| 197 | |
| 198 | LayerTestResult<int16_t, 4> SubtractionBroadcast1ElementInt16Test( |
| 199 | armnn::IWorkloadFactory& workloadFactory, |
| 200 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 201 | { |
| 202 | const unsigned int shape0[] = { 1, 1, 2, 2 }; |
| 203 | const unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 204 | |
| 205 | std::vector<int16_t> input0 = { 10, 12, 14, 16 }; |
| 206 | |
| 207 | std::vector<int16_t> input1 = { 2 }; |
| 208 | |
| 209 | std::vector<int16_t> output = { 3, 4, 5, 6 }; |
| 210 | |
| 211 | return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::QuantisedSymm16>( |
| 212 | workloadFactory, |
| 213 | memoryManager, |
| 214 | shape0, |
| 215 | input0, |
| 216 | 0.5f, |
| 217 | 0, |
| 218 | shape1, |
| 219 | input1, |
| 220 | 1.0f, |
| 221 | 0, |
| 222 | shape0, |
| 223 | output, |
| 224 | 1.0f, |
| 225 | 0); |
| 226 | } |
| 227 | |
| 228 | LayerTestResult<int16_t, 4> SubtractionBroadcastInt16Test( |
| 229 | armnn::IWorkloadFactory& workloadFactory, |
| 230 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 231 | { |
| 232 | const unsigned int shape0[] = { 1, 1, 2, 2 }; |
| 233 | const unsigned int shape1[] = { 1, 1, 2, 1 }; |
| 234 | |
| 235 | std::vector<int16_t> input0 = { 10, 12, 14, 16 }; |
| 236 | |
| 237 | std::vector<int16_t> input1 = { 2, 1 }; |
| 238 | |
| 239 | std::vector<int16_t> output = { 8, 11, 12, 15 }; |
| 240 | |
| 241 | return ElementwiseTestHelper<4, armnn::SubtractionQueueDescriptor, armnn::DataType::QuantisedSymm16>( |
| 242 | workloadFactory, |
| 243 | memoryManager, |
| 244 | shape0, |
| 245 | input0, |
| 246 | shape1, |
| 247 | input1, |
| 248 | shape0, |
| 249 | output); |
| 250 | } |