blob: 9dcdfb83e16c6fbe79025bcef5f6c9cda0f34eba [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});
Michalis Spyrou0a887922018-06-11 16:30:23 +010062} // namespace
63
64TEST_SUITE(CL)
65TEST_SUITE(ArithmeticDivision)
66
67// *INDENT-OFF*
68// clang-format off
69DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
giuros0149f7c022018-12-03 19:25:22 +000070 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
71 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
giuros0149f7c022018-12-03 19:25:22 +000072 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Invalid data type combination
Michalis Spyrou0a887922018-06-11 16:30:23 +010073 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
Michalis Spyrou0a887922018-06-11 16:30:23 +010074 }),
giuros0149f7c022018-12-03 19:25:22 +000075 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
76 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16),
Michalis Spyrou0a887922018-06-11 16:30:23 +010077 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
78 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Michalis Spyrou0a887922018-06-11 16:30:23 +010079 })),
giuros0149f7c022018-12-03 19:25:22 +000080 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
81 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
giuros0149f7c022018-12-03 19:25:22 +000082 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
Michalis Spyrou0a887922018-06-11 16:30:23 +010083 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Michalis Spyrou0a887922018-06-11 16:30:23 +010084 })),
Manuel Bottinied2a8ed2020-10-07 17:17:16 +010085 framework::dataset::make("Expected", { true, false, false, false})),
Michalis Spyrou0a887922018-06-11 16:30:23 +010086 input1_info, input2_info, output_info, expected)
87{
88 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);
89}
90// clang-format on
91// *INDENT-ON*
92
Suhail Munshiae1c9fe2021-04-14 12:16:49 +010093using CLArithmeticDivisionIntegerFixture = ArithmeticDivisionValidationIntegerFixture<CLTensor, CLAccessor, CLArithmeticDivision, int>;
94
95TEST_SUITE(Integer)
96TEST_SUITE(S32)
97
98FIXTURE_DATA_TEST_CASE(RunSmallInteger, CLArithmeticDivisionIntegerFixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticDivisionS32Dataset),
99 EmptyActivationFunctionsDataset))
100{
101 // Validate output
102 validate(CLAccessor(_target), _reference);
103}
104FIXTURE_DATA_TEST_CASE(RunIntegerWithActivation, CLArithmeticDivisionIntegerFixture, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticDivisionS32Dataset),
105 ActivationFunctionsDataset))
106{
107 // Validate output
108 validate(CLAccessor(_target), _reference);
109}
110
111TEST_SUITE_END()
112TEST_SUITE_END()
113
Michalis Spyrou0a887922018-06-11 16:30:23 +0100114template <typename T>
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000115using CLArithmeticDivisionFloatFixture = ArithmeticDivisionValidationFloatFixture<CLTensor, CLAccessor, CLArithmeticDivision, T>;
Michalis Spyrou0a887922018-06-11 16:30:23 +0100116
giuros01164a2722018-11-20 18:34:46 +0000117TEST_SUITE(Float)
118TEST_SUITE(FP16)
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000119FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticDivisionFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticDivisionFP16Dataset),
120 EmptyActivationFunctionsDataset))
121{
122 // Validate output
123 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
124}
125FIXTURE_DATA_TEST_CASE(RunWithActivation, CLArithmeticDivisionFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), ArithmeticDivisionFP16Dataset),
126 ActivationFunctionsDataset))
giuros01164a2722018-11-20 18:34:46 +0000127{
128 // Validate output
129 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
130}
131TEST_SUITE_END()
Michalis Spyrou0a887922018-06-11 16:30:23 +0100132
133TEST_SUITE(FP32)
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000134FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticDivisionFloatFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticDivisionFP32Dataset),
135 EmptyActivationFunctionsDataset))
136{
137 // Validate output
138 validate(CLAccessor(_target), _reference, tolerance_fp32);
139}
140FIXTURE_DATA_TEST_CASE(RunWithActivation, CLArithmeticDivisionFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), ArithmeticDivisionFP32Dataset),
141 ActivationFunctionsDataset))
Michalis Spyrou0a887922018-06-11 16:30:23 +0100142{
143 // Validate output
144 validate(CLAccessor(_target), _reference, tolerance_fp32);
145}
146
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000147FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticDivisionFloatFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticDivisionFP32Dataset),
148 EmptyActivationFunctionsDataset))
Michalis Spyrou0a887922018-06-11 16:30:23 +0100149{
150 // Validate output
151 validate(CLAccessor(_target), _reference, tolerance_fp32);
152}
153
154template <typename T>
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000155using CLArithmeticDivisionBroadcastFloatFixture = ArithmeticDivisionBroadcastValidationFloatFixture<CLTensor, CLAccessor, CLArithmeticDivision, T>;
Michalis Spyrou0a887922018-06-11 16:30:23 +0100156
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000157FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLArithmeticDivisionBroadcastFloatFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(),
158 ArithmeticDivisionFP32Dataset),
159 EmptyActivationFunctionsDataset))
160{
161 // Validate output
162 validate(CLAccessor(_target), _reference, tolerance_fp32);
163}
164FIXTURE_DATA_TEST_CASE(RunWithActivationBroadcast, CLArithmeticDivisionBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapesBroadcast(),
165 ArithmeticDivisionFP32Dataset),
166 ActivationFunctionsDataset))
Michalis Spyrou0a887922018-06-11 16:30:23 +0100167{
168 // Validate output
169 validate(CLAccessor(_target), _reference, tolerance_fp32);
170}
171
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000172FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLArithmeticDivisionBroadcastFloatFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(),
173 ArithmeticDivisionFP32Dataset),
174 EmptyActivationFunctionsDataset))
Michalis Spyrou0a887922018-06-11 16:30:23 +0100175{
176 // Validate output
177 validate(CLAccessor(_target), _reference, tolerance_fp32);
178}
giuros01164a2722018-11-20 18:34:46 +0000179TEST_SUITE_END()
180TEST_SUITE_END()
Michalis Spyrou0a887922018-06-11 16:30:23 +0100181
giuros01164a2722018-11-20 18:34:46 +0000182TEST_SUITE_END()
183TEST_SUITE_END()
Michalis Spyrou0a887922018-06-11 16:30:23 +0100184} // namespace validation
185} // namespace test
186} // namespace arm_compute