blob: b2a645be5500a24f36f8fb411fe0de1b53a42ddc [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
Kevin May43a799c2019-02-08 16:31:42 +00006#include "ParserFlatbuffersSerializeFixture.hpp"
Finn Williams85d36712021-01-26 22:30:06 +00007#include <armnnDeserializer/IDeserializer.hpp>
Kevin May43a799c2019-02-08 16:31:42 +00008
Jan Eilers8eb25602020-03-09 12:13:48 +00009#include <armnn/utility/IgnoreUnused.hpp>
Derek Lamberti859f9ce2019-12-10 22:05:21 +000010
Sadik Armagan1625efc2021-06-10 18:24:34 +010011#include <doctest/doctest.h>
12
Kevin May43a799c2019-02-08 16:31:42 +000013#include <string>
Kevin May43a799c2019-02-08 16:31:42 +000014
Sadik Armagan1625efc2021-06-10 18:24:34 +010015TEST_SUITE("Deserializer_Add")
16{
Kevin May43a799c2019-02-08 16:31:42 +000017struct AddFixture : public ParserFlatbuffersSerializeFixture
18{
19 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 {
Jan Eilers8eb25602020-03-09 12:13:48 +000025 armnn::IgnoreUnused(activation);
Kevin May43a799c2019-02-08 16:31:42 +000026 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:{
Saoirse Stewart3fcef202019-02-14 14:57:37 +0000105 layerBindingId: 0,
Kevin May43a799c2019-02-08 16:31:42 +0000106 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
130struct SimpleAddFixture : AddFixture
131{
132 SimpleAddFixture() : AddFixture("[ 2, 2 ]",
133 "[ 2, 2 ]",
134 "[ 2, 2 ]",
135 "QuantisedAsymm8") {}
136};
137
138struct SimpleAddFixture2 : AddFixture
139{
140 SimpleAddFixture2() : AddFixture("[ 2, 2, 1, 1 ]",
141 "[ 2, 2, 1, 1 ]",
142 "[ 2, 2, 1, 1 ]",
143 "Float32") {}
144};
145
Sadik Armagan1625efc2021-06-10 18:24:34 +0100146TEST_CASE_FIXTURE(SimpleAddFixture, "AddQuantisedAsymm8")
Kevin May43a799c2019-02-08 16:31:42 +0000147{
Derek Lambertif90c56d2020-01-10 17:14:08 +0000148 RunTest<2, armnn::DataType::QAsymmU8>(
Kevin May43a799c2019-02-08 16:31:42 +0000149 0,
150 {{"InputLayer1", { 0, 1, 2, 3 }},
151 {"InputLayer2", { 4, 5, 6, 7 }}},
152 {{"OutputLayer", { 4, 6, 8, 10 }}});
153}
154
Sadik Armagan1625efc2021-06-10 18:24:34 +0100155TEST_CASE_FIXTURE(SimpleAddFixture2, "AddFloat32")
Kevin May43a799c2019-02-08 16:31:42 +0000156{
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
Sadik Armagan1625efc2021-06-10 18:24:34 +0100164}