blob: 9ac7a6f01357967ca36156d32dfa30927dc89293 [file] [log] [blame]
George Wort5801a552018-12-13 17:50:26 +00001/*
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 CONCLCTION 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/NESelect.h"
26#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
28#include "tests/NEON/Accessor.h"
29#include "tests/datasets/ShapeDatasets.h"
30#include "tests/framework/Asserts.h"
31#include "tests/framework/Macros.h"
32#include "tests/framework/datasets/Datasets.h"
33#include "tests/validation/Validation.h"
34#include "tests/validation/fixtures/SelectFixture.h"
35
36namespace arm_compute
37{
38namespace test
39{
40namespace validation
41{
42namespace
43{
44auto configuration_dataset = combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()),
45 framework::dataset::make("has_same_rank", { false, true }));
46auto run_small_dataset = combine(datasets::SmallShapes(), framework::dataset::make("has_same_rank", { false, true }));
47auto run_large_dataset = combine(datasets::LargeShapes(), framework::dataset::make("has_same_rank", { false, true }));
48} // namespace
49
50TEST_SUITE(NEON)
51TEST_SUITE(Select)
52
53// *INDENT-OFF*
54// clang-format off
55DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
56 framework::dataset::make("CInfo", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S8), // Invalid condition datatype
57 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid output datatype
58 TensorInfo(TensorShape(13U), 1, DataType::U8), // Invalid c shape
59 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Mismatching shapes
60 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
61 TensorInfo(TensorShape(2U), 1, DataType::U8),
62 }),
63 framework::dataset::make("XInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
64 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
65 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
66 TensorInfo(TensorShape(32U, 10U, 2U), 1, DataType::F32),
67 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
68 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
69 })),
70 framework::dataset::make("YInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
71 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
72 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
73 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
74 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
75 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
76 })),
77 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
78 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S8),
79 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
80 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
81 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
82 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
83 })),
84 framework::dataset::make("Expected", { false, false, false, false, true, true})),
85 c_info, x_info, y_info, output_info, expected)
86{
87 Status s = NESelect::validate(&c_info.clone()->set_is_resizable(false),
88 &x_info.clone()->set_is_resizable(false),
89 &y_info.clone()->set_is_resizable(false),
90 &output_info.clone()->set_is_resizable(false));
91 ARM_COMPUTE_EXPECT(bool(s) == expected, framework::LogLevel::ERRORS);
92}
93// clang-format on
94// *INDENT-ON*
95
96template <typename T>
97using NESelectFixture = SelectValidationFixture<Tensor, Accessor, NESelect, T>;
98
99TEST_SUITE(Float)
100
101#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
102TEST_SUITE(F16)
103DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, configuration_dataset,
104 shape, same_rank)
105{
106 const DataType dt = DataType::F16;
107
108 // Create tensors
109 Tensor ref_c = create_tensor<Tensor>(detail::select_condition_shape(shape, same_rank), DataType::U8);
110 Tensor ref_x = create_tensor<Tensor>(shape, dt);
111 Tensor ref_y = create_tensor<Tensor>(shape, dt);
112 Tensor dst = create_tensor<Tensor>(shape, dt);
113
114 // Create and Configure function
115 NESelect select;
116 select.configure(&ref_c, &ref_x, &ref_y, &dst);
117
118 // Validate valid region
119 const ValidRegion valid_region = shape_to_valid_region(shape);
120 validate(dst.info()->valid_region(), valid_region);
121}
122
123FIXTURE_DATA_TEST_CASE(RunSmall,
124 NESelectFixture<half>,
125 framework::DatasetMode::PRECOMMIT,
126 combine(run_small_dataset, framework::dataset::make("DataType", DataType::F16)))
127{
128 // Validate output
129 validate(Accessor(_target), _reference);
130}
131
132FIXTURE_DATA_TEST_CASE(RunLarge,
133 NESelectFixture<half>,
134 framework::DatasetMode::NIGHTLY,
135 combine(run_large_dataset, framework::dataset::make("DataType", DataType::F16)))
136{
137 // Validate output
138 validate(Accessor(_target), _reference);
139}
140TEST_SUITE_END() // F16
141#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
142
143TEST_SUITE(FP32)
144DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, configuration_dataset,
145 shape, same_rank)
146{
147 const DataType dt = DataType::F32;
148
149 // Create tensors
150 Tensor ref_c = create_tensor<Tensor>(detail::select_condition_shape(shape, same_rank), DataType::U8);
151 Tensor ref_x = create_tensor<Tensor>(shape, dt);
152 Tensor ref_y = create_tensor<Tensor>(shape, dt);
153 Tensor dst = create_tensor<Tensor>(shape, dt);
154
155 // Create and Configure function
156 NESelect select;
157 select.configure(&ref_c, &ref_x, &ref_y, &dst);
158
159 // Validate valid region
160 const ValidRegion valid_region = shape_to_valid_region(shape);
161 validate(dst.info()->valid_region(), valid_region);
162}
163
164FIXTURE_DATA_TEST_CASE(RunSmall,
165 NESelectFixture<float>,
166 framework::DatasetMode::PRECOMMIT,
167 combine(run_small_dataset, framework::dataset::make("DataType", DataType::F32)))
168{
169 // Validate output
170 validate(Accessor(_target), _reference);
171}
172
173FIXTURE_DATA_TEST_CASE(RunLarge,
174 NESelectFixture<float>,
175 framework::DatasetMode::NIGHTLY,
176 combine(run_large_dataset, framework::dataset::make("DataType", DataType::F32)))
177{
178 // Validate output
179 validate(Accessor(_target), _reference);
180}
181TEST_SUITE_END() // FP32
182TEST_SUITE_END() // Float
183
184TEST_SUITE_END() // Select
185TEST_SUITE_END() // NEON
186} // namespace validation
187} // namespace test
188} // namespace arm_compute