blob: 330a999c24a8c46cf1a9a07b91b5882905e93c05 [file] [log] [blame]
Michalis Spyrou0a887922018-06-11 16:30:23 +01001/*
2 * Copyright (c) 2018 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"
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
49constexpr unsigned int num_elems_processed_per_iteration = 16;
50/** Input data sets **/
giuros01164a2722018-11-20 18:34:46 +000051const auto ArithmeticDivisionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
52 framework::dataset::make("DataType", DataType::F16));
53const auto ArithmeticDivisionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
54 framework::dataset::make("DataType", DataType::F32));
Michalis Spyrou0a887922018-06-11 16:30:23 +010055} // namespace
56
57TEST_SUITE(CL)
58TEST_SUITE(ArithmeticDivision)
59
60// *INDENT-OFF*
61// clang-format off
62DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
giuros0149f7c022018-12-03 19:25:22 +000063 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
64 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
65 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Window shrink
66 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Invalid data type combination
Michalis Spyrou0a887922018-06-11 16:30:23 +010067 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
Michalis Spyrou0a887922018-06-11 16:30:23 +010068 }),
giuros0149f7c022018-12-03 19:25:22 +000069 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
70 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16),
71 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
Michalis Spyrou0a887922018-06-11 16:30:23 +010072 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
73 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Michalis Spyrou0a887922018-06-11 16:30:23 +010074 })),
giuros0149f7c022018-12-03 19:25:22 +000075 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
76 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
77 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),
78 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
Michalis Spyrou0a887922018-06-11 16:30:23 +010079 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
Michalis Spyrou0a887922018-06-11 16:30:23 +010080 })),
giuros0149f7c022018-12-03 19:25:22 +000081 framework::dataset::make("Expected", { true, false, false, false, false})),
Michalis Spyrou0a887922018-06-11 16:30:23 +010082 input1_info, input2_info, output_info, expected)
83{
84 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);
85}
86// clang-format on
87// *INDENT-ON*
88
89template <typename T>
90using CLArithmeticDivisionFixture = ArithmeticDivisionValidationFixture<CLTensor, CLAccessor, CLArithmeticDivision, T>;
91
giuros01164a2722018-11-20 18:34:46 +000092TEST_SUITE(Float)
93TEST_SUITE(FP16)
94FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticDivisionFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ArithmeticDivisionFP16Dataset))
95{
96 // Validate output
97 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
98}
99TEST_SUITE_END()
Michalis Spyrou0a887922018-06-11 16:30:23 +0100100
101TEST_SUITE(FP32)
giuros01164a2722018-11-20 18:34:46 +0000102DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()),
103 shape)
Michalis Spyrou0a887922018-06-11 16:30:23 +0100104{
105 // Create tensors
106 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
107 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
108 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
109
110 // Create and Configure function
giuros01164a2722018-11-20 18:34:46 +0000111 CLArithmeticDivision add;
112 add.configure(&ref_src1, &ref_src2, &dst);
Michalis Spyrou0a887922018-06-11 16:30:23 +0100113
114 // Validate valid region
115 const ValidRegion valid_region = shape_to_valid_region(shape);
116 validate(dst.info()->valid_region(), valid_region);
117
118 // Validate padding
giuros01164a2722018-11-20 18:34:46 +0000119 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
Michalis Spyrou0a887922018-06-11 16:30:23 +0100120 validate(ref_src1.info()->padding(), padding);
121 validate(ref_src2.info()->padding(), padding);
122 validate(dst.info()->padding(), padding);
123}
124
giuros01164a2722018-11-20 18:34:46 +0000125FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticDivisionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ArithmeticDivisionFP32Dataset))
Michalis Spyrou0a887922018-06-11 16:30:23 +0100126{
127 // Validate output
128 validate(CLAccessor(_target), _reference, tolerance_fp32);
129}
130
giuros01164a2722018-11-20 18:34:46 +0000131FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticDivisionFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), ArithmeticDivisionFP32Dataset))
Michalis Spyrou0a887922018-06-11 16:30:23 +0100132{
133 // Validate output
134 validate(CLAccessor(_target), _reference, tolerance_fp32);
135}
136
137template <typename T>
138using CLArithmeticDivisionBroadcastFixture = ArithmeticDivisionBroadcastValidationFixture<CLTensor, CLAccessor, CLArithmeticDivision, T>;
139
140FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLArithmeticDivisionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapesBroadcast(),
giuros01164a2722018-11-20 18:34:46 +0000141 ArithmeticDivisionFP32Dataset))
Michalis Spyrou0a887922018-06-11 16:30:23 +0100142{
143 // Validate output
144 validate(CLAccessor(_target), _reference, tolerance_fp32);
145}
146
147FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLArithmeticDivisionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapesBroadcast(),
giuros01164a2722018-11-20 18:34:46 +0000148 ArithmeticDivisionFP32Dataset))
Michalis Spyrou0a887922018-06-11 16:30:23 +0100149{
150 // Validate output
151 validate(CLAccessor(_target), _reference, tolerance_fp32);
152}
giuros01164a2722018-11-20 18:34:46 +0000153TEST_SUITE_END()
154TEST_SUITE_END()
Michalis Spyrou0a887922018-06-11 16:30:23 +0100155
giuros01164a2722018-11-20 18:34:46 +0000156TEST_SUITE_END()
157TEST_SUITE_END()
Michalis Spyrou0a887922018-06-11 16:30:23 +0100158} // namespace validation
159} // namespace test
160} // namespace arm_compute