Compute Library
 22.11
Comparisons.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020 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"
28 #include "tests/NEON/Accessor.h"
30 #include "tests/datasets/ComparisonOperationsDataset.h"
31 #include "tests/datasets/ShapeDatasets.h"
33 #include "tests/framework/Macros.h"
36 #include "tests/validation/fixtures/ComparisonFixture.h"
37 
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 namespace
45 {
46 const auto run_small_dataset = combine(datasets::ComparisonOperations(), datasets::SmallShapes());
47 const auto run_small_broadcast_dataset = combine(datasets::ComparisonOperations(), datasets::SmallShapesBroadcast());
48 const auto run_large_dataset = combine(datasets::ComparisonOperations(), datasets::LargeShapes());
49 
50 } // namespace
51 
52 TEST_SUITE(NEON)
53 TEST_SUITE(Comparison)
54 
55 // *INDENT-OFF*
56 // clang-format off
57 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
58  framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Invalid output type
59  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching input types
60  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
61  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
62  }),
63  framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
64  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
65  TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
66  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
67  })),
68  framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
69  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
70  TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::U8),
71  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
72  })),
73  framework::dataset::make("Expected", { false, false, false, true})),
75 {
76  Status s = NEElementwiseComparison::validate(&input1_info.clone()->set_is_resizable(false),
77  &input2_info.clone()->set_is_resizable(false),
78  &output_info.clone()->set_is_resizable(false),
81 }
82 // clang-format on
83 // *INDENT-ON*
84 
85 template <typename T>
86 using NEComparisonFixture = ComparisonValidationFixture<Tensor, Accessor, NEElementwiseComparison, T>;
87 
88 TEST_SUITE(Bool)
90  NEComparisonFixture<uint8_t>,
91  framework::DatasetMode::PRECOMMIT,
92  combine(run_small_dataset, framework::dataset::make("DataType", DataType::U8)))
93 {
94  // Validate output
95  validate(Accessor(_target), _reference);
96 }
98 
99 TEST_SUITE(Float)
100 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
101 TEST_SUITE(FP16)
102 FIXTURE_DATA_TEST_CASE(RunSmall,
105  combine(run_small_dataset, framework::dataset::make("DataType", DataType::F16)))
106 {
107  // Validate output
108  validate(Accessor(_target), _reference);
109 }
110 FIXTURE_DATA_TEST_CASE(RunLarge,
113  combine(run_large_dataset, framework::dataset::make("DataType", DataType::F16)))
114 {
115  // Validate output
116  validate(Accessor(_target), _reference);
117 }
118 TEST_SUITE_END() // FP16
119 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
120 
121 TEST_SUITE(FP32)
123  NEComparisonFixture<float>,
124  framework::DatasetMode::PRECOMMIT,
125  combine(run_small_dataset, framework::dataset::make("DataType", DataType::F32)))
126 {
127  // Validate output
128  validate(Accessor(_target), _reference);
129 }
133  combine(run_large_dataset, framework::dataset::make("DataType", DataType::F32)))
134 {
135  // Validate output
136  validate(Accessor(_target), _reference);
137 }
138 TEST_SUITE_END() // FP32
139 TEST_SUITE_END() // Float
140 
141 template <typename T>
142 using NEComparisonQuantizedFixture = ComparisonValidationQuantizedFixture<Tensor, Accessor, NEElementwiseComparison, T>;
143 template <typename T>
144 using NEComparisonQuantizedBroadcastFixture = ComparisonQuantizedBroadcastValidationFixture<Tensor, Accessor, NEElementwiseComparison, T>;
145 
146 TEST_SUITE(Quantized)
147 TEST_SUITE(QASYMM8)
149  NEComparisonQuantizedFixture<uint8_t>,
150  framework::DatasetMode::PRECOMMIT,
151  combine(combine(combine(run_small_dataset, framework::dataset::make("DataType", DataType::QASYMM8)),
152  framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
153  framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })))
154 {
155  // Validate output
156  validate(Accessor(_target), _reference);
157 }
160 FIXTURE_DATA_TEST_CASE(RunSmallBroadcast,
162  framework::DatasetMode::ALL,
163  combine(combine(combine(run_small_broadcast_dataset, framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
164  framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.1, -30) })),
165  framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.3f, 2) })))
166 {
167  // Validate output
168  validate(Accessor(_target), _reference);
169 }
170 
172  NEComparisonQuantizedFixture<int8_t>,
175  framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.1, -30) })),
176  framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.3f, 2) })))
177 {
178  // Validate output
179  validate(Accessor(_target), _reference);
180 }
183 
184 TEST_SUITE_END() // Comparison
185 TEST_SUITE_END() // CL
186 } // namespace validation
187 } // namespace test
188 } // namespace arm_compute
Shape of a tensor.
Definition: TensorShape.h:39
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ComparisonOperation op)
Static function to check if given info will lead to a valid configuration of cpu::kernels::CpuCompari...
ComparisonValidationFixture< Tensor, Accessor, NEElementwiseComparison, T > NEComparisonFixture
Definition: Comparisons.cpp:86
1 channel, 1 U8 per channel
ComparisonQuantizedBroadcastValidationFixture< Tensor, Accessor, NEElementwiseComparison, T > NEComparisonQuantizedBroadcastFixture
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.
Status class.
Definition: Error.h:52
Copyright (c) 2017-2022 Arm Limited.
1 channel, 1 F16 per channel
1 channel, 1 S32 per channel
Quantization information.
DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16), }), framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QSYMM16, QuantizationInfo(1.f/32768.f, 0)), })), framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::TANH), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC), ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::SQRT), })), framework::dataset::make("Expected", { false, true, true, true, false, false, true, true, false })), input_info, output_info, act_info, expected)
Accessor implementation for Tensor objects.
Definition: Accessor.h:35
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
validate(CLAccessor(output_state), expected_output)
FIXTURE_DATA_TEST_CASE(RunSmall, CLAbsLayerFixture< half >, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
Definition: AbsLayer.cpp:50
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:43
quantized, asymmetric fixed-point 8-bit number signed
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}))
TEST_SUITE(QASYMM8_to_F32) FIXTURE_DATA_TEST_CASE(RunSmall
DataType
Available data types.
Definition: Types.h:79
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65