blob: 94bacba7e5b0ec752333adbaa1c73aebaf239335 [file] [log] [blame]
Michalis Spyrou0a887922018-06-11 16:30:23 +01001/*
Suhail Munshiae1c9fe2021-04-14 12:16:49 +01002 * Copyright (c) 2018-2021 Arm Limited.
Michalis Spyrou0a887922018-06-11 16:30:23 +01003 *
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"
giuros01164a2722018-11-20 18:34:46 +000027#include "arm_compute/runtime/CL/functions/CLElementwiseOperations.h"
Michalis Spyrou0a887922018-06-11 16:30:23 +010028#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"
giuros01164a2722018-11-20 18:34:46 +000036#include "tests/validation/fixtures/ElementwiseOperationsFixture.h"
Michalis Spyrou0a887922018-06-11 16:30:23 +010037
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46RelativeTolerance<float> tolerance_fp32(0.000001f);
Michalis Spyrouf5f0ecc2018-06-20 10:16:31 +010047RelativeTolerance<float> tolerance_fp16(0.001f);
giuros01164a2722018-11-20 18:34:46 +000048
giuros01164a2722018-11-20 18:34:46 +000049/** Input data sets **/
giuros01164a2722018-11-20 18:34:46 +000050const auto ArithmeticDivisionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
51 framework::dataset::make("DataType", DataType::F16));
52const auto ArithmeticDivisionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
53 framework::dataset::make("DataType", DataType::F32));
Suhail Munshiae1c9fe2021-04-14 12:16:49 +010054const auto ArithmeticDivisionS32Dataset = combine(combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::S32)),
55 framework::dataset::make("DataType", DataType::S32));
56const auto EmptyActivationFunctionsDataset = framework::dataset::make("ActivationInfo", { ActivationLayerInfo() });
57const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000058{
59 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.75f, 0.25f),
60 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC, 0.75f, 0.25f)
61});
Sheri Zhanga387e272021-06-29 17:34:06 +010062const auto InPlaceDataSet = framework::dataset::make("InPlace", { false, true });
63const auto OutOfPlaceDataSet = framework::dataset::make("InPlace", { false });
Michalis Spyrou0a887922018-06-11 16:30:23 +010064} // namespace
65
66TEST_SUITE(CL)
67TEST_SUITE(ArithmeticDivision)
68
69// *INDENT-OFF*
70// clang-format off
71DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
giuros0149f7c022018-12-03 19:25:22 +000072 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
73 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
giuros0149f7c022018-12-03 19:25:22 +000074 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Invalid data type combination
Michalis Spyrou0a887922018-06-11 16:30:23 +010075 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
Michalis Spyrou0a887922018-06-11 16:30:23 +010076 }),
giuros0149f7c022018-12-03 19:25:22 +000077 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
78 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16),
Michalis Spyrou0a887922018-06-11 16:30:23 +010079 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
80 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Michalis Spyrou0a887922018-06-11 16:30:23 +010081 })),
giuros0149f7c022018-12-03 19:25:22 +000082 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
83 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
giuros0149f7c022018-12-03 19:25:22 +000084 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
Michalis Spyrou0a887922018-06-11 16:30:23 +010085 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Michalis Spyrou0a887922018-06-11 16:30:23 +010086 })),
Manuel Bottinied2a8ed2020-10-07 17:17:16 +010087 framework::dataset::make("Expected", { true, false, false, false})),
Michalis Spyrou0a887922018-06-11 16:30:23 +010088 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
Suhail Munshiae1c9fe2021-04-14 12:16:49 +010095using CLArithmeticDivisionIntegerFixture = ArithmeticDivisionValidationIntegerFixture<CLTensor, CLAccessor, CLArithmeticDivision, int>;
96
97TEST_SUITE(Integer)
98TEST_SUITE(S32)
99
Sheri Zhanga387e272021-06-29 17:34:06 +0100100FIXTURE_DATA_TEST_CASE(RunSmallInteger, CLArithmeticDivisionIntegerFixture, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), ArithmeticDivisionS32Dataset),
101 EmptyActivationFunctionsDataset),
102 InPlaceDataSet))
Suhail Munshiae1c9fe2021-04-14 12:16:49 +0100103{
104 // Validate output
105 validate(CLAccessor(_target), _reference);
106}
Sheri Zhanga387e272021-06-29 17:34:06 +0100107FIXTURE_DATA_TEST_CASE(RunIntegerWithActivation, CLArithmeticDivisionIntegerFixture, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), ArithmeticDivisionS32Dataset),
108 ActivationFunctionsDataset),
109 InPlaceDataSet))
Suhail Munshiae1c9fe2021-04-14 12:16:49 +0100110{
111 // Validate output
112 validate(CLAccessor(_target), _reference);
113}
114
115TEST_SUITE_END()
116TEST_SUITE_END()
117
Michalis Spyrou0a887922018-06-11 16:30:23 +0100118template <typename T>
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000119using CLArithmeticDivisionFloatFixture = ArithmeticDivisionValidationFloatFixture<CLTensor, CLAccessor, CLArithmeticDivision, T>;
Michalis Spyrou0a887922018-06-11 16:30:23 +0100120
giuros01164a2722018-11-20 18:34:46 +0000121TEST_SUITE(Float)
122TEST_SUITE(FP16)
Sheri Zhanga387e272021-06-29 17:34:06 +0100123FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticDivisionFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), ArithmeticDivisionFP16Dataset),
124 EmptyActivationFunctionsDataset),
125 InPlaceDataSet))
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000126{
127 // Validate output
128 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
129}
Sheri Zhanga387e272021-06-29 17:34:06 +0100130FIXTURE_DATA_TEST_CASE(RunWithActivation, CLArithmeticDivisionFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::TinyShapes(), ArithmeticDivisionFP16Dataset),
131 ActivationFunctionsDataset),
132 InPlaceDataSet))
giuros01164a2722018-11-20 18:34:46 +0000133{
134 // Validate output
135 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
136}
137TEST_SUITE_END()
Michalis Spyrou0a887922018-06-11 16:30:23 +0100138
139TEST_SUITE(FP32)
Sheri Zhanga387e272021-06-29 17:34:06 +0100140FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticDivisionFloatFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), ArithmeticDivisionFP32Dataset),
141 EmptyActivationFunctionsDataset),
142 InPlaceDataSet))
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000143{
144 // Validate output
145 validate(CLAccessor(_target), _reference, tolerance_fp32);
146}
Sheri Zhanga387e272021-06-29 17:34:06 +0100147FIXTURE_DATA_TEST_CASE(RunWithActivation, CLArithmeticDivisionFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::TinyShapes(), ArithmeticDivisionFP32Dataset),
148 ActivationFunctionsDataset),
149 InPlaceDataSet))
Michalis Spyrou0a887922018-06-11 16:30:23 +0100150{
151 // Validate output
152 validate(CLAccessor(_target), _reference, tolerance_fp32);
153}
154
Sheri Zhanga387e272021-06-29 17:34:06 +0100155FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticDivisionFloatFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), ArithmeticDivisionFP32Dataset),
156 EmptyActivationFunctionsDataset),
157 InPlaceDataSet))
Michalis Spyrou0a887922018-06-11 16:30:23 +0100158{
159 // Validate output
160 validate(CLAccessor(_target), _reference, tolerance_fp32);
161}
162
163template <typename T>
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000164using CLArithmeticDivisionBroadcastFloatFixture = ArithmeticDivisionBroadcastValidationFloatFixture<CLTensor, CLAccessor, CLArithmeticDivision, T>;
Michalis Spyrou0a887922018-06-11 16:30:23 +0100165
Sheri Zhanga387e272021-06-29 17:34:06 +0100166FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLArithmeticDivisionBroadcastFloatFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapesBroadcast(),
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000167 ArithmeticDivisionFP32Dataset),
Sheri Zhanga387e272021-06-29 17:34:06 +0100168 EmptyActivationFunctionsDataset),
169 OutOfPlaceDataSet))
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000170{
171 // Validate output
172 validate(CLAccessor(_target), _reference, tolerance_fp32);
173}
Sheri Zhanga387e272021-06-29 17:34:06 +0100174FIXTURE_DATA_TEST_CASE(RunWithActivationBroadcast, CLArithmeticDivisionBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::TinyShapesBroadcast(),
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000175 ArithmeticDivisionFP32Dataset),
Sheri Zhanga387e272021-06-29 17:34:06 +0100176 ActivationFunctionsDataset),
177 OutOfPlaceDataSet))
Michalis Spyrou0a887922018-06-11 16:30:23 +0100178{
179 // Validate output
180 validate(CLAccessor(_target), _reference, tolerance_fp32);
181}
182
Sheri Zhanga387e272021-06-29 17:34:06 +0100183FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLArithmeticDivisionBroadcastFloatFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapesBroadcast(),
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000184 ArithmeticDivisionFP32Dataset),
Sheri Zhanga387e272021-06-29 17:34:06 +0100185 EmptyActivationFunctionsDataset),
186 OutOfPlaceDataSet))
Michalis Spyrou0a887922018-06-11 16:30:23 +0100187{
188 // Validate output
189 validate(CLAccessor(_target), _reference, tolerance_fp32);
190}
giuros01164a2722018-11-20 18:34:46 +0000191TEST_SUITE_END()
192TEST_SUITE_END()
Michalis Spyrou0a887922018-06-11 16:30:23 +0100193
giuros01164a2722018-11-20 18:34:46 +0000194TEST_SUITE_END()
195TEST_SUITE_END()
Michalis Spyrou0a887922018-06-11 16:30:23 +0100196} // namespace validation
197} // namespace test
198} // namespace arm_compute