blob: 5ac6d1decefd29fd9b04448e8002047ab4ca6b99 [file] [log] [blame]
Ryan OShea86704732020-05-26 11:41:04 +01001//
Finn Williamsb49ed182021-06-29 15:50:08 +01002// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
Ryan OShea86704732020-05-26 11:41:04 +01003// SPDX-License-Identifier: MIT
4//
5
Ryan OShea86704732020-05-26 11:41:04 +01006#include "ParserFlatbuffersFixture.hpp"
Ryan OShea86704732020-05-26 11:41:04 +01007
Ryan OShea86704732020-05-26 11:41:04 +01008
Sadik Armagan1625efc2021-06-10 18:24:34 +01009TEST_SUITE("TensorflowLiteParser")
10{
Ryan OShea86704732020-05-26 11:41:04 +010011struct SplitVFixture : public ParserFlatbuffersFixture
12{
13 explicit SplitVFixture(const std::string& inputShape,
14 const std::string& splitValues,
15 const std::string& sizeSplitsShape,
16 const std::string& axisShape,
17 const std::string& numSplits,
18 const std::string& outputShape1,
19 const std::string& outputShape2,
20 const std::string& axisData,
21 const std::string& dataType)
22 {
23 m_JsonString = R"(
24 {
25 "version": 3,
26 "operator_codes": [ { "builtin_code": "SPLIT_V" } ],
27 "subgraphs": [ {
28 "tensors": [
29 {
30 "shape": )" + inputShape + R"(,
31 "type": )" + dataType + R"(,
32 "buffer": 0,
33 "name": "inputTensor",
34 "quantization": {
35 "min": [ 0.0 ],
36 "max": [ 255.0 ],
37 "scale": [ 1.0 ],
38 "zero_point": [ 0 ],
39 }
40 },
41 {
42 "shape": )" + sizeSplitsShape + R"(,
43 "type": "INT32",
44 "buffer": 1,
45 "name": "sizeSplits",
46 "quantization": {
47 "min": [ 0.0 ],
48 "max": [ 255.0 ],
49 "scale": [ 1.0 ],
50 "zero_point": [ 0 ],
51 }
52 },
53 {
54 "shape": )" + axisShape + R"(,
55 "type": "INT32",
56 "buffer": 2,
57 "name": "axis",
58 "quantization": {
59 "min": [ 0.0 ],
60 "max": [ 255.0 ],
61 "scale": [ 1.0 ],
62 "zero_point": [ 0 ],
63 }
64 },
65 {
66 "shape": )" + outputShape1 + R"( ,
67 "type":)" + dataType + R"(,
68 "buffer": 3,
69 "name": "outputTensor1",
70 "quantization": {
71 "min": [ 0.0 ],
72 "max": [ 255.0 ],
73 "scale": [ 1.0 ],
74 "zero_point": [ 0 ],
75 }
76 },
77 {
78 "shape": )" + outputShape2 + R"( ,
79 "type":)" + dataType + R"(,
80 "buffer": 4,
81 "name": "outputTensor2",
82 "quantization": {
83 "min": [ 0.0 ],
84 "max": [ 255.0 ],
85 "scale": [ 1.0 ],
86 "zero_point": [ 0 ],
87 }
88 }
89 ],
90 "inputs": [ 0, 1, 2 ],
91 "outputs": [ 3, 4 ],
92 "operators": [
93 {
94 "opcode_index": 0,
95 "inputs": [ 0, 1, 2 ],
96 "outputs": [ 3, 4 ],
97 "builtin_options_type": "SplitVOptions",
98 "builtin_options": {
99 "num_splits": )" + numSplits + R"(
100 },
101 "custom_options_format": "FLEXBUFFERS"
102 }
103 ],
104 } ],
105 "buffers" : [ {}, { "data": )" + splitValues + R"( }, { "data": )" + axisData + R"( }, {}, {}]
106 }
107 )";
108
109 Setup();
110 }
111};
112
113/*
114 * Tested inferred splitSizes with splitValues [-1, 1] locally.
115 */
116
117struct SimpleSplitVAxisOneFixture : SplitVFixture
118{
119 SimpleSplitVAxisOneFixture()
Jan Eilersc0761e92020-06-29 16:48:44 +0100120 : SplitVFixture( "[ 4, 2, 2, 2 ]", "[ 1, 0, 0, 0, 3, 0, 0, 0 ]", "[ 2 ]","[ ]", "2",
Ryan OShea86704732020-05-26 11:41:04 +0100121 "[ 1, 2, 2, 2 ]", "[ 3, 2, 2, 2 ]", "[ 0, 0, 0, 0 ]", "FLOAT32")
122 {}
123};
124
Sadik Armagan1625efc2021-06-10 18:24:34 +0100125TEST_CASE_FIXTURE(SimpleSplitVAxisOneFixture, "ParseAxisOneSplitVTwo")
Ryan OShea86704732020-05-26 11:41:04 +0100126{
127 RunTest<4, armnn::DataType::Float32>(
128 0,
129 { {"inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
130 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f,
131 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f,
132 25.0f, 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, 31.0f, 32.0f } } },
133 { {"outputTensor1", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f } },
134 {"outputTensor2", { 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f,
135 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f,
136 25.0f, 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, 31.0f, 32.0f } } } );
137}
138
139struct SimpleSplitVAxisTwoFixture : SplitVFixture
140{
141 SimpleSplitVAxisTwoFixture()
Jan Eilersc0761e92020-06-29 16:48:44 +0100142 : SplitVFixture( "[ 2, 4, 2, 2 ]", "[ 3, 0, 0, 0, 1, 0, 0, 0 ]", "[ 2 ]","[ ]", "2",
Ryan OShea86704732020-05-26 11:41:04 +0100143 "[ 2, 3, 2, 2 ]", "[ 2, 1, 2, 2 ]", "[ 1, 0, 0, 0 ]", "FLOAT32")
144 {}
145};
146
Sadik Armagan1625efc2021-06-10 18:24:34 +0100147TEST_CASE_FIXTURE(SimpleSplitVAxisTwoFixture, "ParseAxisTwoSplitVTwo")
Ryan OShea86704732020-05-26 11:41:04 +0100148{
149 RunTest<4, armnn::DataType::Float32>(
150 0,
151 { {"inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
152 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f,
153 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f,
154 25.0f, 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, 31.0f, 32.0f } } },
155 { {"outputTensor1", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
156 9.0f, 10.0f, 11.0f, 12.0f, 17.0f, 18.0f, 19.0f, 20.0f,
157 21.0f, 22.0f, 23.0f, 24.0f, 25.0f, 26.0f, 27.0f, 28.0f } },
158 {"outputTensor2", { 13.0f, 14.0f, 15.0f, 16.0f, 29.0f, 30.0f, 31.0f, 32.0f } } } );
159}
160
161struct SimpleSplitVAxisThreeFixture : SplitVFixture
162{
163 SimpleSplitVAxisThreeFixture()
Jan Eilersc0761e92020-06-29 16:48:44 +0100164 : SplitVFixture( "[ 2, 2, 4, 2 ]", "[ 1, 0, 0, 0, 3, 0, 0, 0 ]", "[ 2 ]","[ ]", "2",
Ryan OShea86704732020-05-26 11:41:04 +0100165 "[ 2, 2, 1, 2 ]", "[ 2, 2, 3, 2 ]", "[ 2, 0, 0, 0 ]", "FLOAT32")
166 {}
167};
168
Sadik Armagan1625efc2021-06-10 18:24:34 +0100169TEST_CASE_FIXTURE(SimpleSplitVAxisThreeFixture, "ParseAxisThreeSplitVTwo")
Ryan OShea86704732020-05-26 11:41:04 +0100170{
171 RunTest<4, armnn::DataType::Float32>(
172 0,
173 { {"inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
174 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f,
175 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f,
176 25.0f, 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, 31.0f, 32.0f } } },
177 { {"outputTensor1", { 1.0f, 2.0f, 9.0f, 10.0f, 17.0f, 18.0f, 25.0f, 26.0f } },
178 {"outputTensor2", { 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 11.0f, 12.0f,
179 13.0f, 14.0f, 15.0f, 16.0f, 19.0f, 20.0f, 21.0f, 22.0f,
180 23.0f, 24.0f, 27.0f, 28.0f, 29.0f, 30.0f, 31.0f, 32.0f } } } );
181}
182
183struct SimpleSplitVAxisFourFixture : SplitVFixture
184{
185 SimpleSplitVAxisFourFixture()
Jan Eilersc0761e92020-06-29 16:48:44 +0100186 : SplitVFixture( "[ 2, 2, 2, 4 ]", "[ 3, 0, 0, 0, 1, 0, 0, 0 ]", "[ 2 ]","[ ]", "2",
Ryan OShea86704732020-05-26 11:41:04 +0100187 "[ 2, 2, 2, 3 ]", "[ 2, 2, 2, 1 ]", "[ 3, 0, 0, 0 ]", "FLOAT32")
188 {}
189};
190
Sadik Armagan1625efc2021-06-10 18:24:34 +0100191TEST_CASE_FIXTURE(SimpleSplitVAxisFourFixture, "ParseAxisFourSplitVTwo")
Ryan OShea86704732020-05-26 11:41:04 +0100192{
193 RunTest<4, armnn::DataType::Float32>(
194 0,
195 { {"inputTensor", { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f,
196 9.0f, 10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f,
197 17.0f, 18.0f, 19.0f, 20.0f, 21.0f, 22.0f, 23.0f, 24.0f,
198 25.0f, 26.0f, 27.0f, 28.0f, 29.0f, 30.0f, 31.0f, 32.0f } } },
199 { {"outputTensor1", { 1.0f, 2.0f, 3.0f, 5.0f, 6.0f, 7.0f, 9.0f, 10.0f,
200 11.0f, 13.0f, 14.0f, 15.0f, 17.0f, 18.0f, 19.0f, 21.0f,
201 22.0f, 23.0f, 25.0f, 26.0f, 27.0f, 29.0f, 30.0f, 31.0f} },
202 {"outputTensor2", { 4.0f, 8.0f, 12.0f, 16.0f, 20.0f, 24.0f, 28.0f, 32.0f } } } );
203}
204
Sadik Armagan1625efc2021-06-10 18:24:34 +0100205}