blob: 275641cb35ba80b0a148acd131abafb02343041d [file] [log] [blame]
Michalis Spyrou7930db42018-11-22 17:36:28 +00001/*
Michalis Spyroub9626ab2019-05-13 17:41:01 +01002 * Copyright (c) 2018-2019 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
86DATA_TEST_CASE(Configuration,
87 framework::DatasetMode::ALL,
88 combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::F16, DataType::F32 })),
89 shape, data_type)
90{
91 // Create tensors
92 CLTensor ref_src = create_tensor<CLTensor>(shape, data_type);
93 CLTensor dst;
94
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010095 constexpr int axis = 1;
96
Michalis Spyrou7930db42018-11-22 17:36:28 +000097 // Create and Configure function
98 CLArgMinMaxLayer arg_min_max_layer;
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010099 arg_min_max_layer.configure(&ref_src, axis, &dst, ReductionOperation::ARG_IDX_MAX);
Michalis Spyrou7930db42018-11-22 17:36:28 +0000100
Sang-Hoon Park2697fd82019-10-15 16:49:24 +0100101 const auto output_shape = arm_compute::misc::shape_calculator::compute_reduced_shape(shape, axis, false);
Michalis Spyrou7930db42018-11-22 17:36:28 +0000102 const ValidRegion valid_region = shape_to_valid_region(output_shape);
103 validate(dst.info()->valid_region(), valid_region);
104}
105
106template <typename T>
107using CLArgMinMaxValidationFixture = ArgMinMaxValidationFixture<CLTensor, CLAccessor, CLArgMinMaxLayer, T>;
108
Michalis Spyroub9626ab2019-05-13 17:41:01 +0100109TEST_SUITE(S32)
110FIXTURE_DATA_TEST_CASE(RunSmall,
111 CLArgMinMaxValidationFixture<int32_t>,
112 framework::DatasetMode::PRECOMMIT,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100113 combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
114 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
115{
116 // Validate output
117 validate(CLAccessor(_target), _reference);
118}
119FIXTURE_DATA_TEST_CASE(RunLarge,
120 CLArgMinMaxValidationFixture<int32_t>,
121 framework::DatasetMode::NIGHTLY,
122 combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
123 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyroub9626ab2019-05-13 17:41:01 +0100124{
125 // Validate output
126 validate(CLAccessor(_target), _reference);
127}
128TEST_SUITE_END() // S32
129
Michalis Spyrou7930db42018-11-22 17:36:28 +0000130TEST_SUITE(Float)
131TEST_SUITE(FP16)
132FIXTURE_DATA_TEST_CASE(RunSmall,
133 CLArgMinMaxValidationFixture<half>,
134 framework::DatasetMode::PRECOMMIT,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100135 combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
136 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyrou7930db42018-11-22 17:36:28 +0000137{
138 // Validate output
139 validate(CLAccessor(_target), _reference);
140}
141
142FIXTURE_DATA_TEST_CASE(RunLarge,
143 CLArgMinMaxValidationFixture<half>,
144 framework::DatasetMode::NIGHTLY,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100145 combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
146 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyrou7930db42018-11-22 17:36:28 +0000147{
148 // Validate output
149 validate(CLAccessor(_target), _reference);
150}
151TEST_SUITE_END() // FP16
152
153TEST_SUITE(FP32)
154FIXTURE_DATA_TEST_CASE(RunSmall,
155 CLArgMinMaxValidationFixture<float>,
156 framework::DatasetMode::PRECOMMIT,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100157 combine(combine(combine(ArgMinMaxSmallDataset, framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
158 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyrou7930db42018-11-22 17:36:28 +0000159{
160 // Validate output
161 validate(CLAccessor(_target), _reference);
162}
163
164FIXTURE_DATA_TEST_CASE(RunLarge,
165 CLArgMinMaxValidationFixture<float>,
166 framework::DatasetMode::NIGHTLY,
Manuel Bottini7b9998d2019-10-21 17:59:07 +0100167 combine(combine(combine(ArgMinMaxLargeDataset, framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
168 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
Michalis Spyrou7930db42018-11-22 17:36:28 +0000169{
170 // Validate output
171 validate(CLAccessor(_target), _reference);
172}
173TEST_SUITE_END() // FP32
174TEST_SUITE_END() // Float
175TEST_SUITE_END() // ArgMinMax
176TEST_SUITE_END() // CL
177} // namespace validation
178} // namespace test
179} // namespace arm_compute