8198001f58e49f6c6da442f42aae300831a6da52
[platform/upstream/armnn.git] / src / armnnDeserializer / test / DeserializeMultiplication.cpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include "ParserFlatbuffersSerializeFixture.hpp"
7 #include "../Deserializer.hpp"
8
9 #include <armnn/utility/IgnoreUnused.hpp>
10
11 #include <boost/test/unit_test.hpp>
12
13 #include <string>
14 #include <iostream>
15
16 BOOST_AUTO_TEST_SUITE(Deserializer)
17
18 struct MultiplicationFixture : public ParserFlatbuffersSerializeFixture
19 {
20     explicit MultiplicationFixture(const std::string & inputShape1,
21                                    const std::string & inputShape2,
22                                    const std::string & outputShape,
23                                    const std::string & dataType,
24                                    const std::string & activation="NONE")
25     {
26         armnn::IgnoreUnused(activation);
27         m_JsonString = R"(
28         {
29                 inputIds: [0, 1],
30                 outputIds: [3],
31                 layers: [
32                 {
33                     layer_type: "InputLayer",
34                     layer: {
35                           base: {
36                                 layerBindingId: 0,
37                                 base: {
38                                     index: 0,
39                                     layerName: "InputLayer1",
40                                     layerType: "Input",
41                                     inputSlots: [{
42                                         index: 0,
43                                         connection: {sourceLayerIndex:0, outputSlotIndex:0 },
44                                     }],
45                                     outputSlots: [ {
46                                         index: 0,
47                                         tensorInfo: {
48                                             dimensions: )" + inputShape1 + R"(,
49                                             dataType: )" + dataType + R"(
50                                         },
51                                     }],
52                                  },}},
53                 },
54                 {
55                 layer_type: "InputLayer",
56                 layer: {
57                        base: {
58                             layerBindingId: 1,
59                             base: {
60                                   index:1,
61                                   layerName: "InputLayer2",
62                                   layerType: "Input",
63                                   inputSlots: [{
64                                       index: 0,
65                                       connection: {sourceLayerIndex:0, outputSlotIndex:0 },
66                                   }],
67                                   outputSlots: [ {
68                                       index: 0,
69                                       tensorInfo: {
70                                           dimensions: )" + inputShape2 + R"(,
71                                           dataType: )" + dataType + R"(
72                                       },
73                                   }],
74                                 },}},
75                 },
76                 {
77                 layer_type: "MultiplicationLayer",
78                 layer : {
79                         base: {
80                              index:2,
81                              layerName: "MultiplicationLayer",
82                              layerType: "Multiplication",
83                              inputSlots: [
84                                             {
85                                              index: 0,
86                                              connection: {sourceLayerIndex:0, outputSlotIndex:0 },
87                                             },
88                                             {
89                                              index: 1,
90                                              connection: {sourceLayerIndex:1, outputSlotIndex:0 },
91                                             }
92                              ],
93                              outputSlots: [ {
94                                  index: 0,
95                                  tensorInfo: {
96                                      dimensions: )" + outputShape + R"(,
97                                      dataType: )" + dataType + R"(
98                                  },
99                              }],
100                             }},
101                 },
102                 {
103                 layer_type: "OutputLayer",
104                 layer: {
105                         base:{
106                               layerBindingId: 0,
107                               base: {
108                                     index: 3,
109                                     layerName: "OutputLayer",
110                                     layerType: "Output",
111                                     inputSlots: [{
112                                         index: 0,
113                                         connection: {sourceLayerIndex:2, outputSlotIndex:0 },
114                                     }],
115                                     outputSlots: [ {
116                                         index: 0,
117                                         tensorInfo: {
118                                             dimensions: )" + outputShape + R"(,
119                                             dataType: )" + dataType + R"(
120                                         },
121                                 }],
122                             }}},
123                 }]
124          }
125         )";
126         Setup();
127     }
128 };
129
130
131 struct SimpleMultiplicationFixture : MultiplicationFixture
132 {
133     SimpleMultiplicationFixture() : MultiplicationFixture("[ 2, 2 ]",
134                                                           "[ 2, 2 ]",
135                                                           "[ 2, 2 ]",
136                                                           "QuantisedAsymm8") {}
137 };
138
139 struct SimpleMultiplicationFixture2 : MultiplicationFixture
140 {
141     SimpleMultiplicationFixture2() : MultiplicationFixture("[ 2, 2, 1, 1 ]",
142                                                            "[ 2, 2, 1, 1 ]",
143                                                            "[ 2, 2, 1, 1 ]",
144                                                            "Float32") {}
145 };
146
147 BOOST_FIXTURE_TEST_CASE(MultiplicationQuantisedAsymm8, SimpleMultiplicationFixture)
148 {
149   RunTest<2, armnn::DataType::QAsymmU8>(
150       0,
151       {{"InputLayer1", { 0, 1, 2, 3 }},
152       {"InputLayer2", { 4, 5, 6, 7 }}},
153       {{"OutputLayer", { 0, 5, 12, 21 }}});
154 }
155
156 BOOST_FIXTURE_TEST_CASE(MultiplicationFloat32, SimpleMultiplicationFixture2)
157 {
158     RunTest<4, armnn::DataType::Float32>(
159     0,
160     {{"InputLayer1", { 100, 40, 226, 9 }},
161     {"InputLayer2", {   5,   8,  1, 12 }}},
162     {{"OutputLayer", { 500, 320, 226, 108 }}});
163 }
164
165 BOOST_AUTO_TEST_SUITE_END()