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 "ParserFlatbuffersSerializeFixture.hpp"
8 #include "../Deserializer.hpp"
9
10 #include <armnn/utility/IgnoreUnused.hpp>
11
12 #include <string>
13 #include <iostream>
14
15 BOOST_AUTO_TEST_SUITE(Deserializer)
16
17 struct AddFixture : public ParserFlatbuffersSerializeFixture
18 {
AddFixtureAddFixture19 explicit AddFixture(const std::string & inputShape1,
20 const std::string & inputShape2,
21 const std::string & outputShape,
22 const std::string & dataType,
23 const std::string & activation="NONE")
24 {
25 armnn::IgnoreUnused(activation);
26 m_JsonString = R"(
27 {
28 inputIds: [0, 1],
29 outputIds: [3],
30 layers: [
31 {
32 layer_type: "InputLayer",
33 layer: {
34 base: {
35 layerBindingId: 0,
36 base: {
37 index: 0,
38 layerName: "InputLayer1",
39 layerType: "Input",
40 inputSlots: [{
41 index: 0,
42 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
43 }],
44 outputSlots: [ {
45 index: 0,
46 tensorInfo: {
47 dimensions: )" + inputShape1 + R"(,
48 dataType: )" + dataType + R"(
49 },
50 }],
51 },}},
52 },
53 {
54 layer_type: "InputLayer",
55 layer: {
56 base: {
57 layerBindingId: 1,
58 base: {
59 index:1,
60 layerName: "InputLayer2",
61 layerType: "Input",
62 inputSlots: [{
63 index: 0,
64 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
65 }],
66 outputSlots: [ {
67 index: 0,
68 tensorInfo: {
69 dimensions: )" + inputShape2 + R"(,
70 dataType: )" + dataType + R"(
71 },
72 }],
73 },}},
74 },
75 {
76 layer_type: "AdditionLayer",
77 layer : {
78 base: {
79 index:2,
80 layerName: "AdditionLayer",
81 layerType: "Addition",
82 inputSlots: [
83 {
84 index: 0,
85 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
86 },
87 {
88 index: 1,
89 connection: {sourceLayerIndex:1, outputSlotIndex:0 },
90 }
91 ],
92 outputSlots: [ {
93 index: 0,
94 tensorInfo: {
95 dimensions: )" + outputShape + R"(,
96 dataType: )" + dataType + R"(
97 },
98 }],
99 }},
100 },
101 {
102 layer_type: "OutputLayer",
103 layer: {
104 base:{
105 layerBindingId: 0,
106 base: {
107 index: 3,
108 layerName: "OutputLayer",
109 layerType: "Output",
110 inputSlots: [{
111 index: 0,
112 connection: {sourceLayerIndex:2, outputSlotIndex:0 },
113 }],
114 outputSlots: [ {
115 index: 0,
116 tensorInfo: {
117 dimensions: )" + outputShape + R"(,
118 dataType: )" + dataType + R"(
119 },
120 }],
121 }}},
122 }]
123 }
124 )";
125 Setup();
126 }
127 };
128
129
130 struct SimpleAddFixture : AddFixture
131 {
SimpleAddFixtureSimpleAddFixture132 SimpleAddFixture() : AddFixture("[ 2, 2 ]",
133 "[ 2, 2 ]",
134 "[ 2, 2 ]",
135 "QuantisedAsymm8") {}
136 };
137
138 struct SimpleAddFixture2 : AddFixture
139 {
SimpleAddFixture2SimpleAddFixture2140 SimpleAddFixture2() : AddFixture("[ 2, 2, 1, 1 ]",
141 "[ 2, 2, 1, 1 ]",
142 "[ 2, 2, 1, 1 ]",
143 "Float32") {}
144 };
145
BOOST_FIXTURE_TEST_CASE(AddQuantisedAsymm8,SimpleAddFixture)146 BOOST_FIXTURE_TEST_CASE(AddQuantisedAsymm8, SimpleAddFixture)
147 {
148 RunTest<2, armnn::DataType::QAsymmU8>(
149 0,
150 {{"InputLayer1", { 0, 1, 2, 3 }},
151 {"InputLayer2", { 4, 5, 6, 7 }}},
152 {{"OutputLayer", { 4, 6, 8, 10 }}});
153 }
154
BOOST_FIXTURE_TEST_CASE(AddFloat32,SimpleAddFixture2)155 BOOST_FIXTURE_TEST_CASE(AddFloat32, SimpleAddFixture2)
156 {
157 RunTest<4, armnn::DataType::Float32>(
158 0,
159 {{"InputLayer1", { 111, 85, 226, 3 }},
160 {"InputLayer2", { 5, 8, 10, 12 }}},
161 {{"OutputLayer", { 116, 93, 236, 15 }}});
162 }
163
164 BOOST_AUTO_TEST_SUITE_END()
165