John Richardson | 6f4d49f | 2017-09-07 11:21:10 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | 5c9f0c4 | 2019-01-16 14:48:48 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
John Richardson | 6f4d49f | 2017-09-07 11:21:10 +0100 | [diff] [blame] | 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/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 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace test |
| 38 | { |
| 39 | namespace validation |
| 40 | { |
| 41 | TEST_SUITE(NEON) |
| 42 | TEST_SUITE(NonLinearFilter) |
| 43 | |
Michalis Spyrou | 5c9f0c4 | 2019-01-16 14:48:48 +0000 | [diff] [blame] | 44 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallShapes(), datasets::NonLinearFilterFunctions()), |
John Richardson | 6f4d49f | 2017-09-07 11:21:10 +0100 | [diff] [blame] | 45 | 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 |
| 55 | uint8_t mask[mask_size * mask_size]; |
| 56 | fill_mask_from_pattern(mask, mask_size, mask_size, pattern); |
| 57 | 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; |
| 68 | filter.configure(&src, &dst, function, mask_size, pattern, mask, border_mode, constant_border_value); |
| 69 | |
| 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 | |
| 90 | template <typename T> |
| 91 | using NENonLinearFilterFixture = NonLinearFilterValidationFixture<Tensor, Accessor, NENonLinearFilter, T>; |
| 92 | |
| 93 | FIXTURE_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 | |
| 104 | FIXTURE_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 | |
| 115 | TEST_SUITE_END() |
| 116 | TEST_SUITE_END() |
| 117 | } // namespace validation |
| 118 | } // namespace test |
| 119 | } // namespace arm_compute |