xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/CL/ArithmeticDivision.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
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"
25 #include "arm_compute/runtime/CL/CLTensor.h"
26 #include "arm_compute/runtime/CL/CLTensorAllocator.h"
27 #include "arm_compute/runtime/CL/functions/CLElementwiseOperations.h"
28 #include "tests/CL/CLAccessor.h"
29 #include "tests/PaddingCalculator.h"
30 #include "tests/datasets/ConvertPolicyDataset.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/ElementwiseOperationsFixture.h"
37 
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 namespace
45 {
46 RelativeTolerance<float> tolerance_fp32(0.000001f);
47 RelativeTolerance<float> tolerance_fp16(0.001f);
48 
49 /** Input data sets **/
50 const auto ArithmeticDivisionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
51                                                    framework::dataset::make("DataType", DataType::F16));
52 const auto ArithmeticDivisionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
53                                                    framework::dataset::make("DataType", DataType::F32));
54 const auto ArithmeticDivisionS32Dataset = combine(combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::S32)),
55                                                   framework::dataset::make("DataType", DataType::S32));
56 const auto EmptyActivationFunctionsDataset = framework::dataset::make("ActivationInfo", { ActivationLayerInfo() });
57 const auto ActivationFunctionsDataset      = framework::dataset::make("ActivationInfo",
58 {
59     ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.75f, 0.25f),
60     ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC, 0.75f, 0.25f)
61 });
62 const auto InPlaceDataSet    = framework::dataset::make("InPlace", { false, true });
63 const auto OutOfPlaceDataSet = framework::dataset::make("InPlace", { false });
64 } // namespace
65 
66 TEST_SUITE(CL)
TEST_SUITE(ArithmeticDivision)67 TEST_SUITE(ArithmeticDivision)
68 
69 // *INDENT-OFF*
70 // clang-format off
71 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
72                framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
73                                                         TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
74                                                         TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),      // Invalid data type combination
75                                                         TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),     // Mismatching shapes
76                                                       }),
77                framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
78                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16),
79                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
80                                                        TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
81                                                      })),
82                framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
83                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
84                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
85                                                        TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
86                                                      })),
87                framework::dataset::make("Expected", { true, false, false, false})),
88                input1_info, input2_info, output_info, expected)
89 {
90     ARM_COMPUTE_EXPECT(bool(CLArithmeticDivision::validate(&input1_info.clone()->set_is_resizable(false), &input2_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS);
91 }
92 // clang-format on
93 // *INDENT-ON*
94 
95 using CLArithmeticDivisionIntegerFixture = ArithmeticDivisionValidationIntegerFixture<CLTensor, CLAccessor, CLArithmeticDivision, int>;
96 
97 TEST_SUITE(Integer)
TEST_SUITE(S32)98 TEST_SUITE(S32)
99 
100 FIXTURE_DATA_TEST_CASE(RunSmallInteger, CLArithmeticDivisionIntegerFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), ArithmeticDivisionS32Dataset),
101                                                                                                                        EmptyActivationFunctionsDataset),
102                                                                                                                        InPlaceDataSet))
103 {
104     // Validate output
105     validate(CLAccessor(_target), _reference);
106 }
FIXTURE_DATA_TEST_CASE(RunIntegerWithActivation,CLArithmeticDivisionIntegerFixture,framework::DatasetMode::ALL,combine (combine (combine (datasets::SmallShapes (),ArithmeticDivisionS32Dataset),ActivationFunctionsDataset),InPlaceDataSet))107 FIXTURE_DATA_TEST_CASE(RunIntegerWithActivation, CLArithmeticDivisionIntegerFixture, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), ArithmeticDivisionS32Dataset),
108                        ActivationFunctionsDataset),
109                        InPlaceDataSet))
110 {
111     // Validate output
112     validate(CLAccessor(_target), _reference);
113 }
114 
115 TEST_SUITE_END()
116 TEST_SUITE_END()
117 
118 template <typename T>
119 using CLArithmeticDivisionFloatFixture = ArithmeticDivisionValidationFloatFixture<CLTensor, CLAccessor, CLArithmeticDivision, T>;
120 
121 TEST_SUITE(Float)
TEST_SUITE(FP16)122 TEST_SUITE(FP16)
123 FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticDivisionFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), ArithmeticDivisionFP16Dataset),
124                                                                                                                       EmptyActivationFunctionsDataset),
125                                                                                                               InPlaceDataSet))
126 {
127     // Validate output
128     validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
129 }
FIXTURE_DATA_TEST_CASE(RunWithActivation,CLArithmeticDivisionFloatFixture<half>,framework::DatasetMode::ALL,combine (combine (combine (datasets::TinyShapes (),ArithmeticDivisionFP16Dataset),ActivationFunctionsDataset),InPlaceDataSet))130 FIXTURE_DATA_TEST_CASE(RunWithActivation, CLArithmeticDivisionFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::TinyShapes(), ArithmeticDivisionFP16Dataset),
131                                                                                                                        ActivationFunctionsDataset),
132                                                                                                                        InPlaceDataSet))
133 {
134     // Validate output
135     validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
136 }
137 TEST_SUITE_END()
138 
TEST_SUITE(FP32)139 TEST_SUITE(FP32)
140 FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticDivisionFloatFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), ArithmeticDivisionFP32Dataset),
141                                                                                                                      EmptyActivationFunctionsDataset),
142                                                                                                                      InPlaceDataSet))
143 {
144     // Validate output
145     validate(CLAccessor(_target), _reference, tolerance_fp32);
146 }
FIXTURE_DATA_TEST_CASE(RunWithActivation,CLArithmeticDivisionFloatFixture<float>,framework::DatasetMode::ALL,combine (combine (combine (datasets::TinyShapes (),ArithmeticDivisionFP32Dataset),ActivationFunctionsDataset),InPlaceDataSet))147 FIXTURE_DATA_TEST_CASE(RunWithActivation, CLArithmeticDivisionFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::TinyShapes(), ArithmeticDivisionFP32Dataset),
148                                                                                                                         ActivationFunctionsDataset),
149                                                                                                                         InPlaceDataSet))
150 {
151     // Validate output
152     validate(CLAccessor(_target), _reference, tolerance_fp32);
153 }
154 
FIXTURE_DATA_TEST_CASE(RunLarge,CLArithmeticDivisionFloatFixture<float>,framework::DatasetMode::NIGHTLY,combine (combine (combine (datasets::LargeShapes (),ArithmeticDivisionFP32Dataset),EmptyActivationFunctionsDataset),InPlaceDataSet))155 FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticDivisionFloatFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), ArithmeticDivisionFP32Dataset),
156                                                                                                                    EmptyActivationFunctionsDataset),
157                                                                                                                    InPlaceDataSet))
158 {
159     // Validate output
160     validate(CLAccessor(_target), _reference, tolerance_fp32);
161 }
162 
163 template <typename T>
164 using CLArithmeticDivisionBroadcastFloatFixture = ArithmeticDivisionBroadcastValidationFloatFixture<CLTensor, CLAccessor, CLArithmeticDivision, T>;
165 
FIXTURE_DATA_TEST_CASE(RunSmallBroadcast,CLArithmeticDivisionBroadcastFloatFixture<float>,framework::DatasetMode::PRECOMMIT,combine (combine (combine (datasets::SmallShapesBroadcast (),ArithmeticDivisionFP32Dataset),EmptyActivationFunctionsDataset),OutOfPlaceDataSet))166 FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLArithmeticDivisionBroadcastFloatFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapesBroadcast(),
167                        ArithmeticDivisionFP32Dataset),
168                        EmptyActivationFunctionsDataset),
169                        OutOfPlaceDataSet))
170 {
171     // Validate output
172     validate(CLAccessor(_target), _reference, tolerance_fp32);
173 }
FIXTURE_DATA_TEST_CASE(RunWithActivationBroadcast,CLArithmeticDivisionBroadcastFloatFixture<float>,framework::DatasetMode::ALL,combine (combine (combine (datasets::TinyShapesBroadcast (),ArithmeticDivisionFP32Dataset),ActivationFunctionsDataset),OutOfPlaceDataSet))174 FIXTURE_DATA_TEST_CASE(RunWithActivationBroadcast, CLArithmeticDivisionBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::TinyShapesBroadcast(),
175                        ArithmeticDivisionFP32Dataset),
176                        ActivationFunctionsDataset),
177                        OutOfPlaceDataSet))
178 {
179     // Validate output
180     validate(CLAccessor(_target), _reference, tolerance_fp32);
181 }
182 
FIXTURE_DATA_TEST_CASE(RunLargeBroadcast,CLArithmeticDivisionBroadcastFloatFixture<float>,framework::DatasetMode::NIGHTLY,combine (combine (combine (datasets::LargeShapesBroadcast (),ArithmeticDivisionFP32Dataset),EmptyActivationFunctionsDataset),OutOfPlaceDataSet))183 FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLArithmeticDivisionBroadcastFloatFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapesBroadcast(),
184                        ArithmeticDivisionFP32Dataset),
185                        EmptyActivationFunctionsDataset),
186                        OutOfPlaceDataSet))
187 {
188     // Validate output
189     validate(CLAccessor(_target), _reference, tolerance_fp32);
190 }
191 TEST_SUITE_END()
192 TEST_SUITE_END()
193 
194 TEST_SUITE_END()
195 TEST_SUITE_END()
196 } // namespace validation
197 } // namespace test
198 } // namespace arm_compute
199