blob: 2e33540b5d844d86b44a401ddc8e9cd4fb7440a4 [file] [log] [blame]
Ioan-Cristian Szabo432a7d42017-10-12 09:25:19 +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 "arm_compute/core/Types.h"
25#include "arm_compute/runtime/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
27#include "arm_compute/runtime/CL/functions/CLAccumulate.h"
28#include "tests/CL/CLAccessor.h"
29#include "tests/PaddingCalculator.h"
30#include "tests/datasets/ConvertPolicyDataset.h"
31#include "tests/datasets/ShapeDatasets.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Macros.h"
34#include "tests/framework/datasets/Datasets.h"
35#include "tests/validation/Validation.h"
36#include "tests/validation/fixtures/AccumulateFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46/** Tolerance value for comparing reference's output against implementation's output for floating point data types */
47constexpr AbsoluteTolerance<float> tolerance(1.0f);
48/** Input data sets **/
49const auto AccumulateU8Dataset = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8));
50const auto AccumulateS16Dataset = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::S16));
51} // namespace
52TEST_SUITE(CL)
53TEST_SUITE(Accumulate)
54
55TEST_SUITE(U8)
56DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), AccumulateS16Dataset),
57 shape, data_type, output_data_type)
58{
59 // Create tensors
60 CLTensor ref_src = create_tensor<CLTensor>(shape, data_type);
61 CLTensor dst = create_tensor<CLTensor>(shape, output_data_type);
62
63 // Create and Configure function
64 CLAccumulate accum;
65 accum.configure(&ref_src, &dst);
66
67 // Validate valid region
68 const ValidRegion valid_region = shape_to_valid_region(shape);
69 validate(dst.info()->valid_region(), valid_region);
70
71 // Validate padding
72 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
73 validate(ref_src.info()->padding(), padding);
74 validate(dst.info()->padding(), padding);
75}
76
77template <typename T1>
78using CLAccumulateFixture = AccumulateValidationFixture<CLTensor, CLAccessor, CLAccumulate, T1, int16_t>;
79
80FIXTURE_DATA_TEST_CASE(RunSmall, CLAccumulateFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), AccumulateS16Dataset))
81{
82 // Validate output
83 validate(CLAccessor(_target), _reference, tolerance);
84}
85FIXTURE_DATA_TEST_CASE(RunLarge, CLAccumulateFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), AccumulateS16Dataset))
86{
87 // Validate output
88 validate(CLAccessor(_target), _reference, tolerance);
89}
90
91TEST_SUITE_END()
92TEST_SUITE_END()
93
94TEST_SUITE(AccumulateWeighted)
95
96TEST_SUITE(U8)
97DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), AccumulateU8Dataset),
98 shape, data_type, output_data_type)
99{
100 // Generate a random alpha value
101 std::mt19937 gen(library->seed());
102 std::uniform_real_distribution<> float_dist(0, 1);
103 const float alpha = float_dist(gen);
104
105 // Create tensors
106 CLTensor ref_src = create_tensor<CLTensor>(shape, data_type);
107 CLTensor dst = create_tensor<CLTensor>(shape, output_data_type);
108
109 // Create and Configure function
110 CLAccumulateWeighted accum_weight;
111 accum_weight.configure(&ref_src, alpha, &dst);
112
113 // Validate valid region
114 const ValidRegion valid_region = shape_to_valid_region(shape);
115 validate(dst.info()->valid_region(), valid_region);
116
117 // Validate padding
118 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
119 validate(ref_src.info()->padding(), padding);
120 validate(dst.info()->padding(), padding);
121}
122
123template <typename T1>
124using CLAccumulateWeightedFixture = AccumulateWeightedValidationFixture<CLTensor, CLAccessor, CLAccumulateWeighted, T1, uint8_t>;
125
126FIXTURE_DATA_TEST_CASE(RunSmall, CLAccumulateWeightedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), AccumulateU8Dataset))
127{
128 // Validate output
129 validate(CLAccessor(_target), _reference, tolerance);
130}
131FIXTURE_DATA_TEST_CASE(RunLarge, CLAccumulateWeightedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), AccumulateU8Dataset))
132{
133 // Validate output
134 validate(CLAccessor(_target), _reference, tolerance);
135}
136
137TEST_SUITE_END()
138TEST_SUITE_END()
139
140TEST_SUITE(AccumulateSquared)
141
142TEST_SUITE(U8)
143DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), AccumulateS16Dataset),
144 shape, data_type, output_data_type)
145{
146 // Generate a random shift value
147 std::mt19937 gen(library->seed());
148 std::uniform_int_distribution<uint32_t> int_dist(0, 15);
149 const uint32_t shift = int_dist(gen);
150
151 // Create tensors
152 CLTensor ref_src = create_tensor<CLTensor>(shape, data_type);
153 CLTensor dst = create_tensor<CLTensor>(shape, output_data_type);
154
155 // Create and Configure function
156 CLAccumulateSquared accum_square;
157 accum_square.configure(&ref_src, shift, &dst);
158
159 // Validate valid region
160 const ValidRegion valid_region = shape_to_valid_region(shape);
161 validate(dst.info()->valid_region(), valid_region);
162
163 // Validate padding
164 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
165 validate(ref_src.info()->padding(), padding);
166 validate(dst.info()->padding(), padding);
167}
168
169template <typename T1>
170using CLAccumulateSquaredFixture = AccumulateSquaredValidationFixture<CLTensor, CLAccessor, CLAccumulateSquared, T1, int16_t>;
171
172FIXTURE_DATA_TEST_CASE(RunSmall, CLAccumulateSquaredFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), AccumulateS16Dataset))
173{
174 // Validate output
175 validate(CLAccessor(_target), _reference, tolerance);
176}
177FIXTURE_DATA_TEST_CASE(RunLarge, CLAccumulateSquaredFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), AccumulateS16Dataset))
178{
179 // Validate output
180 validate(CLAccessor(_target), _reference, tolerance);
181}
182
183TEST_SUITE_END()
184TEST_SUITE_END()
185
186TEST_SUITE_END()
187} // namespace validation
188} // namespace test
189} // namespace arm_compute