blob: 7619baae1e4652979ed0ec8de1c4840530ea57a1 [file] [log] [blame]
Manuel Bottini8529bd62018-11-21 11:53:04 +00001/*
Omar Al Khatibcdd1e032023-04-26 11:31:45 +01002 * Copyright (c) 2018-2020, 2023 Arm Limited.
Manuel Bottini8529bd62018-11-21 11:53:04 +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/CLGather.h"
Manuel Bottini8529bd62018-11-21 11:53:04 +000028#include "tests/CL/CLAccessor.h"
29#include "tests/datasets/GatherDataset.h"
30#include "tests/framework/Asserts.h"
31#include "tests/framework/Macros.h"
32#include "tests/framework/datasets/Datasets.h"
33#include "tests/validation/Validation.h"
34#include "tests/validation/fixtures/GatherFixture.h"
35
36namespace arm_compute
37{
38namespace test
39{
40namespace validation
41{
42TEST_SUITE(CL)
43TEST_SUITE(Gather)
44
45// *INDENT-OFF*
46// clang-format off
47DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
48 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 27U), 1, DataType::F16),
49 TensorInfo(TensorShape(27U, 27U), 1, DataType::F32),
50 TensorInfo(TensorShape(27U, 27U), 1, DataType::F32),
Omar Al Khatibcdd1e032023-04-26 11:31:45 +010051 TensorInfo(TensorShape(27U, 27U), 1, DataType::F32), // Invalid Output shape
52 TensorInfo(TensorShape(27U, 27U), 1, DataType::F32), // Invalid Indices data type
53 TensorInfo(TensorShape(27U, 27U), 1, DataType::F32), // Invalid Indices dimensionality
54 TensorInfo(TensorShape(5U, 5U, 5U, 5U, 5U), 1, DataType::F32), // Invalid Input dimensionality
55 TensorInfo(TensorShape(27U, 27U), 1, DataType::F16), // Mismatching data type input/output
56 TensorInfo(TensorShape(27U, 27U), 1, DataType::F32), // Invalid positive axis value
57 TensorInfo(TensorShape(27U, 27U), 1, DataType::F16), // Invalid negative axis value
Manuel Bottini8529bd62018-11-21 11:53:04 +000058 }),
59 framework::dataset::make("IndicesInfo", {
60 TensorInfo(TensorShape(10U), 1, DataType::U32),
61 TensorInfo(TensorShape(10U), 1, DataType::U32),
62 TensorInfo(TensorShape(10U), 1, DataType::U32),
Manuel Bottini8529bd62018-11-21 11:53:04 +000063 TensorInfo(TensorShape(10U, 10U), 1, DataType::U32),
Omar Al Khatibcdd1e032023-04-26 11:31:45 +010064 TensorInfo(TensorShape(10U), 1, DataType::U8),
65 TensorInfo(TensorShape(10U, 10U, 10U, 10U), 1, DataType::U32),
Manuel Bottini8529bd62018-11-21 11:53:04 +000066 TensorInfo(TensorShape(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 })),
71 framework::dataset::make("OutputInfo", {
72 TensorInfo(TensorShape(10U, 27U), 1, DataType::F16),
73 TensorInfo(TensorShape(27U, 10U), 1, DataType::F32),
74 TensorInfo(TensorShape(10U, 27U), 1, DataType::F32),
75 TensorInfo(TensorShape(10U, 27U), 1, DataType::F32),
Omar Al Khatibcdd1e032023-04-26 11:31:45 +010076 TensorInfo(TensorShape(10U, 27U), 1, DataType::F32),
77 TensorInfo(TensorShape(27U, 10U, 10U, 10U, 10U), 1, DataType::F32),
Manuel Bottini8529bd62018-11-21 11:53:04 +000078 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,
Omar Al Khatibcdd1e032023-04-26 11:31:45 +010088 0,
Manuel Bottini8529bd62018-11-21 11:53:04 +000089 1,
90 0,
91 1,
92 2,
93 -3,
94 })),
Omar Al Khatibcdd1e032023-04-26 11:31:45 +010095 framework::dataset::make("Expected", { true, true, true, false, false, false, false, false, false, false })),
Manuel Bottini8529bd62018-11-21 11:53:04 +000096 input_info, indices_info, output_info, axis, expected)
97{
98 const Status status = CLGather::validate(&input_info.clone()->set_is_resizable(true), &indices_info.clone()->set_is_resizable(true), &output_info.clone()->set_is_resizable(true), axis);
99 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
100}
101// clang-format on
102// *INDENT-ON*
103
Manuel Bottini8529bd62018-11-21 11:53:04 +0000104template <typename T>
105using CLGatherFixture = GatherFixture<CLTensor, CLAccessor, CLGather, T>;
106
107TEST_SUITE(Float)
108TEST_SUITE(FP16)
109FIXTURE_DATA_TEST_CASE(RunSmall,
110 CLGatherFixture<half>,
111 framework::DatasetMode::PRECOMMIT,
112 combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::F16)))
113{
114 // Validate output
115 validate(CLAccessor(_target), _reference);
116}
117
Omar Al Khatibcdd1e032023-04-26 11:31:45 +0100118FIXTURE_DATA_TEST_CASE(RunSmallMultiDimIndices,
119 CLGatherFixture<half>,
120 framework::DatasetMode::PRECOMMIT,
121 combine(datasets::CLSmallGatherMultiDimIndicesDataset(), framework::dataset::make("DataType", DataType::F16)))
122{
123 // Validate output
124 validate(CLAccessor(_target), _reference);
125}
126
Manuel Bottini8529bd62018-11-21 11:53:04 +0000127FIXTURE_DATA_TEST_CASE(RunLarge,
128 CLGatherFixture<half>,
129 framework::DatasetMode::NIGHTLY,
130 combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::F16)))
131{
132 // Validate output
133 validate(CLAccessor(_target), _reference);
134}
135TEST_SUITE_END() // FP16
136
137TEST_SUITE(FP32)
138FIXTURE_DATA_TEST_CASE(RunSmall,
139 CLGatherFixture<float>,
140 framework::DatasetMode::PRECOMMIT,
141 combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::F32)))
142{
143 // Validate output
144 validate(CLAccessor(_target), _reference);
145}
146
Omar Al Khatibcdd1e032023-04-26 11:31:45 +0100147FIXTURE_DATA_TEST_CASE(RunSmallMultiDimIndices,
148 CLGatherFixture<float>,
149 framework::DatasetMode::PRECOMMIT,
150 combine(datasets::CLSmallGatherMultiDimIndicesDataset(), framework::dataset::make("DataType", DataType::F32)))
151{
152 // Validate output
153 validate(CLAccessor(_target), _reference);
154}
155
Manuel Bottini8529bd62018-11-21 11:53:04 +0000156FIXTURE_DATA_TEST_CASE(RunLarge,
157 CLGatherFixture<float>,
158 framework::DatasetMode::NIGHTLY,
159 combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::F32)))
160{
161 // Validate output
162 validate(CLAccessor(_target), _reference);
163}
164TEST_SUITE_END() // FP32
165TEST_SUITE_END() // Float
166
167TEST_SUITE(U8)
168FIXTURE_DATA_TEST_CASE(RunSmall,
169 CLGatherFixture<uint8_t>,
170 framework::DatasetMode::PRECOMMIT,
171 combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::U8)))
172{
173 // Validate output
174 validate(CLAccessor(_target), _reference);
175}
176
Omar Al Khatibcdd1e032023-04-26 11:31:45 +0100177FIXTURE_DATA_TEST_CASE(RunSmallMultiDimIndices,
178 CLGatherFixture<uint8_t>,
179 framework::DatasetMode::PRECOMMIT,
180 combine(datasets::CLSmallGatherMultiDimIndicesDataset(), framework::dataset::make("DataType", DataType::U8)))
181{
182 // Validate output
183 validate(CLAccessor(_target), _reference);
184}
185
Manuel Bottini8529bd62018-11-21 11:53:04 +0000186FIXTURE_DATA_TEST_CASE(RunLarge,
187 CLGatherFixture<uint8_t>,
188 framework::DatasetMode::NIGHTLY,
189 combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::U8)))
190{
191 // Validate output
192 validate(CLAccessor(_target), _reference);
193}
194TEST_SUITE_END() // U8
195
196TEST_SUITE(U16)
197FIXTURE_DATA_TEST_CASE(RunSmall,
198 CLGatherFixture<uint16_t>,
199 framework::DatasetMode::PRECOMMIT,
200 combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::U16)))
201{
202 // Validate output
203 validate(CLAccessor(_target), _reference);
204}
205
Omar Al Khatibcdd1e032023-04-26 11:31:45 +0100206FIXTURE_DATA_TEST_CASE(RunSmallMultiDimIndices,
207 CLGatherFixture<uint16_t>,
208 framework::DatasetMode::PRECOMMIT,
209 combine(datasets::CLSmallGatherMultiDimIndicesDataset(), framework::dataset::make("DataType", DataType::U16)))
210{
211 // Validate output
212 validate(CLAccessor(_target), _reference);
213}
214
215
Manuel Bottini8529bd62018-11-21 11:53:04 +0000216FIXTURE_DATA_TEST_CASE(RunLarge,
217 CLGatherFixture<uint16_t>,
218 framework::DatasetMode::NIGHTLY,
219 combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::U16)))
220{
221 // Validate output
222 validate(CLAccessor(_target), _reference);
223}
224TEST_SUITE_END() // U16
225
226TEST_SUITE_END() // Gather
227TEST_SUITE_END() // CL
228} // namespace validation
229} // namespace test
230} // namespace arm_compute