blob: a173338542b32768fbaed04b93e8920085543dff [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 */
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010024#include "NEON/Accessor.h"
Moritz Pflanzer5b512292017-06-21 15:54:07 +010025#include "PaddingCalculator.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026#include "Utils.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010027#include "tests/AssetsLibrary.h"
28#include "tests/Globals.h"
29#include "tests/validation_old/Datasets.h"
30#include "tests/validation_old/Reference.h"
31#include "tests/validation_old/Validation.h"
Anthony Barbier2a07e182017-08-04 18:20:27 +010032#include "utils/TypePrinter.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033
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
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010040#include "tests/validation_old/boost_wrapper.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010041
42#include <random>
43#include <string>
44
45using namespace arm_compute;
46using namespace arm_compute::test;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010047using namespace arm_compute::test::validation;
48
49namespace
50{
51/** Compute Neon accumulate function.
52 *
53 * @param[in] shape Shape of the input and output tensors.
54 *
55 * @return Computed output tensor.
56 */
57Tensor compute_accumulate(const TensorShape &shape)
58{
59 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +010060 Tensor src = create_tensor<Tensor>(shape, DataType::U8);
61 Tensor dst = create_tensor<Tensor>(shape, DataType::S16);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010062
63 // Create and configure function
64 NEAccumulate acc;
65 acc.configure(&src, &dst);
66
67 // Allocate tensors
68 src.allocator()->allocate();
69 dst.allocator()->allocate();
70
71 BOOST_TEST(!src.info()->is_resizable());
72 BOOST_TEST(!dst.info()->is_resizable());
73
74 // Fill tensors
Moritz Pflanzerd58cec02017-07-18 15:44:21 +010075 library->fill_tensor_uniform(Accessor(src), 0);
76 library->fill_tensor_uniform(Accessor(dst), 1);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010077
78 // Compute function
79 acc.run();
80
81 return dst;
82}
83} // namespace
84
85#ifndef DOXYGEN_SKIP_THIS
86BOOST_AUTO_TEST_SUITE(NEON)
87BOOST_AUTO_TEST_SUITE(Accumulate)
88
89BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit") * boost::unit_test::label("nightly"))
90BOOST_DATA_TEST_CASE(Configuration, (SmallShapes() + LargeShapes()),
91 shape)
92{
93 // Create tensors
Moritz Pflanzer94450f12017-06-30 12:48:43 +010094 Tensor src = create_tensor<Tensor>(shape, DataType::U8);
95 Tensor dst = create_tensor<Tensor>(shape, DataType::S16);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010096
97 BOOST_TEST(src.info()->is_resizable());
98 BOOST_TEST(dst.info()->is_resizable());
99
100 // Create and configure function
101 NEAccumulate acc;
102 acc.configure(&src, &dst);
103
104 // Validate valid region
105 const ValidRegion valid_region = shape_to_valid_region(shape);
106 validate(src.info()->valid_region(), valid_region);
107 validate(dst.info()->valid_region(), valid_region);
108
109 // Validate padding
Moritz Pflanzer2509fba2017-06-23 14:15:03 +0100110 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100111 validate(src.info()->padding(), padding);
112 validate(dst.info()->padding(), padding);
113}
114
115BOOST_TEST_DECORATOR(*boost::unit_test::label("precommit"))
116BOOST_DATA_TEST_CASE(RunSmall, SmallShapes(),
117 shape)
118{
119 // Compute function
120 Tensor dst = compute_accumulate(shape);
121
122 // Compute reference
123 RawTensor ref_dst = Reference::compute_reference_accumulate(shape);
124
125 // Validate output
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100126 validate(Accessor(dst), ref_dst);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100127}
128
129BOOST_TEST_DECORATOR(*boost::unit_test::label("nightly"))
130BOOST_DATA_TEST_CASE(RunLarge, LargeShapes(),
131 shape)
132{
133 // Compute function
134 Tensor dst = compute_accumulate(shape);
135
136 // Compute reference
137 RawTensor ref_dst = Reference::compute_reference_accumulate(shape);
138
139 // Validate output
Moritz Pflanzerd58cec02017-07-18 15:44:21 +0100140 validate(Accessor(dst), ref_dst);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100141}
142
143BOOST_AUTO_TEST_SUITE_END()
144BOOST_AUTO_TEST_SUITE_END()
Anthony Barbierac69aa12017-07-03 17:39:37 +0100145#endif /* DOXYGEN_SKIP_THIS */