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 <string>
11 #include <iostream>
12
13 BOOST_AUTO_TEST_SUITE(DeserializeParser)
14
15 struct ActivationFixture : public ParserFlatbuffersSerializeFixture
16 {
ActivationFixtureActivationFixture17 explicit ActivationFixture(const std::string& inputShape,
18 const std::string& outputShape,
19 const std::string& dataType,
20 const std::string& activationType="Sigmoid",
21 const std::string& a = "0.0",
22 const std::string& b = "0.0")
23 {
24 m_JsonString = R"(
25 {
26 inputIds: [0],
27 outputIds: [2],
28 layers: [{
29 layer_type: "InputLayer",
30 layer: {
31 base: {
32 layerBindingId: 0,
33 base: {
34 index: 0,
35 layerName: "InputLayer",
36 layerType: "Input",
37 inputSlots: [{
38 index: 0,
39 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
40 }],
41 outputSlots: [{
42 index: 0,
43 tensorInfo: {
44 dimensions: )" + inputShape + R"(,
45 dataType: )" + dataType + R"(
46 },
47 }],
48 },
49 }
50 },
51 },
52 {
53 layer_type: "ActivationLayer",
54 layer : {
55 base: {
56 index:1,
57 layerName: "ActivationLayer",
58 layerType: "Activation",
59 inputSlots: [{
60 index: 0,
61 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
62 }],
63 outputSlots: [{
64 index: 0,
65 tensorInfo: {
66 dimensions: )" + outputShape + R"(,
67 dataType: )" + dataType + R"(
68 },
69 }],
70 },
71 descriptor: {
72 a: )" + a + R"(,
73 b: )" + b + R"(,
74 activationFunction: )" + activationType + R"(
75 },
76 },
77 },
78 {
79 layer_type: "OutputLayer",
80 layer: {
81 base:{
82 layerBindingId: 2,
83 base: {
84 index: 2,
85 layerName: "OutputLayer",
86 layerType: "Output",
87 inputSlots: [{
88 index: 0,
89 connection: {sourceLayerIndex:1, outputSlotIndex:0 },
90 }],
91 outputSlots: [{
92 index: 0,
93 tensorInfo: {
94 dimensions: )" + outputShape + R"(,
95 dataType: )" + dataType + R"(
96 },
97 }],
98 }
99 }
100 },
101 }]
102 }
103 )";
104 Setup();
105 }
106 };
107
108 struct SimpleActivationFixture : ActivationFixture
109 {
SimpleActivationFixtureSimpleActivationFixture110 SimpleActivationFixture() : ActivationFixture("[1, 2, 2, 1]",
111 "[1, 2, 2, 1]",
112 "QuantisedAsymm8",
113 "ReLu") {}
114 };
115
116 struct SimpleActivationFixture2 : ActivationFixture
117 {
SimpleActivationFixture2SimpleActivationFixture2118 SimpleActivationFixture2() : ActivationFixture("[1, 2, 2, 1]",
119 "[1, 2, 2, 1]",
120 "Float32",
121 "ReLu") {}
122 };
123
124 struct SimpleActivationFixture3 : ActivationFixture
125 {
SimpleActivationFixture3SimpleActivationFixture3126 SimpleActivationFixture3() : ActivationFixture("[1, 2, 2, 1]",
127 "[1, 2, 2, 1]",
128 "QuantisedAsymm8",
129 "BoundedReLu",
130 "5.0",
131 "0.0") {}
132 };
133
134 struct SimpleActivationFixture4 : ActivationFixture
135 {
SimpleActivationFixture4SimpleActivationFixture4136 SimpleActivationFixture4() : ActivationFixture("[1, 2, 2, 1]",
137 "[1, 2, 2, 1]",
138 "Float32",
139 "BoundedReLu",
140 "5.0",
141 "0.0") {}
142 };
143
144
BOOST_FIXTURE_TEST_CASE(ActivationReluQuantisedAsymm8,SimpleActivationFixture)145 BOOST_FIXTURE_TEST_CASE(ActivationReluQuantisedAsymm8, SimpleActivationFixture)
146 {
147 RunTest<4, armnn::DataType::QAsymmU8>(
148 0,
149 {{"InputLayer", {10, 0, 2, 0}}},
150 {{"OutputLayer", {10, 0, 2, 0}}});
151 }
152
BOOST_FIXTURE_TEST_CASE(ActivationReluFloat32,SimpleActivationFixture2)153 BOOST_FIXTURE_TEST_CASE(ActivationReluFloat32, SimpleActivationFixture2)
154 {
155 RunTest<4, armnn::DataType::Float32>(
156 0,
157 {{"InputLayer", {111, -85, 226, 3}}},
158 {{"OutputLayer", {111, 0, 226, 3}}});
159 }
160
161
BOOST_FIXTURE_TEST_CASE(ActivationBoundedReluQuantisedAsymm8,SimpleActivationFixture3)162 BOOST_FIXTURE_TEST_CASE(ActivationBoundedReluQuantisedAsymm8, SimpleActivationFixture3)
163 {
164 RunTest<4, armnn::DataType::QAsymmU8>(
165 0,
166 {{"InputLayer", {10, 0, 2, 0}}},
167 {{"OutputLayer", {5, 0, 2, 0}}});
168 }
169
BOOST_FIXTURE_TEST_CASE(ActivationBoundedReluFloat32,SimpleActivationFixture4)170 BOOST_FIXTURE_TEST_CASE(ActivationBoundedReluFloat32, SimpleActivationFixture4)
171 {
172 RunTest<4, armnn::DataType::Float32>(
173 0,
174 {{"InputLayer", {111, -85, 226, 3}}},
175 {{"OutputLayer", {5, 0, 5, 3}}});
176 }
177
178 BOOST_AUTO_TEST_SUITE_END()
179