ArmNN
 22.05
ReshapeDynamic.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
8 
9 TEST_SUITE("TensorflowLiteParser_Reshape_Dynamic")
10 {
11 struct ReshapeDynamicFixture1 : public ParserFlatbuffersFixture
12 {
13  explicit ReshapeDynamicFixture1()
14  {
15  m_JsonString = R"(
16 {
17  "version": 3,
18  "operator_codes": [
19  {
20  "deprecated_builtin_code": 77,
21  "version": 1,
22  "builtin_code": "ADD"
23  },
24  {
25  "deprecated_builtin_code": 22,
26  "version": 1,
27  "builtin_code": "ADD"
28  }
29  ],
30  "subgraphs": [
31  {
32  "tensors": [
33  {
34  "shape": [
35  2,
36  5
37  ],
38  "type": "FLOAT32",
39  "buffer": 1,
40  "name": "input_33",
41  "quantization": {
42  "details_type": "NONE",
43  "quantized_dimension": 0
44  },
45  "is_variable": false,
46  "shape_signature": [
47  -1,
48  10
49  ]
50  },
51  {
52  "shape": [
53  2
54  ],
55  "type": "INT32",
56  "buffer": 2,
57  "name": "functional_15/tf_op_layer_Shape_9/Shape_9",
58  "quantization": {
59  "details_type": "NONE",
60  "quantized_dimension": 0
61  },
62  "is_variable": false
63  },
64  {
65  "shape": [
66  2,
67  5
68  ],
69  "type": "FLOAT32",
70  "buffer": 3,
71  "name": "Identity",
72  "quantization": {
73  "details_type": "NONE",
74  "quantized_dimension": 0
75  },
76  "is_variable": false,
77  "shape_signature": [
78  -1,
79  5
80  ]
81  }
82  ],
83  "inputs": [
84  0
85  ],
86  "outputs": [
87  2
88  ],
89  "operators": [
90  {
91  "opcode_index": 0,
92  "inputs": [
93  0
94  ],
95  "outputs": [
96  1
97  ],
98  "builtin_options_type": "ShapeOptions",
99  "builtin_options": {
100  "out_type": "INT32"
101  },
102  "custom_options_format": "FLEXBUFFERS"
103  },
104  {
105  "opcode_index": 1,
106  "inputs": [
107  0,
108  1
109  ],
110  "outputs": [
111  2
112  ],
113  "builtin_options_type": "NONE",
114  "custom_options_format": "FLEXBUFFERS"
115  }
116  ],
117  "name": "main"
118  }
119  ],
120  "description": "MLIR Converted.",
121  "buffers": [
122  {
123  },
124  {
125  },
126  {
127  },
128  {
129  },
130  {
131  "data": [
132  49,
133  46,
134  49,
135  48,
136  46,
137  48,
138  0,
139  0,
140  0,
141  0,
142  0,
143  0,
144  0,
145  0,
146  0,
147  0
148  ]
149  }
150  ],
151  "metadata": [
152  {
153  "name": "min_runtime_version",
154  "buffer": 4
155  }
156  ]
157 }
158 )";
159 
160  }
161 };
162 
163 // ParseReshape test case: reshapeShapes[0] == 2
164 TEST_CASE_FIXTURE(ReshapeDynamicFixture1, "ParseReshapeDynamic1")
165 {
166  SetupSingleInputSingleOutput("input_33", "Identity");
167  RunTest<2, armnn::DataType::Float32>(0,
168  { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
169  { 1, 2, 3, 4, 5,
170  6, 7, 8, 9, 10 });
171 
172  CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "Identity").second.GetShape()
173  == armnn::TensorShape({2,5})));
174 }
175 
176 struct ReshapeDynamicFixture2 : public ParserFlatbuffersFixture
177 {
178  explicit ReshapeDynamicFixture2()
179  {
180  m_JsonString = R"(
181 {
182  "version": 3,
183  "operator_codes": [
184  {
185  "deprecated_builtin_code": 77,
186  "version": 1,
187  "builtin_code": "ADD"
188  },
189  {
190  "deprecated_builtin_code": 22,
191  "version": 1,
192  "builtin_code": "ADD"
193  }
194  ],
195  "subgraphs": [
196  {
197  "tensors": [
198  {
199  "shape": [
200  -1,
201  10
202  ],
203  "type": "FLOAT32",
204  "buffer": 1,
205  "name": "input_33",
206  "quantization": {
207  "details_type": "NONE",
208  "quantized_dimension": 0
209  },
210  "is_variable": false,
211  "shape_signature": [
212  2,
213  5
214  ]
215  },
216  {
217  "shape": [
218  1
219  ],
220  "type": "INT32",
221  "buffer": 2,
222  "name": "functional_15/tf_op_layer_Shape_9/Shape_9",
223  "quantization": {
224  "details_type": "NONE",
225  "quantized_dimension": 0
226  },
227  "is_variable": false
228  },
229  {
230  "shape": [
231  10
232  ],
233  "type": "FLOAT32",
234  "buffer": 3,
235  "name": "Identity",
236  "quantization": {
237  "details_type": "NONE",
238  "quantized_dimension": 0
239  },
240  "is_variable": false,
241  "shape_signature": [
242  -1,
243  10
244  ]
245  }
246  ],
247  "inputs": [
248  0
249  ],
250  "outputs": [
251  2
252  ],
253  "operators": [
254  {
255  "opcode_index": 0,
256  "inputs": [
257  0
258  ],
259  "outputs": [
260  1
261  ],
262  "builtin_options_type": "ShapeOptions",
263  "builtin_options": {
264  "out_type": "INT32"
265  },
266  "custom_options_format": "FLEXBUFFERS"
267  },
268  {
269  "opcode_index": 1,
270  "inputs": [
271  0,
272  1
273  ],
274  "outputs": [
275  2
276  ],
277  "builtin_options_type": "NONE",
278  "custom_options_format": "FLEXBUFFERS"
279  }
280  ],
281  "name": "main"
282  }
283  ],
284  "description": "MLIR Converted.",
285  "buffers": [
286  {
287  },
288  {
289  },
290  {
291  },
292  {
293  },
294  {
295  "data": [
296  49,
297  46,
298  49,
299  48,
300  46,
301  48,
302  0,
303  0,
304  0,
305  0,
306  0,
307  0,
308  0,
309  0,
310  0,
311  0
312  ]
313  }
314  ],
315  "metadata": [
316  {
317  "name": "min_runtime_version",
318  "buffer": 4
319  }
320  ]
321 }
322 )";
323 
324  }
325 };
326 
327 // ParseReshape test case: reshapeShapes[0] == 1
328 TEST_CASE_FIXTURE(ReshapeDynamicFixture2, "ParseReshapeDynamic2")
329 {
330  SetupSingleInputSingleOutput("input_33", "Identity");
331  RunTest<1, armnn::DataType::Float32>(0,
332  { 1, 2, 3, 4, 5,
333  6, 7, 8, 9, 10 },
334  { 1, 2, 3, 4, 5, 6, 7, 8 ,9, 10 });
335  CHECK((m_Parser->GetNetworkOutputBindingInfo(0, "Identity").second.GetShape()
336  == armnn::TensorShape({10})));
337 }
338 
339 struct ReshapeDynamicFixture3 : public ParserFlatbuffersFixture
340 {
341  explicit ReshapeDynamicFixture3()
342  {
343  m_JsonString = R"(
344 {
345  "version": 3,
346  "operator_codes": [
347  {
348  "deprecated_builtin_code": 77,
349  "version": 1,
350  "builtin_code": "ADD"
351  },
352  {
353  "deprecated_builtin_code": 22,
354  "version": 1,
355  "builtin_code": "ADD"
356  }
357  ],
358  "subgraphs": [
359  {
360  "tensors": [
361  {
362  "shape": [
363  1,
364  9
365  ],
366  "type": "FLOAT32",
367  "buffer": 1,
368  "name": "input_33",
369  "quantization": {
370  "details_type": "NONE",
371  "quantized_dimension": 0
372  },
373  "is_variable": false,
374  "shape_signature": [
375  -1,
376  9
377  ]
378  },
379  {
380  "shape": [
381  3
382  ],
383  "type": "INT32",
384  "buffer": 2,
385  "name": "functional_15/tf_op_layer_Shape_9/Shape_9",
386  "quantization": {
387  "details_type": "NONE",
388  "quantized_dimension": 0
389  },
390  "is_variable": false
391  },
392  {
393  "shape": [
394  1,
395  9
396  ],
397  "type": "FLOAT32",
398  "buffer": 3,
399  "name": "Identity",
400  "quantization": {
401  "details_type": "NONE",
402  "quantized_dimension": 0
403  },
404  "is_variable": false,
405  "shape_signature": [
406  -1,
407  9
408  ]
409  }
410  ],
411  "inputs": [
412  0
413  ],
414  "outputs": [
415  2
416  ],
417  "operators": [
418  {
419  "opcode_index": 0,
420  "inputs": [
421  0
422  ],
423  "outputs": [
424  1
425  ],
426  "builtin_options_type": "ShapeOptions",
427  "builtin_options": {
428  "out_type": "INT32"
429  },
430  "custom_options_format": "FLEXBUFFERS"
431  },
432  {
433  "opcode_index": 1,
434  "inputs": [
435  0,
436  1
437  ],
438  "outputs": [
439  2
440  ],
441  "builtin_options_type": "NONE",
442  "custom_options_format": "FLEXBUFFERS"
443  }
444  ],
445  "name": "main"
446  }
447  ],
448  "description": "MLIR Converted.",
449  "buffers": [
450  {
451  },
452  {
453  },
454  {
455  },
456  {
457  },
458  {
459  "data": [
460  49,
461  46,
462  49,
463  48,
464  46,
465  48,
466  0,
467  0,
468  0,
469  0,
470  0,
471  0,
472  0,
473  0,
474  0,
475  0
476  ]
477  }
478  ],
479  "metadata": [
480  {
481  "name": "min_runtime_version",
482  "buffer": 4
483  }
484  ]
485 }
486 )";
487 
488  }
489 };
490 
491 // ParseReshape test case: reshapeShapes[0] > 2
492 TEST_CASE_FIXTURE(ReshapeDynamicFixture3, "ParseReshapeDynamic3")
493 {
494  CHECK_THROWS_AS(SetupSingleInputSingleOutput("input_33", "Identity"), armnn::ParseException);
495 }
496 
497 }
TEST_CASE_FIXTURE(ClContextControlFixture, "CopyBetweenNeonAndGpu")
TEST_SUITE("TensorflowLiteParser_Reshape_Dynamic")
void SetupSingleInputSingleOutput(const std::string &inputName, const std::string &outputName)