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