Compute Library
 22.11
ElementwiseMax.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2021 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"
29 #include "tests/datasets/ShapeDatasets.h"
31 #include "tests/framework/Macros.h"
34 #include "tests/validation/fixtures/ElementwiseOperationsFixture.h"
35 
36 namespace arm_compute
37 {
38 namespace test
39 {
40 namespace validation
41 {
42 namespace
43 {
44 constexpr RelativeTolerance<float> tolerance_fp32(0.000001f);
45 constexpr AbsoluteTolerance<int8_t> tolerance_qasymm8_signed(1);
46 /** Input data sets **/
47 const auto ElementwiseMaxQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)),
48  framework::dataset::make("DataType",
50 const auto ElementwiseMaxQASYMM8SignedDataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8_SIGNED), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
51  framework::dataset::make("DataType",
53 
54 /** Input data sets **/
55 const auto ElementwiseMaxS32Dataset = combine(combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("DataType",
56  DataType::S32));
57 const auto ElementwiseMaxS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
59 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
60 const auto ElementwiseMaxFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
62 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
63 const auto ElementwiseMaxFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
65 const auto InPlaceDataSet = framework::dataset::make("InPlace", { false, true });
66 const auto OutOfPlaceDataSet = framework::dataset::make("InPlace", { false });
67 } // namespace
68 
69 TEST_SUITE(NEON)
70 TEST_SUITE(ElementwiseMax)
71 
72 template <typename T>
73 using NEElementwiseMaxFixture = ElementwiseMaxValidationFixture<Tensor, Accessor, NEElementwiseMax, T>;
74 
75 // *INDENT-OFF*
76 // clang-format off
78  framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
79  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
80  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32),
81  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), // Invalid data type combination
82  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
84  TensorInfo(TensorShape(8U, 8U, 3U), 1, DataType::QASYMM8_SIGNED), // Mismatching data types
85  }),
86  framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
87  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
88  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32),
89  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
90  TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
93  })),
94  framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
95  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
96  TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32),
97  TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
98  TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
101  })),
102 
103  framework::dataset::make("Expected", { true, true, true, false, false, true, false, false })),
105 {
107  &input1_info.clone()->set_is_resizable(false),
108  &input2_info.clone()->set_is_resizable(false),
109  &output_info.clone()->set_is_resizable(false))
111 }
112 // clang-format on
113 // *INDENT-ON*
114 
116 FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxFixture<int32_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ElementwiseMaxS32Dataset),
117  InPlaceDataSet))
118 {
119  // Validate output
120  validate(Accessor(_target), _reference);
121 }
122 TEST_SUITE_END() // S32
123 
125 FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwiseMaxS16Dataset),
126  InPlaceDataSet))
127 {
128  // Validate output
129  validate(Accessor(_target), _reference);
130 }
131 TEST_SUITE_END() // S16
132 
133 template <typename T>
134 using NEElementwiseMaxQuantizedFixture = ElementwiseMaxValidationQuantizedFixture<Tensor, Accessor, NEElementwiseMax, T>;
135 
136 TEST_SUITE(Quantized)
138 FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(),
139  ElementwiseMaxQASYMM8Dataset),
140  framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
141  framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
142  framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) })),
143  OutOfPlaceDataSet))
144 {
145  // Validate output
146  validate(Accessor(_target), _reference, tolerance_fp32, 0.01);
147 }
148 
149 template <typename T>
150 using NEElementwiseMaxQuantizedBroadcastFixture = ElementwiseMaxQuantizedBroadcastValidationFixture<Tensor, Accessor, NEElementwiseMax, T>;
151 
153  combine(combine(combine(combine(combine(datasets::SmallShapesBroadcast(),
154  ElementwiseMaxQASYMM8Dataset),
155  framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
156  framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
157  framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) })),
158  OutOfPlaceDataSet))
159 {
160  // Validate output
161  validate(Accessor(_target), _reference);
162 }
164 
166 FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(),
167  ElementwiseMaxQASYMM8SignedDataset),
168  framework::dataset::make("QuantizationInfo", { QuantizationInfo(10.f, 20) })),
169  framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f, 0) })),
170  framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f, -27) })),
171  OutOfPlaceDataSet))
172 {
173  // Validate output
174  validate(Accessor(_target), _reference, tolerance_qasymm8_signed);
175 }
176 FIXTURE_DATA_TEST_CASE(RunSmallInPlace, NEElementwiseMaxQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(),
177  ElementwiseMaxQASYMM8SignedDataset),
178  framework::dataset::make("QuantizationInfo", { QuantizationInfo(10.f, -20) })),
179  framework::dataset::make("QuantizationInfo", { QuantizationInfo(10.f, -20) })),
180  framework::dataset::make("QuantizationInfo", { QuantizationInfo(10.f, -20) })),
181  InPlaceDataSet))
182 {
183  // Validate output
184  validate(Accessor(_target), _reference, tolerance_qasymm8_signed);
185 }
187 
189 
190 TEST_SUITE(Float)
191 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
193 FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwiseMaxFP16Dataset),
194  InPlaceDataSet))
195 {
196  // Validate output
197  validate(Accessor(_target), _reference);
198 }
199 TEST_SUITE_END() // F16
200 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
201 
203 FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwiseMaxFP32Dataset),
204  InPlaceDataSet))
205 {
206  // Validate output
207  validate(Accessor(_target), _reference);
208 }
209 template <typename T>
210 using NEElementwiseMaxBroadcastFixture = ElementwiseMaxBroadcastValidationFixture<Tensor, Accessor, NEElementwiseMax, T>;
211 
213  ElementwiseMaxFP32Dataset),
214  OutOfPlaceDataSet))
215 {
216  // Validate output
217  validate(Accessor(_target), _reference);
218 }
219 FIXTURE_DATA_TEST_CASE(RunTinyBroadcastInPlace, NEElementwiseMaxBroadcastFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapesBroadcastInplace(),
220  ElementwiseMaxFP32Dataset),
221  InPlaceDataSet))
222 {
223  // Validate output
224  validate(Accessor(_target), _reference);
225 }
226 TEST_SUITE_END() // F32
227 TEST_SUITE_END() // Float
228 
229 TEST_SUITE_END() // ElementwiseMax
230 TEST_SUITE_END() // Neon
231 } // namespace validation
232 } // namespace test
233 } // namespace arm_compute
Shape of a tensor.
Definition: TensorShape.h:39
1 channel, 1 F32 per channel
ARM_COMPUTE_EXPECT(has_error==expected, framework::LogLevel::ERRORS)
ElementwiseMaxBroadcastValidationFixture< Tensor, Accessor, NEElementwiseMax, T > NEElementwiseMaxBroadcastFixture
constexpr AbsoluteTolerance< int8_t > tolerance_qasymm8_signed
Definition: Scale.cpp:550
std::enable_if< is_container< T >::value, ContainerDataset< T > >::type make(std::string name, T &&values)
Helper function to create a ContainerDataset.
RelativeTolerance< float > tolerance_fp32(0.001f)
Copyright (c) 2017-2022 Arm Limited.
1 channel, 1 F16 per channel
1 channel, 1 S32 per channel
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of cpu::kernels::CpuArithme...
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]
quantized, asymmetric fixed-point 8-bit number unsigned
ElementwiseMaxQuantizedBroadcastValidationFixture< Tensor, Accessor, NEElementwiseMax, T > NEElementwiseMaxQuantizedBroadcastFixture
validate(CLAccessor(output_state), expected_output)
1 channel, 1 S16 per channel
FIXTURE_DATA_TEST_CASE(RunSmall, CLAbsLayerFixture< half >, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
Definition: AbsLayer.cpp:50
ElementwiseMaxValidationFixture< Tensor, Accessor, NEElementwiseMax, T > NEElementwiseMaxFixture
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
combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
Definition: AbsLayer.cpp:65