blob: c673ff1be36ecde4b8141e8b32ec06dab68fae92 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +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 "Globals.h"
25#include "NEON/Helper.h"
26#include "NEON/NEAccessor.h"
Moritz Pflanzer5b512292017-06-21 15:54:07 +010027#include "PaddingCalculator.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028#include "TensorLibrary.h"
29#include "TypePrinter.h"
30#include "Utils.h"
31#include "validation/Datasets.h"
32#include "validation/Reference.h"
33#include "validation/Validation.h"
SiCong Libacaf9a2017-06-19 13:41:45 +010034#include "validation/ValidationUserConfiguration.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010035
36#include "arm_compute/core/Helpers.h"
37#include "arm_compute/core/Types.h"
38#include "arm_compute/runtime/NEON/functions/NEBox3x3.h"
39#include "arm_compute/runtime/SubTensor.h"
40#include "arm_compute/runtime/Tensor.h"
41#include "arm_compute/runtime/TensorAllocator.h"
42
43#include "boost_wrapper.h"
44
45#include <random>
46#include <string>
47
48using namespace arm_compute;
49using namespace arm_compute::test;
50using namespace arm_compute::test::neon;
51using namespace arm_compute::test::validation;
52
53namespace
54{
SiCong Li7a035752017-06-28 15:27:02 +010055constexpr unsigned int filter_size = 3; /** Size of the kernel/filter in number of elements. */
56constexpr BorderSize border_size(filter_size / 2); /** Border size of the kernel/filter around its central element. */
57
SiCong Libacaf9a2017-06-19 13:41:45 +010058/** Compute Neon box3x3 filter.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010059 *
SiCong Libacaf9a2017-06-19 13:41:45 +010060 * @param[in] shape Shape of the input and output tensors.
61 * @param[in] border_mode BorderMode used by the input tensor.
62 * @param[in] constant_border_value Constant to use if @p border_mode == CONSTANT.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010063 *
64 * @return Computed output tensor.
65 */
SiCong Libacaf9a2017-06-19 13:41:45 +010066Tensor compute_box3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010067{
68 // Create tensors
69 Tensor src = create_tensor(shape, DataType::U8);
70 Tensor dst = create_tensor(shape, DataType::U8);
71
72 // Create and configure function
SiCong Libacaf9a2017-06-19 13:41:45 +010073 NEBox3x3 box3x3;
74 box3x3.configure(&src, &dst, border_mode, constant_border_value);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010075
76 // Allocate tensors
77 src.allocator()->allocate();
78 dst.allocator()->allocate();
79
80 BOOST_TEST(!src.info()->is_resizable());
81 BOOST_TEST(!dst.info()->is_resizable());
82
83 // Fill tensors
84 library->fill_tensor_uniform(NEAccessor(src), 0);
85
86 // Compute function
SiCong Libacaf9a2017-06-19 13:41:45 +010087 box3x3.run();
Anthony Barbier6ff3b192017-09-04 18:44:23 +010088
89 return dst;
90}
91} // namespace
92
93#ifndef DOXYGEN_SKIP_THIS
94BOOST_AUTO_TEST_SUITE(NEON)
95BOOST_AUTO_TEST_SUITE(Box3x3)
96
97BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
SiCong Libacaf9a2017-06-19 13:41:45 +010098BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * BorderModes(), shape, border_mode)
Anthony Barbier6ff3b192017-09-04 18:44:23 +010099{
100 // Create tensors
101 Tensor src = create_tensor(shape, DataType::U8);
102 Tensor dst = create_tensor(shape, DataType::U8);
103
104 BOOST_TEST(src.info()->is_resizable());
105 BOOST_TEST(dst.info()->is_resizable());
106
107 // Create and configure function
SiCong Libacaf9a2017-06-19 13:41:45 +0100108 NEBox3x3 box3x3;
109 box3x3.configure(&src, &dst, border_mode);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100110
111 // Validate valid region
112 const ValidRegion src_valid_region = shape_to_valid_region(shape);
SiCong Li7a035752017-06-28 15:27:02 +0100113 const ValidRegion dst_valid_region = shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100114 validate(src.info()->valid_region(), src_valid_region);
115 validate(dst.info()->valid_region(), dst_valid_region);
116
117 // Validate padding
Moritz Pflanzer5b512292017-06-21 15:54:07 +0100118 PaddingCalculator calculator(shape.x(), 8);
119 calculator.set_border_size(1);
SiCong Libacaf9a2017-06-19 13:41:45 +0100120 calculator.set_border_mode(border_mode);
Moritz Pflanzer5b512292017-06-21 15:54:07 +0100121
Moritz Pflanzer2509fba2017-06-23 14:15:03 +0100122 const PaddingSize dst_padding = calculator.required_padding();
Moritz Pflanzer5b512292017-06-21 15:54:07 +0100123
124 calculator.set_accessed_elements(16);
125 calculator.set_access_offset(-1);
126
Moritz Pflanzer2509fba2017-06-23 14:15:03 +0100127 const PaddingSize src_padding = calculator.required_padding();
Moritz Pflanzer5b512292017-06-21 15:54:07 +0100128
Moritz Pflanzer2509fba2017-06-23 14:15:03 +0100129 validate(src.info()->padding(), src_padding);
130 validate(dst.info()->padding(), dst_padding);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100131}
132
133BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
SiCong Libacaf9a2017-06-19 13:41:45 +0100134BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * BorderModes(), shape, border_mode)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100135{
SiCong Libacaf9a2017-06-19 13:41:45 +0100136 std::mt19937 gen(user_config.seed.get());
137 std::uniform_int_distribution<uint8_t> distribution(0, 255);
138 const uint8_t border_value = distribution(gen);
139
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100140 // Compute function
SiCong Libacaf9a2017-06-19 13:41:45 +0100141 Tensor dst = compute_box3x3(shape, border_mode, border_value);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100142
143 // Compute reference
SiCong Libacaf9a2017-06-19 13:41:45 +0100144 RawTensor ref_dst = Reference::compute_reference_box3x3(shape, border_mode, border_value);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100145
146 // Validate output
SiCong Li7a035752017-06-28 15:27:02 +0100147 validate(NEAccessor(dst), ref_dst, shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100148}
149
150BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
SiCong Libacaf9a2017-06-19 13:41:45 +0100151BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * BorderModes(), shape, border_mode)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100152{
SiCong Libacaf9a2017-06-19 13:41:45 +0100153 std::mt19937 gen(user_config.seed.get());
154 std::uniform_int_distribution<uint8_t> distribution(0, 255);
155 const uint8_t border_value = distribution(gen);
156
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100157 // Compute function
SiCong Libacaf9a2017-06-19 13:41:45 +0100158 Tensor dst = compute_box3x3(shape, border_mode, border_value);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100159
160 // Compute reference
SiCong Libacaf9a2017-06-19 13:41:45 +0100161 RawTensor ref_dst = Reference::compute_reference_box3x3(shape, border_mode, border_value);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100162
163 // Validate output
SiCong Li7a035752017-06-28 15:27:02 +0100164 validate(NEAccessor(dst), ref_dst, shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100165}
166
167BOOST_AUTO_TEST_SUITE_END()
168BOOST_AUTO_TEST_SUITE_END()
169#endif