blob: 2e6a3d4ed23df5e0d14dfde558285a11f09c389c [file] [log] [blame]
John Kesapides2dce6cc2019-01-14 09:47:09 +00001/*
2 * Copyright (c) 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/NEGather.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/PaddingCalculator.h"
31#include "tests/datasets/GatherDataset.h"
32#include "tests/datasets/ShapeDatasets.h"
33#include "tests/framework/Asserts.h"
34#include "tests/framework/Macros.h"
35#include "tests/framework/datasets/Datasets.h"
36#include "tests/validation/Validation.h"
37#include "tests/validation/fixtures/GatherFixture.h"
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45TEST_SUITE(NEON)
46TEST_SUITE(Gather)
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, 27U), 1, DataType::F16),
52 TensorInfo(TensorShape(27U, 27U), 1, DataType::F32),
53 TensorInfo(TensorShape(27U, 27U), 1, DataType::F32),
54 TensorInfo(TensorShape(27U, 27U), 1, DataType::F32), // Invalid Indices data type
55 TensorInfo(TensorShape(27U, 27U), 1, DataType::F32), // Invalid Indices dimensionality
56 TensorInfo(TensorShape(5U, 5U, 5U, 5U, 5U), 1, DataType::F32), // Invalid Input dimensionality
57 TensorInfo(TensorShape(27U, 27U), 1, DataType::F16), // Mismatching data type input/output
58 TensorInfo(TensorShape(27U, 27U), 1, DataType::F32), // Invalid positive axis value
59 TensorInfo(TensorShape(27U, 27U), 1, DataType::F16), // Invalid negative axis value
60 }),
61 framework::dataset::make("IndicesInfo", {
62 TensorInfo(TensorShape(10U), 1, DataType::U32),
63 TensorInfo(TensorShape(10U), 1, DataType::U32),
64 TensorInfo(TensorShape(10U), 1, DataType::U32),
65 TensorInfo(TensorShape(10U), 1, DataType::U8),
66 TensorInfo(TensorShape(10U, 10U), 1, DataType::U32),
67 TensorInfo(TensorShape(10U), 1, DataType::U32),
68 TensorInfo(TensorShape(10U), 1, DataType::U32),
69 TensorInfo(TensorShape(10U), 1, DataType::U32),
70 TensorInfo(TensorShape(10U), 1, DataType::U32),
71 })),
72 framework::dataset::make("OutputInfo", {
73 TensorInfo(TensorShape(10U, 27U), 1, DataType::F16),
74 TensorInfo(TensorShape(27U, 10U), 1, DataType::F32),
75 TensorInfo(TensorShape(10U, 27U), 1, DataType::F32),
76 TensorInfo(TensorShape(10U, 27U), 1, DataType::F32),
77 TensorInfo(TensorShape(27U, 10U), 1, DataType::F32),
78 TensorInfo(TensorShape(10U, 5U, 5U, 5U, 5U), 1, DataType::F32),
79 TensorInfo(TensorShape(27U, 10U), 1, DataType::F32),
80 TensorInfo(TensorShape(27U, 27U), 1, DataType::F32),
81 TensorInfo(TensorShape(27U, 27U), 1, DataType::F16),
82 })),
83 framework::dataset::make("Axis", {
84 0,
85 1,
86 -2,
87 0,
88 1,
89 0,
90 1,
91 2,
92 -3,
93 })),
94 framework::dataset::make("Expected", { true, true, true, false, false, false, false, false, false })),
95 input_info, indices_info, output_info, axis, expected)
96{
97 const Status status = NEGather::validate(&input_info.clone()->set_is_resizable(true), &indices_info.clone()->set_is_resizable(true), &output_info.clone()->set_is_resizable(true), axis);
98 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
99}
100// clang-format on
101// *INDENT-ON*
102
103DATA_TEST_CASE(Configuration,
104 framework::DatasetMode::ALL,
105 combine(arm_compute::test::datasets::SmallGatherDataset(), framework::dataset::make("DataType", { DataType::F16, DataType::F32 })),
106 input_shape, indices_shape, axis, data_type)
107{
108 const uint32_t actual_axis = wrap_around(axis, static_cast<int>(input_shape.num_dimensions()));
109 Tensor src = create_tensor<Tensor>(input_shape, data_type);
110 Tensor indices = create_tensor<Tensor>(indices_shape, DataType::U32);
111 TensorShape dst_shape = arm_compute::misc::shape_calculator::compute_gather_shape(input_shape, indices_shape, actual_axis);
112 Tensor dst = create_tensor<Tensor>(dst_shape, data_type);
113
114 // Create and Configure function
115 NEGather gather;
116 gather.configure(&src, &indices, &dst, axis);
117
118 // Validate valid region
119 const ValidRegion valid_region = shape_to_valid_region(dst.info()->tensor_shape());
120 validate(dst.info()->valid_region(), valid_region);
121}
122
123template <typename T>
124using NEGatherFixture = GatherFixture<Tensor, Accessor, NEGather, T>;
125
126TEST_SUITE(Float)
127TEST_SUITE(FP16)
128FIXTURE_DATA_TEST_CASE(RunSmall,
129 NEGatherFixture<half>,
130 framework::DatasetMode::PRECOMMIT,
131 combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::F16)))
132{
133 // Validate output
134 validate(Accessor(_target), _reference);
135}
136
137FIXTURE_DATA_TEST_CASE(RunLarge,
138 NEGatherFixture<half>,
139 framework::DatasetMode::NIGHTLY,
140 combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::F16)))
141{
142 // Validate output
143 validate(Accessor(_target), _reference);
144}
145TEST_SUITE_END() // FP16
146
147TEST_SUITE(FP32)
148FIXTURE_DATA_TEST_CASE(RunSmall,
149 NEGatherFixture<float>,
150 framework::DatasetMode::PRECOMMIT,
151 combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::F32)))
152{
153 // Validate output
154 validate(Accessor(_target), _reference);
155}
156
157FIXTURE_DATA_TEST_CASE(RunLarge,
158 NEGatherFixture<float>,
159 framework::DatasetMode::NIGHTLY,
160 combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::F32)))
161{
162 // Validate output
163 validate(Accessor(_target), _reference);
164}
165TEST_SUITE_END() // FP32
166TEST_SUITE_END() // Float
167
168TEST_SUITE(U8)
169FIXTURE_DATA_TEST_CASE(RunSmall,
170 NEGatherFixture<uint8_t>,
171 framework::DatasetMode::PRECOMMIT,
172 combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::U8)))
173{
174 // Validate output
175 validate(Accessor(_target), _reference);
176}
177
178FIXTURE_DATA_TEST_CASE(RunLarge,
179 NEGatherFixture<uint8_t>,
180 framework::DatasetMode::NIGHTLY,
181 combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::U8)))
182{
183 // Validate output
184 validate(Accessor(_target), _reference);
185}
186TEST_SUITE_END() // U8
187
188TEST_SUITE(U16)
189FIXTURE_DATA_TEST_CASE(RunSmall,
190 NEGatherFixture<uint16_t>,
191 framework::DatasetMode::PRECOMMIT,
192 combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::U16)))
193{
194 // Validate output
195 validate(Accessor(_target), _reference);
196}
197
198FIXTURE_DATA_TEST_CASE(RunLarge,
199 NEGatherFixture<uint16_t>,
200 framework::DatasetMode::NIGHTLY,
201 combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::U16)))
202{
203 // Validate output
204 validate(Accessor(_target), _reference);
205}
206TEST_SUITE_END() // U16
207
208TEST_SUITE_END() // Gather
209TEST_SUITE_END() // NEON
210} // namespace validation
211} // namespace test
212} // namespace arm_compute