blob: 642a69ba5fe45ecb3e803803df933bf60065e9c0 [file] [log] [blame]
Michalis Spyrouaea14c62019-01-03 11:10:25 +00001/*
2 * Copyright (c) 2018-2019 ARM Limited.
3 *
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"
Michalis Spyroub9626ab2019-05-13 17:41:01 +010025#include "arm_compute/core/utils/misc/Traits.h"
Michalis Spyrouaea14c62019-01-03 11:10:25 +000026#include "arm_compute/runtime/NEON/functions/NEArgMinMaxLayer.h"
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010027#include "arm_compute/runtime/NEON/functions/NEReductionOperation.h"
Michalis Spyrouaea14c62019-01-03 11:10:25 +000028#include "arm_compute/runtime/Tensor.h"
29#include "arm_compute/runtime/TensorAllocator.h"
30
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010031#include "arm_compute/core/utils/misc/ShapeCalculator.h"
Michalis Spyrouaea14c62019-01-03 11:10:25 +000032#include "tests/NEON/Accessor.h"
33#include "tests/datasets/ShapeDatasets.h"
34#include "tests/datasets/SplitDataset.h"
35#include "tests/framework/Asserts.h"
36#include "tests/framework/Macros.h"
37#include "tests/validation/Validation.h"
38#include "tests/validation/fixtures/ArgMinMaxFixture.h"
39
40namespace arm_compute
41{
42namespace test
43{
44namespace validation
45{
46TEST_SUITE(NEON)
47TEST_SUITE(ArgMinMax)
48
49// *INDENT-OFF*
50// clang-format off
51DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
52 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid axis
53 TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid output shape
54 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32),
55 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32) // Invalid operation
56 }),
57 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(27U, 3U, 1U, 2U), 1, DataType::F32),
58 TensorInfo(TensorShape(27U, 3U, 1U, 2U), 1, DataType::F32),
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010059 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::U32),
Michalis Spyrouaea14c62019-01-03 11:10:25 +000060 TensorInfo(TensorShape(32U, 16U, 1U, 2U), 1, DataType::F32)
61 })),
62 framework::dataset::make("Axis", { 4, 0, 2, 0 })),
63 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::MEAN_SUM })),
64 framework::dataset::make("Expected", { false, false, true, false })),
65 input_info, output_info, axis, operation, expected)
66{
67 const Status status = NEArgMinMaxLayer::validate(&input_info.clone()->set_is_resizable(false), axis, &output_info.clone()->set_is_resizable(false), operation);
68 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
69}
70// clang-format on
71// *INDENT-ON*
72
73DATA_TEST_CASE(Configuration,
74 framework::DatasetMode::ALL,
Georgios Pinitas8f5802f2019-02-22 11:08:32 +000075 combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::F32 })),
Michalis Spyrouaea14c62019-01-03 11:10:25 +000076 shape, data_type)
77{
78 // Create tensors
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010079 Tensor ref_src = create_tensor<Tensor>(shape, data_type);
80 Tensor dst;
81 const int axis = 1;
Michalis Spyrouaea14c62019-01-03 11:10:25 +000082
83 // Create and Configure function
84 NEArgMinMaxLayer arg_min_max_layer;
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010085 arg_min_max_layer.configure(&ref_src, axis, &dst, ReductionOperation::ARG_IDX_MAX);
Michalis Spyrouaea14c62019-01-03 11:10:25 +000086
87 // Validate valid region
Sang-Hoon Park2697fd82019-10-15 16:49:24 +010088 const auto expected_output_shape = arm_compute::misc::shape_calculator::compute_reduced_shape(shape, axis, false);
89 const ValidRegion valid_region = shape_to_valid_region(expected_output_shape);
Michalis Spyrouaea14c62019-01-03 11:10:25 +000090 validate(dst.info()->valid_region(), valid_region);
91}
92
93template <typename T>
94using NEArgMinMaxValidationFixture = ArgMinMaxValidationFixture<Tensor, Accessor, NEArgMinMaxLayer, T>;
95
Michalis Spyroub9626ab2019-05-13 17:41:01 +010096TEST_SUITE(S32)
97FIXTURE_DATA_TEST_CASE(RunSmall,
98 NEArgMinMaxValidationFixture<int32_t>,
99 framework::DatasetMode::PRECOMMIT,
100 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 })))
101{
102 // Validate output
103 validate(Accessor(_target), _reference);
104}
105
106FIXTURE_DATA_TEST_CASE(RunLarge,
107 NEArgMinMaxValidationFixture<int32_t>,
108 framework::DatasetMode::NIGHTLY,
109 combine(combine(combine(datasets::Large4DShapes(), 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 })))
110{
111 // Validate output
112 validate(Accessor(_target), _reference);
113}
114TEST_SUITE_END() // S32
115
Michalis Spyrouaea14c62019-01-03 11:10:25 +0000116TEST_SUITE(Float)
117#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
118TEST_SUITE(FP16)
119FIXTURE_DATA_TEST_CASE(RunSmall,
120 NEArgMinMaxValidationFixture<half>,
121 framework::DatasetMode::PRECOMMIT,
122 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 })))
123{
124 // Validate output
125 validate(Accessor(_target), _reference);
126}
127
128FIXTURE_DATA_TEST_CASE(RunLarge,
129 NEArgMinMaxValidationFixture<half>,
130 framework::DatasetMode::NIGHTLY,
131 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 })))
132{
133 // Validate output
134 validate(Accessor(_target), _reference);
135}
136TEST_SUITE_END() // FP16
137#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
138
Michalis Spyrou254a48a2019-01-14 17:27:39 +0000139TEST_SUITE(FP32)
140FIXTURE_DATA_TEST_CASE(RunSmall,
141 NEArgMinMaxValidationFixture<float>,
142 framework::DatasetMode::PRECOMMIT,
143 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 })))
144{
145 // Validate output
146 validate(Accessor(_target), _reference);
147}
148
149FIXTURE_DATA_TEST_CASE(RunLarge,
150 NEArgMinMaxValidationFixture<float>,
151 framework::DatasetMode::NIGHTLY,
152 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 })))
153{
154 // Validate output
155 validate(Accessor(_target), _reference);
156}
157TEST_SUITE_END() // FP32
158TEST_SUITE_END() // Float
159
Michalis Spyrouaea14c62019-01-03 11:10:25 +0000160template <typename T>
161using NEArgMinMaxQuantizedValidationFixture = ArgMinMaxValidationQuantizedFixture<Tensor, Accessor, NEArgMinMaxLayer, T>;
162
163TEST_SUITE(QASYMM8)
164FIXTURE_DATA_TEST_CASE(RunSmall,
165 NEArgMinMaxQuantizedValidationFixture<uint8_t>,
166 framework::DatasetMode::PRECOMMIT,
167 combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
168 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
169 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
170{
171 // Validate output
172 validate(Accessor(_target), _reference);
173}
174
175FIXTURE_DATA_TEST_CASE(RunLarge,
176 NEArgMinMaxQuantizedValidationFixture<uint8_t>,
177 framework::DatasetMode::NIGHTLY,
178 combine(combine(combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
179 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
180 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
181{
182 // Validate output
183 validate(Accessor(_target), _reference);
184}
185TEST_SUITE_END() // QASYMM8
Michalis Spyrouaea14c62019-01-03 11:10:25 +0000186TEST_SUITE_END() // ArgMinMax
187TEST_SUITE_END() // NEON
188} // namespace validation
189} // namespace test
190} // namespace arm_compute