blob: e17b15ada1ee94193afdf24e5a92ee3d7952640c [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/NEAccumulate.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 accumulate squared function.
54 *
55 * @param[in] shape Shape of the input and output tensors.
56 *
57 * @return Computed output tensor.
58 */
59Tensor compute_accumulate_squared(const TensorShape &shape, uint32_t shift)
60{
61 // Create tensors
62 Tensor src = create_tensor(shape, DataType::U8);
63 Tensor dst = create_tensor(shape, DataType::S16);
64
65 // Create and configure function
66 NEAccumulateSquared acc;
67 acc.configure(&src, shift, &dst);
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 // dst tensor filled with non-negative values
78 library->fill_tensor_uniform(NEAccessor(src), 0);
79 library->fill_tensor_uniform(NEAccessor(dst), 1, static_cast<int16_t>(0), std::numeric_limits<int16_t>::max());
80
81 // Compute function
82 acc.run();
83
84 return dst;
85}
86} // namespace
87
88#ifndef DOXYGEN_SKIP_THIS
89BOOST_AUTO_TEST_SUITE(NEON)
90BOOST_AUTO_TEST_SUITE(AccumulateSquared)
91
92BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
93BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::xrange(0U, 16U),
94 shape, shift)
95{
96 // Create tensors
97 Tensor src = create_tensor(shape, DataType::U8);
98 Tensor dst = create_tensor(shape, DataType::S16);
99
100 BOOST_TEST(src.info()->is_resizable());
101 BOOST_TEST(dst.info()->is_resizable());
102
103 // Create and configure function
104 NEAccumulateSquared acc;
105 acc.configure(&src, shift, &dst);
106
107 // Validate valid region
108 const ValidRegion valid_region = shape_to_valid_region(shape);
109 validate(src.info()->valid_region(), valid_region);
110 validate(dst.info()->valid_region(), valid_region);
111
112 // Validate padding
Moritz Pflanzer5b512292017-06-21 15:54:07 +0100113 const PaddingSize padding(0, PaddingCalculator(shape.x(), 16).required_padding(), 0, 0);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100114 validate(src.info()->padding(), padding);
115 validate(dst.info()->padding(), padding);
116}
117
118BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
119BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::xrange(0U, 16U),
120 shape, shift)
121{
122 // Compute function
123 Tensor dst = compute_accumulate_squared(shape, shift);
124
125 // Compute reference
126 RawTensor ref_dst = Reference::compute_reference_accumulate_squared(shape, shift);
127
128 // Validate output
129 validate(NEAccessor(dst), ref_dst);
130}
131
132BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
133BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ 0U, 1U, 15U }),
134 shape, shift)
135{
136 // Compute function
137 Tensor dst = compute_accumulate_squared(shape, shift);
138
139 // Compute reference
140 RawTensor ref_dst = Reference::compute_reference_accumulate_squared(shape, shift);
141
142 // Validate output
143 validate(NEAccessor(dst), ref_dst);
144}
145
146BOOST_AUTO_TEST_SUITE_END()
147BOOST_AUTO_TEST_SUITE_END()
148#endif