blob: 611495a41db1df3b88d6d31e52763584357009cb [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"
25#include "arm_compute/runtime/NEON/functions/NEArgMinMaxLayer.h"
26#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
28
29#include "tests/NEON/Accessor.h"
30#include "tests/datasets/ShapeDatasets.h"
31#include "tests/datasets/SplitDataset.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Macros.h"
34#include "tests/validation/Validation.h"
35#include "tests/validation/fixtures/ArgMinMaxFixture.h"
36
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43TEST_SUITE(NEON)
44TEST_SUITE(ArgMinMax)
45
46// *INDENT-OFF*
47// clang-format off
48DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
49 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid axis
50 TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid output shape
51 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32),
52 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32) // Invalid operation
53 }),
54 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(27U, 3U, 1U, 2U), 1, DataType::F32),
55 TensorInfo(TensorShape(27U, 3U, 1U, 2U), 1, DataType::F32),
56 TensorInfo(TensorShape(32U, 16U, 1U, 2U), 1, DataType::U32),
57 TensorInfo(TensorShape(32U, 16U, 1U, 2U), 1, DataType::F32)
58 })),
59 framework::dataset::make("Axis", { 4, 0, 2, 0 })),
60 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::ARG_IDX_MAX, ReductionOperation::MEAN_SUM })),
61 framework::dataset::make("Expected", { false, false, true, false })),
62 input_info, output_info, axis, operation, expected)
63{
64 const Status status = NEArgMinMaxLayer::validate(&input_info.clone()->set_is_resizable(false), axis, &output_info.clone()->set_is_resizable(false), operation);
65 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
66}
67// clang-format on
68// *INDENT-ON*
69
70DATA_TEST_CASE(Configuration,
71 framework::DatasetMode::ALL,
72 combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::F16, DataType::F32 })),
73 shape, data_type)
74{
75 // Create tensors
76 Tensor ref_src = create_tensor<Tensor>(shape, data_type);
77 Tensor dst;
78
79 // Create and Configure function
80 NEArgMinMaxLayer arg_min_max_layer;
81 arg_min_max_layer.configure(&ref_src, 1, &dst, ReductionOperation::ARG_IDX_MAX);
82
83 // Validate valid region
84 TensorShape output_shape = shape;
85 output_shape.set(1, 1);
86 const ValidRegion valid_region = shape_to_valid_region(output_shape);
87 validate(dst.info()->valid_region(), valid_region);
88}
89
90template <typename T>
91using NEArgMinMaxValidationFixture = ArgMinMaxValidationFixture<Tensor, Accessor, NEArgMinMaxLayer, T>;
92
93TEST_SUITE(Float)
94#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
95TEST_SUITE(FP16)
96FIXTURE_DATA_TEST_CASE(RunSmall,
97 NEArgMinMaxValidationFixture<half>,
98 framework::DatasetMode::PRECOMMIT,
99 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 })))
100{
101 // Validate output
102 validate(Accessor(_target), _reference);
103}
104
105FIXTURE_DATA_TEST_CASE(RunLarge,
106 NEArgMinMaxValidationFixture<half>,
107 framework::DatasetMode::NIGHTLY,
108 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 })))
109{
110 // Validate output
111 validate(Accessor(_target), _reference);
112}
113TEST_SUITE_END() // FP16
114#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
115
116template <typename T>
117using NEArgMinMaxQuantizedValidationFixture = ArgMinMaxValidationQuantizedFixture<Tensor, Accessor, NEArgMinMaxLayer, T>;
118
119TEST_SUITE(QASYMM8)
120FIXTURE_DATA_TEST_CASE(RunSmall,
121 NEArgMinMaxQuantizedValidationFixture<uint8_t>,
122 framework::DatasetMode::PRECOMMIT,
123 combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
124 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
125 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
126{
127 // Validate output
128 validate(Accessor(_target), _reference);
129}
130
131FIXTURE_DATA_TEST_CASE(RunLarge,
132 NEArgMinMaxQuantizedValidationFixture<uint8_t>,
133 framework::DatasetMode::NIGHTLY,
134 combine(combine(combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8)), framework::dataset::make("Axis", { 0, 1, 2, 3 })),
135 framework::dataset::make("Operation", { ReductionOperation::ARG_IDX_MIN, ReductionOperation::ARG_IDX_MAX })),
136 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })))
137{
138 // Validate output
139 validate(Accessor(_target), _reference);
140}
141TEST_SUITE_END() // QASYMM8
142
143TEST_SUITE(FP32)
144FIXTURE_DATA_TEST_CASE(RunSmall,
145 NEArgMinMaxValidationFixture<float>,
146 framework::DatasetMode::PRECOMMIT,
147 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 })))
148{
149 // Validate output
150 validate(Accessor(_target), _reference);
151}
152
153FIXTURE_DATA_TEST_CASE(RunLarge,
154 NEArgMinMaxValidationFixture<float>,
155 framework::DatasetMode::NIGHTLY,
156 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 })))
157{
158 // Validate output
159 validate(Accessor(_target), _reference);
160}
161TEST_SUITE_END() // FP32
162TEST_SUITE_END() // Float
163TEST_SUITE_END() // ArgMinMax
164TEST_SUITE_END() // NEON
165} // namespace validation
166} // namespace test
167} // namespace arm_compute