blob: cc892a30d10c964dd246363059194e1ae0bb8ae6 [file] [log] [blame]
Manuel Bottini8529bd62018-11-21 11:53:04 +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/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
101DATA_TEST_CASE(Configuration,
102 framework::DatasetMode::ALL,
103 combine(arm_compute::test::datasets::SmallGatherDataset(), framework::dataset::make("DataType", { DataType::F16, DataType::F32 })),
104 input_shape, indices_shape, axis, data_type)
105{
106 const uint32_t actual_axis = wrap_around(axis, static_cast<int>(input_shape.num_dimensions()));
107 CLTensor src = create_tensor<CLTensor>(input_shape, data_type);
108 CLTensor indices = create_tensor<CLTensor>(indices_shape, DataType::U32);
109 TensorShape dst_shape = arm_compute::misc::shape_calculator::compute_gather_shape(input_shape, indices_shape, actual_axis);
110 CLTensor dst = create_tensor<CLTensor>(dst_shape, data_type);
111
112 // Create and Configure function
113 CLGather gather;
114 gather.configure(&src, &indices, &dst, axis);
115
116 // Validate valid region
117 const ValidRegion valid_region = shape_to_valid_region(dst.info()->tensor_shape());
118 validate(dst.info()->valid_region(), valid_region);
119}
120
121template <typename T>
122using CLGatherFixture = GatherFixture<CLTensor, CLAccessor, CLGather, T>;
123
124TEST_SUITE(Float)
125TEST_SUITE(FP16)
126FIXTURE_DATA_TEST_CASE(RunSmall,
127 CLGatherFixture<half>,
128 framework::DatasetMode::PRECOMMIT,
129 combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::F16)))
130{
131 // Validate output
132 validate(CLAccessor(_target), _reference);
133}
134
135FIXTURE_DATA_TEST_CASE(RunLarge,
136 CLGatherFixture<half>,
137 framework::DatasetMode::NIGHTLY,
138 combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::F16)))
139{
140 // Validate output
141 validate(CLAccessor(_target), _reference);
142}
143TEST_SUITE_END() // FP16
144
145TEST_SUITE(FP32)
146FIXTURE_DATA_TEST_CASE(RunSmall,
147 CLGatherFixture<float>,
148 framework::DatasetMode::PRECOMMIT,
149 combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::F32)))
150{
151 // Validate output
152 validate(CLAccessor(_target), _reference);
153}
154
155FIXTURE_DATA_TEST_CASE(RunLarge,
156 CLGatherFixture<float>,
157 framework::DatasetMode::NIGHTLY,
158 combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::F32)))
159{
160 // Validate output
161 validate(CLAccessor(_target), _reference);
162}
163TEST_SUITE_END() // FP32
164TEST_SUITE_END() // Float
165
166TEST_SUITE(U8)
167FIXTURE_DATA_TEST_CASE(RunSmall,
168 CLGatherFixture<uint8_t>,
169 framework::DatasetMode::PRECOMMIT,
170 combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::U8)))
171{
172 // Validate output
173 validate(CLAccessor(_target), _reference);
174}
175
176FIXTURE_DATA_TEST_CASE(RunLarge,
177 CLGatherFixture<uint8_t>,
178 framework::DatasetMode::NIGHTLY,
179 combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::U8)))
180{
181 // Validate output
182 validate(CLAccessor(_target), _reference);
183}
184TEST_SUITE_END() // U8
185
186TEST_SUITE(U16)
187FIXTURE_DATA_TEST_CASE(RunSmall,
188 CLGatherFixture<uint16_t>,
189 framework::DatasetMode::PRECOMMIT,
190 combine(datasets::SmallGatherDataset(), framework::dataset::make("DataType", DataType::U16)))
191{
192 // Validate output
193 validate(CLAccessor(_target), _reference);
194}
195
196FIXTURE_DATA_TEST_CASE(RunLarge,
197 CLGatherFixture<uint16_t>,
198 framework::DatasetMode::NIGHTLY,
199 combine(datasets::LargeGatherDataset(), framework::dataset::make("DataType", DataType::U16)))
200{
201 // Validate output
202 validate(CLAccessor(_target), _reference);
203}
204TEST_SUITE_END() // U16
205
206TEST_SUITE_END() // Gather
207TEST_SUITE_END() // CL
208} // namespace validation
209} // namespace test
210} // namespace arm_compute