blob: 99f9e1ff5da42df7da9410ab1c5aeb09bd6602ac [file] [log] [blame]
Moritz Pflanzer7655a672017-09-23 11:57:33 +01001/*
2 * Copyright (c) 2017 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
40namespace arm_compute
41{
42namespace test
43{
44namespace validation
45{
46TEST_SUITE(NEON)
47TEST_SUITE(Sobel)
48
49TEST_SUITE(W3x3)
50using NESobel3x3Fixture = SobelValidationFixture<Tensor, Accessor, NESobel3x3, uint8_t, int16_t>;
51
52DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), datasets::BorderModes()), framework::dataset::make("Format",
53 Format::U8)),
54 shape, border_mode, format)
55{
56 // Generate a random constant value
57 std::mt19937 gen(library->seed());
58 std::uniform_int_distribution<uint8_t> int_dist(0, 255);
59 const uint8_t constant_border_value = int_dist(gen);
60
61 // Create tensors
62 Tensor src = create_tensor<Tensor>(shape, data_type_from_format(format));
63 Tensor dst_x = create_tensor<Tensor>(shape, DataType::S16);
64 Tensor dst_y = create_tensor<Tensor>(shape, DataType::S16);
65
66 src.info()->set_format(format);
67 dst_x.info()->set_format(Format::S16);
68 dst_y.info()->set_format(Format::S16);
69
70 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
71 ARM_COMPUTE_EXPECT(dst_x.info()->is_resizable(), framework::LogLevel::ERRORS);
72 ARM_COMPUTE_EXPECT(dst_y.info()->is_resizable(), framework::LogLevel::ERRORS);
73
74 // Create sobel 3x3 configure function
75 NESobel3x3 sobel;
76 sobel.configure(&src, &dst_x, &dst_y, border_mode, constant_border_value);
77
78 // Validate valid region
79 constexpr BorderSize border_size{ 1 };
80 const ValidRegion dst_valid_region = shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size);
81
82 validate(dst_x.info()->valid_region(), dst_valid_region);
83 validate(dst_y.info()->valid_region(), dst_valid_region);
84
85 // Validate padding
86 PaddingCalculator calculator(shape.x(), 8);
87
88 calculator.set_border_mode(border_mode);
89 calculator.set_border_size(1);
90
91 const PaddingSize dst_padding = calculator.required_padding();
92
93 calculator.set_accessed_elements(16);
94 calculator.set_access_offset(-1);
95
96 const PaddingSize src_padding = calculator.required_padding();
97
98 validate(src.info()->padding(), src_padding);
99 validate(dst_x.info()->padding(), dst_padding);
100 validate(dst_y.info()->padding(), dst_padding);
101}
102
103FIXTURE_DATA_TEST_CASE(RunSmall, NESobel3x3Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
104 Format::U8)))
105{
106 // Validate output
107 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1));
108 validate(Accessor(_target.first), _reference.first, valid_region_x);
109
110 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1));
111 validate(Accessor(_target.second), _reference.second, valid_region_y);
112}
113
114FIXTURE_DATA_TEST_CASE(RunLarge, NESobel3x3Fixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
115 Format::U8)))
116{
117 // Validate output
118 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1));
119 validate(Accessor(_target.first), _reference.first, valid_region_x);
120
121 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(1));
122 validate(Accessor(_target.second), _reference.second, valid_region_y);
123}
124TEST_SUITE_END()
125
126TEST_SUITE(W5x5)
127using NESobel5x5Fixture = SobelValidationFixture<Tensor, Accessor, NESobel5x5, uint8_t, int16_t>;
128
129DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), datasets::BorderModes()), framework::dataset::make("Format",
130 Format::U8)),
131 shape, border_mode, format)
132{
133 // Generate a random constant value
134 std::mt19937 gen(library->seed());
135 std::uniform_int_distribution<uint8_t> int_dist(0, 255);
136 const uint8_t constant_border_value = int_dist(gen);
137
138 // Create tensors
139 Tensor src = create_tensor<Tensor>(shape, data_type_from_format(format));
140 Tensor dst_x = create_tensor<Tensor>(shape, DataType::S16);
141 Tensor dst_y = create_tensor<Tensor>(shape, DataType::S16);
142
143 src.info()->set_format(format);
144 dst_x.info()->set_format(Format::S16);
145 dst_y.info()->set_format(Format::S16);
146
147 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
148 ARM_COMPUTE_EXPECT(dst_x.info()->is_resizable(), framework::LogLevel::ERRORS);
149 ARM_COMPUTE_EXPECT(dst_y.info()->is_resizable(), framework::LogLevel::ERRORS);
150
151 // Create sobel 5x5 configure function
152 NESobel5x5 sobel;
153 sobel.configure(&src, &dst_x, &dst_y, border_mode, constant_border_value);
154
155 // Validate valid region
156 constexpr BorderSize border_size{ 2 };
157 const ValidRegion dst_valid_region = shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size);
158
159 validate(dst_x.info()->valid_region(), dst_valid_region);
160 validate(dst_y.info()->valid_region(), dst_valid_region);
161
162 // Validate padding
163 PaddingCalculator calculator(shape.x(), 16);
164
165 calculator.set_border_mode(border_mode);
166 calculator.set_border_size(2);
167
168 const PaddingSize dst_padding = calculator.required_padding();
169
170 calculator.set_processed_elements(8);
171 calculator.set_access_offset(-2);
172
173 const PaddingSize src_padding = calculator.required_padding();
174
175 validate(src.info()->padding(), src_padding);
176 validate(dst_x.info()->padding(), dst_padding);
177 validate(dst_y.info()->padding(), dst_padding);
178}
179
180FIXTURE_DATA_TEST_CASE(RunSmall, NESobel5x5Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
181 Format::U8)))
182{
183 // Validate output
184 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(2));
185 validate(Accessor(_target.first), _reference.first, valid_region_x);
186
187 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(2));
188 validate(Accessor(_target.second), _reference.second, valid_region_y);
189}
190
191FIXTURE_DATA_TEST_CASE(RunLarge, NESobel5x5Fixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
192 Format::U8)))
193{
194 // Validate output
195 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(2));
196 validate(Accessor(_target.first), _reference.first, valid_region_x);
197
198 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(2));
199 validate(Accessor(_target.second), _reference.second, valid_region_y);
200}
201TEST_SUITE_END()
202
203TEST_SUITE(W7x7)
204using NESobel7x7Fixture = SobelValidationFixture<Tensor, Accessor, NESobel7x7, uint8_t, int32_t>;
205
206DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(concat(datasets::Small2DShapes(), datasets::Large2DShapes()), datasets::BorderModes()), framework::dataset::make("Format",
207 Format::U8)),
208 shape, border_mode, format)
209{
210 // Generate a random constant value
211 std::mt19937 gen(library->seed());
212 std::uniform_int_distribution<uint8_t> int_dist(0, 255);
213 const uint8_t constant_border_value = int_dist(gen);
214
215 // Create tensors
216 Tensor src = create_tensor<Tensor>(shape, data_type_from_format(format));
217 Tensor dst_x = create_tensor<Tensor>(shape, DataType::S32);
218 Tensor dst_y = create_tensor<Tensor>(shape, DataType::S32);
219
220 src.info()->set_format(format);
221 dst_x.info()->set_format(Format::S32);
222 dst_y.info()->set_format(Format::S32);
223
224 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
225 ARM_COMPUTE_EXPECT(dst_x.info()->is_resizable(), framework::LogLevel::ERRORS);
226 ARM_COMPUTE_EXPECT(dst_y.info()->is_resizable(), framework::LogLevel::ERRORS);
227
228 // Create sobel 7x7 configure function
229 NESobel7x7 sobel;
230 sobel.configure(&src, &dst_x, &dst_y, border_mode, constant_border_value);
231
232 // Validate valid region
233 constexpr BorderSize border_size{ 3 };
234 const ValidRegion dst_valid_region = shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size);
235
236 validate(dst_x.info()->valid_region(), dst_valid_region);
237 validate(dst_y.info()->valid_region(), dst_valid_region);
238
239 // Validate padding
240 PaddingCalculator calculator(shape.x(), 8);
241
242 calculator.set_border_mode(border_mode);
243 calculator.set_border_size(3);
244
245 const PaddingSize dst_padding = calculator.required_padding();
246
247 calculator.set_accessed_elements(16);
248 calculator.set_access_offset(-3);
249
250 const PaddingSize src_padding = calculator.required_padding();
251
252 validate(src.info()->padding(), src_padding);
253 validate(dst_x.info()->padding(), dst_padding);
254 validate(dst_y.info()->padding(), dst_padding);
255}
256
257FIXTURE_DATA_TEST_CASE(RunSmall, NESobel7x7Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::Small2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
258 Format::U8)))
259{
260 // Validate output
261 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(3));
262 validate(Accessor(_target.first), _reference.first, valid_region_x);
263
264 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(3));
265 validate(Accessor(_target.second), _reference.second, valid_region_y);
266}
267
268FIXTURE_DATA_TEST_CASE(RunLarge, NESobel7x7Fixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::Large2DShapes(), datasets::BorderModes()), framework::dataset::make("Format",
269 Format::U8)))
270{
271 // Validate output
272 ValidRegion valid_region_x = shape_to_valid_region(_reference.first.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(3));
273 validate(Accessor(_target.first), _reference.first, valid_region_x);
274
275 ValidRegion valid_region_y = shape_to_valid_region(_reference.second.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(3));
276 validate(Accessor(_target.second), _reference.second, valid_region_y);
277}
278TEST_SUITE_END()
279
280TEST_SUITE_END()
281TEST_SUITE_END()
282} // namespace validation
283} // namespace test
284} // namespace arm_compute