blob: e5b07fdbb7bae1cae4c5a0ee22b7bd9d33686d5d [file] [log] [blame]
Georgios Pinitas7900a9e2018-11-23 11:44:58 +00001/*
Michalis Spyrou80943252019-01-10 17:19:50 +00002 * Copyright (c) 2018-2019 ARM Limited.
Georgios Pinitas7900a9e2018-11-23 11:44:58 +00003 *
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/CLComparison.h"
28#include "tests/CL/CLAccessor.h"
29#include "tests/PaddingCalculator.h"
30#include "tests/datasets/ComparisonOperationsDataset.h"
31#include "tests/datasets/ShapeDatasets.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Macros.h"
34#include "tests/framework/datasets/Datasets.h"
35#include "tests/validation/Validation.h"
36#include "tests/validation/fixtures/ComparisonFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
Michalis Spyrou80943252019-01-10 17:19:50 +000046const auto configure_dataset = combine(datasets::SmallShapes(),
Georgios Pinitas7900a9e2018-11-23 11:44:58 +000047 framework::dataset::make("DataType", { DataType::QASYMM8, DataType::F16, DataType::F32 }));
48
49const auto run_small_dataset = combine(datasets::ComparisonOperations(), datasets::SmallShapes());
50const auto run_large_dataset = combine(datasets::ComparisonOperations(), datasets::LargeShapes());
51
52} // namespace
53
54TEST_SUITE(CL)
55TEST_SUITE(Comparison)
56
57// *INDENT-OFF*
58// clang-format off
59DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
60 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Invalid output type
61 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching input types
62 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Window shrink
63 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
64 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
65 }),
66 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
67 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
68 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
69 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
70 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
71 })),
72 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
73 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
74 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
75 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::U8),
76 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
77 })),
78 framework::dataset::make("Expected", { false, false, false, false, true})),
79 input1_info, input2_info, output_info, expected)
80{
81 Status s = CLComparison::validate(&input1_info.clone()->set_is_resizable(false),
82 &input2_info.clone()->set_is_resizable(false),
83 &output_info.clone()->set_is_resizable(false),
84 ComparisonOperation::Equal);
85 ARM_COMPUTE_EXPECT(bool(s) == expected, framework::LogLevel::ERRORS);
86}
87// clang-format on
88// *INDENT-ON*
89
90DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, configure_dataset,
91 shape, data_type)
92{
93 // Create tensors
94 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
95 CLTensor ref_src2 = create_tensor<CLTensor>(shape, data_type);
96 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
97
98 // Create and Configure function
99 CLComparison compare;
100 compare.configure(&ref_src1, &ref_src2, &dst, ComparisonOperation::Equal);
101
102 // Validate valid region
103 const ValidRegion valid_region = shape_to_valid_region(shape);
104 validate(dst.info()->valid_region(), valid_region);
105
106 const int num_elems_processed_per_iteration = 16 / ref_src1.info()->element_size();
107
108 // Validate padding
109 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
110 validate(ref_src1.info()->padding(), padding);
111 validate(ref_src2.info()->padding(), padding);
112 validate(dst.info()->padding(), padding);
113}
114
115template <typename T>
116using CLComparisonFixture = ComparisonValidationFixture<CLTensor, CLAccessor, CLComparison, T>;
117
118TEST_SUITE(Float)
119TEST_SUITE(FP16)
120FIXTURE_DATA_TEST_CASE(RunSmall,
121 CLComparisonFixture<half>,
122 framework::DatasetMode::PRECOMMIT,
123 combine(run_small_dataset, framework::dataset::make("DataType", DataType::F16)))
124{
125 // Validate output
126 validate(CLAccessor(_target), _reference);
127}
128FIXTURE_DATA_TEST_CASE(RunLarge,
129 CLComparisonFixture<half>,
130 framework::DatasetMode::NIGHTLY,
131 combine(run_large_dataset, framework::dataset::make("DataType", DataType::F16)))
132{
133 // Validate output
134 validate(CLAccessor(_target), _reference);
135}
136TEST_SUITE_END() // FP16
137
138TEST_SUITE(FP32)
139FIXTURE_DATA_TEST_CASE(RunSmall,
140 CLComparisonFixture<float>,
141 framework::DatasetMode::PRECOMMIT,
142 combine(run_small_dataset, framework::dataset::make("DataType", DataType::F32)))
143{
144 // Validate output
145 validate(CLAccessor(_target), _reference);
146}
147FIXTURE_DATA_TEST_CASE(RunLarge,
148 CLComparisonFixture<float>,
149 framework::DatasetMode::NIGHTLY,
150 combine(run_large_dataset, framework::dataset::make("DataType", DataType::F32)))
151{
152 // Validate output
153 validate(CLAccessor(_target), _reference);
154}
155TEST_SUITE_END() // FP32
156TEST_SUITE_END() // Float
157
158template <typename T>
159using CLComparisonQuantizedFixture = ComparisonValidationQuantizedFixture<CLTensor, CLAccessor, CLComparison, T>;
160
161TEST_SUITE(Quantized)
162TEST_SUITE(QASYMM8)
163FIXTURE_DATA_TEST_CASE(RunSmall,
164 CLComparisonQuantizedFixture<uint8_t>,
165 framework::DatasetMode::PRECOMMIT,
166 combine(combine(combine(run_small_dataset, framework::dataset::make("DataType", DataType::QASYMM8)),
167 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
168 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })))
169{
170 // Validate output
171 validate(CLAccessor(_target), _reference);
172}
173TEST_SUITE_END()
174TEST_SUITE_END()
175
176TEST_SUITE_END() // Comparison
177TEST_SUITE_END() // CL
178} // namespace validation
179} // namespace test
180} // namespace arm_compute