• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include <boost/test/unit_test.hpp>
7 #include "ParserFlatbuffersFixture.hpp"
8 #include "../TfLiteParser.hpp"
9 
10 #include <string>
11 #include <iostream>
12 
13 BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
14 
15 struct SubFixture : public ParserFlatbuffersFixture
16 {
SubFixtureSubFixture17     explicit SubFixture(const std::string & inputShape1,
18                         const std::string & inputShape2,
19                         const std::string & outputShape,
20                         const std::string & activation="NONE")
21     {
22         m_JsonString = R"(
23             {
24                 "version": 3,
25                 "operator_codes": [ { "builtin_code": "SUB" } ],
26                 "subgraphs": [ {
27                     "tensors": [
28                         {
29                             "shape": )" + inputShape1 + R"(,
30                             "type": "UINT8",
31                             "buffer": 0,
32                             "name": "inputTensor1",
33                             "quantization": {
34                                 "min": [ 0.0 ],
35                                 "max": [ 255.0 ],
36                                 "scale": [ 1.0 ],
37                                 "zero_point": [ 0 ],
38                             }
39                         },
40                         {
41                             "shape": )" + inputShape2 + R"(,
42                             "type": "UINT8",
43                             "buffer": 1,
44                             "name": "inputTensor2",
45                             "quantization": {
46                                 "min": [ 0.0 ],
47                                 "max": [ 255.0 ],
48                                 "scale": [ 1.0 ],
49                                 "zero_point": [ 0 ],
50                             }
51                         },
52                         {
53                             "shape": )" + outputShape + R"( ,
54                             "type": "UINT8",
55                             "buffer": 2,
56                             "name": "outputTensor",
57                             "quantization": {
58                                 "min": [ 0.0 ],
59                                 "max": [ 255.0 ],
60                                 "scale": [ 1.0 ],
61                                 "zero_point": [ 0 ],
62                             }
63                         }
64                     ],
65                     "inputs": [ 0, 1 ],
66                     "outputs": [ 2 ],
67                     "operators": [
68                         {
69                             "opcode_index": 0,
70                             "inputs": [ 0, 1 ],
71                             "outputs": [ 2 ],
72                             "builtin_options_type": "SubOptions",
73                             "builtin_options": {
74                                 "fused_activation_function": )" + activation + R"(
75                             },
76                             "custom_options_format": "FLEXBUFFERS"
77                         }
78                     ],
79                 } ],
80                 "buffers" : [
81                     { },
82                     { }
83                 ]
84             }
85         )";
86         Setup();
87     }
88 };
89 
90 
91 struct SimpleSubFixture : SubFixture
92 {
SimpleSubFixtureSimpleSubFixture93     SimpleSubFixture() : SubFixture("[ 1, 4 ]",
94                                     "[ 1, 4 ]",
95                                     "[ 1, 4 ]") {}
96 };
97 
BOOST_FIXTURE_TEST_CASE(SimpleSub,SimpleSubFixture)98 BOOST_FIXTURE_TEST_CASE(SimpleSub, SimpleSubFixture)
99 {
100   RunTest<2, armnn::DataType::QAsymmU8>(
101       0,
102       {{"inputTensor1", { 4, 5, 6, 7 }},
103       {"inputTensor2", { 3, 2, 1, 0 }}},
104       {{"outputTensor", { 1, 3, 5, 7 }}});
105 }
106 
107 struct DynamicSubFixture : SubFixture
108 {
DynamicSubFixtureDynamicSubFixture109     DynamicSubFixture() : SubFixture("[ 1, 4 ]",
110                                      "[ 1, 4 ]",
111                                      "[  ]") {}
112 };
113 
BOOST_FIXTURE_TEST_CASE(DynamicSub,DynamicSubFixture)114 BOOST_FIXTURE_TEST_CASE(DynamicSub, DynamicSubFixture)
115 {
116     RunTest<2, armnn::DataType::QAsymmU8, armnn::DataType::QAsymmU8>(
117         0,
118         {{"inputTensor1", { 4, 5, 6, 7 }},
119          {"inputTensor2", { 3, 2, 1, 0 }}},
120         {{"outputTensor", { 1, 3, 5, 7 }}},
121         true);
122 }
123 
124 BOOST_AUTO_TEST_SUITE_END()
125