blob: dab3f750188477cbeb7c1cbb79fa1e7362aa7244 [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"
27#include "arm_compute/runtime/CL/functions/CLArithmeticDivision.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/ArithmeticDivisionFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46RelativeTolerance<float> tolerance_fp32(0.000001f);
47RelativeTolerance<float> tolerance_fp16(0.0001f);
48} // namespace
49
50TEST_SUITE(CL)
51TEST_SUITE(ArithmeticDivision)
52
53// *INDENT-OFF*
54// clang-format off
55DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
56 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Wrong data type
57 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
58 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
59 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
60 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32, 2),
61 }),
62 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
63 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
64 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
65 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
66 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32, 2),
67 })),
68 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
69 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
70 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
71 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
72 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32, 2),
73 })),
74 framework::dataset::make("Expected", { false, false, false, false, true })),
75 input1_info, input2_info, output_info, expected)
76{
77 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);
78}
79// clang-format on
80// *INDENT-ON*
81
82template <typename T>
83using CLArithmeticDivisionFixture = ArithmeticDivisionValidationFixture<CLTensor, CLAccessor, CLArithmeticDivision, T>;
84
85TEST_SUITE(Float)
86TEST_SUITE(FP16)
87FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticDivisionFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)))
88{
89 // Validate output
90 validate(CLAccessor(_target), _reference, tolerance_fp16);
91}
92TEST_SUITE_END() // FP16
93
94TEST_SUITE(FP32)
95DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, concat(datasets::SmallShapes(), datasets::LargeShapes()), shape)
96{
97 // Create tensors
98 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
99 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
100 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
101
102 // Create and Configure function
103 CLArithmeticDivision div;
104 div.configure(&ref_src1, &ref_src2, &dst);
105
106 // Validate valid region
107 const ValidRegion valid_region = shape_to_valid_region(shape);
108 validate(dst.info()->valid_region(), valid_region);
109
110 // Validate padding
111 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
112 validate(ref_src1.info()->padding(), padding);
113 validate(ref_src2.info()->padding(), padding);
114 validate(dst.info()->padding(), padding);
115}
116
117FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticDivisionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)))
118{
119 // Validate output
120 validate(CLAccessor(_target), _reference, tolerance_fp32);
121}
122
123FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticDivisionFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F32)))
124{
125 // Validate output
126 validate(CLAccessor(_target), _reference, tolerance_fp32);
127}
128
129template <typename T>
130using CLArithmeticDivisionBroadcastFixture = ArithmeticDivisionBroadcastValidationFixture<CLTensor, CLAccessor, CLArithmeticDivision, T>;
131
132FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLArithmeticDivisionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapesBroadcast(),
133 framework::dataset::make("DataType", DataType::F32)))
134{
135 // Validate output
136 validate(CLAccessor(_target), _reference, tolerance_fp32);
137}
138
139FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLArithmeticDivisionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapesBroadcast(),
140 framework::dataset::make("DataType", DataType::F32)))
141{
142 // Validate output
143 validate(CLAccessor(_target), _reference, tolerance_fp32);
144}
145TEST_SUITE_END() // FP32
146TEST_SUITE_END() // Float
147
148TEST_SUITE_END() // ArithmeticDivision
149TEST_SUITE_END() // CL
150} // namespace validation
151} // namespace test
152} // namespace arm_compute