blob: 0148216285eb7c01bc660ac513041bc15e2cbd4a [file] [log] [blame]
Aron Virginas-Tare89ebad2019-08-27 18:14:26 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "GreaterTestImpl.hpp"
Aron Virginas-Tare89ebad2019-08-27 18:14:26 +01007#include "ElementwiseTestImpl.hpp"
8
Matthew Jackson9bff1442019-09-12 09:08:23 +01009#include <Half.hpp>
10
Aron Virginas-Tare89ebad2019-08-27 18:14:26 +010011template<>
12std::unique_ptr<armnn::IWorkload> CreateWorkload<armnn::GreaterQueueDescriptor>(
13 const armnn::IWorkloadFactory& workloadFactory,
14 const armnn::WorkloadInfo& info,
15 const armnn::GreaterQueueDescriptor& descriptor)
16{
17 return workloadFactory.CreateGreater(descriptor, info);
18}
19
20LayerTestResult<uint8_t, 4> GreaterSimpleTest(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 =
37 {
38 1.f, 1.f, 1.f, 1.f, 3.f, 3.f, 3.f, 3.f,
39 5.f, 5.f, 5.f, 5.f, 4.f, 4.f, 4.f, 4.f
40 };
41
42 std::vector<uint8_t> output =
43 {
44 0, 0, 0, 0, 1, 1, 1, 1,
45 0, 0, 0, 0, 0, 0, 0, 0
46 };
47
48 return ElementwiseTestHelper<4,
49 armnn::GreaterQueueDescriptor,
50 armnn::DataType::Float32,
51 armnn::DataType::Boolean>(
52 workloadFactory,
53 memoryManager,
54 shape,
55 input0,
56 shape,
57 input1,
58 shape,
59 output);
60}
61
62LayerTestResult<uint8_t, 4> GreaterBroadcast1ElementTest(
63 armnn::IWorkloadFactory& workloadFactory,
64 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
65{
66 unsigned int shape0[] = { 1, 2, 2, 2 };
67 unsigned int shape1[] = { 1, 1, 1, 1 };
68
69 std::vector<float> input0 = { 1, 2, 3, 4, 5, 6, 7, 8};
70 std::vector<float> input1 = { 1 };
71
72 std::vector<uint8_t> output = { 0, 1, 1, 1, 1, 1, 1, 1};
73
74 return ElementwiseTestHelper<4,
75 armnn::GreaterQueueDescriptor,
76 armnn::DataType::Float32,
77 armnn::DataType::Boolean>(
78 workloadFactory,
79 memoryManager,
80 shape0,
81 input0,
82 shape1,
83 input1,
84 shape0,
85 output);
86}
87
88LayerTestResult<uint8_t, 4> GreaterBroadcast1DVectorTest(
89 armnn::IWorkloadFactory& workloadFactory,
90 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
91{
92 const unsigned int shape0[] = { 1, 2, 2, 3 };
93 const unsigned int shape1[] = { 1, 1, 1, 3 };
94
95 std::vector<float> input0 =
96 {
97 1.0f, 2.9f, 2.1f, 4.0f, 5.0f, 6.0f,
98 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f
99 };
100
101 std::vector<float> input1 = { 1.f, 3.f, 2.f };
102
103 std::vector<uint8_t> output =
104 {
105 0, 0, 1, 1, 1, 1,
106 1, 1, 1, 1, 1, 1
107 };
108
109 return ElementwiseTestHelper<4,
110 armnn::GreaterQueueDescriptor,
111 armnn::DataType::Float32,
112 armnn::DataType::Boolean>(
113 workloadFactory,
114 memoryManager,
115 shape0,
116 input0,
117 shape1,
118 input1,
119 shape0,
120 output);
121}
122
Matthew Jackson9bff1442019-09-12 09:08:23 +0100123LayerTestResult<uint8_t, 4> GreaterFloat16Test(
124 armnn::IWorkloadFactory& workloadFactory,
125 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
126{
127 using namespace half_float::literal;
128
129 const unsigned int width = 2u;
130 const unsigned int height = 2u;
131 const unsigned int channelCount = 2u;
132 const unsigned int batchSize = 2u;
133
134 unsigned int shape[] = { batchSize, channelCount, height, width };
135
136 std::vector<armnn::Half> input0 =
137 {
138 1._h, 1._h, 1._h, 1._h, 5._h, 5._h, 5._h, 5._h,
139 3._h, 3._h, 3._h, 3._h, 4._h, 4._h, 4._h, 4._h
140 };
141
142 std::vector<armnn::Half> input1 =
143 {
144 1._h, 1._h, 1._h, 1._h, 3._h, 3._h, 3._h, 3._h,
145 5._h, 5._h, 5._h, 5._h, 4._h, 4._h, 4._h, 4._h
146 };
147
148 std::vector<uint8_t> output =
149 {
150 0, 0, 0, 0, 1, 1, 1, 1,
151 0, 0, 0, 0, 0, 0, 0, 0
152 };
153
154 return ElementwiseTestHelper<4,
155 armnn::GreaterQueueDescriptor,
156 armnn::DataType::Float16,
157 armnn::DataType::Boolean>(
158 workloadFactory,
159 memoryManager,
160 shape,
161 input0,
162 shape,
163 input1,
164 shape,
165 output);
166}
167
168LayerTestResult<uint8_t, 4> GreaterBroadcast1ElementFloat16Test(
169 armnn::IWorkloadFactory& workloadFactory,
170 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
171{
172 using namespace half_float::literal;
173
174 unsigned int shape0[] = { 1, 2, 2, 2 };
175 unsigned int shape1[] = { 1, 1, 1, 1 };
176
177 std::vector<armnn::Half> input0 = { 1._h, 2._h, 3._h, 4._h, 5._h, 6._h, 7._h, 8._h };
178 std::vector<armnn::Half> input1 = { 1._h };
179
180 std::vector<uint8_t> output = { 0, 1, 1, 1, 1, 1, 1, 1};
181
182 return ElementwiseTestHelper<4,
183 armnn::GreaterQueueDescriptor,
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
196LayerTestResult<uint8_t, 4> GreaterBroadcast1DVectorFloat16Test(
197 armnn::IWorkloadFactory& workloadFactory,
198 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
199{
200 using namespace half_float::literal;
201
202 const unsigned int shape0[] = { 1, 2, 2, 3 };
203 const unsigned int shape1[] = { 1, 1, 1, 3 };
204
205 std::vector<armnn::Half> input0 =
206 {
207 1.0_h, 2.9_h, 2.1_h, 4.0_h, 5.0_h, 6.0_h,
208 7.0_h, 8.0_h, 9.0_h, 10.0_h, 11.0_h, 12.0_h
209 };
210
211 std::vector<armnn::Half> input1 = { 1._h, 3._h, 2._h };
212
213 std::vector<uint8_t> output =
214 {
215 0, 0, 1, 1, 1, 1,
216 1, 1, 1, 1, 1, 1
217 };
218
219 return ElementwiseTestHelper<4,
220 armnn::GreaterQueueDescriptor,
221 armnn::DataType::Float16,
222 armnn::DataType::Boolean>(
223 workloadFactory,
224 memoryManager,
225 shape0,
226 input0,
227 shape1,
228 input1,
229 shape0,
230 output);
231}
232
Aron Virginas-Tare89ebad2019-08-27 18:14:26 +0100233LayerTestResult<uint8_t, 4> GreaterUint8Test(
234 armnn::IWorkloadFactory& workloadFactory,
235 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
236{
237 unsigned int shape[] = { 2, 2, 2, 2 };
238
239 // See dequantized values to the right.
240 std::vector<uint8_t> input0 =
241 {
242 1, 1, 1, 1, 6, 6, 6, 6,
243 3, 3, 3, 3, 5, 5, 5, 5
244 };
245
246 std::vector<uint8_t> input1 =
247 {
248 2, 2, 2, 2, 6, 6, 6, 6,
249 2, 2, 2, 2, 5, 5, 5, 5
250 };
251
252 std::vector<uint8_t> output =
253 {
254 0, 0, 0, 0, 0, 0, 0, 0,
255 1, 1, 1, 1, 0, 0, 0, 0
256 };
257
258 return ElementwiseTestHelper<4,
259 armnn::GreaterQueueDescriptor,
260 armnn::DataType::QuantisedAsymm8,
261 armnn::DataType::Boolean>(
262 workloadFactory,
263 memoryManager,
264 shape,
265 input0,
266 shape,
267 input1,
268 shape,
269 output);
270}
271
272LayerTestResult<uint8_t, 4> GreaterBroadcast1ElementUint8Test(
273 armnn::IWorkloadFactory& workloadFactory,
274 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
275{
276 const unsigned int shape0[] = { 1, 2, 2, 3 };
277 const unsigned int shape1[] = { 1, 1, 1, 1 };
278
279 std::vector<uint8_t> input0 =
280 {
281 1, 2, 3, 4, 5, 6,
282 7, 8, 9, 10, 11, 12
283 };
284
285 std::vector<uint8_t> input1 = { 1 };
286
287 std::vector<uint8_t> output =
288 {
289 0, 1, 1, 1, 1, 1,
290 1, 1, 1, 1, 1, 1
291 };
292
293 return ElementwiseTestHelper<4,
294 armnn::GreaterQueueDescriptor,
295 armnn::DataType::QuantisedAsymm8,
296 armnn::DataType::Boolean>(
297 workloadFactory,
298 memoryManager,
299 shape0,
300 input0,
301 shape1,
302 input1,
303 shape0,
304 output);
305}
306
307LayerTestResult<uint8_t, 4> GreaterBroadcast1DVectorUint8Test(
308 armnn::IWorkloadFactory& workloadFactory,
309 const armnn::IBackendInternal::IMemoryManagerSharedPtr& memoryManager)
310{
311 const unsigned int shape0[] = { 1, 2, 2, 3 };
312 const unsigned int shape1[] = { 1, 1, 1, 3 };
313
314 std::vector<uint8_t> input0 =
315 {
316 1, 2, 3, 4, 5, 6,
317 7, 8, 9, 10, 11, 12
318 };
319
320 std::vector<uint8_t> input1 = { 1, 1, 3 };
321
322 std::vector<uint8_t> output =
323 {
324 0, 1, 0, 1, 1, 1,
325 1, 1, 1, 1, 1, 1
326 };
327
328 return ElementwiseTestHelper<4,
329 armnn::GreaterQueueDescriptor,
330 armnn::DataType::QuantisedAsymm8,
331 armnn::DataType::Boolean>(
332 workloadFactory,
333 memoryManager,
334 shape0,
335 input0,
336 shape1,
337 input1,
338 shape0,
339 output);
340}