blob: b6f207c9d14f75048c9f96356e866d3c6d4f66f0 [file] [log] [blame]
Tracy Narine944fb502023-07-04 15:08:57 +01001//
2// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "ParserFlatbuffersSerializeFixture.hpp"
7#include <armnnDeserializer/IDeserializer.hpp>
8
9#include <doctest/doctest.h>
10
11#include <string>
12
13TEST_SUITE("Deserializer_ReverseV2")
14{
15 struct ReverseV2Fixture : public ParserFlatbuffersSerializeFixture
16 {
Tracy Narinebb8d7592023-07-13 16:50:54 +010017 explicit ReverseV2Fixture(const std::string& inputShape0,
18 const std::string& inputShape1,
Tracy Narine944fb502023-07-04 15:08:57 +010019 const std::string& outputShape,
Tracy Narinebb8d7592023-07-13 16:50:54 +010020 const std::string& dataType0,
21 const std::string& dataType1)
Tracy Narine944fb502023-07-04 15:08:57 +010022 {
23 m_JsonString = R"(
24 {
Tracy Narinebb8d7592023-07-13 16:50:54 +010025 inputIds: [0, 1],
26 outputIds: [3],
27 layers:
28 [
Tracy Narine944fb502023-07-04 15:08:57 +010029 {
30 layer_type: "InputLayer",
31 layer: {
Tracy Narinebb8d7592023-07-13 16:50:54 +010032 base: {
33 layerBindingId: 0,
34 base: {
Tracy Narine944fb502023-07-04 15:08:57 +010035 index: 0,
Tracy Narinebb8d7592023-07-13 16:50:54 +010036 layerName: "InputLayer0",
37 layerType: "Input",
38 inputSlots:
39 [{
40 index: 0,
41 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
42 }],
43 outputSlots:
44 [ {
45 index: 0,
46 tensorInfo: {
47 dimensions: )" + inputShape0 + R"(,
48 dataType: )" + dataType0 + R"(
49 }
50 }]
51 }
52 }
Tracy Narine944fb502023-07-04 15:08:57 +010053 }
54 },
55 {
Tracy Narinebb8d7592023-07-13 16:50:54 +010056 layer_type: "InputLayer",
Tracy Narine944fb502023-07-04 15:08:57 +010057 layer: {
Tracy Narinebb8d7592023-07-13 16:50:54 +010058 base: {
59 layerBindingId: 1,
60 base: {
61 index:1,
62 layerName: "InputLayer1",
63 layerType: "Input",
64 inputSlots:
65 [{
66 index: 0,
67 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
68 }],
69 outputSlots:
70 [{
71 index: 0,
72 tensorInfo: {
73 dimensions: )" + inputShape1 + R"(,
74 dataType: )" + dataType1 + R"(
75 }
76 }]
Tracy Narine944fb502023-07-04 15:08:57 +010077 }
Tracy Narinebb8d7592023-07-13 16:50:54 +010078 }
79 }
80 },
81 {
82 layer_type: "ReverseV2Layer",
83 layer : {
84 base: {
85 index:2,
86 layerName: "ReverseV2Layer",
87 layerType: "ReverseV2",
88 inputSlots:
89 [
90 {
91 index: 0,
92 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
93 },
94 {
95 index: 1,
96 connection: {sourceLayerIndex:1, outputSlotIndex:0 },
97 }
98 ],
99 outputSlots:
100 [{
101 index: 0,
102 tensorInfo: {
103 dimensions: )" + outputShape + R"(,
104 dataType: )" + dataType0 + R"(
105 }
Tracy Narine944fb502023-07-04 15:08:57 +0100106 }]
Tracy Narine944fb502023-07-04 15:08:57 +0100107 }
108 }
109 },
110 {
111 layer_type: "OutputLayer",
112 layer: {
113 base:{
Tracy Narinebb8d7592023-07-13 16:50:54 +0100114 layerBindingId: 0,
115 base: {
116 index: 3,
117 layerName: "OutputLayer",
118 layerType: "Output",
119 inputSlots:
120 [{
121 index: 0,
122 connection: {sourceLayerIndex:2, outputSlotIndex:0 },
123 }],
124 outputSlots:
125 [{
126 index: 0,
127 tensorInfo: {
128 dimensions: )" + outputShape + R"(,
129 dataType: )" + dataType0 + R"(
130 }
131 }]
132 }
Tracy Narine944fb502023-07-04 15:08:57 +0100133 }
134 }
135 }
136 ]
Tracy Narinebb8d7592023-07-13 16:50:54 +0100137 } )";
Tracy Narine944fb502023-07-04 15:08:57 +0100138
Tracy Narinebb8d7592023-07-13 16:50:54 +0100139 Setup();
Tracy Narine944fb502023-07-04 15:08:57 +0100140 }
141 };
142
143 // Test cases
144
145 struct SimpleReverseV2FixtureFloat32 : ReverseV2Fixture
146 {
147 SimpleReverseV2FixtureFloat32()
Tracy Narinebb8d7592023-07-13 16:50:54 +0100148 : ReverseV2Fixture("[ 2, 2 ]",
149 "[ 1 ]",
150 "[ 2, 2 ]",
151 "Float32",
152 "Signed32")
Tracy Narine944fb502023-07-04 15:08:57 +0100153 {}
154 };
155
156 TEST_CASE_FIXTURE(SimpleReverseV2FixtureFloat32, "SimpleReverseV2TestFloat32")
157 {
Tracy Narinebb8d7592023-07-13 16:50:54 +0100158 RunTest<2, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32>(
Tracy Narine944fb502023-07-04 15:08:57 +0100159 0,
Tracy Narinebb8d7592023-07-13 16:50:54 +0100160 {
161 {
162 "InputLayer0",
163 { 1.0f, 2.0f,
164 3.0f, 4.0f }
165 }
166 },
167 {
168 {
169 "InputLayer1",
170 { 1 }
171 }
172 },
173 {
174 {
175 "OutputLayer",
176 { 2.0f, 1.0f,
177 4.0f, 3.0f }
178 }
179 }
Tracy Narine944fb502023-07-04 15:08:57 +0100180 );
181 }
182
Tracy Narinebb8d7592023-07-13 16:50:54 +0100183 struct SimpleReverseV2FixtureFloat32OtherAxis : ReverseV2Fixture
Tracy Narine944fb502023-07-04 15:08:57 +0100184 {
Tracy Narinebb8d7592023-07-13 16:50:54 +0100185 SimpleReverseV2FixtureFloat32OtherAxis()
186 : ReverseV2Fixture("[ 2, 2 ]",
187 "[ 1 ]",
188 "[ 2, 2 ]",
189 "Float32",
190 "Signed32")
Tracy Narine944fb502023-07-04 15:08:57 +0100191 {}
192 };
193
Tracy Narinebb8d7592023-07-13 16:50:54 +0100194 TEST_CASE_FIXTURE(SimpleReverseV2FixtureFloat32OtherAxis, "SimpleReverseV2FixtureFloat32OtherAxis")
Tracy Narine944fb502023-07-04 15:08:57 +0100195 {
Tracy Narinebb8d7592023-07-13 16:50:54 +0100196 RunTest<2, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32>(
197 0,
198 {
199 {
200 "InputLayer0",
201 { 1.0f, 2.0f,
202 3.0f, 4.0f }
203 }
204 },
205 {
206 {
207 "InputLayer1",
208 { 1 }
209 }
210 },
211 {
212 {
213 "OutputLayer",
214 { 2.0f, 1.0f,
215 4.0f, 3.0f }
216 }
217 }
218 );
219 }
220
221 struct SimpleReverseV2FixtureFloat32NegativeFirstAxis : ReverseV2Fixture
222 {
223 SimpleReverseV2FixtureFloat32NegativeFirstAxis()
224 : ReverseV2Fixture("[ 2, 2 ]",
225 "[ 1 ]",
226 "[ 2, 2 ]",
227 "Float32",
228 "Signed32")
229 {}
230 };
231
232 TEST_CASE_FIXTURE(SimpleReverseV2FixtureFloat32NegativeFirstAxis, "SimpleReverseV2FixtureFloat32NegativeFirstAxis")
233 {
234 RunTest<2, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32>(
235 0,
236 {
237 {
238 "InputLayer0",
239 { 1.0f, 2.0f,
240 3.0f, 4.0f }
241 }
242 },
243 {
244 {
245 "InputLayer1",
246 { -2 }
247 }
248 },
249 {
250 {
251 "OutputLayer",
252 { 3.0f, 4.0f,
253 1.0f, 2.0f }
254 }
255 }
256 );
257 }
258
259 struct SimpleReverseV2FixtureFloat32NegativeSecondAxis : ReverseV2Fixture
260 {
261 SimpleReverseV2FixtureFloat32NegativeSecondAxis()
262 : ReverseV2Fixture("[ 3, 3 ]",
263 "[ 1 ]",
264 "[ 3, 3 ]",
265 "Float32",
266 "Signed32")
267 {}
268 };
269
270 TEST_CASE_FIXTURE(SimpleReverseV2FixtureFloat32NegativeSecondAxis,
271 "SimpleReverseV2FixtureFloat32NegativeSecondAxis")
272 {
273 RunTest<2, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32>(
274 0,
275 {
276 {
277 "InputLayer0",
278 { 1.0f, 2.0f, 3.0f,
279 4.0f, 5.0f, 6.0f,
280 7.0f, 8.0f, 9.0f }
281 }
282 },
283 {
284 {
285 "InputLayer1",
286 { -1 }
287 }
288 },
289 {
290 {
291 "OutputLayer",
292 { 3.0f, 2.0f, 1.0f,
293 6.0f, 5.0f, 4.0f,
294 9.0f, 8.0f, 7.0f }
295 }
296 }
Tracy Narine944fb502023-07-04 15:08:57 +0100297 );
298 }
299
300 struct SimpleReverseV2FixtureFloat32ThreeAxis : ReverseV2Fixture
301 {
302 SimpleReverseV2FixtureFloat32ThreeAxis()
303 : ReverseV2Fixture("[ 3, 3, 3 ]",
Tracy Narinebb8d7592023-07-13 16:50:54 +0100304 "[ 3 ]",
Tracy Narine944fb502023-07-04 15:08:57 +0100305 "[ 3, 3, 3 ]",
306 "Float32",
Tracy Narinebb8d7592023-07-13 16:50:54 +0100307 "Signed32")
Tracy Narine944fb502023-07-04 15:08:57 +0100308 {}
309 };
310
311 TEST_CASE_FIXTURE(SimpleReverseV2FixtureFloat32ThreeAxis, "SimpleReverseV2TestFloat32ThreeAxis")
312 {
Tracy Narinebb8d7592023-07-13 16:50:54 +0100313 RunTest<2, armnn::DataType::Float32, armnn::DataType::Signed32, armnn::DataType::Float32>(
314 0,
315 {
316 {
317 "InputLayer0",
318 { 1.0f, 2.0f, 3.0f,
319 4.0f, 5.0f, 6.0f,
320 7.0f, 8.0f, 9.0f,
Tracy Narine944fb502023-07-04 15:08:57 +0100321
Tracy Narinebb8d7592023-07-13 16:50:54 +0100322 11.0f, 12.0f, 13.0f,
323 14.0f, 15.0f, 16.0f,
324 17.0f, 18.0f, 19.0f,
Tracy Narine944fb502023-07-04 15:08:57 +0100325
Tracy Narinebb8d7592023-07-13 16:50:54 +0100326 21.0f, 22.0f, 23.0f,
327 24.0f, 25.0f, 26.0f,
328 27.0f, 28.0f, 29.0f },
329 }
330 },
331 {
332 {
333 "InputLayer1",
334 { 0, 2, 1 }
335 }
336 },
337 {
338 {
339 "OutputLayer",
340 { 29.0f, 28.0f, 27.0f,
341 26.0f, 25.0f, 24.0f,
342 23.0f, 22.0f, 21.0f,
Tracy Narine944fb502023-07-04 15:08:57 +0100343
Tracy Narinebb8d7592023-07-13 16:50:54 +0100344 19.0f, 18.0f, 17.0f,
345 16.0f, 15.0f, 14.0f,
346 13.0f, 12.0f, 11.0f,
Tracy Narine944fb502023-07-04 15:08:57 +0100347
Tracy Narinebb8d7592023-07-13 16:50:54 +0100348 9.0f, 8.0f, 7.0f,
349 6.0f, 5.0f, 4.0f,
350 3.0f, 2.0f, 1.0f }
351 }
352 }
Tracy Narine944fb502023-07-04 15:08:57 +0100353 );
354 }
355
356 struct SimpleReverseV2FixtureQuantisedAsymm8ThreeAxis : ReverseV2Fixture
357 {
358 SimpleReverseV2FixtureQuantisedAsymm8ThreeAxis()
359 : ReverseV2Fixture("[ 3, 3, 3 ]",
Tracy Narinebb8d7592023-07-13 16:50:54 +0100360 "[ 3 ]",
Tracy Narine944fb502023-07-04 15:08:57 +0100361 "[ 3, 3, 3 ]",
362 "QuantisedAsymm8",
Tracy Narinebb8d7592023-07-13 16:50:54 +0100363 "Signed32")
Tracy Narine944fb502023-07-04 15:08:57 +0100364 {}
365 };
366
367 TEST_CASE_FIXTURE(SimpleReverseV2FixtureQuantisedAsymm8ThreeAxis, "SimpleReverseV2TestQuantisedAsymm8ThreeAxis")
368 {
Tracy Narinebb8d7592023-07-13 16:50:54 +0100369 RunTest<2, armnn::DataType::QAsymmU8, armnn::DataType::Signed32, armnn::DataType::QAsymmU8>(
370 0,
371 {
372 {
373 "InputLayer0",
374 { 1, 2, 3,
375 4, 5, 6,
376 7, 8, 9,
Tracy Narine944fb502023-07-04 15:08:57 +0100377
Tracy Narinebb8d7592023-07-13 16:50:54 +0100378 11, 12, 13,
379 14, 15, 16,
380 17, 18, 19,
Tracy Narine944fb502023-07-04 15:08:57 +0100381
Tracy Narinebb8d7592023-07-13 16:50:54 +0100382 21, 22, 23,
383 24, 25, 26,
384 27, 28, 29 },
385 }
386 },
387 {
388 {
389 "InputLayer1",
390 { 0, 2, 1 }
391 }
392 },
393 {
394 {
395 "OutputLayer",
396 { 29, 28, 27,
397 26, 25, 24,
398 23, 22, 21,
Tracy Narine944fb502023-07-04 15:08:57 +0100399
Tracy Narinebb8d7592023-07-13 16:50:54 +0100400 19, 18, 17,
401 16, 15, 14,
402 13, 12, 11,
Tracy Narine944fb502023-07-04 15:08:57 +0100403
Tracy Narinebb8d7592023-07-13 16:50:54 +0100404 9, 8, 7,
405 6, 5, 4,
406 3, 2, 1 }
407 }
408 }
Tracy Narine944fb502023-07-04 15:08:57 +0100409 );
410 }
411}