blob: 845fdbf493bc39e76ab798e2a44a6fa7eec321d5 [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{
45TEST_SUITE(CL)
46TEST_SUITE(ArgMinMax)
47
48// *INDENT-OFF*
49// clang-format off
50DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
51 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid axis
52 TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid output shape
53 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32),
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010054 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32), // Invalid operation
55 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32) // Not allowed keeping the dimension
Michalis Spyrou7930db42018-11-22 17:36:28 +000056 }),
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010057 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32),
58 TensorInfo(TensorShape(27U, 3U, 2U), 1, DataType::F32),
59 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::U32),
60 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32),
61 TensorInfo(TensorShape(32U, 16U, 1U, 2U), 1, DataType::U32)
Michalis Spyrou7930db42018-11-22 17:36:28 +000062 })),
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010063 framework::dataset::make("Axis", { 4, 0, 2, 0, 2 })),
64 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::MEAN_SUM, ReductionOperation::ARG_IDX_MAX })),
65 framework::dataset::make("Expected", { false, false, true, false, false })),
Michalis Spyrou7930db42018-11-22 17:36:28 +000066 input_info, output_info, axis, operation, expected)
67{
68 const Status status = CLArgMinMaxLayer::validate(&input_info.clone()->set_is_resizable(false), axis, &output_info.clone()->set_is_resizable(false), operation);
69 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
70}
71// clang-format on
72// *INDENT-ON*
73
74DATA_TEST_CASE(Configuration,
75 framework::DatasetMode::ALL,
76 combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::F16, DataType::F32 })),
77 shape, data_type)
78{
79 // Create tensors
80 CLTensor ref_src = create_tensor<CLTensor>(shape, data_type);
81 CLTensor dst;
82
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010083 constexpr int axis = 1;
84
Michalis Spyrou7930db42018-11-22 17:36:28 +000085 // Create and Configure function
86 CLArgMinMaxLayer arg_min_max_layer;
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010087 arg_min_max_layer.configure(&ref_src, axis, &dst, ReductionOperation::ARG_IDX_MAX);
Michalis Spyrou7930db42018-11-22 17:36:28 +000088
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010089 const auto output_shape = arm_compute::misc::shape_calculator::compute_reduced_shape(shape, axis, false);
Michalis Spyrou7930db42018-11-22 17:36:28 +000090 const ValidRegion valid_region = shape_to_valid_region(output_shape);
91 validate(dst.info()->valid_region(), valid_region);
92}
93
94template <typename T>
95using CLArgMinMaxValidationFixture = ArgMinMaxValidationFixture<CLTensor, CLAccessor, CLArgMinMaxLayer, T>;
96
Michalis Spyroub9626ab2019-05-13 17:41:01 +010097TEST_SUITE(S32)
98FIXTURE_DATA_TEST_CASE(RunSmall,
99 CLArgMinMaxValidationFixture<int32_t>,
100 framework::DatasetMode::PRECOMMIT,
101 combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
102{
103 // Validate output
104 validate(CLAccessor(_target), _reference);
105}
106TEST_SUITE_END() // S32
107
Michalis Spyrou7930db42018-11-22 17:36:28 +0000108TEST_SUITE(Float)
109TEST_SUITE(FP16)
110FIXTURE_DATA_TEST_CASE(RunSmall,
111 CLArgMinMaxValidationFixture<half>,
112 framework::DatasetMode::PRECOMMIT,
113 combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
114{
115 // Validate output
116 validate(CLAccessor(_target), _reference);
117}
118
119FIXTURE_DATA_TEST_CASE(RunLarge,
120 CLArgMinMaxValidationFixture<half>,
121 framework::DatasetMode::NIGHTLY,
122 combine(combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
123{
124 // Validate output
125 validate(CLAccessor(_target), _reference);
126}
127TEST_SUITE_END() // FP16
128
129TEST_SUITE(FP32)
130FIXTURE_DATA_TEST_CASE(RunSmall,
131 CLArgMinMaxValidationFixture<float>,
132 framework::DatasetMode::PRECOMMIT,
133 combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
134{
135 // Validate output
136 validate(CLAccessor(_target), _reference);
137}
138
139FIXTURE_DATA_TEST_CASE(RunLarge,
140 CLArgMinMaxValidationFixture<float>,
141 framework::DatasetMode::NIGHTLY,
142 combine(combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("Axis", { 0, 1, 2, 3 })), framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })))
143{
144 // Validate output
145 validate(CLAccessor(_target), _reference);
146}
147TEST_SUITE_END() // FP32
148TEST_SUITE_END() // Float
149TEST_SUITE_END() // ArgMinMax
150TEST_SUITE_END() // CL
151} // namespace validation
152} // namespace test
153} // namespace arm_compute