blob: 71fb39a30db2d1ca9ff03a62da33f3ddfdab00aa [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"
27#include "arm_compute/runtime/Tensor.h"
28#include "arm_compute/runtime/TensorAllocator.h"
29
30#include "tests/NEON/Accessor.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{
44TEST_SUITE(NEON)
45TEST_SUITE(ArgMinMax)
46
47// *INDENT-OFF*
48// clang-format off
49DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
50 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid axis
51 TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid output shape
52 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32),
53 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32) // Invalid operation
54 }),
55 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(27U, 3U, 1U, 2U), 1, DataType::F32),
56 TensorInfo(TensorShape(27U, 3U, 1U, 2U), 1, DataType::F32),
57 TensorInfo(TensorShape(32U, 16U, 1U, 2U), 1, DataType::U32),
58 TensorInfo(TensorShape(32U, 16U, 1U, 2U), 1, DataType::F32)
59 })),
60 framework::dataset::make("Axis", { 4, 0, 2, 0 })),
61 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::MEAN_SUM })),
62 framework::dataset::make("Expected", { false, false, true, false })),
63 input_info, output_info, axis, operation, expected)
64{
65 const Status status = NEArgMinMaxLayer::validate(&input_info.clone()->set_is_resizable(false), axis, &output_info.clone()->set_is_resizable(false), operation);
66 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
67}
68// clang-format on
69// *INDENT-ON*
70
71DATA_TEST_CASE(Configuration,
72 framework::DatasetMode::ALL,
Georgios Pinitas8f5802f2019-02-22 11:08:32 +000073 combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::F32 })),
Michalis Spyrouaea14c62019-01-03 11:10:25 +000074 shape, data_type)
75{
76 // Create tensors
77 Tensor ref_src = create_tensor<Tensor>(shape, data_type);
78 Tensor dst;
79
80 // Create and Configure function
81 NEArgMinMaxLayer arg_min_max_layer;
82 arg_min_max_layer.configure(&ref_src, 1, &dst, ReductionOperation::ARG_IDX_MAX);
83
84 // Validate valid region
85 TensorShape output_shape = shape;
86 output_shape.set(1, 1);
87 const ValidRegion valid_region = shape_to_valid_region(output_shape);
88 validate(dst.info()->valid_region(), valid_region);
89}
90
91template <typename T>
92using NEArgMinMaxValidationFixture = ArgMinMaxValidationFixture<Tensor, Accessor, NEArgMinMaxLayer, T>;
93
Michalis Spyroub9626ab2019-05-13 17:41:01 +010094TEST_SUITE(S32)
95FIXTURE_DATA_TEST_CASE(RunSmall,
96 NEArgMinMaxValidationFixture<int32_t>,
97 framework::DatasetMode::PRECOMMIT,
98 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 })))
99{
100 // Validate output
101 validate(Accessor(_target), _reference);
102}
103
104FIXTURE_DATA_TEST_CASE(RunLarge,
105 NEArgMinMaxValidationFixture<int32_t>,
106 framework::DatasetMode::NIGHTLY,
107 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 })))
108{
109 // Validate output
110 validate(Accessor(_target), _reference);
111}
112TEST_SUITE_END() // S32
113
Michalis Spyrouaea14c62019-01-03 11:10:25 +0000114TEST_SUITE(Float)
115#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
116TEST_SUITE(FP16)
117FIXTURE_DATA_TEST_CASE(RunSmall,
118 NEArgMinMaxValidationFixture<half>,
119 framework::DatasetMode::PRECOMMIT,
120 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 })))
121{
122 // Validate output
123 validate(Accessor(_target), _reference);
124}
125
126FIXTURE_DATA_TEST_CASE(RunLarge,
127 NEArgMinMaxValidationFixture<half>,
128 framework::DatasetMode::NIGHTLY,
129 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 })))
130{
131 // Validate output
132 validate(Accessor(_target), _reference);
133}
134TEST_SUITE_END() // FP16
135#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
136
Michalis Spyrou254a48a2019-01-14 17:27:39 +0000137TEST_SUITE(FP32)
138FIXTURE_DATA_TEST_CASE(RunSmall,
139 NEArgMinMaxValidationFixture<float>,
140 framework::DatasetMode::PRECOMMIT,
141 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 })))
142{
143 // Validate output
144 validate(Accessor(_target), _reference);
145}
146
147FIXTURE_DATA_TEST_CASE(RunLarge,
148 NEArgMinMaxValidationFixture<float>,
149 framework::DatasetMode::NIGHTLY,
150 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 })))
151{
152 // Validate output
153 validate(Accessor(_target), _reference);
154}
155TEST_SUITE_END() // FP32
156TEST_SUITE_END() // Float
157
Michalis Spyrouaea14c62019-01-03 11:10:25 +0000158template <typename T>
159using NEArgMinMaxQuantizedValidationFixture = ArgMinMaxValidationQuantizedFixture<Tensor, Accessor, NEArgMinMaxLayer, T>;
160
161TEST_SUITE(QASYMM8)
162FIXTURE_DATA_TEST_CASE(RunSmall,
163 NEArgMinMaxQuantizedValidationFixture<uint8_t>,
164 framework::DatasetMode::PRECOMMIT,
165 combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
166 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
167 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
168{
169 // Validate output
170 validate(Accessor(_target), _reference);
171}
172
173FIXTURE_DATA_TEST_CASE(RunLarge,
174 NEArgMinMaxQuantizedValidationFixture<uint8_t>,
175 framework::DatasetMode::NIGHTLY,
176 combine(combine(combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
177 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
178 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
179{
180 // Validate output
181 validate(Accessor(_target), _reference);
182}
183TEST_SUITE_END() // QASYMM8
Michalis Spyrouaea14c62019-01-03 11:10:25 +0000184TEST_SUITE_END() // ArgMinMax
185TEST_SUITE_END() // NEON
186} // namespace validation
187} // namespace test
188} // namespace arm_compute