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 "GreaterTestImpl.hpp" |
| 7 | |
| 8 | #include "ElementwiseTestImpl.hpp" |
| 9 | |
| 10 | template<> |
| 11 | std::unique_ptr<armnn::IWorkload> CreateWorkload<armnn::GreaterQueueDescriptor>( |
| 12 | const armnn::IWorkloadFactory& workloadFactory, |
| 13 | const armnn::WorkloadInfo& info, |
| 14 | const armnn::GreaterQueueDescriptor& descriptor) |
| 15 | { |
| 16 | return workloadFactory.CreateGreater(descriptor, info); |
| 17 | } |
| 18 | |
| 19 | LayerTestResult<uint8_t, 4> GreaterSimpleTest(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 | 1.f, 1.f, 1.f, 1.f, 3.f, 3.f, 3.f, 3.f, |
| 38 | 5.f, 5.f, 5.f, 5.f, 4.f, 4.f, 4.f, 4.f |
| 39 | }; |
| 40 | |
| 41 | std::vector<uint8_t> output = |
| 42 | { |
| 43 | 0, 0, 0, 0, 1, 1, 1, 1, |
| 44 | 0, 0, 0, 0, 0, 0, 0, 0 |
| 45 | }; |
| 46 | |
| 47 | return ElementwiseTestHelper<4, |
| 48 | armnn::GreaterQueueDescriptor, |
| 49 | armnn::DataType::Float32, |
| 50 | armnn::DataType::Boolean>( |
| 51 | workloadFactory, |
| 52 | memoryManager, |
| 53 | shape, |
| 54 | input0, |
| 55 | shape, |
| 56 | input1, |
| 57 | shape, |
| 58 | output); |
| 59 | } |
| 60 | |
| 61 | LayerTestResult<uint8_t, 4> GreaterBroadcast1ElementTest( |
| 62 | armnn::IWorkloadFactory& workloadFactory, |
| 63 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 64 | { |
| 65 | unsigned int shape0[] = { 1, 2, 2, 2 }; |
| 66 | unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 67 | |
| 68 | std::vector<float> input0 = { 1, 2, 3, 4, 5, 6, 7, 8}; |
| 69 | std::vector<float> input1 = { 1 }; |
| 70 | |
| 71 | std::vector<uint8_t> output = { 0, 1, 1, 1, 1, 1, 1, 1}; |
| 72 | |
| 73 | return ElementwiseTestHelper<4, |
| 74 | armnn::GreaterQueueDescriptor, |
| 75 | armnn::DataType::Float32, |
| 76 | armnn::DataType::Boolean>( |
| 77 | workloadFactory, |
| 78 | memoryManager, |
| 79 | shape0, |
| 80 | input0, |
| 81 | shape1, |
| 82 | input1, |
| 83 | shape0, |
| 84 | output); |
| 85 | } |
| 86 | |
| 87 | LayerTestResult<uint8_t, 4> GreaterBroadcast1DVectorTest( |
| 88 | armnn::IWorkloadFactory& workloadFactory, |
| 89 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 90 | { |
| 91 | const unsigned int shape0[] = { 1, 2, 2, 3 }; |
| 92 | const unsigned int shape1[] = { 1, 1, 1, 3 }; |
| 93 | |
| 94 | std::vector<float> input0 = |
| 95 | { |
| 96 | 1.0f, 2.9f, 2.1f, 4.0f, 5.0f, 6.0f, |
| 97 | 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f |
| 98 | }; |
| 99 | |
| 100 | std::vector<float> input1 = { 1.f, 3.f, 2.f }; |
| 101 | |
| 102 | std::vector<uint8_t> output = |
| 103 | { |
| 104 | 0, 0, 1, 1, 1, 1, |
| 105 | 1, 1, 1, 1, 1, 1 |
| 106 | }; |
| 107 | |
| 108 | return ElementwiseTestHelper<4, |
| 109 | armnn::GreaterQueueDescriptor, |
| 110 | armnn::DataType::Float32, |
| 111 | armnn::DataType::Boolean>( |
| 112 | workloadFactory, |
| 113 | memoryManager, |
| 114 | shape0, |
| 115 | input0, |
| 116 | shape1, |
| 117 | input1, |
| 118 | shape0, |
| 119 | output); |
| 120 | } |
| 121 | |
| 122 | LayerTestResult<uint8_t, 4> GreaterUint8Test( |
| 123 | armnn::IWorkloadFactory& workloadFactory, |
| 124 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 125 | { |
| 126 | unsigned int shape[] = { 2, 2, 2, 2 }; |
| 127 | |
| 128 | // See dequantized values to the right. |
| 129 | std::vector<uint8_t> input0 = |
| 130 | { |
| 131 | 1, 1, 1, 1, 6, 6, 6, 6, |
| 132 | 3, 3, 3, 3, 5, 5, 5, 5 |
| 133 | }; |
| 134 | |
| 135 | std::vector<uint8_t> input1 = |
| 136 | { |
| 137 | 2, 2, 2, 2, 6, 6, 6, 6, |
| 138 | 2, 2, 2, 2, 5, 5, 5, 5 |
| 139 | }; |
| 140 | |
| 141 | std::vector<uint8_t> output = |
| 142 | { |
| 143 | 0, 0, 0, 0, 0, 0, 0, 0, |
| 144 | 1, 1, 1, 1, 0, 0, 0, 0 |
| 145 | }; |
| 146 | |
| 147 | return ElementwiseTestHelper<4, |
| 148 | armnn::GreaterQueueDescriptor, |
| 149 | armnn::DataType::QuantisedAsymm8, |
| 150 | armnn::DataType::Boolean>( |
| 151 | workloadFactory, |
| 152 | memoryManager, |
| 153 | shape, |
| 154 | input0, |
| 155 | shape, |
| 156 | input1, |
| 157 | shape, |
| 158 | output); |
| 159 | } |
| 160 | |
| 161 | LayerTestResult<uint8_t, 4> GreaterBroadcast1ElementUint8Test( |
| 162 | armnn::IWorkloadFactory& workloadFactory, |
| 163 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 164 | { |
| 165 | const unsigned int shape0[] = { 1, 2, 2, 3 }; |
| 166 | const unsigned int shape1[] = { 1, 1, 1, 1 }; |
| 167 | |
| 168 | std::vector<uint8_t> input0 = |
| 169 | { |
| 170 | 1, 2, 3, 4, 5, 6, |
| 171 | 7, 8, 9, 10, 11, 12 |
| 172 | }; |
| 173 | |
| 174 | std::vector<uint8_t> input1 = { 1 }; |
| 175 | |
| 176 | std::vector<uint8_t> output = |
| 177 | { |
| 178 | 0, 1, 1, 1, 1, 1, |
| 179 | 1, 1, 1, 1, 1, 1 |
| 180 | }; |
| 181 | |
| 182 | return ElementwiseTestHelper<4, |
| 183 | armnn::GreaterQueueDescriptor, |
| 184 | armnn::DataType::QuantisedAsymm8, |
| 185 | armnn::DataType::Boolean>( |
| 186 | workloadFactory, |
| 187 | memoryManager, |
| 188 | shape0, |
| 189 | input0, |
| 190 | shape1, |
| 191 | input1, |
| 192 | shape0, |
| 193 | output); |
| 194 | } |
| 195 | |
| 196 | LayerTestResult<uint8_t, 4> GreaterBroadcast1DVectorUint8Test( |
| 197 | armnn::IWorkloadFactory& workloadFactory, |
| 198 | const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager) |
| 199 | { |
| 200 | const unsigned int shape0[] = { 1, 2, 2, 3 }; |
| 201 | const unsigned int shape1[] = { 1, 1, 1, 3 }; |
| 202 | |
| 203 | std::vector<uint8_t> input0 = |
| 204 | { |
| 205 | 1, 2, 3, 4, 5, 6, |
| 206 | 7, 8, 9, 10, 11, 12 |
| 207 | }; |
| 208 | |
| 209 | std::vector<uint8_t> input1 = { 1, 1, 3 }; |
| 210 | |
| 211 | std::vector<uint8_t> output = |
| 212 | { |
| 213 | 0, 1, 0, 1, 1, 1, |
| 214 | 1, 1, 1, 1, 1, 1 |
| 215 | }; |
| 216 | |
| 217 | return ElementwiseTestHelper<4, |
| 218 | armnn::GreaterQueueDescriptor, |
| 219 | armnn::DataType::QuantisedAsymm8, |
| 220 | armnn::DataType::Boolean>( |
| 221 | workloadFactory, |
| 222 | memoryManager, |
| 223 | shape0, |
| 224 | input0, |
| 225 | shape1, |
| 226 | input1, |
| 227 | shape0, |
| 228 | output); |
| 229 | } |