blob: 2d7f12aeb341f2e4ee8ca998b36c6e011981b72e [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"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010025#include "NEON/NEAccessor.h"
Moritz Pflanzer5b512292017-06-21 15:54:07 +010026#include "PaddingCalculator.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#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/NEAccumulate.h"
37#include "arm_compute/runtime/Tensor.h"
38#include "arm_compute/runtime/TensorAllocator.h"
39
40#include "boost_wrapper.h"
41
42#include <random>
43#include <string>
44
45using namespace arm_compute;
46using namespace arm_compute::test;
47using namespace arm_compute::test::neon;
48using namespace arm_compute::test::validation;
49
50namespace
51{
52/** Compute Neon accumulate weighted function.
53 *
54 * @param[in] shape Shape of the input and output tensors.
55 *
56 * @return Computed output tensor.
57 */
58Tensor compute_accumulate_weighted(const TensorShape &shape, float alpha)
59{
60 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +010061 Tensor src = create_tensor<Tensor>(shape, DataType::U8);
62 Tensor dst = create_tensor<Tensor>(shape, DataType::U8);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010063
64 // Create and configure function
65 NEAccumulateWeighted acc;
66 acc.configure(&src, alpha, &dst);
67
68 // Allocate tensors
69 src.allocator()->allocate();
70 dst.allocator()->allocate();
71
72 BOOST_TEST(!src.info()->is_resizable());
73 BOOST_TEST(!dst.info()->is_resizable());
74
75 // Fill tensors
76 library->fill_tensor_uniform(NEAccessor(src), 0);
77 library->fill_tensor_uniform(NEAccessor(dst), 1);
78
79 // Compute function
80 acc.run();
81
82 return dst;
83}
84} // namespace
85
86#ifndef DOXYGEN_SKIP_THIS
87BOOST_AUTO_TEST_SUITE(NEON)
88BOOST_AUTO_TEST_SUITE(AccumulateWeighted)
89
90BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
91BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()) * boost::unit_test::data::make({ 0.f, 0.5f, 1.f }),
92 shape, alpha)
93{
94 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +010095 Tensor src = create_tensor<Tensor>(shape, DataType::U8);
96 Tensor dst = create_tensor<Tensor>(shape, DataType::U8);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010097
98 BOOST_TEST(src.info()->is_resizable());
99 BOOST_TEST(dst.info()->is_resizable());
100
101 // Create and configure function
102 NEAccumulateWeighted acc;
103 acc.configure(&src, alpha, &dst);
104
105 // Validate valid region
106 const ValidRegion valid_region = shape_to_valid_region(shape);
107 validate(src.info()->valid_region(), valid_region);
108 validate(dst.info()->valid_region(), valid_region);
109
110 // Validate padding
Moritz Pflanzer2509fba2017-06-23 14:15:03 +0100111 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100112 validate(src.info()->padding(), padding);
113 validate(dst.info()->padding(), padding);
114}
115
116BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
117BOOST_DATA_TEST_CASE(RunSmall, SmallShapes() * boost::unit_test::data::make({ 0.f, 0.5f, 1.f }),
118 shape, alpha)
119{
120 // Compute function
121 Tensor dst = compute_accumulate_weighted(shape, alpha);
122
123 // Compute reference
124 RawTensor ref_dst = Reference::compute_reference_accumulate_weighted(shape, alpha);
125
126 // Validate output
127 validate(NEAccessor(dst), ref_dst);
128}
129
130BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
131BOOST_DATA_TEST_CASE(RunLarge, LargeShapes() * boost::unit_test::data::make({ 0.f, 0.5f, 1.f }),
132 shape, alpha)
133{
134 // Compute function
135 Tensor dst = compute_accumulate_weighted(shape, alpha);
136
137 // Compute reference
138 RawTensor ref_dst = Reference::compute_reference_accumulate_weighted(shape, alpha);
139
140 // Validate output
141 validate(NEAccessor(dst), ref_dst);
142}
143
144BOOST_AUTO_TEST_SUITE_END()
145BOOST_AUTO_TEST_SUITE_END()
Anthony Barbierac69aa12017-07-03 17:39:37 +0100146#endif /* DOXYGEN_SKIP_THIS */