blob: 5da015c73ab36afcaae74253d01c17d9c736c7d6 [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"
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
34#include "arm_compute/core/Helpers.h"
35#include "arm_compute/core/Types.h"
36#include "arm_compute/runtime/NEON/functions/NEBox3x3.h"
37#include "arm_compute/runtime/SubTensor.h"
38#include "arm_compute/runtime/Tensor.h"
39#include "arm_compute/runtime/TensorAllocator.h"
40
41#include "boost_wrapper.h"
42
43#include <random>
44#include <string>
45
46using namespace arm_compute;
47using namespace arm_compute::test;
48using namespace arm_compute::test::neon;
49using namespace arm_compute::test::validation;
50
51namespace
52{
53/** Compute Neon 3-by-3 box filter.
54 *
55 * @param[in] shape Shape of the input and output tensors.
56 *
57 * @return Computed output tensor.
58 */
59Tensor compute_box3x3(const TensorShape &shape)
60{
61 // Create tensors
62 Tensor src = create_tensor(shape, DataType::U8);
63 Tensor dst = create_tensor(shape, DataType::U8);
64
65 // Create and configure function
66 NEBox3x3 band;
67 band.configure(&src, &dst, BorderMode::UNDEFINED);
68
69 // Allocate tensors
70 src.allocator()->allocate();
71 dst.allocator()->allocate();
72
73 BOOST_TEST(!src.info()->is_resizable());
74 BOOST_TEST(!dst.info()->is_resizable());
75
76 // Fill tensors
77 library->fill_tensor_uniform(NEAccessor(src), 0);
78
79 // Compute function
80 band.run();
81
82 return dst;
83}
84} // namespace
85
86#ifndef DOXYGEN_SKIP_THIS
87BOOST_AUTO_TEST_SUITE(NEON)
88BOOST_AUTO_TEST_SUITE(Box3x3)
89
90BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
91BOOST_DATA_TEST_CASE(Configuration, SmallShapes() + LargeShapes(), shape)
92{
93 // Create tensors
94 Tensor src = create_tensor(shape, DataType::U8);
95 Tensor dst = create_tensor(shape, DataType::U8);
96
97 BOOST_TEST(src.info()->is_resizable());
98 BOOST_TEST(dst.info()->is_resizable());
99
100 // Create and configure function
101 NEBox3x3 band;
102 band.configure(&src, &dst, BorderMode::UNDEFINED);
103
104 // Validate valid region
105 const ValidRegion src_valid_region = shape_to_valid_region(shape);
106 const ValidRegion dst_valid_region = shape_to_valid_region_undefined_border(shape, BorderSize(1));
107 validate(src.info()->valid_region(), src_valid_region);
108 validate(dst.info()->valid_region(), dst_valid_region);
109
110 // Validate padding
111 const PaddingSize read_padding(0, required_padding_undefined_border_read(shape.x(), 16, 8), 0, 0);
112 const PaddingSize write_padding(0, required_padding_undefined_border_write(shape.x(), 8, 1), 0, 0);
113 validate(src.info()->padding(), read_padding);
114 validate(dst.info()->padding(), write_padding);
115}
116
117BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
118BOOST_DATA_TEST_CASE(RunSmall, SmallShapes(), shape)
119{
120 // Compute function
121 Tensor dst = compute_box3x3(shape);
122
123 // Compute reference
124 RawTensor ref_dst = Reference::compute_reference_box3x3(shape);
125
126 // Validate output
127 validate(NEAccessor(dst), ref_dst, shape_to_valid_region_undefined_border(shape, BorderSize(1)));
128}
129
130BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
131BOOST_DATA_TEST_CASE(RunLarge, LargeShapes(), shape)
132{
133 // Compute function
134 Tensor dst = compute_box3x3(shape);
135
136 // Compute reference
137 RawTensor ref_dst = Reference::compute_reference_box3x3(shape);
138
139 // Validate output
140 validate(NEAccessor(dst), ref_dst, shape_to_valid_region_undefined_border(shape, BorderSize(1)));
141}
142
143BOOST_AUTO_TEST_SUITE_END()
144BOOST_AUTO_TEST_SUITE_END()
145#endif