1 /*
2 * Copyright (c) 2017-2020 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/NESobel3x3.h"
26 #include "arm_compute/runtime/NEON/functions/NESobel5x5.h"
27 #include "arm_compute/runtime/NEON/functions/NESobel7x7.h"
28 #include "arm_compute/runtime/Tensor.h"
29 #include "arm_compute/runtime/TensorAllocator.h"
30 #include "tests/NEON/Accessor.h"
31 #include "tests/PaddingCalculator.h"
32 #include "tests/datasets/BorderModeDataset.h"
33 #include "tests/datasets/ShapeDatasets.h"
34 #include "tests/framework/Asserts.h"
35 #include "tests/framework/Macros.h"
36 #include "tests/framework/datasets/Datasets.h"
37 #include "tests/validation/Validation.h"
38 #include "tests/validation/fixtures/SobelFixture.h"
39
40 namespace arm_compute
41 {
42 namespace test
43 {
44 namespace validation
45 {
46 TEST_SUITE(NEON)
47 TEST_SUITE(Sobel)
48
49 TEST_SUITE(W3x3)
50 using NESobel3x3Fixture = SobelValidationFixture<Tensor, Accessor, NESobel3x3, uint8_t, int16_t>;
51
52 TEST_SUITE(X)
53 FIXTURE_DATA_TEST_CASE(RunSmall, NESobel3x3Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
54 Format::U8)),
55 framework::dataset::make("GradientDimension", GradientDimension::GRAD_X)))
56 {
57 // Validate output
58 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1));
59 validate(Accessor(_target.first), _reference.first, valid_region_x);
60 }
61
62 FIXTURE_DATA_TEST_CASE(RunLarge, NESobel3x3Fixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
63 Format::U8)),
64 framework::dataset::make("GradientDimension", GradientDimension::GRAD_X)))
65 {
66 // Validate output
67 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1));
68 validate(Accessor(_target.first), _reference.first, valid_region_x);
69 }
70 TEST_SUITE_END()
TEST_SUITE(Y)71 TEST_SUITE(Y)
72 FIXTURE_DATA_TEST_CASE(RunSmall, NESobel3x3Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
73 Format::U8)),
74 framework::dataset::make("GradientDimension", GradientDimension::GRAD_Y)))
75 {
76 // Validate output
77 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1));
78 validate(Accessor(_target.second), _reference.second, valid_region_y);
79 }
80
81 FIXTURE_DATA_TEST_CASE(RunLarge, NESobel3x3Fixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
82 Format::U8)),
83 framework::dataset::make("GradientDimension", GradientDimension::GRAD_Y)))
84 {
85 // Validate output
86 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1));
87 validate(Accessor(_target.second), _reference.second, valid_region_y);
88 }
89 TEST_SUITE_END()
TEST_SUITE(XY)90 TEST_SUITE(XY)
91 FIXTURE_DATA_TEST_CASE(RunSmall, NESobel3x3Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
92 Format::U8)),
93 framework::dataset::make("GradientDimension", GradientDimension::GRAD_XY)))
94 {
95 // Validate output
96 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1));
97 validate(Accessor(_target.first), _reference.first, valid_region_x);
98
99 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1));
100 validate(Accessor(_target.second), _reference.second, valid_region_y);
101 }
102
103 FIXTURE_DATA_TEST_CASE(RunLarge, NESobel3x3Fixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
104 Format::U8)),
105 framework::dataset::make("GradientDimension", GradientDimension::GRAD_XY)))
106 {
107 // Validate output
108 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1));
109 validate(Accessor(_target.first), _reference.first, valid_region_x);
110
111 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1));
112 validate(Accessor(_target.second), _reference.second, valid_region_y);
113 }
114 TEST_SUITE_END()
115 TEST_SUITE_END()
116
117 TEST_SUITE(W5x5)
118 using NESobel5x5Fixture = SobelValidationFixture<Tensor, Accessor, NESobel5x5, uint8_t, int16_t>;
119
120 TEST_SUITE(X)
121 FIXTURE_DATA_TEST_CASE(RunSmall, NESobel5x5Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
122 Format::U8)),
123 framework::dataset::make("GradientDimension", GradientDimension::GRAD_X)))
124 {
125 // Validate output
126 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(2));
127 validate(Accessor(_target.first), _reference.first, valid_region_x);
128 }
129
130 FIXTURE_DATA_TEST_CASE(RunLarge, NESobel5x5Fixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
131 Format::U8)),
132 framework::dataset::make("GradientDimension", GradientDimension::GRAD_X)))
133 {
134 // Validate output
135 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(2));
136 validate(Accessor(_target.first), _reference.first, valid_region_x);
137 }
138 TEST_SUITE_END()
TEST_SUITE(Y)139 TEST_SUITE(Y)
140 FIXTURE_DATA_TEST_CASE(RunSmall, NESobel5x5Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
141 Format::U8)),
142 framework::dataset::make("GradientDimension", GradientDimension::GRAD_Y)))
143 {
144 // Validate output
145 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(2));
146 validate(Accessor(_target.second), _reference.second, valid_region_y);
147 }
148
149 FIXTURE_DATA_TEST_CASE(RunLarge, NESobel5x5Fixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
150 Format::U8)),
151 framework::dataset::make("GradientDimension", GradientDimension::GRAD_Y)))
152 {
153 // Validate output
154 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(2));
155 validate(Accessor(_target.second), _reference.second, valid_region_y);
156 }
157 TEST_SUITE_END()
TEST_SUITE(XY)158 TEST_SUITE(XY)
159 FIXTURE_DATA_TEST_CASE(RunSmall, NESobel5x5Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
160 Format::U8)),
161 framework::dataset::make("GradientDimension", GradientDimension::GRAD_XY)))
162 {
163 // Validate output
164 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(2));
165 validate(Accessor(_target.first), _reference.first, valid_region_x);
166
167 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(2));
168 validate(Accessor(_target.second), _reference.second, valid_region_y);
169 }
170
171 FIXTURE_DATA_TEST_CASE(RunLarge, NESobel5x5Fixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
172 Format::U8)),
173 framework::dataset::make("GradientDimension", GradientDimension::GRAD_XY)))
174 {
175 // Validate output
176 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(2));
177 validate(Accessor(_target.first), _reference.first, valid_region_x);
178
179 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(2));
180 validate(Accessor(_target.second), _reference.second, valid_region_y);
181 }
182 TEST_SUITE_END()
183 TEST_SUITE_END()
184
185 TEST_SUITE(W7x7)
186 using NESobel7x7Fixture = SobelValidationFixture<Tensor, Accessor, NESobel7x7, uint8_t, int32_t>;
187 TEST_SUITE(X)
188 FIXTURE_DATA_TEST_CASE(RunSmall, NESobel7x7Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
189 Format::U8)),
190 framework::dataset::make("GradientDimension", GradientDimension::GRAD_X)))
191 {
192 // Validate output
193 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(3));
194 validate(Accessor(_target.first), _reference.first, valid_region_x);
195 }
196
197 FIXTURE_DATA_TEST_CASE(RunLarge, NESobel7x7Fixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
198 Format::U8)),
199 framework::dataset::make("GradientDimension", GradientDimension::GRAD_X)))
200 {
201 // Validate output
202 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(3));
203 validate(Accessor(_target.first), _reference.first, valid_region_x);
204 }
205 TEST_SUITE_END()
TEST_SUITE(Y)206 TEST_SUITE(Y)
207 FIXTURE_DATA_TEST_CASE(RunSmall, NESobel7x7Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
208 Format::U8)),
209 framework::dataset::make("GradientDimension", GradientDimension::GRAD_Y)))
210 {
211 // Validate output
212 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(3));
213 validate(Accessor(_target.second), _reference.second, valid_region_y);
214 }
215
216 FIXTURE_DATA_TEST_CASE(RunLarge, NESobel7x7Fixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
217 Format::U8)),
218 framework::dataset::make("GradientDimension", GradientDimension::GRAD_Y)))
219 {
220 // Validate output
221 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(3));
222 validate(Accessor(_target.second), _reference.second, valid_region_y);
223 }
224 TEST_SUITE_END()
TEST_SUITE(XY)225 TEST_SUITE(XY)
226 FIXTURE_DATA_TEST_CASE(RunSmall, NESobel7x7Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
227 Format::U8)),
228 framework::dataset::make("GradientDimension", GradientDimension::GRAD_XY)))
229 {
230 // Validate output
231 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(3));
232 validate(Accessor(_target.first), _reference.first, valid_region_x);
233
234 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(3));
235 validate(Accessor(_target.second), _reference.second, valid_region_y);
236 }
237
238 FIXTURE_DATA_TEST_CASE(RunLarge, NESobel7x7Fixture, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
239 Format::U8)),
240 framework::dataset::make("GradientDimension", GradientDimension::GRAD_XY)))
241 {
242 // Validate output
243 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(3));
244 validate(Accessor(_target.first), _reference.first, valid_region_x);
245
246 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(3));
247 validate(Accessor(_target.second), _reference.second, valid_region_y);
248 }
249 TEST_SUITE_END()
250 TEST_SUITE_END()
251
252 TEST_SUITE_END()
253 TEST_SUITE_END()
254 } // namespace validation
255 } // namespace test
256 } // namespace arm_compute
257