blob: b2a66cde30de4f561f7d8ea889ab7bf5621803f1 [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"
34
35#include "arm_compute/core/Helpers.h"
36#include "arm_compute/core/Types.h"
37#include "arm_compute/runtime/NEON/functions/NEBox3x3.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 <random>
45#include <string>
46
47using namespace arm_compute;
48using namespace arm_compute::test;
49using namespace arm_compute::test::neon;
50using namespace arm_compute::test::validation;
51
52namespace
53{
54/** Compute Neon 3-by-3 box filter.
55 *
56 * @param[in] shape Shape of the input and output tensors.
57 *
58 * @return Computed output tensor.
59 */
60Tensor compute_box3x3(const TensorShape &shape)
61{
62 // Create tensors
63 Tensor src = create_tensor(shape, DataType::U8);
64 Tensor dst = create_tensor(shape, DataType::U8);
65
66 // Create and configure function
67 NEBox3x3 band;
68 band.configure(&src, &dst, BorderMode::UNDEFINED);
69
70 // Allocate tensors
71 src.allocator()->allocate();
72 dst.allocator()->allocate();
73
74 BOOST_TEST(!src.info()->is_resizable());
75 BOOST_TEST(!dst.info()->is_resizable());
76
77 // Fill tensors
78 library->fill_tensor_uniform(NEAccessor(src), 0);
79
80 // Compute function
81 band.run();
82
83 return dst;
84}
85} // namespace
86
87#ifndef DOXYGEN_SKIP_THIS
88BOOST_AUTO_TEST_SUITE(NEON)
89BOOST_AUTO_TEST_SUITE(Box3x3)
90
91BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
92BOOST_DATA_TEST_CASE(Configuration, SmallShapes() + LargeShapes(), shape)
93{
94 // Create tensors
95 Tensor src = create_tensor(shape, DataType::U8);
96 Tensor dst = create_tensor(shape, DataType::U8);
97
98 BOOST_TEST(src.info()->is_resizable());
99 BOOST_TEST(dst.info()->is_resizable());
100
101 // Create and configure function
102 NEBox3x3 band;
103 band.configure(&src, &dst, BorderMode::UNDEFINED);
104
105 // Validate valid region
106 const ValidRegion src_valid_region = shape_to_valid_region(shape);
107 const ValidRegion dst_valid_region = shape_to_valid_region_undefined_border(shape, BorderSize(1));
108 validate(src.info()->valid_region(), src_valid_region);
109 validate(dst.info()->valid_region(), dst_valid_region);
110
111 // Validate padding
Moritz Pflanzer5b512292017-06-21 15:54:07 +0100112 PaddingCalculator calculator(shape.x(), 8);
113 calculator.set_border_size(1);
114
Moritz Pflanzer2509fba2017-06-23 14:15:03 +0100115 const PaddingSize dst_padding = calculator.required_padding();
Moritz Pflanzer5b512292017-06-21 15:54:07 +0100116
117 calculator.set_accessed_elements(16);
118 calculator.set_access_offset(-1);
119
Moritz Pflanzer2509fba2017-06-23 14:15:03 +0100120 const PaddingSize src_padding = calculator.required_padding();
Moritz Pflanzer5b512292017-06-21 15:54:07 +0100121
Moritz Pflanzer2509fba2017-06-23 14:15:03 +0100122 validate(src.info()->padding(), src_padding);
123 validate(dst.info()->padding(), dst_padding);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100124}
125
126BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
127BOOST_DATA_TEST_CASE(RunSmall, SmallShapes(), shape)
128{
129 // Compute function
130 Tensor dst = compute_box3x3(shape);
131
132 // Compute reference
133 RawTensor ref_dst = Reference::compute_reference_box3x3(shape);
134
135 // Validate output
136 validate(NEAccessor(dst), ref_dst, shape_to_valid_region_undefined_border(shape, BorderSize(1)));
137}
138
139BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
140BOOST_DATA_TEST_CASE(RunLarge, LargeShapes(), shape)
141{
142 // Compute function
143 Tensor dst = compute_box3x3(shape);
144
145 // Compute reference
146 RawTensor ref_dst = Reference::compute_reference_box3x3(shape);
147
148 // Validate output
149 validate(NEAccessor(dst), ref_dst, shape_to_valid_region_undefined_border(shape, BorderSize(1)));
150}
151
152BOOST_AUTO_TEST_SUITE_END()
153BOOST_AUTO_TEST_SUITE_END()
154#endif