blob: bbb4589d30d722eb0ead07e7bc0ba34e02588728 [file] [log] [blame]
Giorgio Arena2ca209e2017-06-13 15:49:37 +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
25#include "Globals.h"
26#include "NEON/Helper.h"
27#include "NEON/NEAccessor.h"
28#include "PaddingCalculator.h"
29#include "TensorLibrary.h"
30#include "TypePrinter.h"
31#include "Utils.h"
32#include "validation/Datasets.h"
33#include "validation/Reference.h"
34#include "validation/Validation.h"
35
36#include "arm_compute/core/Helpers.h"
37#include "arm_compute/core/Types.h"
38#include "arm_compute/runtime/NEON/functions/NEMinMaxLocation.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 MinMaxLocation function.
55 *
56 * @param[in] shape Shape of the input and output tensors.
57 * @param[in] dt_in Data type of first input tensor.
58 * @param[out] min Minimum value of tensor
59 * @param[out] max Maximum value of tensor
60 * @param[out] min_loc Array with locations of minimum values
61 * @param[out] max_loc Array with locations of maximum values
62 * @param[out] min_count Number of minimum values found
63 * @param[out] max_count Number of maximum values found
64 *
65 * @return Computed output tensor.
66 */
67
68void compute_min_max_location(const TensorShape &shape, DataType dt_in, int32_t &min, int32_t &max,
69 Coordinates2DArray &min_loc, Coordinates2DArray &max_loc, uint32_t &min_count, uint32_t &max_count)
70{
71 // Create tensor
72 Tensor src = create_tensor<Tensor>(shape, dt_in);
73 src.info()->set_format((dt_in == DataType::U8) ? Format::U8 : Format::S16);
74
75 // Create and configure min_max_location configure function
76 NEMinMaxLocation min_max_loc;
77 min_max_loc.configure(&src, &min, &max, &min_loc, &max_loc, &min_count, &max_count);
78
79 // Allocate tensors
80 src.allocator()->allocate();
81
82 BOOST_TEST(!src.info()->is_resizable());
83
84 // Fill tensors
85 library->fill_tensor_uniform(NEAccessor(src), 0);
86
87 // Compute function
88 min_max_loc.run();
89}
90
91void validate_configuration(const Tensor &src, TensorShape shape)
92{
93 BOOST_TEST(src.info()->is_resizable());
94
95 // Create output storage
96 int32_t min;
97 int32_t max;
98 Coordinates2DArray min_loc;
99 Coordinates2DArray max_loc;
100 uint32_t min_count;
101 uint32_t max_count;
102
103 // Create and configure function
104 NEMinMaxLocation min_max_loc;
105 min_max_loc.configure(&src, &min, &max, &min_loc, &max_loc, &min_count, &max_count);
106
107 // Validate valid region
108 const ValidRegion valid_region = shape_to_valid_region(shape);
109 validate(src.info()->valid_region(), valid_region);
110
111 // Validate padding
112 const PaddingSize padding = PaddingCalculator(shape.x(), 1).required_padding();
113 validate(src.info()->padding(), padding);
114}
115} // namespace
116
117#ifndef DOXYGEN_SKIP_THIS
118BOOST_AUTO_TEST_SUITE(NEON)
119BOOST_AUTO_TEST_SUITE(MinMaxLocation)
120
121BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
122BOOST_DATA_TEST_CASE(Configuration, (Small2DShapes() + Large2DShapes()) * boost::unit_test::data::make({ DataType::U8, DataType::S16 }),
123 shape, dt)
124{
125 // Create tensor
126 Tensor src = create_tensor<Tensor>(shape, dt);
127 src.info()->set_format(dt == DataType::U8 ? Format::U8 : Format::S16);
128
129 validate_configuration(src, shape);
130}
131
132BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
133BOOST_DATA_TEST_CASE(RunSmall, Small2DShapes() * boost::unit_test::data::make({ DataType::U8, DataType::S16 }),
134 shape, dt)
135{
136 // Create output storage
137 int32_t min;
138 int32_t max;
139 Coordinates2DArray min_loc(shape.total_size());
140 Coordinates2DArray max_loc(shape.total_size());
141 uint32_t min_count;
142 uint32_t max_count;
143
144 int32_t ref_min;
145 int32_t ref_max;
146 Coordinates2DArray ref_min_loc(shape.total_size());
147 Coordinates2DArray ref_max_loc(shape.total_size());
148 uint32_t ref_min_count;
149 uint32_t ref_max_count;
150
151 // Compute function
152 compute_min_max_location(shape, dt, min, max, min_loc, max_loc, min_count, max_count);
153
154 // Compute reference
155 Reference::compute_reference_min_max_location(shape, dt, ref_min, ref_max, ref_min_loc, ref_max_loc, ref_min_count, ref_max_count);
156
157 // Validate output
158 validate_min_max_loc(min, ref_min, max, ref_max, min_loc, ref_min_loc, max_loc, ref_max_loc, min_count, ref_min_count, max_count, ref_max_count);
159}
160
161BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
162BOOST_DATA_TEST_CASE(RunLarge, Large2DShapes() * boost::unit_test::data::make({ DataType::U8, DataType::S16 }),
163 shape, dt)
164{
165 // Create output storage
166 int32_t min;
167 int32_t max;
168 Coordinates2DArray min_loc(shape.total_size());
169 Coordinates2DArray max_loc(shape.total_size());
170 uint32_t min_count;
171 uint32_t max_count;
172
173 int32_t ref_min;
174 int32_t ref_max;
175 Coordinates2DArray ref_min_loc(shape.total_size());
176 Coordinates2DArray ref_max_loc(shape.total_size());
177 uint32_t ref_min_count;
178 uint32_t ref_max_count;
179
180 // Compute function
181 compute_min_max_location(shape, dt, min, max, min_loc, max_loc, min_count, max_count);
182
183 // Compute reference
184 Reference::compute_reference_min_max_location(shape, dt, ref_min, ref_max, ref_min_loc, ref_max_loc, ref_min_count, ref_max_count);
185
186 // Validate output
187 validate_min_max_loc(min, ref_min, max, ref_max, min_loc, ref_min_loc, max_loc, ref_max_loc, min_count, ref_min_count, max_count, ref_max_count);
188}
189
190BOOST_AUTO_TEST_SUITE_END()
191BOOST_AUTO_TEST_SUITE_END()
192#endif /* DOXYGEN_SKIP_THIS */