blob: 7e6c6f9e92cab0bedfc106cc22c1d36fc74f0c17 [file] [log] [blame]
Georgios Pinitase1a352c2018-09-03 12:42:19 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Georgios Pinitase1a352c2018-09-03 12:42:19 +01003 *
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/CLSplit.h"
28
29#include "tests/CL/CLAccessor.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(CL)
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 Pinitase1a352c2018-09-03 12:42:19 +010061 for(auto &output_info : outputs_info)
62 {
63 outputs_info_ptr.emplace_back(&output_info);
64 }
65 const Status status = CLSplit::validate(&input_info.clone()->set_is_resizable(false), outputs_info_ptr, axis);
66 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
67}
Kurtis Charnockec00da12019-11-29 11:42:30 +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 = CLSplit::validate(&input_info.clone()->set_is_resizable(false), outputs_info_ptr, axis);
89 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
90}
Georgios Pinitase1a352c2018-09-03 12:42:19 +010091// clang-format on
92// *INDENT-ON*
93
Georgios Pinitase1a352c2018-09-03 12:42:19 +010094template <typename T>
95using CLSplitFixture = SplitFixture<CLTensor, ICLTensor, CLAccessor, CLSplit, T>;
96
Kurtis Charnockec00da12019-11-29 11:42:30 +000097template <typename T>
98using CLSplitShapesFixture = SplitShapesFixture<CLTensor, ICLTensor, CLAccessor, CLSplit, T>;
99
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100100TEST_SUITE(Float)
101TEST_SUITE(FP16)
102FIXTURE_DATA_TEST_CASE(RunSmall,
103 CLSplitFixture<half>,
104 framework::DatasetMode::PRECOMMIT,
105 combine(datasets::SmallSplitDataset(), framework::dataset::make("DataType", DataType::F16)))
106{
107 // Validate outputs
108 for(unsigned int i = 0; i < _target.size(); ++i)
109 {
110 validate(CLAccessor(_target[i]), _reference[i]);
111 }
112}
113
114FIXTURE_DATA_TEST_CASE(RunLarge,
115 CLSplitFixture<half>,
116 framework::DatasetMode::NIGHTLY,
117 combine(datasets::LargeSplitDataset(), framework::dataset::make("DataType", DataType::F16)))
118{
119 // Validate outputs
120 for(unsigned int i = 0; i < _target.size(); ++i)
121 {
122 validate(CLAccessor(_target[i]), _reference[i]);
123 }
124}
Michalis Spyroud175ece2020-07-30 23:39:32 +0100125
126FIXTURE_DATA_TEST_CASE(RunSmallSplitShapes,
127 CLSplitShapesFixture<half>,
128 framework::DatasetMode::PRECOMMIT,
129 combine(datasets::SmallSplitShapesDataset(), framework::dataset::make("DataType", DataType::F16)))
130{
131 // Validate outputs
132 for(unsigned int i = 0; i < _target.size(); ++i)
133 {
134 validate(CLAccessor(_target[i]), _reference[i]);
135 }
136}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100137TEST_SUITE_END() // FP16
138
139TEST_SUITE(FP32)
140FIXTURE_DATA_TEST_CASE(RunSmall,
141 CLSplitFixture<float>,
142 framework::DatasetMode::PRECOMMIT,
143 combine(datasets::SmallSplitDataset(), framework::dataset::make("DataType", DataType::F32)))
144{
145 // Validate outputs
146 for(unsigned int i = 0; i < _target.size(); ++i)
147 {
148 validate(CLAccessor(_target[i]), _reference[i]);
149 }
150}
151
152FIXTURE_DATA_TEST_CASE(RunLarge,
153 CLSplitFixture<float>,
154 framework::DatasetMode::NIGHTLY,
155 combine(datasets::LargeSplitDataset(), framework::dataset::make("DataType", DataType::F32)))
156{
157 // Validate outputs
158 for(unsigned int i = 0; i < _target.size(); ++i)
159 {
160 validate(CLAccessor(_target[i]), _reference[i]);
161 }
162}
Kurtis Charnockec00da12019-11-29 11:42:30 +0000163
164FIXTURE_DATA_TEST_CASE(RunSmallSplitShapes,
165 CLSplitShapesFixture<float>,
166 framework::DatasetMode::PRECOMMIT,
167 combine(datasets::SmallSplitShapesDataset(), framework::dataset::make("DataType", DataType::F32)))
168{
169 // Validate outputs
170 for(unsigned int i = 0; i < _target.size(); ++i)
171 {
172 validate(CLAccessor(_target[i]), _reference[i]);
173 }
174}
Georgios Pinitase1a352c2018-09-03 12:42:19 +0100175TEST_SUITE_END() // FP32
176TEST_SUITE_END() // Float
177
178TEST_SUITE_END() // Split
179TEST_SUITE_END() // CL
180} // namespace validation
181} // namespace test
182} // namespace arm_compute