blob: 2508c63524f19d1af2daf1a523e48362d7c9403c [file] [log] [blame]
Michalis Spyrou7930db42018-11-22 17:36:28 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 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"
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010025#include "arm_compute/core/utils/misc/ShapeCalculator.h"
Michalis Spyrou7930db42018-11-22 17:36:28 +000026#include "arm_compute/runtime/CL/CLTensor.h"
27#include "arm_compute/runtime/CL/CLTensorAllocator.h"
28#include "arm_compute/runtime/CL/functions/CLArgMinMaxLayer.h"
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010029#include "arm_compute/runtime/CL/functions/CLReductionOperation.h"
Michalis Spyrou7930db42018-11-22 17:36:28 +000030#include "tests/CL/CLAccessor.h"
31#include "tests/datasets/ShapeDatasets.h"
32#include "tests/datasets/SplitDataset.h"
33#include "tests/framework/Asserts.h"
34#include "tests/framework/Macros.h"
35#include "tests/validation/Validation.h"
36#include "tests/validation/fixtures/ArgMinMaxFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
Manuel Bottini7b9998d2019-10-21 17:59:07 +010044namespace
45{
46const auto ArgMinMaxSmallDataset = framework::dataset::make("Shape",
47{
48 TensorShape{ 2U, 7U, 1U, 3U },
Manuel Bottini5c829ca2020-01-28 17:25:48 +000049 TensorShape{ 149U, 5U, 1U, 2U },
50 TensorShape{ 166U, 5U, 1U, 2U },
51 TensorShape{ 322U, 5U, 1U, 2U },
52 TensorShape{ 128U, 5U, 21U, 3U },
Manuel Bottini7b9998d2019-10-21 17:59:07 +010053 TensorShape{ 2560, 2U, 2U, 2U },
54});
55
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010056const auto ArgMinMaxLargeDataset = framework::dataset::make("Shape",
57{ TensorShape{ 517U, 123U, 13U, 2U } });
Manuel Bottini7b9998d2019-10-21 17:59:07 +010058} // namespace
Michalis Spyrou7930db42018-11-22 17:36:28 +000059TEST_SUITE(CL)
60TEST_SUITE(ArgMinMax)
61
62// *INDENT-OFF*
63// clang-format off
64DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
65 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid axis
66 TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid output shape
67 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32),
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010068 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32), // Invalid operation
69 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32) // Not allowed keeping the dimension
Michalis Spyrou7930db42018-11-22 17:36:28 +000070 }),
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010071 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32),
72 TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32),
Sang-Hoon Parkeaa01ab2019-11-11 17:33:28 +000073 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::S32),
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010074 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32),
75 TensorInfo(TensorShape(32U, 16U, 1U, 2U), 1, DataType::U32)
Michalis Spyrou7930db42018-11-22 17:36:28 +000076 })),
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010077 framework::dataset::make("Axis", { 4, 0, 2, 0, 2 })),
78 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::MEAN_SUM, ReductionOperation::ARG_IDX_MAX })),
79 framework::dataset::make("Expected", { false, false, true, false, false })),
Michalis Spyrou7930db42018-11-22 17:36:28 +000080 input_info, output_info, axis, operation, expected)
81{
82 const Status status = CLArgMinMaxLayer::validate(&input_info.clone()->set_is_resizable(false), axis, &output_info.clone()->set_is_resizable(false), operation);
83 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
84}
85// clang-format on
86// *INDENT-ON*
87
Michalis Spyrou7930db42018-11-22 17:36:28 +000088template <typename T>
89using CLArgMinMaxValidationFixture = ArgMinMaxValidationFixture<CLTensor, CLAccessor, CLArgMinMaxLayer, T>;
90
Michalis Spyroub9626ab2019-05-13 17:41:01 +010091TEST_SUITE(S32)
92FIXTURE_DATA_TEST_CASE(RunSmall,
93 CLArgMinMaxValidationFixture<int32_t>,
94 framework::DatasetMode::PRECOMMIT,
Manuel Bottini7b9998d2019-10-21 17:59:07 +010095 combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
96 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
97{
98 // Validate output
99 validate(CLAccessor(_target), _reference);
100}
101FIXTURE_DATA_TEST_CASE(RunLarge,
102 CLArgMinMaxValidationFixture<int32_t>,
103 framework::DatasetMode::NIGHTLY,
104 combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
105 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyroub9626ab2019-05-13 17:41:01 +0100106{
107 // Validate output
108 validate(CLAccessor(_target), _reference);
109}
110TEST_SUITE_END() // S32
111
Michalis Spyrou7930db42018-11-22 17:36:28 +0000112TEST_SUITE(Float)
113TEST_SUITE(FP16)
114FIXTURE_DATA_TEST_CASE(RunSmall,
115 CLArgMinMaxValidationFixture<half>,
116 framework::DatasetMode::PRECOMMIT,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100117 combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
118 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyrou7930db42018-11-22 17:36:28 +0000119{
120 // Validate output
121 validate(CLAccessor(_target), _reference);
122}
123
124FIXTURE_DATA_TEST_CASE(RunLarge,
125 CLArgMinMaxValidationFixture<half>,
126 framework::DatasetMode::NIGHTLY,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100127 combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
128 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyrou7930db42018-11-22 17:36:28 +0000129{
130 // Validate output
131 validate(CLAccessor(_target), _reference);
132}
133TEST_SUITE_END() // FP16
134
135TEST_SUITE(FP32)
136FIXTURE_DATA_TEST_CASE(RunSmall,
137 CLArgMinMaxValidationFixture<float>,
138 framework::DatasetMode::PRECOMMIT,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100139 combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
140 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyrou7930db42018-11-22 17:36:28 +0000141{
142 // Validate output
143 validate(CLAccessor(_target), _reference);
144}
145
146FIXTURE_DATA_TEST_CASE(RunLarge,
147 CLArgMinMaxValidationFixture<float>,
148 framework::DatasetMode::NIGHTLY,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100149 combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
150 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyrou7930db42018-11-22 17:36:28 +0000151{
152 // Validate output
153 validate(CLAccessor(_target), _reference);
154}
155TEST_SUITE_END() // FP32
156TEST_SUITE_END() // Float
Michalis Spyrou7317e392020-01-17 11:27:49 +0000157
158template <typename T>
159using CLArgMinMaxQuantizedValidationFixture = ArgMinMaxValidationQuantizedFixture<CLTensor, CLAccessor, CLArgMinMaxLayer, T>;
160
161TEST_SUITE(Quantized)
162TEST_SUITE(QASYMM8)
163FIXTURE_DATA_TEST_CASE(RunSmall,
164 CLArgMinMaxQuantizedValidationFixture<uint8_t>,
165 framework::DatasetMode::PRECOMMIT,
166 combine(combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
167 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
168 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
169{
170 // Validate output
171 validate(CLAccessor(_target), _reference);
172}
173
174FIXTURE_DATA_TEST_CASE(RunLarge,
175 CLArgMinMaxQuantizedValidationFixture<uint8_t>,
176 framework::DatasetMode::NIGHTLY,
177 combine(combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
178 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
179 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
180{
181 // Validate output
182 validate(CLAccessor(_target), _reference);
183}
184TEST_SUITE_END() // QASYMM8
Sheri Zhangc5b6d882020-06-26 14:46:59 +0100185
186TEST_SUITE(QASYMM8_SIGNED)
187FIXTURE_DATA_TEST_CASE(RunSmall,
188 CLArgMinMaxQuantizedValidationFixture<int8_t>,
189 framework::DatasetMode::PRECOMMIT,
190 combine(combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
191 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
192 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
193{
194 // Validate output
195 validate(CLAccessor(_target), _reference);
196}
197
198FIXTURE_DATA_TEST_CASE(RunLarge,
199 CLArgMinMaxQuantizedValidationFixture<int8_t>,
200 framework::DatasetMode::NIGHTLY,
201 combine(combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
202 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
203 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
204{
205 // Validate output
206 validate(CLAccessor(_target), _reference);
207}
208TEST_SUITE_END() // QASYMM8_SIGNED
209
Michalis Spyrou7317e392020-01-17 11:27:49 +0000210TEST_SUITE_END() // Quantized
Michalis Spyrou7930db42018-11-22 17:36:28 +0000211TEST_SUITE_END() // ArgMinMax
212TEST_SUITE_END() // CL
213} // namespace validation
214} // namespace test
215} // namespace arm_compute