blob: 4bee942d708505e29664eb20c0a299341a207cef [file] [log] [blame]
Michalis Spyrou7930db42018-11-22 17:36:28 +00001/*
Michalis Spyrou7317e392020-01-17 11:27:49 +00002 * 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"
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"
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010028#include "arm_compute/runtime/CL/functions/CLReductionOperation.h"
Michalis Spyrou7930db42018-11-22 17:36:28 +000029
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010030#include "arm_compute/core/utils/misc/ShapeCalculator.h"
Michalis Spyrou7930db42018-11-22 17:36:28 +000031#include "tests/CL/CLAccessor.h"
32#include "tests/datasets/ShapeDatasets.h"
33#include "tests/datasets/SplitDataset.h"
34#include "tests/framework/Asserts.h"
35#include "tests/framework/Macros.h"
36#include "tests/validation/Validation.h"
37#include "tests/validation/fixtures/ArgMinMaxFixture.h"
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
Manuel Bottini7b9998d2019-10-21 17:59:07 +010045namespace
46{
47const auto ArgMinMaxSmallDataset = framework::dataset::make("Shape",
48{
49 TensorShape{ 2U, 7U, 1U, 3U },
50 TensorShape{ 128U, 64U, 21U, 3U },
51 TensorShape{ 2560, 2U, 2U, 2U },
52});
53
54const auto ArgMinMaxLargeDataset = framework::dataset::make("Shape",
55{ TensorShape{ 517U, 123U, 13U, 2U } });
56} // namespace
Michalis Spyrou7930db42018-11-22 17:36:28 +000057TEST_SUITE(CL)
58TEST_SUITE(ArgMinMax)
59
60// *INDENT-OFF*
61// clang-format off
62DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
63 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid axis
64 TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid output shape
65 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32),
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010066 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32), // Invalid operation
67 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32) // Not allowed keeping the dimension
Michalis Spyrou7930db42018-11-22 17:36:28 +000068 }),
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010069 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32),
70 TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32),
Sang-Hoon Parkeaa01ab2019-11-11 17:33:28 +000071 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::S32),
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010072 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32),
73 TensorInfo(TensorShape(32U, 16U, 1U, 2U), 1, DataType::U32)
Michalis Spyrou7930db42018-11-22 17:36:28 +000074 })),
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010075 framework::dataset::make("Axis", { 4, 0, 2, 0, 2 })),
76 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::MEAN_SUM, ReductionOperation::ARG_IDX_MAX })),
77 framework::dataset::make("Expected", { false, false, true, false, false })),
Michalis Spyrou7930db42018-11-22 17:36:28 +000078 input_info, output_info, axis, operation, expected)
79{
80 const Status status = CLArgMinMaxLayer::validate(&input_info.clone()->set_is_resizable(false), axis, &output_info.clone()->set_is_resizable(false), operation);
81 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
82}
83// clang-format on
84// *INDENT-ON*
85
Michalis Spyrou7930db42018-11-22 17:36:28 +000086template <typename T>
87using CLArgMinMaxValidationFixture = ArgMinMaxValidationFixture<CLTensor, CLAccessor, CLArgMinMaxLayer, T>;
88
Michalis Spyroub9626ab2019-05-13 17:41:01 +010089TEST_SUITE(S32)
90FIXTURE_DATA_TEST_CASE(RunSmall,
91 CLArgMinMaxValidationFixture<int32_t>,
92 framework::DatasetMode::PRECOMMIT,
Manuel Bottini7b9998d2019-10-21 17:59:07 +010093 combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
94 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
95{
96 // Validate output
97 validate(CLAccessor(_target), _reference);
98}
99FIXTURE_DATA_TEST_CASE(RunLarge,
100 CLArgMinMaxValidationFixture<int32_t>,
101 framework::DatasetMode::NIGHTLY,
102 combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
103 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyroub9626ab2019-05-13 17:41:01 +0100104{
105 // Validate output
106 validate(CLAccessor(_target), _reference);
107}
108TEST_SUITE_END() // S32
109
Michalis Spyrou7930db42018-11-22 17:36:28 +0000110TEST_SUITE(Float)
111TEST_SUITE(FP16)
112FIXTURE_DATA_TEST_CASE(RunSmall,
113 CLArgMinMaxValidationFixture<half>,
114 framework::DatasetMode::PRECOMMIT,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100115 combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
116 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyrou7930db42018-11-22 17:36:28 +0000117{
118 // Validate output
119 validate(CLAccessor(_target), _reference);
120}
121
122FIXTURE_DATA_TEST_CASE(RunLarge,
123 CLArgMinMaxValidationFixture<half>,
124 framework::DatasetMode::NIGHTLY,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100125 combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
126 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyrou7930db42018-11-22 17:36:28 +0000127{
128 // Validate output
129 validate(CLAccessor(_target), _reference);
130}
131TEST_SUITE_END() // FP16
132
133TEST_SUITE(FP32)
134FIXTURE_DATA_TEST_CASE(RunSmall,
135 CLArgMinMaxValidationFixture<float>,
136 framework::DatasetMode::PRECOMMIT,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100137 combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::F32)), 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<float>,
146 framework::DatasetMode::NIGHTLY,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100147 combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::F32)), 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() // FP32
154TEST_SUITE_END() // Float
Michalis Spyrou7317e392020-01-17 11:27:49 +0000155
156template <typename T>
157using CLArgMinMaxQuantizedValidationFixture = ArgMinMaxValidationQuantizedFixture<CLTensor, CLAccessor, CLArgMinMaxLayer, T>;
158
159TEST_SUITE(Quantized)
160TEST_SUITE(QASYMM8)
161FIXTURE_DATA_TEST_CASE(RunSmall,
162 CLArgMinMaxQuantizedValidationFixture<uint8_t>,
163 framework::DatasetMode::PRECOMMIT,
164 combine(combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
165 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
166 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
167{
168 // Validate output
169 validate(CLAccessor(_target), _reference);
170}
171
172FIXTURE_DATA_TEST_CASE(RunLarge,
173 CLArgMinMaxQuantizedValidationFixture<uint8_t>,
174 framework::DatasetMode::NIGHTLY,
175 combine(combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
176 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
177 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
178{
179 // Validate output
180 validate(CLAccessor(_target), _reference);
181}
182TEST_SUITE_END() // QASYMM8
183TEST_SUITE_END() // Quantized
Michalis Spyrou7930db42018-11-22 17:36:28 +0000184TEST_SUITE_END() // ArgMinMax
185TEST_SUITE_END() // CL
186} // namespace validation
187} // namespace test
188} // namespace arm_compute