blob: f33b63f9195c7ea731d3bc4580f393efc567f4a5 [file] [log] [blame]
SiCong Li5a536642017-06-19 14:47:05 +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 "PaddingCalculator.h"
28#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#include "validation/ValidationUserConfiguration.h"
35
36#include "arm_compute/core/Helpers.h"
37#include "arm_compute/core/Types.h"
38#include "arm_compute/runtime/NEON/functions/NEGaussian3x3.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{
55/** Compute Neon gaussian3x3 filter.
56 *
57 * @param[in] shape Shape of the input and output tensors.
58 * @param[in] border_mode BorderMode used by the input tensor.
59 * @param[in] constant_border_value Constant to use if @p border_mode == CONSTANT.
60 *
61 * @return Computed output tensor.
62 */
63Tensor compute_gaussian3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value)
64{
65 // Create tensors
66 Tensor src = create_tensor(shape, DataType::U8);
67 Tensor dst = create_tensor(shape, DataType::U8);
68
69 // Create and configure function
70 NEGaussian3x3 gaussian3x3;
71 gaussian3x3.configure(&src, &dst, border_mode, constant_border_value);
72
73 // Allocate tensors
74 src.allocator()->allocate();
75 dst.allocator()->allocate();
76
77 BOOST_TEST(!src.info()->is_resizable());
78 BOOST_TEST(!dst.info()->is_resizable());
79
80 // Fill tensors
81 library->fill_tensor_uniform(NEAccessor(src), 0);
82
83 // Compute function
84 gaussian3x3.run();
85
86 return dst;
87}
88} // namespace
89
90#ifndef DOXYGEN_SKIP_THIS
91BOOST_AUTO_TEST_SUITE(NEON)
92BOOST_AUTO_TEST_SUITE(Gaussian3x3)
93
94BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
95BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * BorderModes(), shape, border_mode)
96{
97 // Create tensors
98 Tensor src = create_tensor(shape, DataType::U8);
99 Tensor dst = create_tensor(shape, DataType::U8);
100
101 BOOST_TEST(src.info()->is_resizable());
102 BOOST_TEST(dst.info()->is_resizable());
103
104 // Create and configure function
105 NEGaussian3x3 gaussian3x3;
106 gaussian3x3.configure(&src, &dst, border_mode);
107
108 // Validate valid region
109 const ValidRegion src_valid_region = shape_to_valid_region(shape);
110 const ValidRegion dst_valid_region = shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, BorderSize(1));
111 validate(src.info()->valid_region(), src_valid_region);
112 validate(dst.info()->valid_region(), dst_valid_region);
113
114 // Validate padding
115 PaddingCalculator calculator(shape.x(), 8);
116 calculator.set_border_size(1);
117 calculator.set_border_mode(border_mode);
118
119 const PaddingSize dst_padding = calculator.required_padding();
120
121 calculator.set_accessed_elements(16);
122 calculator.set_access_offset(-1);
123
124 const PaddingSize src_padding = calculator.required_padding();
125
126 validate(src.info()->padding(), src_padding);
127 validate(dst.info()->padding(), dst_padding);
128}
129
130BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
131BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * BorderModes(), shape, border_mode)
132{
133 std::mt19937 gen(user_config.seed.get());
134 std::uniform_int_distribution<uint8_t> distribution(0, 255);
135 const uint8_t border_value = distribution(gen);
136
137 // Compute function
138 Tensor dst = compute_gaussian3x3(shape, border_mode, border_value);
139
140 // Compute reference
141 RawTensor ref_dst = Reference::compute_reference_gaussian3x3(shape, border_mode, border_value);
142
143 // Validate output
144 validate(NEAccessor(dst), ref_dst, shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, BorderSize(1)));
145}
146
147BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
148BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * BorderModes(), shape, border_mode)
149{
150 std::mt19937 gen(user_config.seed.get());
151 std::uniform_int_distribution<uint8_t> distribution(0, 255);
152 const uint8_t border_value = distribution(gen);
153
154 // Compute function
155 Tensor dst = compute_gaussian3x3(shape, border_mode, border_value);
156
157 // Compute reference
158 RawTensor ref_dst = Reference::compute_reference_gaussian3x3(shape, border_mode, border_value);
159
160 // Validate output
161 validate(NEAccessor(dst), ref_dst, shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, BorderSize(1)));
162}
163
164BOOST_AUTO_TEST_SUITE_END()
165BOOST_AUTO_TEST_SUITE_END()
166#endif