Compute Library
 19.08
Select.cpp
Go to the documentation of this file.
1 /*
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 
25 #include "arm_compute/core/Types.h"
29 #include "tests/CL/CLAccessor.h"
31 #include "tests/datasets/ShapeDatasets.h"
33 #include "tests/framework/Macros.h"
36 #include "tests/validation/fixtures/SelectFixture.h"
37 
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 namespace
45 {
46 auto run_small_dataset = combine(datasets::SmallShapes(), framework::dataset::make("has_same_rank", { false, true }));
47 auto run_large_dataset = combine(datasets::LargeShapes(), framework::dataset::make("has_same_rank", { false, true }));
48 
49 } // namespace
50 TEST_SUITE(CL)
51 TEST_SUITE(Select)
52 
53 // *INDENT-OFF*
54 // clang-format off
55 DATA_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),
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 = CLSelect::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));
92 }
93 // clang-format on
94 // *INDENT-ON*
95 
96 template <typename T>
97 using CLSelectFixture = SelectValidationFixture<CLTensor, CLAccessor, CLSelect, T>;
98 
99 TEST_SUITE(Float)
100 TEST_SUITE(F16)
101 DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, run_small_dataset,
102  shape, same_rank)
103 {
104  const DataType dt = DataType::F16;
105 
106  // Create tensors
107  CLTensor ref_c = create_tensor<CLTensor>(detail::select_condition_shape(shape, same_rank), DataType::U8);
108  CLTensor ref_x = create_tensor<CLTensor>(shape, dt);
109  CLTensor ref_y = create_tensor<CLTensor>(shape, dt);
110  CLTensor dst = create_tensor<CLTensor>(shape, dt);
111 
112  // Create and Configure function
115 
116  // Validate valid region
119 
120  // Validate padding
121  const int step = 16 / arm_compute::data_size_from_type(dt);
122  const PaddingSize padding = PaddingCalculator(shape.x(), step).required_padding();
123  if(same_rank)
124  {
126  }
130 }
131 
136 {
137  // Validate output
138  validate(CLAccessor(_target), _reference);
139 }
140 
144  combine(run_large_dataset, framework::dataset::make("DataType", DataType::F16)))
145 {
146  // Validate output
147  validate(CLAccessor(_target), _reference);
148 }
149 TEST_SUITE_END() // F16
150 
151 TEST_SUITE(FP32)
152 DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, run_small_dataset,
153  shape, same_rank)
154 {
155  const DataType dt = DataType::F32;
156 
157  // Create tensors
158  CLTensor ref_c = create_tensor<CLTensor>(detail::select_condition_shape(shape, same_rank), DataType::U8);
159  CLTensor ref_x = create_tensor<CLTensor>(shape, dt);
160  CLTensor ref_y = create_tensor<CLTensor>(shape, dt);
161  CLTensor dst = create_tensor<CLTensor>(shape, dt);
162 
163  // Create and Configure function
166 
167  // Validate valid region
170 
171  // Validate padding
173  const PaddingSize padding = PaddingCalculator(shape.x(), step).required_padding();
175  {
177  }
181 }
182 
187 {
188  // Validate output
189  validate(CLAccessor(_target), _reference);
190 }
191 
195  combine(run_large_dataset, framework::dataset::make("DataType", DataType::F32)))
196 {
197  // Validate output
198  validate(CLAccessor(_target), _reference);
199 }
200 TEST_SUITE_END() // F32
201 TEST_SUITE_END() // Float
202 
203 TEST_SUITE(Quantized)
204 TEST_SUITE(QASYMM8)
205 DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, run_small_dataset,
206  shape, same_rank)
207 {
208  const DataType dt = DataType::QASYMM8;
209 
210  // Create tensors
211  CLTensor ref_c = create_tensor<CLTensor>(detail::select_condition_shape(shape, same_rank), DataType::U8);
212  CLTensor ref_x = create_tensor<CLTensor>(shape, dt);
213  CLTensor ref_y = create_tensor<CLTensor>(shape, dt);
214  CLTensor dst = create_tensor<CLTensor>(shape, dt);
215 
216  // Create and Configure function
219 
220  // Validate valid region
223 
224  // Validate padding
225  const int step = 16 / arm_compute::data_size_from_type(dt);
226  const PaddingSize padding = PaddingCalculator(shape.x(), step).required_padding();
227  if(same_rank)
228  {
230  }
234 }
235 
240 {
241  // Validate output
242  validate(CLAccessor(_target), _reference);
243 }
244 
248  combine(run_large_dataset, framework::dataset::make("DataType", DataType::QASYMM8)))
249 {
250  // Validate output
251  validate(CLAccessor(_target), _reference);
252 }
253 TEST_SUITE_END() // QASYMM8
254 TEST_SUITE_END() // Quantized
255 
256 TEST_SUITE_END() // Select
257 TEST_SUITE_END() // CL
258 } // namespace validation
259 } // namespace test
260 } // namespace arm_compute
Shape of a tensor.
Definition: TensorShape.h:39
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor's metadata.
Definition: CLTensor.cpp:35
static Status validate(const ITensorInfo *c, const ITensorInfo *x, const ITensorInfo *y, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLSelect.
Definition: CLSelect.cpp:41
Container for 2D border size.
Definition: Types.h:259
ValidRegion valid_region() const override
Valid region of the tensor.
Definition: TensorInfo.h:285
1 channel, 1 U8 per channel
1 channel, 1 F32 per channel
ARM_COMPUTE_EXPECT(has_error==expected, framework::LogLevel::ERRORS)
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
PaddingSize padding() const override
Padding of tensor.
Definition: TensorInfo.h:268
Copyright (c) 2017-2018 ARM Limited.
1 channel, 1 F16 per channel
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
quantized, asymmetric fixed-point 8-bit number
Accessor implementation for CLTensor objects.
Definition: CLAccessor.h:35
size_t data_size_from_type(DataType data_type)
The size in bytes of the data type.
Definition: Utils.h:109
void configure(const ICLTensor *c, const ICLTensor *x, const ICLTensor *y, ICLTensor *output)
Initialise the kernel's inputs and output.
Definition: CLSelect.cpp:34
FIXTURE_DATA_TEST_CASE(RunSmall, CLAbsLayerFixture< half >, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
Definition: AbsLayer.cpp:50
SelectValidationFixture< CLTensor, CLAccessor, CLSelect, T > CLSelectFixture
Definition: Select.cpp:97
validate(dst.info() ->valid_region(), valid_region)
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
Input data sets.
Definition: Unstack.cpp:96
Basic function to run CLSelect.
Definition: CLSelect.h:37
Store the tensor's metadata.
Definition: TensorInfo.h:45
Container for valid region of a window.
Definition: Types.h:174
zip(zip(framework::dataset::make("Weights", { TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U, 1U), 1, DataType::F32), }), framework::dataset::make("MVBGInfo",{ TensorInfo(TensorShape(2U), 1, DataType::F32), TensorInfo(TensorShape(2U), 1, DataType::F16), TensorInfo(TensorShape(5U), 1, DataType::F32), })), framework::dataset::make("Expected", { true, false, false}))
DataType
Available data types.
Definition: Types.h:74
signed 8-bit number
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65
TEST_SUITE(U8_to_S8) DATA_TEST_CASE(Configuration
ValidRegion shape_to_valid_region(const TensorShape &a_shape, bool border_undefined=false, BorderSize border_size=BorderSize(0))
Create a valid region based on tensor shape, border mode and border size.
Definition: Utils.h:221
Calculate required padding.
DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), AbsoluteDifferenceU8Dataset), shape, data_type0, data_type1, output_data_type)
Basic implementation of the OpenCL tensor interface.
Definition: CLTensor.h:40