IVGCVSW-5593 Implement Pimpl Idiom for serialization classes
[platform/upstream/armnn.git] / src / armnnDeserializer / test / DeserializePooling2d.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 Pooling2dFixture : public ParserFlatbuffersSerializeFixture
15 {
16     explicit Pooling2dFixture(const std::string &inputShape,
17                               const std::string &outputShape,
18                               const std::string &dataType,
19                               const std::string &dataLayout,
20                               const std::string &poolingAlgorithm)
21     {
22         m_JsonString = R"(
23     {
24             inputIds: [0],
25             outputIds: [2],
26             layers: [
27             {
28                 layer_type: "InputLayer",
29                 layer: {
30                       base: {
31                             layerBindingId: 0,
32                             base: {
33                                 index: 0,
34                                 layerName: "InputLayer",
35                                 layerType: "Input",
36                                 inputSlots: [{
37                                     index: 0,
38                                     connection: {sourceLayerIndex:0, outputSlotIndex:0 },
39                                 }],
40                                 outputSlots: [ {
41                                     index: 0,
42                                     tensorInfo: {
43                                         dimensions: )" + inputShape + R"(,
44                                         dataType: )" + dataType + R"(
45                                         }}]
46                                 }
47                 }}},
48                 {
49                 layer_type: "Pooling2dLayer",
50                 layer: {
51                       base: {
52                            index: 1,
53                            layerName: "Pooling2dLayer",
54                            layerType: "Pooling2d",
55                            inputSlots: [{
56                                   index: 0,
57                                   connection: {sourceLayerIndex:0, outputSlotIndex:0 },
58                            }],
59                            outputSlots: [ {
60                                   index: 0,
61                                   tensorInfo: {
62                                        dimensions: )" + outputShape + R"(,
63                                        dataType: )" + dataType + R"(
64
65                            }}]},
66                       descriptor: {
67                            poolType: )" + poolingAlgorithm + R"(,
68                            outputShapeRounding: "Floor",
69                            paddingMethod: Exclude,
70                            dataLayout: )" + dataLayout + R"(,
71                            padLeft: 0,
72                            padRight: 0,
73                            padTop: 0,
74                            padBottom: 0,
75                            poolWidth: 2,
76                            poolHeight: 2,
77                            strideX: 2,
78                            strideY: 2
79                            }
80                 }},
81                 {
82                 layer_type: "OutputLayer",
83                 layer: {
84                     base:{
85                           layerBindingId: 0,
86                           base: {
87                                 index: 2,
88                                 layerName: "OutputLayer",
89                                 layerType: "Output",
90                                 inputSlots: [{
91                                     index: 0,
92                                     connection: {sourceLayerIndex:1, outputSlotIndex:0 },
93                                 }],
94                                 outputSlots: [ {
95                                     index: 0,
96                                     tensorInfo: {
97                                         dimensions: )" + outputShape + R"(,
98                                         dataType: )" + dataType + R"(
99                                     },
100                             }],
101                         }}},
102             }]
103      }
104  )";
105         SetupSingleInputSingleOutput("InputLayer", "OutputLayer");
106     }
107 };
108
109 struct SimpleAvgPooling2dFixture : Pooling2dFixture
110 {
111     SimpleAvgPooling2dFixture() : Pooling2dFixture("[ 1, 2, 2, 1 ]", "[ 1, 1, 1, 1 ]",
112                                                    "Float32", "NHWC", "Average") {}
113 };
114
115 struct SimpleAvgPooling2dFixture2 : Pooling2dFixture
116 {
117     SimpleAvgPooling2dFixture2() : Pooling2dFixture("[ 1, 2, 2, 1 ]",
118                                                     "[ 1, 1, 1, 1 ]",
119                                                     "QuantisedAsymm8", "NHWC", "Average") {}
120 };
121
122 struct SimpleMaxPooling2dFixture : Pooling2dFixture
123 {
124     SimpleMaxPooling2dFixture() : Pooling2dFixture("[ 1, 1, 2, 2 ]",
125                                                    "[ 1, 1, 1, 1 ]",
126                                                    "Float32", "NCHW", "Max") {}
127 };
128
129 struct SimpleMaxPooling2dFixture2 : Pooling2dFixture
130 {
131     SimpleMaxPooling2dFixture2() : Pooling2dFixture("[ 1, 1, 2, 2 ]",
132                                                     "[ 1, 1, 1, 1 ]",
133                                                     "QuantisedAsymm8", "NCHW", "Max") {}
134 };
135
136 BOOST_FIXTURE_TEST_CASE(Pooling2dFloat32Avg, SimpleAvgPooling2dFixture)
137 {
138     RunTest<4, armnn::DataType::Float32>(0, { 2, 3, 5, 2 }, { 3 });
139 }
140
141 BOOST_FIXTURE_TEST_CASE(Pooling2dQuantisedAsymm8Avg, SimpleAvgPooling2dFixture2)
142 {
143     RunTest<4, armnn::DataType::QAsymmU8>(0,
144                                                 { 20, 40, 60, 80 },
145                                                 { 50 });
146 }
147
148 BOOST_FIXTURE_TEST_CASE(Pooling2dFloat32Max, SimpleMaxPooling2dFixture)
149 {
150     RunTest<4, armnn::DataType::Float32>(0, { 2, 5, 5, 2 }, { 5 });
151 }
152
153 BOOST_FIXTURE_TEST_CASE(Pooling2dQuantisedAsymm8Max, SimpleMaxPooling2dFixture2)
154 {
155     RunTest<4, armnn::DataType::QAsymmU8>(0,
156                                                 { 20, 40, 60, 80 },
157                                                 { 80 });
158 }
159
160 BOOST_AUTO_TEST_SUITE_END()
161