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