SiCong Li | 3eb263e | 2017-06-19 15:31:43 +0100 | [diff] [blame] | 1 | /* |
| 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 "Globals.h" |
SiCong Li | 3eb263e | 2017-06-19 15:31:43 +0100 | [diff] [blame] | 25 | #include "NEON/NEAccessor.h" |
| 26 | #include "PaddingCalculator.h" |
| 27 | #include "TensorLibrary.h" |
| 28 | #include "TypePrinter.h" |
| 29 | #include "Utils.h" |
| 30 | #include "validation/Datasets.h" |
| 31 | #include "validation/Reference.h" |
| 32 | #include "validation/Validation.h" |
| 33 | #include "validation/ValidationUserConfiguration.h" |
| 34 | |
| 35 | #include "arm_compute/core/Helpers.h" |
| 36 | #include "arm_compute/core/Types.h" |
| 37 | #include "arm_compute/runtime/NEON/functions/NEGaussian5x5.h" |
| 38 | #include "arm_compute/runtime/SubTensor.h" |
| 39 | #include "arm_compute/runtime/Tensor.h" |
| 40 | #include "arm_compute/runtime/TensorAllocator.h" |
| 41 | |
| 42 | #include "boost_wrapper.h" |
| 43 | |
| 44 | #include <iostream> |
| 45 | |
| 46 | #include <random> |
| 47 | #include <string> |
| 48 | |
| 49 | using namespace arm_compute; |
| 50 | using namespace arm_compute::test; |
| 51 | using namespace arm_compute::test::neon; |
| 52 | using namespace arm_compute::test::validation; |
| 53 | |
| 54 | namespace |
| 55 | { |
SiCong Li | 7a03575 | 2017-06-28 15:27:02 +0100 | [diff] [blame] | 56 | constexpr unsigned int filter_size = 5; /** Size of the kernel/filter in number of elements. */ |
| 57 | constexpr BorderSize border_size(filter_size / 2); /** Border size of the kernel/filter around its central element. */ |
| 58 | |
SiCong Li | 3eb263e | 2017-06-19 15:31:43 +0100 | [diff] [blame] | 59 | /** Compute Neon gaussian5x5 filter. |
| 60 | * |
| 61 | * @param[in] shape Shape of the input and output tensors. |
| 62 | * @param[in] border_mode BorderMode used by the input tensor. |
| 63 | * @param[in] constant_border_value Constant to use if @p border_mode == CONSTANT. |
| 64 | * |
| 65 | * @return Computed output tensor. |
| 66 | */ |
| 67 | Tensor compute_gaussian5x5(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value) |
| 68 | { |
| 69 | // Create tensors |
Moritz Pflanzer | 94450f1 | 2017-06-30 12:48:43 +0100 | [diff] [blame] | 70 | Tensor src = create_tensor<Tensor>(shape, DataType::U8); |
| 71 | Tensor dst = create_tensor<Tensor>(shape, DataType::U8); |
SiCong Li | 3eb263e | 2017-06-19 15:31:43 +0100 | [diff] [blame] | 72 | |
| 73 | // Create and configure function |
| 74 | NEGaussian5x5 gaussian5x5; |
| 75 | gaussian5x5.configure(&src, &dst, border_mode, constant_border_value); |
| 76 | |
| 77 | // Allocate tensors |
| 78 | src.allocator()->allocate(); |
| 79 | dst.allocator()->allocate(); |
| 80 | |
| 81 | BOOST_TEST(!src.info()->is_resizable()); |
| 82 | BOOST_TEST(!dst.info()->is_resizable()); |
| 83 | |
| 84 | // Fill tensors |
| 85 | library->fill_tensor_uniform(NEAccessor(src), 0); |
| 86 | |
| 87 | // Compute function |
| 88 | gaussian5x5.run(); |
| 89 | |
| 90 | return dst; |
| 91 | } |
| 92 | } // namespace |
| 93 | |
| 94 | #ifndef DOXYGEN_SKIP_THIS |
| 95 | BOOST_AUTO_TEST_SUITE(NEON) |
| 96 | BOOST_AUTO_TEST_SUITE(Gaussian5x5) |
| 97 | |
| 98 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly")) |
| 99 | BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * BorderModes(), shape, border_mode) |
| 100 | { |
| 101 | // Create tensors |
Moritz Pflanzer | 94450f1 | 2017-06-30 12:48:43 +0100 | [diff] [blame] | 102 | Tensor src = create_tensor<Tensor>(shape, DataType::U8); |
| 103 | Tensor dst = create_tensor<Tensor>(shape, DataType::U8); |
SiCong Li | 3eb263e | 2017-06-19 15:31:43 +0100 | [diff] [blame] | 104 | |
| 105 | BOOST_TEST(src.info()->is_resizable()); |
| 106 | BOOST_TEST(dst.info()->is_resizable()); |
| 107 | |
| 108 | // Create and configure function |
| 109 | NEGaussian5x5 gaussian5x5; |
| 110 | gaussian5x5.configure(&src, &dst, border_mode); |
| 111 | |
| 112 | // Validate valid region |
| 113 | const ValidRegion src_valid_region = shape_to_valid_region(shape); |
SiCong Li | 7a03575 | 2017-06-28 15:27:02 +0100 | [diff] [blame] | 114 | const ValidRegion dst_valid_region = shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size); |
SiCong Li | 3eb263e | 2017-06-19 15:31:43 +0100 | [diff] [blame] | 115 | validate(src.info()->valid_region(), src_valid_region); |
| 116 | validate(dst.info()->valid_region(), dst_valid_region); |
| 117 | |
| 118 | // Validate padding |
| 119 | PaddingCalculator calculator(shape.x(), 16); |
| 120 | calculator.set_border_size(2); |
| 121 | calculator.set_border_mode(border_mode); |
| 122 | |
| 123 | const PaddingSize dst_padding = calculator.required_padding(); |
| 124 | |
| 125 | calculator.set_processed_elements(8); |
| 126 | calculator.set_access_offset(-2); |
| 127 | |
| 128 | const PaddingSize src_padding = calculator.required_padding(); |
| 129 | |
| 130 | validate(src.info()->padding(), src_padding); |
| 131 | validate(dst.info()->padding(), dst_padding); |
| 132 | } |
| 133 | |
| 134 | BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit")) |
| 135 | BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * BorderModes(), shape, border_mode) |
| 136 | { |
| 137 | std::mt19937 gen(user_config.seed.get()); |
| 138 | std::uniform_int_distribution<uint8_t> distribution(0, 255); |
| 139 | const uint8_t border_value = distribution(gen); |
| 140 | |
| 141 | // Compute function |
| 142 | Tensor dst = compute_gaussian5x5(shape, border_mode, border_value); |
| 143 | |
| 144 | // Compute reference |
| 145 | RawTensor ref_dst = Reference::compute_reference_gaussian5x5(shape, border_mode, border_value); |
| 146 | |
| 147 | // Validate output |
SiCong Li | 7a03575 | 2017-06-28 15:27:02 +0100 | [diff] [blame] | 148 | validate(NEAccessor(dst), ref_dst, shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size)); |
SiCong Li | 3eb263e | 2017-06-19 15:31:43 +0100 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly")) |
| 152 | BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * BorderModes(), shape, border_mode) |
| 153 | { |
| 154 | std::mt19937 gen(user_config.seed.get()); |
| 155 | std::uniform_int_distribution<uint8_t> distribution(0, 255); |
| 156 | const uint8_t border_value = distribution(gen); |
| 157 | |
| 158 | // Compute function |
| 159 | Tensor dst = compute_gaussian5x5(shape, border_mode, border_value); |
| 160 | |
| 161 | // Compute reference |
| 162 | RawTensor ref_dst = Reference::compute_reference_gaussian5x5(shape, border_mode, border_value); |
| 163 | |
| 164 | // Validate output |
SiCong Li | 7a03575 | 2017-06-28 15:27:02 +0100 | [diff] [blame] | 165 | validate(NEAccessor(dst), ref_dst, shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size)); |
SiCong Li | 3eb263e | 2017-06-19 15:31:43 +0100 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | BOOST_AUTO_TEST_SUITE_END() |
| 169 | BOOST_AUTO_TEST_SUITE_END() |
Anthony Barbier | ac69aa1 | 2017-07-03 17:39:37 +0100 | [diff] [blame^] | 170 | #endif /* DOXYGEN_SKIP_THIS */ |