blob: 773a91905ee8515882ce2a1abad39eabe5f405f6 [file] [log] [blame]
giuros01164a2722018-11-20 18:34:46 +00001/*
Michalis Spyrou80943252019-01-10 17:19:50 +00002 * Copyright (c) 2018-2019 ARM Limited.
giuros01164a2722018-11-20 18:34:46 +00003 *
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/CLElementwiseOperations.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/ElementwiseOperationsFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46RelativeTolerance<float> tolerance_fp32(0.000001f);
47RelativeTolerance<float> tolerance_fp16(0.001f);
48
49constexpr unsigned int num_elems_processed_per_iteration = 16;
50/** Input data sets **/
51const auto ElementwiseMaxU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)), framework::dataset::make("DataType",
52 DataType::U8));
53const auto ElementwiseMaxQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)),
54 framework::dataset::make("DataType",
55 DataType::QASYMM8));
56const auto ElementwiseMaxS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
57 framework::dataset::make("DataType", DataType::S16));
58const auto ElementwiseMaxFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
59 framework::dataset::make("DataType", DataType::F16));
60const auto ElementwiseMaxFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
61 framework::dataset::make("DataType", DataType::F32));
62} // namespace
63
64TEST_SUITE(CL)
65TEST_SUITE(ElementwiseMax)
66
67// *INDENT-OFF*
68// clang-format off
69DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
70 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
71 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
72 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
73 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
74 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
75 }),
76 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
77 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
78 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
79 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
80 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
81 })),
82 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
83 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
84 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
85 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
86 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
87 })),
88 framework::dataset::make("Expected", { true, true, false, false, false})),
89 input1_info, input2_info, output_info, expected)
90{
91 ARM_COMPUTE_EXPECT(bool(CLElementwiseMax::validate(&input1_info.clone()->set_is_resizable(false), &input2_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS);
92}
93// clang-format on
94// *INDENT-ON*
95
96template <typename T>
97using CLElementwiseMaxFixture = ElementwiseMaxValidationFixture<CLTensor, CLAccessor, CLElementwiseMax, T>;
98
99TEST_SUITE(U8)
Michalis Spyrou80943252019-01-10 17:19:50 +0000100DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
giuros01164a2722018-11-20 18:34:46 +0000101 shape)
102{
103 // Create tensors
104 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
105 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
106 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
107
108 // Create and Configure function
109 CLElementwiseMax add;
110 add.configure(&ref_src1, &ref_src2, &dst);
111
112 // Validate valid region
113 const ValidRegion valid_region = shape_to_valid_region(shape);
114 validate(dst.info()->valid_region(), valid_region);
115
116 // Validate padding
117 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
118 validate(ref_src1.info()->padding(), padding);
119 validate(ref_src2.info()->padding(), padding);
120 validate(dst.info()->padding(), padding);
121}
122
123FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMaxFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseMaxU8Dataset))
124{
125 // Validate output
126 validate(CLAccessor(_target), _reference);
127}
128TEST_SUITE_END()
129
130template <typename T>
131using CLElementwiseMaxQuantizedFixture = ElementwiseMaxValidationQuantizedFixture<CLTensor, CLAccessor, CLElementwiseMax, T>;
132
133TEST_SUITE(Quantized)
134TEST_SUITE(QASYMM8)
Michalis Spyrou80943252019-01-10 17:19:50 +0000135DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
giuros01164a2722018-11-20 18:34:46 +0000136 shape)
137{
138 // Create tensors
139 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
140 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
141 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8);
142
143 // Create and Configure function
144 CLElementwiseMax add;
145 add.configure(&ref_src1, &ref_src2, &dst);
146
147 // Validate valid region
148 const ValidRegion valid_region = shape_to_valid_region(shape);
149 validate(dst.info()->valid_region(), valid_region);
150
151 // Validate padding
152 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
153 validate(ref_src1.info()->padding(), padding);
154 validate(ref_src2.info()->padding(), padding);
155 validate(dst.info()->padding(), padding);
156}
157
158FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMaxQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
159 ElementwiseMaxQASYMM8Dataset),
160 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
161 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
162 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) }))
163
164 )
165{
166 // Validate output
167 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
168}
169TEST_SUITE_END()
170TEST_SUITE_END()
171
172TEST_SUITE(S16)
Michalis Spyrou80943252019-01-10 17:19:50 +0000173DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
giuros01164a2722018-11-20 18:34:46 +0000174 shape, data_type)
175{
176 // Create tensors
177 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
178 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
179 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
180
181 // Create and Configure function
182 CLElementwiseMax add;
183 add.configure(&ref_src1, &ref_src2, &dst);
184
185 // Validate valid region
186 const ValidRegion valid_region = shape_to_valid_region(shape);
187 validate(dst.info()->valid_region(), valid_region);
188
189 // Validate padding
190 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
191 validate(ref_src1.info()->padding(), padding);
192 validate(ref_src2.info()->padding(), padding);
193 validate(dst.info()->padding(), padding);
194}
195
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000196FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMaxFixture<int16_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMaxS16Dataset))
giuros01164a2722018-11-20 18:34:46 +0000197{
198 // Validate output
199 validate(CLAccessor(_target), _reference);
200}
201TEST_SUITE_END()
202
203TEST_SUITE(Float)
204TEST_SUITE(FP16)
205FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMaxFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMaxFP16Dataset))
206{
207 // Validate output
208 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
209}
210TEST_SUITE_END()
211
212TEST_SUITE(FP32)
Michalis Spyrou80943252019-01-10 17:19:50 +0000213DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
giuros01164a2722018-11-20 18:34:46 +0000214 shape)
215{
216 // Create tensors
217 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
218 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
219 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
220
221 // Create and Configure function
222 CLElementwiseMax add;
223 add.configure(&ref_src1, &ref_src2, &dst);
224
225 // Validate valid region
226 const ValidRegion valid_region = shape_to_valid_region(shape);
227 validate(dst.info()->valid_region(), valid_region);
228
229 // Validate padding
230 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
231 validate(ref_src1.info()->padding(), padding);
232 validate(ref_src2.info()->padding(), padding);
233 validate(dst.info()->padding(), padding);
234}
235
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000236FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMaxFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMaxFP32Dataset))
giuros01164a2722018-11-20 18:34:46 +0000237{
238 // Validate output
239 validate(CLAccessor(_target), _reference, tolerance_fp32);
240}
241
242template <typename T>
243using CLElementwiseMaxBroadcastFixture = ElementwiseMaxBroadcastValidationFixture<CLTensor, CLAccessor, CLElementwiseMax, T>;
244
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000245FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwiseMaxBroadcastFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapesBroadcast(),
246 ElementwiseMaxFP32Dataset))
giuros01164a2722018-11-20 18:34:46 +0000247{
248 // Validate output
249 validate(CLAccessor(_target), _reference, tolerance_fp32);
250}
251TEST_SUITE_END()
252TEST_SUITE_END()
253
254TEST_SUITE_END()
255TEST_SUITE_END()
256} // namespace validation
257} // namespace test
258} // namespace arm_compute