blob: 6126231d0d35cccd1395048fd8958d8d2d725cb7 [file] [log] [blame]
Manuel Bottini8529bd62018-11-21 11:53:04 +00001/*
Michalis Spyroud175ece2020-07-30 23:39:32 +01002 * Copyright (c) 2018-2020 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"
28
29#include "tests/CL/CLAccessor.h"
30#include "tests/datasets/GatherDataset.h"
31#include "tests/framework/Asserts.h"
32#include "tests/framework/Macros.h"
33#include "tests/framework/datasets/Datasets.h"
34#include "tests/validation/Validation.h"
35#include "tests/validation/fixtures/GatherFixture.h"
36
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43TEST_SUITE(CL)
44TEST_SUITE(Gather)
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, 27U), 1, DataType::F16),
50 TensorInfo(TensorShape(27U, 27U), 1, DataType::F32),
51 TensorInfo(TensorShape(27U, 27U), 1, DataType::F32),
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
58 }),
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),
63 TensorInfo(TensorShape(10U), 1, DataType::U8),
64 TensorInfo(TensorShape(10U, 10U), 1, DataType::U32),
65 TensorInfo(TensorShape(10U), 1, DataType::U32),
66 TensorInfo(TensorShape(10U), 1, DataType::U32),
67 TensorInfo(TensorShape(10U), 1, DataType::U32),
68 TensorInfo(TensorShape(10U), 1, DataType::U32),
69 })),
70 framework::dataset::make("OutputInfo", {
71 TensorInfo(TensorShape(10U, 27U), 1, DataType::F16),
72 TensorInfo(TensorShape(27U, 10U), 1, DataType::F32),
73 TensorInfo(TensorShape(10U, 27U), 1, DataType::F32),
74 TensorInfo(TensorShape(10U, 27U), 1, DataType::F32),
75 TensorInfo(TensorShape(27U, 10U), 1, DataType::F32),
76 TensorInfo(TensorShape(10U, 5U, 5U, 5U, 5U), 1, DataType::F32),
77 TensorInfo(TensorShape(27U, 10U), 1, DataType::F32),
78 TensorInfo(TensorShape(27U, 27U), 1, DataType::F32),
79 TensorInfo(TensorShape(27U, 27U), 1, DataType::F16),
80 })),
81 framework::dataset::make("Axis", {
82 0,
83 1,
84 -2,
85 0,
86 1,
87 0,
88 1,
89 2,
90 -3,
91 })),
92 framework::dataset::make("Expected", { true, true, true, false, false, false, false, false, false })),
93 input_info, indices_info, output_info, axis, expected)
94{
95 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);
96 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
97}
98// clang-format on
99// *INDENT-ON*
100
Manuel Bottini8529bd62018-11-21 11:53:04 +0000101template <typename T>
102using CLGatherFixture = GatherFixture<CLTensor, CLAccessor, CLGather, T>;
103
104TEST_SUITE(Float)
105TEST_SUITE(FP16)
106FIXTURE_DATA_TEST_CASE(RunSmall,
107 CLGatherFixture<half>,
108 framework::DatasetMode::PRECOMMIT,
109 combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::F16)))
110{
111 // Validate output
112 validate(CLAccessor(_target), _reference);
113}
114
115FIXTURE_DATA_TEST_CASE(RunLarge,
116 CLGatherFixture<half>,
117 framework::DatasetMode::NIGHTLY,
118 combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::F16)))
119{
120 // Validate output
121 validate(CLAccessor(_target), _reference);
122}
123TEST_SUITE_END() // FP16
124
125TEST_SUITE(FP32)
126FIXTURE_DATA_TEST_CASE(RunSmall,
127 CLGatherFixture<float>,
128 framework::DatasetMode::PRECOMMIT,
129 combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::F32)))
130{
131 // Validate output
132 validate(CLAccessor(_target), _reference);
133}
134
135FIXTURE_DATA_TEST_CASE(RunLarge,
136 CLGatherFixture<float>,
137 framework::DatasetMode::NIGHTLY,
138 combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::F32)))
139{
140 // Validate output
141 validate(CLAccessor(_target), _reference);
142}
143TEST_SUITE_END() // FP32
144TEST_SUITE_END() // Float
145
146TEST_SUITE(U8)
147FIXTURE_DATA_TEST_CASE(RunSmall,
148 CLGatherFixture<uint8_t>,
149 framework::DatasetMode::PRECOMMIT,
150 combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::U8)))
151{
152 // Validate output
153 validate(CLAccessor(_target), _reference);
154}
155
156FIXTURE_DATA_TEST_CASE(RunLarge,
157 CLGatherFixture<uint8_t>,
158 framework::DatasetMode::NIGHTLY,
159 combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::U8)))
160{
161 // Validate output
162 validate(CLAccessor(_target), _reference);
163}
164TEST_SUITE_END() // U8
165
166TEST_SUITE(U16)
167FIXTURE_DATA_TEST_CASE(RunSmall,
168 CLGatherFixture<uint16_t>,
169 framework::DatasetMode::PRECOMMIT,
170 combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::U16)))
171{
172 // Validate output
173 validate(CLAccessor(_target), _reference);
174}
175
176FIXTURE_DATA_TEST_CASE(RunLarge,
177 CLGatherFixture<uint16_t>,
178 framework::DatasetMode::NIGHTLY,
179 combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::U16)))
180{
181 // Validate output
182 validate(CLAccessor(_target), _reference);
183}
184TEST_SUITE_END() // U16
185
186TEST_SUITE_END() // Gather
187TEST_SUITE_END() // CL
188} // namespace validation
189} // namespace test
190} // namespace arm_compute