blob: bf7b8ae8d43a0838a74777c52660c9594526d878 [file] [log] [blame]
Saoirse Stewart3166c3e2019-02-18 15:24:53 +00001//
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"
Finn Williams85d36712021-01-26 22:30:06 +00008#include <armnnDeserializer/IDeserializer.hpp>
Saoirse Stewart3166c3e2019-02-18 15:24:53 +00009
10#include <string>
Saoirse Stewart3166c3e2019-02-18 15:24:53 +000011
Derek Lamberti0028d1b2019-02-20 13:57:42 +000012BOOST_AUTO_TEST_SUITE(Deserializer)
Saoirse Stewart3166c3e2019-02-18 15:24:53 +000013
14struct 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
ruoyan0123e1de62019-02-20 13:53:22 +0000109struct SimpleAvgPooling2dFixture : Pooling2dFixture
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000110{
Teresa Charlin4c600de2021-03-11 21:59:43 +0000111 SimpleAvgPooling2dFixture() : Pooling2dFixture("[ 1, 2, 2, 1 ]",
112 "[ 1, 1, 1, 1 ]",
ruoyan0123e1de62019-02-20 13:53:22 +0000113 "Float32", "NHWC", "Average") {}
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000114};
115
ruoyan0123e1de62019-02-20 13:53:22 +0000116struct SimpleAvgPooling2dFixture2 : Pooling2dFixture
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000117{
ruoyan0123e1de62019-02-20 13:53:22 +0000118 SimpleAvgPooling2dFixture2() : Pooling2dFixture("[ 1, 2, 2, 1 ]",
119 "[ 1, 1, 1, 1 ]",
120 "QuantisedAsymm8", "NHWC", "Average") {}
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000121};
122
ruoyan0123e1de62019-02-20 13:53:22 +0000123struct SimpleMaxPooling2dFixture : Pooling2dFixture
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000124{
ruoyan0123e1de62019-02-20 13:53:22 +0000125 SimpleMaxPooling2dFixture() : Pooling2dFixture("[ 1, 1, 2, 2 ]",
126 "[ 1, 1, 1, 1 ]",
127 "Float32", "NCHW", "Max") {}
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000128};
129
ruoyan0123e1de62019-02-20 13:53:22 +0000130struct SimpleMaxPooling2dFixture2 : Pooling2dFixture
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000131{
ruoyan0123e1de62019-02-20 13:53:22 +0000132 SimpleMaxPooling2dFixture2() : Pooling2dFixture("[ 1, 1, 2, 2 ]",
133 "[ 1, 1, 1, 1 ]",
134 "QuantisedAsymm8", "NCHW", "Max") {}
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000135};
136
Teresa Charlin4c600de2021-03-11 21:59:43 +0000137struct SimpleL2Pooling2dFixture : Pooling2dFixture
138{
139 SimpleL2Pooling2dFixture() : Pooling2dFixture("[ 1, 2, 2, 1 ]",
140 "[ 1, 1, 1, 1 ]",
141 "Float32", "NHWC", "L2") {}
142};
143
ruoyan0123e1de62019-02-20 13:53:22 +0000144BOOST_FIXTURE_TEST_CASE(Pooling2dFloat32Avg, SimpleAvgPooling2dFixture)
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000145{
146 RunTest<4, armnn::DataType::Float32>(0, { 2, 3, 5, 2 }, { 3 });
147}
148
ruoyan0123e1de62019-02-20 13:53:22 +0000149BOOST_FIXTURE_TEST_CASE(Pooling2dQuantisedAsymm8Avg, SimpleAvgPooling2dFixture2)
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000150{
Teresa Charlin4c600de2021-03-11 21:59:43 +0000151 RunTest<4, armnn::DataType::QAsymmU8>(0,{ 20, 40, 60, 80 },{ 50 });
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000152}
153
ruoyan0123e1de62019-02-20 13:53:22 +0000154BOOST_FIXTURE_TEST_CASE(Pooling2dFloat32Max, SimpleMaxPooling2dFixture)
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000155{
156 RunTest<4, armnn::DataType::Float32>(0, { 2, 5, 5, 2 }, { 5 });
157}
158
ruoyan0123e1de62019-02-20 13:53:22 +0000159BOOST_FIXTURE_TEST_CASE(Pooling2dQuantisedAsymm8Max, SimpleMaxPooling2dFixture2)
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000160{
Teresa Charlin4c600de2021-03-11 21:59:43 +0000161 RunTest<4, armnn::DataType::QAsymmU8>(0,{ 20, 40, 60, 80 },{ 80 });
162}
163
164BOOST_FIXTURE_TEST_CASE(Pooling2dFloat32L2, SimpleL2Pooling2dFixture)
165{
166 RunTest<4, armnn::DataType::Float32>(0, { 2, 3, 5, 2 }, { 3.2403703f });
Saoirse Stewart3166c3e2019-02-18 15:24:53 +0000167}
168
169BOOST_AUTO_TEST_SUITE_END()
170