blob: 77363189cfe0d120bafc58af4694dadd688e00fe [file] [log] [blame]
Georgios Pinitase1a352c2018-09-03 12:42:19 +01001/*
2 * Copyright (c) 2018 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/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;
60 for(auto &output_info : outputs_info)
61 {
62 outputs_info_ptr.emplace_back(&output_info);
63 }
64 const Status status = CLSplit::validate(&input_info.clone()->set_is_resizable(false), outputs_info_ptr, axis);
65 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
66}
67// clang-format on
68// *INDENT-ON*
69
70DATA_TEST_CASE(Configuration,
71 framework::DatasetMode::ALL,
72 combine(datasets::SmallSplitDataset(), framework::dataset::make("DataType", { DataType::F16, DataType::F32 })),
73 shape, axis, splits, data_type)
74{
75 // Create tensors
76 CLTensor src = create_tensor<CLTensor>(shape, data_type);
77 std::vector<CLTensor> dsts(splits);
78 std::vector<ICLTensor *> dsts_ptrs;
79 for(auto &dst : dsts)
80 {
81 dsts_ptrs.emplace_back(&dst);
82 }
83
84 // Create and Configure function
85 CLSplit split;
86 split.configure(&src, dsts_ptrs, axis);
87
88 // Validate valid regions
89 for(auto &dst : dsts)
90 {
91 const ValidRegion valid_region = shape_to_valid_region(dst.info()->tensor_shape());
92 validate(dst.info()->valid_region(), valid_region);
93 }
94}
95
96template <typename T>
97using CLSplitFixture = SplitFixture<CLTensor, ICLTensor, CLAccessor, CLSplit, T>;
98
99TEST_SUITE(Float)
100TEST_SUITE(FP16)
101FIXTURE_DATA_TEST_CASE(RunSmall,
102 CLSplitFixture<half>,
103 framework::DatasetMode::PRECOMMIT,
104 combine(datasets::SmallSplitDataset(), framework::dataset::make("DataType", DataType::F16)))
105{
106 // Validate outputs
107 for(unsigned int i = 0; i < _target.size(); ++i)
108 {
109 validate(CLAccessor(_target[i]), _reference[i]);
110 }
111}
112
113FIXTURE_DATA_TEST_CASE(RunLarge,
114 CLSplitFixture<half>,
115 framework::DatasetMode::NIGHTLY,
116 combine(datasets::LargeSplitDataset(), framework::dataset::make("DataType", DataType::F16)))
117{
118 // Validate outputs
119 for(unsigned int i = 0; i < _target.size(); ++i)
120 {
121 validate(CLAccessor(_target[i]), _reference[i]);
122 }
123}
124TEST_SUITE_END() // FP16
125
126TEST_SUITE(FP32)
127FIXTURE_DATA_TEST_CASE(RunSmall,
128 CLSplitFixture<float>,
129 framework::DatasetMode::PRECOMMIT,
130 combine(datasets::SmallSplitDataset(), framework::dataset::make("DataType", DataType::F32)))
131{
132 // Validate outputs
133 for(unsigned int i = 0; i < _target.size(); ++i)
134 {
135 validate(CLAccessor(_target[i]), _reference[i]);
136 }
137}
138
139FIXTURE_DATA_TEST_CASE(RunLarge,
140 CLSplitFixture<float>,
141 framework::DatasetMode::NIGHTLY,
142 combine(datasets::LargeSplitDataset(), framework::dataset::make("DataType", DataType::F32)))
143{
144 // Validate outputs
145 for(unsigned int i = 0; i < _target.size(); ++i)
146 {
147 validate(CLAccessor(_target[i]), _reference[i]);
148 }
149}
150TEST_SUITE_END() // FP32
151TEST_SUITE_END() // Float
152
153TEST_SUITE_END() // Split
154TEST_SUITE_END() // CL
155} // namespace validation
156} // namespace test
157} // namespace arm_compute