blob: b17d57276187a608afc59fd790fd918398d58afe [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 */
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +010024#include "AssetsLibrary.h"
SiCong Li5a536642017-06-19 14:47:05 +010025#include "Globals.h"
SiCong Li5a536642017-06-19 14:47:05 +010026#include "NEON/NEAccessor.h"
27#include "PaddingCalculator.h"
SiCong Li5a536642017-06-19 14:47:05 +010028#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/NEGaussian3x3.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{
SiCong Li7a035752017-06-28 15:27:02 +010054constexpr unsigned int filter_size = 3; /** Size of the kernel/filter in number of elements. */
55constexpr BorderSize border_size(filter_size / 2); /** Border size of the kernel/filter around its central element. */
56
SiCong Li5a536642017-06-19 14:47:05 +010057/** Compute Neon gaussian3x3 filter.
58 *
59 * @param[in] shape Shape of the input and output tensors.
60 * @param[in] border_mode BorderMode used by the input tensor.
61 * @param[in] constant_border_value Constant to use if @p border_mode == CONSTANT.
62 *
63 * @return Computed output tensor.
64 */
65Tensor compute_gaussian3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value)
66{
67 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +010068 Tensor src = create_tensor<Tensor>(shape, DataType::U8);
69 Tensor dst = create_tensor<Tensor>(shape, DataType::U8);
SiCong Li5a536642017-06-19 14:47:05 +010070
71 // Create and configure function
72 NEGaussian3x3 gaussian3x3;
73 gaussian3x3.configure(&src, &dst, border_mode, constant_border_value);
74
75 // Allocate tensors
76 src.allocator()->allocate();
77 dst.allocator()->allocate();
78
79 BOOST_TEST(!src.info()->is_resizable());
80 BOOST_TEST(!dst.info()->is_resizable());
81
82 // Fill tensors
83 library->fill_tensor_uniform(NEAccessor(src), 0);
84
85 // Compute function
86 gaussian3x3.run();
87
88 return dst;
89}
90} // namespace
91
92#ifndef DOXYGEN_SKIP_THIS
93BOOST_AUTO_TEST_SUITE(NEON)
94BOOST_AUTO_TEST_SUITE(Gaussian3x3)
95
96BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
97BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * BorderModes(), shape, border_mode)
98{
99 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +0100100 Tensor src = create_tensor<Tensor>(shape, DataType::U8);
101 Tensor dst = create_tensor<Tensor>(shape, DataType::U8);
SiCong Li5a536642017-06-19 14:47:05 +0100102
103 BOOST_TEST(src.info()->is_resizable());
104 BOOST_TEST(dst.info()->is_resizable());
105
106 // Create and configure function
107 NEGaussian3x3 gaussian3x3;
108 gaussian3x3.configure(&src, &dst, border_mode);
109
110 // Validate valid region
111 const ValidRegion src_valid_region = shape_to_valid_region(shape);
SiCong Li7a035752017-06-28 15:27:02 +0100112 const ValidRegion dst_valid_region = shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size);
SiCong Li5a536642017-06-19 14:47:05 +0100113 validate(src.info()->valid_region(), src_valid_region);
114 validate(dst.info()->valid_region(), dst_valid_region);
115
116 // Validate padding
117 PaddingCalculator calculator(shape.x(), 8);
118 calculator.set_border_size(1);
119 calculator.set_border_mode(border_mode);
120
121 const PaddingSize dst_padding = calculator.required_padding();
122
123 calculator.set_accessed_elements(16);
124 calculator.set_access_offset(-1);
125
126 const PaddingSize src_padding = calculator.required_padding();
127
128 validate(src.info()->padding(), src_padding);
129 validate(dst.info()->padding(), dst_padding);
130}
131
132BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
133BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * BorderModes(), shape, border_mode)
134{
135 std::mt19937 gen(user_config.seed.get());
136 std::uniform_int_distribution<uint8_t> distribution(0, 255);
137 const uint8_t border_value = distribution(gen);
138
139 // Compute function
140 Tensor dst = compute_gaussian3x3(shape, border_mode, border_value);
141
142 // Compute reference
143 RawTensor ref_dst = Reference::compute_reference_gaussian3x3(shape, border_mode, border_value);
144
145 // Validate output
SiCong Li7a035752017-06-28 15:27:02 +0100146 validate(NEAccessor(dst), ref_dst, shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size));
SiCong Li5a536642017-06-19 14:47:05 +0100147}
148
149BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
150BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * BorderModes(), shape, border_mode)
151{
152 std::mt19937 gen(user_config.seed.get());
153 std::uniform_int_distribution<uint8_t> distribution(0, 255);
154 const uint8_t border_value = distribution(gen);
155
156 // Compute function
157 Tensor dst = compute_gaussian3x3(shape, border_mode, border_value);
158
159 // Compute reference
160 RawTensor ref_dst = Reference::compute_reference_gaussian3x3(shape, border_mode, border_value);
161
162 // Validate output
SiCong Li7a035752017-06-28 15:27:02 +0100163 validate(NEAccessor(dst), ref_dst, shape_to_valid_region(shape, border_mode == BorderMode::UNDEFINED, border_size));
SiCong Li5a536642017-06-19 14:47:05 +0100164}
165
166BOOST_AUTO_TEST_SUITE_END()
167BOOST_AUTO_TEST_SUITE_END()
Anthony Barbierac69aa12017-07-03 17:39:37 +0100168#endif /* DOXYGEN_SKIP_THIS */