1 /*
2 * Copyright (c) 2018-2021 Arm Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24 #include "arm_compute/core/Types.h"
25 #include "arm_compute/runtime/NEON/functions/NEPadLayer.h"
26 #include "arm_compute/runtime/Tensor.h"
27 #include "arm_compute/runtime/TensorAllocator.h"
28 #include "tests/NEON/Accessor.h"
29 #include "tests/PaddingCalculator.h"
30 #include "tests/datasets/ShapeDatasets.h"
31 #include "tests/framework/Asserts.h"
32 #include "tests/framework/Macros.h"
33 #include "tests/framework/datasets/Datasets.h"
34 #include "tests/validation/Validation.h"
35 #include "tests/validation/fixtures/PadLayerFixture.h"
36
37 namespace arm_compute
38 {
39 namespace test
40 {
41 namespace validation
42 {
43 namespace
44 {
45 const auto PaddingSizesDataset = framework::dataset::make("PaddingSize",
46 {
47 PaddingList{ { 0, 0 } },
48 PaddingList{ { 1, 1 } },
49 PaddingList{ { 1, 1 }, { 2, 2 } },
50 PaddingList{ { 1, 1 }, { 1, 1 }, { 1, 1 } },
51 PaddingList{ { 0, 0 }, { 1, 0 }, { 0, 1 } },
52 PaddingList{ { 0, 1 }, { 1, 0 }, { 0, 1 } },
53 });
54 } // namespace
55
56 TEST_SUITE(NEON)
TEST_SUITE(PadLayer)57 TEST_SUITE(PadLayer)
58
59 // *INDENT-OFF*
60 // clang-format off
61
62 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
63 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data type input/output
64 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
65 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
66 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
67 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
68 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
69 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data type input/output
70 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
71 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
72 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
73 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
74 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32)
75 }),
76 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16),
77 TensorInfo(TensorShape(28U, 11U, 2U), 1, DataType::F32),
78 TensorInfo(TensorShape(29U, 17U, 2U), 1, DataType::F32),
79 TensorInfo(TensorShape(29U, 15U, 4U, 3U), 1, DataType::F32),
80 TensorInfo(TensorShape(27U, 14U, 3U, 4U), 1, DataType::F32),
81 TensorInfo(TensorShape(32U, 13U, 2U, 3U), 1, DataType::F32),
82 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16),
83 TensorInfo(TensorShape(28U, 11U, 2U), 1, DataType::F32),
84 TensorInfo(TensorShape(29U, 17U, 2U), 1, DataType::F32),
85 TensorInfo(TensorShape(29U, 15U, 4U, 3U), 1, DataType::F32),
86 TensorInfo(TensorShape(27U, 14U, 3U, 4U), 1, DataType::F32),
87 TensorInfo(TensorShape(32U, 13U, 2U, 3U), 1, DataType::F32)
88 })),
89 framework::dataset::make("PaddingSize", { PaddingList{{0, 0}},
90 PaddingList{{1, 1}},
91 PaddingList{{1, 1}, {2, 2}},
92 PaddingList{{1,1}, {1,1}, {1,1}, {1,1}},
93 PaddingList{{0,0}, {1,0}, {0,1}, {1,2}},
94 PaddingList{{0,0}, {0,0}, {0,0}, {1,1}},
95 PaddingList{{0, 0}},
96 PaddingList{{1, 1}},
97 PaddingList{{1, 1}, {2, 2}},
98 PaddingList{{1,1}, {1,1}, {1,1}, {1,1}},
99 PaddingList{{0,0}, {1,0}, {0,1}, {1,2}},
100 PaddingList{{0,0}, {0,0}, {0,0}, {1,1}}
101 })),
102 framework::dataset::make("PaddingMode", { PaddingMode::CONSTANT,
103 PaddingMode::CONSTANT,
104 PaddingMode::CONSTANT,
105 PaddingMode::CONSTANT,
106 PaddingMode::CONSTANT,
107 PaddingMode::CONSTANT,
108 PaddingMode::REFLECT,
109 PaddingMode::REFLECT,
110 PaddingMode::REFLECT,
111 PaddingMode::REFLECT,
112 PaddingMode::REFLECT,
113 PaddingMode::SYMMETRIC })),
114 framework::dataset::make("Expected", { false, false, true, true, true, true, false, false, true, false, false, true })),
115 input_info, output_info, padding, mode, expected)
116 {
117 ARM_COMPUTE_EXPECT(bool(NEPadLayer::validate(&input_info.clone()->set_is_resizable(true), &output_info.clone()->set_is_resizable(true), padding, PixelValue(), mode)) == expected, framework::LogLevel::ERRORS);
118 }
119
120 // clang-format on
121 // *INDENT-ON*
122
123 template <typename T>
124 using NEPaddingFixture = PaddingFixture<Tensor, Accessor, NEPadLayer, T>;
125
126 TEST_SUITE(Float)
127
TEST_SUITE(FP32)128 TEST_SUITE(FP32)
129 FIXTURE_DATA_TEST_CASE(RunSmall, NEPaddingFixture<float>, framework::DatasetMode::ALL,
130 combine(combine(combine(datasets::Small3DShapes(), framework::dataset::make("DataType", { DataType::F32 })),
131 PaddingSizesDataset),
132 framework::dataset::make("PaddingMode", { PaddingMode::CONSTANT, PaddingMode::REFLECT })))
133 {
134 // Validate output
135 validate(Accessor(_target), _reference);
136 }
137 FIXTURE_DATA_TEST_CASE(RunLarge, NEPaddingFixture<float>, framework::DatasetMode::NIGHTLY,
138 combine(combine(combine(datasets::Large3DShapes(), framework::dataset::make("DataType", { DataType::F32 })),
139 PaddingSizesDataset),
140 framework::dataset::make("PaddingMode", { PaddingMode::CONSTANT, PaddingMode::REFLECT, PaddingMode::SYMMETRIC })))
141 {
142 // Validate output
143 validate(Accessor(_target), _reference);
144 }
145 TEST_SUITE_END() // FP32
146
147 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
TEST_SUITE(FP16)148 TEST_SUITE(FP16)
149 FIXTURE_DATA_TEST_CASE(RunSmall, NEPaddingFixture<half>, framework::DatasetMode::ALL,
150 combine(combine(combine(datasets::Small3DShapes(), framework::dataset::make("DataType", { DataType::F16 })),
151 PaddingSizesDataset),
152 framework::dataset::make("PaddingMode", { PaddingMode::CONSTANT, PaddingMode::REFLECT })))
153 {
154 // Validate output
155 validate(Accessor(_target), _reference);
156 }
157 FIXTURE_DATA_TEST_CASE(RunLarge, NEPaddingFixture<half>, framework::DatasetMode::NIGHTLY,
158 combine(combine(combine(datasets::Large3DShapes(), framework::dataset::make("DataType", { DataType::F16 })),
159 PaddingSizesDataset),
160 framework::dataset::make("PaddingMode", { PaddingMode::CONSTANT, PaddingMode::REFLECT, PaddingMode::SYMMETRIC })))
161 {
162 // Validate output
163 validate(Accessor(_target), _reference);
164 }
165 TEST_SUITE_END() // FP16
166 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
TEST_SUITE_END()167 TEST_SUITE_END() // Float
168
169 TEST_SUITE(Quantized)
170 TEST_SUITE(QASYMM8)
171 FIXTURE_DATA_TEST_CASE(RunSmall, NEPaddingFixture<uint8_t>, framework::DatasetMode::ALL,
172 combine(combine(combine(datasets::Small3DShapes(), framework::dataset::make("DataType", { DataType::QASYMM8 })),
173 PaddingSizesDataset),
174 framework::dataset::make("PaddingMode", { PaddingMode::CONSTANT, PaddingMode::REFLECT })))
175 {
176 // Validate output
177 validate(Accessor(_target), _reference);
178 }
179 FIXTURE_DATA_TEST_CASE(RunLarge, NEPaddingFixture<uint8_t>, framework::DatasetMode::NIGHTLY,
180 combine(combine(combine(datasets::Large3DShapes(), framework::dataset::make("DataType", { DataType::QASYMM8 })),
181 PaddingSizesDataset),
182 framework::dataset::make("PaddingMode", { PaddingMode::CONSTANT, PaddingMode::REFLECT, PaddingMode::SYMMETRIC })))
183 {
184 // Validate output
185 validate(Accessor(_target), _reference);
186 }
187 TEST_SUITE_END() // QASYMM8
188 TEST_SUITE_END() // Quantized
189
190 TEST_SUITE_END() // PadLayer
191 TEST_SUITE_END() // Neon
192 } // namespace validation
193 } // namespace test
194 } // namespace arm_compute
195