blob: c54394d3a1b17343a8b3cd640d8a7ca0bf3c3c4f [file] [log] [blame]
John Richardson6f4d49f2017-09-07 11:21:10 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2019 Arm Limited.
John Richardson6f4d49f2017-09-07 11:21:10 +01003 *
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/runtime/NEON/functions/NENonLinearFilter.h"
25#include "tests/NEON/Accessor.h"
26#include "tests/PaddingCalculator.h"
27#include "tests/datasets/BorderModeDataset.h"
28#include "tests/datasets/MatrixPatternDataset.h"
29#include "tests/datasets/NonLinearFilterFunctionDataset.h"
30#include "tests/datasets/ShapeDatasets.h"
31#include "tests/framework/Macros.h"
32#include "tests/validation/Validation.h"
33#include "tests/validation/fixtures/NonLinearFilterFixture.h"
34
35namespace arm_compute
36{
37namespace test
38{
39namespace validation
40{
41TEST_SUITE(NEON)
42TEST_SUITE(NonLinearFilter)
43
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +000044DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallShapes(), datasets::NonLinearFilterFunctions()),
John Richardson6f4d49f2017-09-07 11:21:10 +010045 framework::dataset::make("MaskSize", { 3U, 5U })),
46 datasets::MatrixPatterns()),
47 datasets::BorderModes()),
48 shape, function, mask_size, pattern, border_mode)
49{
50 std::mt19937 generator(library->seed());
51 std::uniform_int_distribution<uint8_t> distribution_u8(0, 255);
52 const uint8_t constant_border_value = distribution_u8(generator);
53
54 // Create the mask
Michalis Spyroubcfd09a2019-05-01 13:03:59 +010055 std::vector<uint8_t> mask(mask_size * mask_size);
56 fill_mask_from_pattern(mask.data(), mask_size, mask_size, pattern);
John Richardson6f4d49f2017-09-07 11:21:10 +010057 const auto half_mask_size = static_cast<int>(mask_size / 2);
58
59 // Create tensors
60 Tensor src = create_tensor<Tensor>(shape, DataType::U8);
61 Tensor dst = create_tensor<Tensor>(shape, DataType::U8);
62
63 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
64 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
65
66 // Create and configure function
67 NENonLinearFilter filter;
Michalis Spyroubcfd09a2019-05-01 13:03:59 +010068 filter.configure(&src, &dst, function, mask_size, pattern, mask.data(), border_mode, constant_border_value);
John Richardson6f4d49f2017-09-07 11:21:10 +010069
70 // Validate valid region
71 const ValidRegion dst_valid_region = shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, BorderSize(half_mask_size));
72 validate(dst.info()->valid_region(), dst_valid_region);
73
74 // Validate padding
75 PaddingCalculator calculator(shape.x(), ((MatrixPattern::OTHER == pattern) ? 1 : 8));
76 calculator.set_border_mode(border_mode);
77 calculator.set_border_size(half_mask_size);
78
79 const PaddingSize write_padding = calculator.required_padding(PaddingCalculator::Option::EXCLUDE_BORDER);
80
81 calculator.set_accessed_elements(16);
82 calculator.set_access_offset(-half_mask_size);
83
84 const PaddingSize read_padding = calculator.required_padding(PaddingCalculator::Option::INCLUDE_BORDER);
85
86 validate(src.info()->padding(), read_padding);
87 validate(dst.info()->padding(), write_padding);
88}
89
90template <typename T>
91using NENonLinearFilterFixture = NonLinearFilterValidationFixture<Tensor, Accessor, NENonLinearFilter, T>;
92
93FIXTURE_DATA_TEST_CASE(RunSmall, NENonLinearFilterFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(),
94 datasets::NonLinearFilterFunctions()),
95 framework::dataset::make("MaskSize", { 3U, 5U })),
96 datasets::MatrixPatterns()),
97 datasets::BorderModes()),
98 framework::dataset::make("DataType", DataType::U8)))
99{
100 // Validate output
101 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), _border_size));
102}
103
104FIXTURE_DATA_TEST_CASE(RunLarge, NENonLinearFilterFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(datasets::LargeShapes(),
105 datasets::NonLinearFilterFunctions()),
106 framework::dataset::make("MaskSize", { 3U, 5U })),
107 datasets::MatrixPatterns()),
108 datasets::BorderModes()),
109 framework::dataset::make("DataType", DataType::U8)))
110{
111 // Validate output
112 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), _border_size));
113}
114
115TEST_SUITE_END()
116TEST_SUITE_END()
117} // namespace validation
118} // namespace test
119} // namespace arm_compute