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 "EqualTestImpl.hpp" |
Aron Virginas-Tar | e89ebad | 2019-08-27 18:14:26 +0100 | [diff] [blame] | 7 | #include "ElementwiseTestImpl.hpp" |
| 8 | |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 9 | #include <Half.hpp> |
| 10 | |
Aron Virginas-Tar | e89ebad | 2019-08-27 18:14:26 +0100 | [diff] [blame] | 11 | template<> |
| 12 | std::unique_ptr<armnn::IWorkload> CreateWorkload<armnn::EqualQueueDescriptor>( |
| 13 | const armnn::IWorkloadFactory& workloadFactory, |
| 14 | const armnn::WorkloadInfo& info, |
| 15 | const armnn::EqualQueueDescriptor& descriptor) |
| 16 | { |
| 17 | return workloadFactory.CreateEqual(descriptor, info); |
| 18 | } |
| 19 | |
| 20 | LayerTestResult<uint8_t, 4> EqualSimpleTest(armnn::IWorkloadFactory& workloadFactory, |
| 21 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 22 | { |
| 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({ 1, 1, 1, 1, 3, 3, 3, 3, |
| 37 | 5, 5, 5, 5, 4, 4, 4, 4 }); |
| 38 | |
| 39 | std::vector<uint8_t> output({ 1, 1, 1, 1, 0, 0, 0, 0, |
| 40 | 0, 0, 0, 0, 1, 1, 1, 1 }); |
| 41 | |
| 42 | return ElementwiseTestHelper<4, armnn::EqualQueueDescriptor, armnn::DataType::Float32, armnn::DataType::Boolean>( |
| 43 | workloadFactory, |
| 44 | memoryManager, |
| 45 | shape, |
| 46 | input0, |
| 47 | shape, |
| 48 | input1, |
| 49 | shape, |
| 50 | output); |
| 51 | } |
| 52 | |
| 53 | LayerTestResult<uint8_t, 4> EqualBroadcast1ElementTest( |
| 54 | armnn::IWorkloadFactory& workloadFactory, |
| 55 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 56 | { |
| 57 | unsigned int shape0[] = { 1, 2, 2, 2 }; |
| 58 | std::vector<float> input0({ 1, 2, 3, 4, 5, 6, 7, 8}); |
| 59 | |
| 60 | unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 61 | std::vector<float> input1({ 1 }); |
| 62 | |
| 63 | std::vector<uint8_t> output({ 1, 0, 0, 0, 0, 0, 0, 0}); |
| 64 | |
| 65 | return ElementwiseTestHelper<4, armnn::EqualQueueDescriptor, armnn::DataType::Float32, armnn::DataType::Boolean>( |
| 66 | workloadFactory, |
| 67 | memoryManager, |
| 68 | shape0, |
| 69 | input0, |
| 70 | shape1, |
| 71 | input1, |
| 72 | shape0, |
| 73 | output); |
| 74 | } |
| 75 | |
| 76 | LayerTestResult<uint8_t, 4> EqualBroadcast1DVectorTest( |
| 77 | armnn::IWorkloadFactory& workloadFactory, |
| 78 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 79 | { |
| 80 | const unsigned int shape0[] = { 1, 2, 2, 3 }; |
| 81 | const unsigned int shape1[] = { 1, 1, 1, 3 }; |
| 82 | |
| 83 | std::vector<float> input0({ 1, 2, 3, 4, 5, 6, |
| 84 | 7, 8, 9, 10, 11, 12 }); |
| 85 | |
| 86 | std::vector<float> input1({ 1, 2, 3}); |
| 87 | |
| 88 | std::vector<uint8_t> output({ 1, 1, 1, 0, 0, 0, |
| 89 | 0, 0, 0, 0, 0, 0 }); |
| 90 | |
| 91 | return ElementwiseTestHelper<4, armnn::EqualQueueDescriptor, armnn::DataType::Float32, armnn::DataType::Boolean>( |
| 92 | workloadFactory, |
| 93 | memoryManager, |
| 94 | shape0, |
| 95 | input0, |
| 96 | shape1, |
| 97 | input1, |
| 98 | shape0, |
| 99 | output); |
| 100 | } |
| 101 | |
Matthew Jackson | 9bff144 | 2019-09-12 09:08:23 +0100 | [diff] [blame] | 102 | LayerTestResult<uint8_t, 4> EqualFloat16Test( |
| 103 | armnn::IWorkloadFactory& workloadFactory, |
| 104 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 105 | { |
| 106 | using namespace half_float::literal; |
| 107 | |
| 108 | unsigned int shape[] = { 2, 2, 2, 2 }; |
| 109 | |
| 110 | // See dequantized values to the right. |
| 111 | std::vector<armnn::Half> input0({ 1._h, 1._h, 1._h, 1._h, 6._h, 6._h, 6._h, 6._h, |
| 112 | 3._h, 3._h, 3._h, 3._h, 7._h, 7._h, 7._h, 7._h }); |
| 113 | |
| 114 | std::vector<armnn::Half> input1({ 2._h, 2._h, 2._h, 2._h, 6._h, 6._h, 6._h, 6._h, |
| 115 | 3._h, 3._h, 3._h, 3._h, 5._h, 5._h, 5._h, 5._h }); |
| 116 | |
| 117 | std::vector<uint8_t> output({ 0, 0, 0, 0, 1, 1, 1, 1, |
| 118 | 1, 1, 1, 1, 0, 0, 0, 0 }); |
| 119 | |
| 120 | return ElementwiseTestHelper<4, |
| 121 | armnn::EqualQueueDescriptor, |
| 122 | armnn::DataType::Float16, |
| 123 | armnn::DataType::Boolean>( |
| 124 | workloadFactory, |
| 125 | memoryManager, |
| 126 | shape, |
| 127 | input0, |
| 128 | shape, |
| 129 | input1, |
| 130 | shape, |
| 131 | output); |
| 132 | } |
| 133 | |
| 134 | LayerTestResult<uint8_t, 4> EqualBroadcast1ElementFloat16Test( |
| 135 | armnn::IWorkloadFactory& workloadFactory, |
| 136 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 137 | { |
| 138 | using namespace half_float::literal; |
| 139 | |
| 140 | const unsigned int shape0[] = { 1, 2, 2, 3 }; |
| 141 | const unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 142 | |
| 143 | std::vector<armnn::Half> input0({ 1._h, 2._h, 3._h, 4._h, 5._h, 6._h, |
| 144 | 7._h, 8._h, 9._h, 10._h, 11._h, 12._h }); |
| 145 | |
| 146 | std::vector<armnn::Half> input1({ 1._h }); |
| 147 | |
| 148 | std::vector<uint8_t> output({ 1, 0, 0, 0, 0, 0, |
| 149 | 0, 0, 0, 0, 0, 0 }); |
| 150 | |
| 151 | return ElementwiseTestHelper<4, |
| 152 | armnn::EqualQueueDescriptor, |
| 153 | armnn::DataType::Float16, |
| 154 | armnn::DataType::Boolean>( |
| 155 | workloadFactory, |
| 156 | memoryManager, |
| 157 | shape0, |
| 158 | input0, |
| 159 | shape1, |
| 160 | input1, |
| 161 | shape0, |
| 162 | output); |
| 163 | } |
| 164 | |
| 165 | LayerTestResult<uint8_t, 4> EqualBroadcast1DVectorFloat16Test( |
| 166 | armnn::IWorkloadFactory& workloadFactory, |
| 167 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 168 | { |
| 169 | using namespace half_float::literal; |
| 170 | |
| 171 | const unsigned int shape0[] = { 1, 2, 2, 3 }; |
| 172 | const unsigned int shape1[] = { 1, 1, 1, 3 }; |
| 173 | |
| 174 | std::vector<armnn::Half> input0({ 1._h, 2._h, 3._h, 4._h, 5._h, 6._h, |
| 175 | 7._h, 8._h, 9._h, 10._h, 11._h, 12._h }); |
| 176 | |
| 177 | std::vector<armnn::Half> input1({ 1._h, 1._h, 3._h }); |
| 178 | |
| 179 | std::vector<uint8_t> output({ 1, 0, 1, 0, 0, 0, |
| 180 | 0, 0, 0, 0, 0, 0 }); |
| 181 | |
| 182 | return ElementwiseTestHelper<4, |
| 183 | armnn::EqualQueueDescriptor, |
| 184 | armnn::DataType::Float16, |
| 185 | armnn::DataType::Boolean>( |
| 186 | workloadFactory, |
| 187 | memoryManager, |
| 188 | shape0, |
| 189 | input0, |
| 190 | shape1, |
| 191 | input1, |
| 192 | shape0, |
| 193 | output); |
| 194 | } |
| 195 | |
Aron Virginas-Tar | e89ebad | 2019-08-27 18:14:26 +0100 | [diff] [blame] | 196 | LayerTestResult<uint8_t, 4> EqualUint8Test( |
| 197 | armnn::IWorkloadFactory& workloadFactory, |
| 198 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 199 | { |
| 200 | unsigned int shape[] = { 2, 2, 2, 2 }; |
| 201 | |
| 202 | // See dequantized values to the right. |
| 203 | std::vector<uint8_t> input0({ 1, 1, 1, 1, 6, 6, 6, 6, |
| 204 | 3, 3, 3, 3, 7, 7, 7, 7 }); |
| 205 | |
| 206 | std::vector<uint8_t> input1({ 2, 2, 2, 2, 6, 6, 6, 6, |
| 207 | 3, 3, 3, 3, 5, 5, 5, 5 }); |
| 208 | |
| 209 | std::vector<uint8_t> output({ 0, 0, 0, 0, 1, 1, 1, 1, |
| 210 | 1, 1, 1, 1, 0, 0, 0, 0 }); |
| 211 | |
| 212 | return ElementwiseTestHelper<4, |
| 213 | armnn::EqualQueueDescriptor, |
| 214 | armnn::DataType::QuantisedAsymm8, |
| 215 | armnn::DataType::Boolean>( |
| 216 | workloadFactory, |
| 217 | memoryManager, |
| 218 | shape, |
| 219 | input0, |
| 220 | shape, |
| 221 | input1, |
| 222 | shape, |
| 223 | output); |
| 224 | } |
| 225 | |
| 226 | LayerTestResult<uint8_t, 4> EqualBroadcast1ElementUint8Test( |
| 227 | armnn::IWorkloadFactory& workloadFactory, |
| 228 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 229 | { |
| 230 | const unsigned int shape0[] = { 1, 2, 2, 3 }; |
| 231 | const unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 232 | |
| 233 | std::vector<uint8_t> input0({ 1, 2, 3, 4, 5, 6, |
| 234 | 7, 8, 9, 10, 11, 12 }); |
| 235 | |
| 236 | std::vector<uint8_t> input1({ 1 }); |
| 237 | |
| 238 | std::vector<uint8_t> output({ 1, 0, 0, 0, 0, 0, |
| 239 | 0, 0, 0, 0, 0, 0 }); |
| 240 | |
| 241 | return ElementwiseTestHelper<4, |
| 242 | armnn::EqualQueueDescriptor, |
| 243 | armnn::DataType::QuantisedAsymm8, |
| 244 | armnn::DataType::Boolean>( |
| 245 | workloadFactory, |
| 246 | memoryManager, |
| 247 | shape0, |
| 248 | input0, |
| 249 | shape1, |
| 250 | input1, |
| 251 | shape0, |
| 252 | output); |
| 253 | } |
| 254 | |
| 255 | LayerTestResult<uint8_t, 4> EqualBroadcast1DVectorUint8Test( |
| 256 | armnn::IWorkloadFactory& workloadFactory, |
| 257 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 258 | { |
| 259 | const unsigned int shape0[] = { 1, 2, 2, 3 }; |
| 260 | const unsigned int shape1[] = { 1, 1, 1, 3 }; |
| 261 | |
| 262 | std::vector<uint8_t> input0({ 1, 2, 3, 4, 5, 6, |
| 263 | 7, 8, 9, 10, 11, 12 }); |
| 264 | |
| 265 | std::vector<uint8_t> input1({ 1, 1, 3}); |
| 266 | |
| 267 | std::vector<uint8_t> output({ 1, 0, 1, 0, 0, 0, |
| 268 | 0, 0, 0, 0, 0, 0 }); |
| 269 | |
| 270 | return ElementwiseTestHelper<4, |
| 271 | armnn::EqualQueueDescriptor, |
| 272 | armnn::DataType::QuantisedAsymm8, |
| 273 | armnn::DataType::Boolean>( |
| 274 | workloadFactory, |
| 275 | memoryManager, |
| 276 | shape0, |
| 277 | input0, |
| 278 | shape1, |
| 279 | input1, |
| 280 | shape0, |
| 281 | output); |
| 282 | } |