blob: 9bfd9d92c134f588e4f7a99d894c38138648b854 [file] [log] [blame]
Michalis Spyrou7930db42018-11-22 17:36:28 +00001/*
Pablo Marquez Tello653b96c2023-07-11 15:15:46 +01002 * Copyright (c) 2018-2021, 2023 Arm Limited.
Michalis Spyrou7930db42018-11-22 17:36:28 +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/CLArgMinMaxLayer.h"
Michalis Spyrou7930db42018-11-22 17:36:28 +000028#include "tests/CL/CLAccessor.h"
29#include "tests/datasets/ShapeDatasets.h"
Michalis Spyrou7930db42018-11-22 17:36:28 +000030#include "tests/framework/Macros.h"
31#include "tests/validation/Validation.h"
32#include "tests/validation/fixtures/ArgMinMaxFixture.h"
33
34namespace arm_compute
35{
36namespace test
37{
38namespace validation
39{
Manuel Bottini7b9998d2019-10-21 17:59:07 +010040namespace
41{
42const auto ArgMinMaxSmallDataset = framework::dataset::make("Shape",
43{
Giorgio Arena76cb7512021-02-03 12:29:57 +000044 TensorShape{ 1U, 7U, 1U, 3U },
Pablo Marquez Tello653b96c2023-07-11 15:15:46 +010045 TensorShape{ 3U, 1U, 3U, 2U },
46 TensorShape{ 2U, 1U, 3U, 2U },
Manuel Bottini5c829ca2020-01-28 17:25:48 +000047 TensorShape{ 149U, 5U, 1U, 2U },
48 TensorShape{ 166U, 5U, 1U, 2U },
49 TensorShape{ 322U, 5U, 1U, 2U },
50 TensorShape{ 128U, 5U, 21U, 3U },
Manuel Bottini7b9998d2019-10-21 17:59:07 +010051 TensorShape{ 2560, 2U, 2U, 2U },
52});
53
Pablo Marquez Tello653b96c2023-07-11 15:15:46 +010054const auto ArgMinMaxSmallDatasetAxis0 = framework::dataset::make("Shape",
55{
56 TensorShape{ 1U, 5U },
57 TensorShape{ 2U, 3U },
58 TensorShape{ 1U },
59 TensorShape{ 3U },
60 TensorShape{ 2U },
61 TensorShape{ 5U },
62 TensorShape{ 17U },
63 TensorShape{ 15U, 2U },
64});
65
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010066const auto ArgMinMaxLargeDataset = framework::dataset::make("Shape",
67{ TensorShape{ 517U, 123U, 13U, 2U } });
Manuel Bottini7b9998d2019-10-21 17:59:07 +010068} // namespace
Michalis Spyrou7930db42018-11-22 17:36:28 +000069TEST_SUITE(CL)
70TEST_SUITE(ArgMinMax)
71
72// *INDENT-OFF*
73// clang-format off
74DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
75 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid axis
76 TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid output shape
77 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32),
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010078 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32), // Invalid operation
79 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32) // Not allowed keeping the dimension
Michalis Spyrou7930db42018-11-22 17:36:28 +000080 }),
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010081 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32),
82 TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32),
Sang-Hoon Parkeaa01ab2019-11-11 17:33:28 +000083 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::S32),
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010084 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32),
85 TensorInfo(TensorShape(32U, 16U, 1U, 2U), 1, DataType::U32)
Michalis Spyrou7930db42018-11-22 17:36:28 +000086 })),
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010087 framework::dataset::make("Axis", { 4, 0, 2, 0, 2 })),
88 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::MEAN_SUM, ReductionOperation::ARG_IDX_MAX })),
89 framework::dataset::make("Expected", { false, false, true, false, false })),
Michalis Spyrou7930db42018-11-22 17:36:28 +000090 input_info, output_info, axis, operation, expected)
91{
92 const Status status = CLArgMinMaxLayer::validate(&input_info.clone()->set_is_resizable(false), axis, &output_info.clone()->set_is_resizable(false), operation);
93 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
94}
95// clang-format on
96// *INDENT-ON*
97
Michalis Spyrou7930db42018-11-22 17:36:28 +000098template <typename T>
99using CLArgMinMaxValidationFixture = ArgMinMaxValidationFixture<CLTensor, CLAccessor, CLArgMinMaxLayer, T>;
100
Michalis Spyroub9626ab2019-05-13 17:41:01 +0100101TEST_SUITE(S32)
Pablo Marquez Tello653b96c2023-07-11 15:15:46 +0100102FIXTURE_DATA_TEST_CASE(RunSmallAxis0,
103 CLArgMinMaxValidationFixture<int32_t>,
104 framework::DatasetMode::PRECOMMIT,
105 combine(combine(combine(ArgMinMaxSmallDatasetAxis0, framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0 })),
106 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
107{
108 // Validate output
109 validate(CLAccessor(_target), _reference);
110}
111
Michalis Spyroub9626ab2019-05-13 17:41:01 +0100112FIXTURE_DATA_TEST_CASE(RunSmall,
113 CLArgMinMaxValidationFixture<int32_t>,
114 framework::DatasetMode::PRECOMMIT,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100115 combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
116 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
117{
118 // Validate output
119 validate(CLAccessor(_target), _reference);
120}
121FIXTURE_DATA_TEST_CASE(RunLarge,
122 CLArgMinMaxValidationFixture<int32_t>,
123 framework::DatasetMode::NIGHTLY,
124 combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
125 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyroub9626ab2019-05-13 17:41:01 +0100126{
127 // Validate output
128 validate(CLAccessor(_target), _reference);
129}
130TEST_SUITE_END() // S32
131
Michalis Spyrou7930db42018-11-22 17:36:28 +0000132TEST_SUITE(Float)
133TEST_SUITE(FP16)
134FIXTURE_DATA_TEST_CASE(RunSmall,
135 CLArgMinMaxValidationFixture<half>,
136 framework::DatasetMode::PRECOMMIT,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100137 combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
138 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyrou7930db42018-11-22 17:36:28 +0000139{
140 // Validate output
141 validate(CLAccessor(_target), _reference);
142}
143
144FIXTURE_DATA_TEST_CASE(RunLarge,
145 CLArgMinMaxValidationFixture<half>,
146 framework::DatasetMode::NIGHTLY,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100147 combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
148 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyrou7930db42018-11-22 17:36:28 +0000149{
150 // Validate output
151 validate(CLAccessor(_target), _reference);
152}
153TEST_SUITE_END() // FP16
154
155TEST_SUITE(FP32)
156FIXTURE_DATA_TEST_CASE(RunSmall,
157 CLArgMinMaxValidationFixture<float>,
158 framework::DatasetMode::PRECOMMIT,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100159 combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
160 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyrou7930db42018-11-22 17:36:28 +0000161{
162 // Validate output
163 validate(CLAccessor(_target), _reference);
164}
165
166FIXTURE_DATA_TEST_CASE(RunLarge,
167 CLArgMinMaxValidationFixture<float>,
168 framework::DatasetMode::NIGHTLY,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100169 combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
170 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyrou7930db42018-11-22 17:36:28 +0000171{
172 // Validate output
173 validate(CLAccessor(_target), _reference);
174}
175TEST_SUITE_END() // FP32
176TEST_SUITE_END() // Float
Michalis Spyrou7317e392020-01-17 11:27:49 +0000177
178template <typename T>
179using CLArgMinMaxQuantizedValidationFixture = ArgMinMaxValidationQuantizedFixture<CLTensor, CLAccessor, CLArgMinMaxLayer, T>;
180
181TEST_SUITE(Quantized)
182TEST_SUITE(QASYMM8)
183FIXTURE_DATA_TEST_CASE(RunSmall,
184 CLArgMinMaxQuantizedValidationFixture<uint8_t>,
185 framework::DatasetMode::PRECOMMIT,
186 combine(combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
187 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
188 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
189{
190 // Validate output
191 validate(CLAccessor(_target), _reference);
192}
193
194FIXTURE_DATA_TEST_CASE(RunLarge,
195 CLArgMinMaxQuantizedValidationFixture<uint8_t>,
196 framework::DatasetMode::NIGHTLY,
197 combine(combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
198 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
199 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
200{
201 // Validate output
202 validate(CLAccessor(_target), _reference);
203}
204TEST_SUITE_END() // QASYMM8
Sheri Zhangc5b6d882020-06-26 14:46:59 +0100205
206TEST_SUITE(QASYMM8_SIGNED)
207FIXTURE_DATA_TEST_CASE(RunSmall,
208 CLArgMinMaxQuantizedValidationFixture<int8_t>,
209 framework::DatasetMode::PRECOMMIT,
210 combine(combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
211 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
212 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
213{
214 // Validate output
215 validate(CLAccessor(_target), _reference);
216}
217
218FIXTURE_DATA_TEST_CASE(RunLarge,
219 CLArgMinMaxQuantizedValidationFixture<int8_t>,
220 framework::DatasetMode::NIGHTLY,
221 combine(combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
222 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
223 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
224{
225 // Validate output
226 validate(CLAccessor(_target), _reference);
227}
228TEST_SUITE_END() // QASYMM8_SIGNED
229
Michalis Spyrou7317e392020-01-17 11:27:49 +0000230TEST_SUITE_END() // Quantized
Michalis Spyrou7930db42018-11-22 17:36:28 +0000231TEST_SUITE_END() // ArgMinMax
232TEST_SUITE_END() // CL
233} // namespace validation
234} // namespace test
235} // namespace arm_compute