blob: 313c78cf05363fb18814faeca582d0ae16233234 [file] [log] [blame]
Sadik Armagan5f450272019-02-12 14:31:45 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Sadik Armagan5f450272019-02-12 14:31:45 +00006#include "ParserFlatbuffersSerializeFixture.hpp"
Finn Williams85d36712021-01-26 22:30:06 +00007#include <armnnDeserializer/IDeserializer.hpp>
Sadik Armagan5f450272019-02-12 14:31:45 +00008
Jan Eilers8eb25602020-03-09 12:13:48 +00009#include <armnn/utility/IgnoreUnused.hpp>
10
11#include <boost/test/unit_test.hpp>
Derek Lamberti859f9ce2019-12-10 22:05:21 +000012
Sadik Armagan5f450272019-02-12 14:31:45 +000013#include <string>
Sadik Armagan5f450272019-02-12 14:31:45 +000014
Derek Lamberti0028d1b2019-02-20 13:57:42 +000015BOOST_AUTO_TEST_SUITE(Deserializer)
Sadik Armagan5f450272019-02-12 14:31:45 +000016
17struct MultiplicationFixture : public ParserFlatbuffersSerializeFixture
18{
19 explicit MultiplicationFixture(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);
Sadik Armagan5f450272019-02-12 14:31:45 +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: "MultiplicationLayer",
77 layer : {
78 base: {
79 index:2,
80 layerName: "MultiplicationLayer",
81 layerType: "Multiplication",
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,
Sadik Armagan5f450272019-02-12 14:31:45 +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 SimpleMultiplicationFixture : MultiplicationFixture
131{
132 SimpleMultiplicationFixture() : MultiplicationFixture("[ 2, 2 ]",
133 "[ 2, 2 ]",
134 "[ 2, 2 ]",
135 "QuantisedAsymm8") {}
136};
137
138struct SimpleMultiplicationFixture2 : MultiplicationFixture
139{
140 SimpleMultiplicationFixture2() : MultiplicationFixture("[ 2, 2, 1, 1 ]",
141 "[ 2, 2, 1, 1 ]",
142 "[ 2, 2, 1, 1 ]",
143 "Float32") {}
144};
145
146BOOST_FIXTURE_TEST_CASE(MultiplicationQuantisedAsymm8, SimpleMultiplicationFixture)
147{
Derek Lambertif90c56d2020-01-10 17:14:08 +0000148 RunTest<2, armnn::DataType::QAsymmU8>(
Sadik Armagan5f450272019-02-12 14:31:45 +0000149 0,
150 {{"InputLayer1", { 0, 1, 2, 3 }},
151 {"InputLayer2", { 4, 5, 6, 7 }}},
152 {{"OutputLayer", { 0, 5, 12, 21 }}});
153}
154
155BOOST_FIXTURE_TEST_CASE(MultiplicationFloat32, SimpleMultiplicationFixture2)
156{
157 RunTest<4, armnn::DataType::Float32>(
158 0,
159 {{"InputLayer1", { 100, 40, 226, 9 }},
160 {"InputLayer2", { 5, 8, 1, 12 }}},
161 {{"OutputLayer", { 500, 320, 226, 108 }}});
162}
163
164BOOST_AUTO_TEST_SUITE_END()