blob: 91b3b9a0472aa77bb02f378583808b357920e53f [file] [log] [blame]
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +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/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}
68// clang-format on
69// *INDENT-ON*
70
71DATA_TEST_CASE(Configuration,
72 framework::DatasetMode::ALL,
73 combine(datasets::SmallSplitDataset(), framework::dataset::make("DataType", { DataType::QASYMM8, DataType::F32 })),
74 shape, axis, splits, data_type)
75{
76 // Create tensors
77 Tensor src = create_tensor<Tensor>(shape, data_type);
78 std::vector<Tensor> dsts(splits);
79 std::vector<ITensor *> dsts_ptrs;
Michalis Spyroubcfd09a2019-05-01 13:03:59 +010080 dsts_ptrs.reserve(splits);
Georgios Pinitas6d9d6f42018-12-24 16:10:47 +000081 for(auto &dst : dsts)
82 {
83 dsts_ptrs.emplace_back(&dst);
84 }
85
86 // Create and Configure function
87 NESplit split;
88 split.configure(&src, dsts_ptrs, axis);
89
90 // Validate valid regions
91 for(auto &dst : dsts)
92 {
93 const ValidRegion valid_region = shape_to_valid_region(dst.info()->tensor_shape());
94 validate(dst.info()->valid_region(), valid_region);
95 }
96}
97
98template <typename T>
99using NESplitFixture = SplitFixture<Tensor, ITensor, Accessor, NESplit, T>;
100
101TEST_SUITE(Float)
102#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
103TEST_SUITE(FP16)
104FIXTURE_DATA_TEST_CASE(RunSmall,
105 NESplitFixture<half>,
106 framework::DatasetMode::PRECOMMIT,
107 combine(datasets::SmallSplitDataset(), framework::dataset::make("DataType", DataType::F16)))
108{
109 // Validate outputs
110 for(unsigned int i = 0; i < _target.size(); ++i)
111 {
112 validate(Accessor(_target[i]), _reference[i]);
113 }
114}
115
116FIXTURE_DATA_TEST_CASE(RunLarge,
117 NESplitFixture<half>,
118 framework::DatasetMode::NIGHTLY,
119 combine(datasets::LargeSplitDataset(), framework::dataset::make("DataType", DataType::F16)))
120{
121 // Validate outputs
122 for(unsigned int i = 0; i < _target.size(); ++i)
123 {
124 validate(Accessor(_target[i]), _reference[i]);
125 }
126}
127TEST_SUITE_END() // FP16
128#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
129
130TEST_SUITE(FP32)
131FIXTURE_DATA_TEST_CASE(RunSmall,
132 NESplitFixture<float>,
133 framework::DatasetMode::PRECOMMIT,
134 combine(datasets::SmallSplitDataset(), framework::dataset::make("DataType", DataType::F32)))
135{
136 // Validate outputs
137 for(unsigned int i = 0; i < _target.size(); ++i)
138 {
139 validate(Accessor(_target[i]), _reference[i]);
140 }
141}
142
143FIXTURE_DATA_TEST_CASE(RunLarge,
144 NESplitFixture<float>,
145 framework::DatasetMode::NIGHTLY,
146 combine(datasets::LargeSplitDataset(), framework::dataset::make("DataType", DataType::F32)))
147{
148 // Validate outputs
149 for(unsigned int i = 0; i < _target.size(); ++i)
150 {
151 validate(Accessor(_target[i]), _reference[i]);
152 }
153}
154TEST_SUITE_END() // FP32
155TEST_SUITE_END() // Float
156
157TEST_SUITE_END() // Split
158TEST_SUITE_END() // NEON
159} // namespace validation
160} // namespace test
161} // namespace arm_compute