• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2018-2020 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 EmptyActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
55 { ActivationLayerInfo() });
56 const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
57 {
58     ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.75f, 0.25f),
59     ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC, 0.75f, 0.25f)
60 });
61 } // namespace
62 
63 TEST_SUITE(CL)
TEST_SUITE(ArithmeticDivision)64 TEST_SUITE(ArithmeticDivision)
65 
66 // *INDENT-OFF*
67 // clang-format off
68 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
69                framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
70                                                         TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
71                                                         TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),      // Invalid data type combination
72                                                         TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),     // Mismatching shapes
73                                                       }),
74                framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
75                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F16),
76                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
77                                                        TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
78                                                      })),
79                framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
80                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
81                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
82                                                        TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
83                                                      })),
84                framework::dataset::make("Expected", { true, false, false, false})),
85                input1_info, input2_info, output_info, expected)
86 {
87     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);
88 }
89 // clang-format on
90 // *INDENT-ON*
91 
92 template <typename T>
93 using CLArithmeticDivisionFloatFixture = ArithmeticDivisionValidationFloatFixture<CLTensor, CLAccessor, CLArithmeticDivision, T>;
94 
95 TEST_SUITE(Float)
TEST_SUITE(FP16)96 TEST_SUITE(FP16)
97 FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticDivisionFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticDivisionFP16Dataset),
98                                                                                                               EmptyActivationFunctionsDataset))
99 {
100     // Validate output
101     validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
102 }
FIXTURE_DATA_TEST_CASE(RunWithActivation,CLArithmeticDivisionFloatFixture<half>,framework::DatasetMode::ALL,combine (combine (datasets::TinyShapes (),ArithmeticDivisionFP16Dataset),ActivationFunctionsDataset))103 FIXTURE_DATA_TEST_CASE(RunWithActivation, CLArithmeticDivisionFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), ArithmeticDivisionFP16Dataset),
104                                                                                                                        ActivationFunctionsDataset))
105 {
106     // Validate output
107     validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
108 }
109 TEST_SUITE_END()
110 
TEST_SUITE(FP32)111 TEST_SUITE(FP32)
112 FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticDivisionFloatFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticDivisionFP32Dataset),
113                                                                                                                      EmptyActivationFunctionsDataset))
114 {
115     // Validate output
116     validate(CLAccessor(_target), _reference, tolerance_fp32);
117 }
FIXTURE_DATA_TEST_CASE(RunWithActivation,CLArithmeticDivisionFloatFixture<float>,framework::DatasetMode::ALL,combine (combine (datasets::TinyShapes (),ArithmeticDivisionFP32Dataset),ActivationFunctionsDataset))118 FIXTURE_DATA_TEST_CASE(RunWithActivation, CLArithmeticDivisionFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), ArithmeticDivisionFP32Dataset),
119                                                                                                                         ActivationFunctionsDataset))
120 {
121     // Validate output
122     validate(CLAccessor(_target), _reference, tolerance_fp32);
123 }
124 
FIXTURE_DATA_TEST_CASE(RunLarge,CLArithmeticDivisionFloatFixture<float>,framework::DatasetMode::NIGHTLY,combine (combine (datasets::LargeShapes (),ArithmeticDivisionFP32Dataset),EmptyActivationFunctionsDataset))125 FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticDivisionFloatFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticDivisionFP32Dataset),
126                                                                                                                    EmptyActivationFunctionsDataset))
127 {
128     // Validate output
129     validate(CLAccessor(_target), _reference, tolerance_fp32);
130 }
131 
132 template <typename T>
133 using CLArithmeticDivisionBroadcastFloatFixture = ArithmeticDivisionBroadcastValidationFloatFixture<CLTensor, CLAccessor, CLArithmeticDivision, T>;
134 
FIXTURE_DATA_TEST_CASE(RunSmallBroadcast,CLArithmeticDivisionBroadcastFloatFixture<float>,framework::DatasetMode::PRECOMMIT,combine (combine (datasets::SmallShapesBroadcast (),ArithmeticDivisionFP32Dataset),EmptyActivationFunctionsDataset))135 FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLArithmeticDivisionBroadcastFloatFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(),
136                        ArithmeticDivisionFP32Dataset),
137                        EmptyActivationFunctionsDataset))
138 {
139     // Validate output
140     validate(CLAccessor(_target), _reference, tolerance_fp32);
141 }
FIXTURE_DATA_TEST_CASE(RunWithActivationBroadcast,CLArithmeticDivisionBroadcastFloatFixture<float>,framework::DatasetMode::ALL,combine (combine (datasets::TinyShapesBroadcast (),ArithmeticDivisionFP32Dataset),ActivationFunctionsDataset))142 FIXTURE_DATA_TEST_CASE(RunWithActivationBroadcast, CLArithmeticDivisionBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapesBroadcast(),
143                        ArithmeticDivisionFP32Dataset),
144                        ActivationFunctionsDataset))
145 {
146     // Validate output
147     validate(CLAccessor(_target), _reference, tolerance_fp32);
148 }
149 
FIXTURE_DATA_TEST_CASE(RunLargeBroadcast,CLArithmeticDivisionBroadcastFloatFixture<float>,framework::DatasetMode::NIGHTLY,combine (combine (datasets::LargeShapesBroadcast (),ArithmeticDivisionFP32Dataset),EmptyActivationFunctionsDataset))150 FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLArithmeticDivisionBroadcastFloatFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(),
151                        ArithmeticDivisionFP32Dataset),
152                        EmptyActivationFunctionsDataset))
153 {
154     // Validate output
155     validate(CLAccessor(_target), _reference, tolerance_fp32);
156 }
157 TEST_SUITE_END()
158 TEST_SUITE_END()
159 
160 TEST_SUITE_END()
161 TEST_SUITE_END()
162 } // namespace validation
163 } // namespace test
164 } // namespace arm_compute
165