blob: a80f9acc884346849368dfa455bb4ef5498775a0 [file] [log] [blame]
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +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/NEON/functions/NESplit.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/SplitDataset.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/SplitFixture.h"
36
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43TEST_SUITE(NEON)
44TEST_SUITE(Split)
45
46// *INDENT-OFF*
47// clang-format off
48DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, 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 number of splits
51 TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32)
52 }),
53 framework::dataset::make("Axis", { 4, 2, 2 })),
54 framework::dataset::make("Splits", { 4, 5, 4 })),
55 framework::dataset::make("Expected", { false, false, true })),
56 input_info, axis, splits, expected)
57{
58 std::vector<TensorInfo> outputs_info(splits);
59 std::vector<ITensorInfo*> outputs_info_ptr;
Michalis Spyroubcfd09a2019-05-01 13:03:59 +010060 outputs_info_ptr.reserve(splits);
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000061 for(auto &output_info : outputs_info)
62 {
63 outputs_info_ptr.emplace_back(&output_info);
64 }
65 const Status status = NESplit::validate(&input_info.clone()->set_is_resizable(false), outputs_info_ptr, axis);
66 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
67}
Kurtis Charnockab709a02019-11-29 11:43:05 +000068
69DATA_TEST_CASE(ValidateSplitShapes, framework::DatasetMode::ALL, zip(zip(zip(
70 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32),
71 TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32)
72 }),
73 framework::dataset::make("Axis", { 2, 2 })),
74 framework::dataset::make("Splits", { std::vector<TensorInfo>{TensorInfo(TensorShape(27U, 3U, 4U, 2U), 1, DataType::F32),
75 TensorInfo(TensorShape(27U, 3U, 4U, 2U), 1, DataType::F32),
76 TensorInfo(TensorShape(27U, 3U, 8U, 2U), 1, DataType::F32)},
77 std::vector<TensorInfo>{TensorInfo(TensorShape(27U, 3U, 3U, 2U), 1, DataType::F32),
78 TensorInfo(TensorShape(27U, 3U, 13U, 2U), 1, DataType::F32)} })),
79 framework::dataset::make("Expected", { true, true })),
80 input_info, axis, splits, expected)
81{
82 std::vector<ITensorInfo*> outputs_info_ptr;
83
84 for(auto &split : splits)
85 {
86 outputs_info_ptr.emplace_back(const_cast<TensorInfo*>(&split));
87 }
88 const Status status = NESplit::validate(&input_info.clone()->set_is_resizable(false), outputs_info_ptr, axis);
89 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
90}
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000091// clang-format on
92// *INDENT-ON*
93
94DATA_TEST_CASE(Configuration,
95 framework::DatasetMode::ALL,
96 combine(datasets::SmallSplitDataset(), framework::dataset::make("DataType", { DataType::QASYMM8, DataType::F32 })),
97 shape, axis, splits, data_type)
98{
99 // Create tensors
100 Tensor src = create_tensor<Tensor>(shape, data_type);
101 std::vector<Tensor> dsts(splits);
102 std::vector<ITensor *> dsts_ptrs;
Michalis Spyroubcfd09a2019-05-01 13:03:59 +0100103 dsts_ptrs.reserve(splits);
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +0000104 for(auto &dst : dsts)
105 {
106 dsts_ptrs.emplace_back(&dst);
107 }
108
109 // Create and Configure function
110 NESplit split;
111 split.configure(&src, dsts_ptrs, axis);
112
113 // Validate valid regions
114 for(auto &dst : dsts)
115 {
116 const ValidRegion valid_region = shape_to_valid_region(dst.info()->tensor_shape());
117 validate(dst.info()->valid_region(), valid_region);
118 }
119}
120
Kurtis Charnockab709a02019-11-29 11:43:05 +0000121DATA_TEST_CASE(ConfigurationSplitShapes,
122 framework::DatasetMode::ALL,
123 combine(datasets::SmallSplitShapesDataset(), framework::dataset::make("DataType", { DataType::F16, DataType::F32 })),
124 shape, axis, split_shapes, data_type)
125{
126 // Create tensors
127 Tensor src = create_tensor<Tensor>(shape, data_type);
128 std::vector<Tensor> dsts;
129
130 for(const auto &split_shape : split_shapes)
131 {
132 Tensor dst = create_tensor<Tensor>(split_shape, data_type);
133 dsts.push_back(std::move(dst));
134 }
135
136 std::vector<ITensor *> dsts_ptrs;
137 for(auto &dst : dsts)
138 {
139 dsts_ptrs.emplace_back(&dst);
140 }
141
142 // Create and Configure function
143 NESplit split;
144 split.configure(&src, dsts_ptrs, axis);
145
146 // Validate valid regions
147 for(auto &dst : dsts)
148 {
149 const ValidRegion valid_region = shape_to_valid_region(dst.info()->tensor_shape());
150 validate(dst.info()->valid_region(), valid_region);
151 }
152}
153
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +0000154template <typename T>
155using NESplitFixture = SplitFixture<Tensor, ITensor, Accessor, NESplit, T>;
156
Kurtis Charnockab709a02019-11-29 11:43:05 +0000157template <typename T>
158using NESplitShapesFixture = SplitShapesFixture<Tensor, ITensor, Accessor, NESplit, T>;
159
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +0000160TEST_SUITE(Float)
161#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
162TEST_SUITE(FP16)
163FIXTURE_DATA_TEST_CASE(RunSmall,
164 NESplitFixture<half>,
165 framework::DatasetMode::PRECOMMIT,
166 combine(datasets::SmallSplitDataset(), framework::dataset::make("DataType", DataType::F16)))
167{
168 // Validate outputs
169 for(unsigned int i = 0; i < _target.size(); ++i)
170 {
171 validate(Accessor(_target[i]), _reference[i]);
172 }
173}
174
175FIXTURE_DATA_TEST_CASE(RunLarge,
176 NESplitFixture<half>,
177 framework::DatasetMode::NIGHTLY,
178 combine(datasets::LargeSplitDataset(), framework::dataset::make("DataType", DataType::F16)))
179{
180 // Validate outputs
181 for(unsigned int i = 0; i < _target.size(); ++i)
182 {
183 validate(Accessor(_target[i]), _reference[i]);
184 }
185}
186TEST_SUITE_END() // FP16
187#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
188
189TEST_SUITE(FP32)
190FIXTURE_DATA_TEST_CASE(RunSmall,
191 NESplitFixture<float>,
192 framework::DatasetMode::PRECOMMIT,
193 combine(datasets::SmallSplitDataset(), framework::dataset::make("DataType", DataType::F32)))
194{
195 // Validate outputs
196 for(unsigned int i = 0; i < _target.size(); ++i)
197 {
198 validate(Accessor(_target[i]), _reference[i]);
199 }
200}
201
202FIXTURE_DATA_TEST_CASE(RunLarge,
203 NESplitFixture<float>,
204 framework::DatasetMode::NIGHTLY,
205 combine(datasets::LargeSplitDataset(), framework::dataset::make("DataType", DataType::F32)))
206{
207 // Validate outputs
208 for(unsigned int i = 0; i < _target.size(); ++i)
209 {
210 validate(Accessor(_target[i]), _reference[i]);
211 }
212}
Kurtis Charnockab709a02019-11-29 11:43:05 +0000213
214FIXTURE_DATA_TEST_CASE(RunSmallSplitShapes,
215 NESplitShapesFixture<float>,
216 framework::DatasetMode::PRECOMMIT,
217 combine(datasets::SmallSplitShapesDataset(), framework::dataset::make("DataType", DataType::F32)))
218{
219 // Validate outputs
220 for(unsigned int i = 0; i < _target.size(); ++i)
221 {
222 validate(Accessor(_target[i]), _reference[i]);
223 }
224}
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +0000225TEST_SUITE_END() // FP32
226TEST_SUITE_END() // Float
227
228TEST_SUITE_END() // Split
229TEST_SUITE_END() // NEON
230} // namespace validation
231} // namespace test
232} // namespace arm_compute