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