xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/CL/RsqrtLayer.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2018-2019 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/functions/CLElementwiseUnaryLayer.h"
26 #include "arm_compute/runtime/Tensor.h"
27 #include "arm_compute/runtime/TensorAllocator.h"
28 #include "tests/CL/CLAccessor.h"
29 #include "tests/PaddingCalculator.h"
30 #include "tests/datasets/ShapeDatasets.h"
31 #include "tests/framework/Asserts.h"
32 #include "tests/framework/Macros.h"
33 #include "tests/framework/datasets/Datasets.h"
34 #include "tests/validation/Validation.h"
35 #include "tests/validation/fixtures/ElementwiseUnaryFixture.h"
36 
37 namespace arm_compute
38 {
39 namespace test
40 {
41 namespace validation
42 {
43 namespace
44 {
45 RelativeTolerance<float> tolerance_fp32(0.000001f);
46 RelativeTolerance<float> tolerance_fp16(0.001f);
47 } // namespace
48 TEST_SUITE(CL)
TEST_SUITE(RsqrtLayer)49 TEST_SUITE(RsqrtLayer)
50 
51 // *INDENT-OFF*
52 // clang-format off
53 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(
54                framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),     // Mismatching data types
55                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),     // Valid
56                                                        TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),     // Mismatching shapes
57                                                      }),
58                framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16),
59                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
60                                                        TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32),
61                                                      })),
62                framework::dataset::make("Expected", { false, true, false })),
63                input_info, output_info, expected)
64 {
65     ARM_COMPUTE_EXPECT(bool(CLRsqrtLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS);
66 }
67 // clang-format on
68 // *INDENT-ON*
69 template <typename T>
70 using CLRsqrtLayerFixture = RsqrtValidationFixture<CLTensor, CLAccessor, CLRsqrtLayer, T>;
71 
72 TEST_SUITE(Float)
TEST_SUITE(FP16)73 TEST_SUITE(FP16)
74 FIXTURE_DATA_TEST_CASE(RunSmall, CLRsqrtLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType",
75                                                                                                        DataType::F16)))
76 {
77     // Validate output
78     validate(CLAccessor(_target), _reference, tolerance_fp16);
79 }
80 FIXTURE_DATA_TEST_CASE(RunLarge, CLRsqrtLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), framework::dataset::make("DataType",
81                                                                                                      DataType::F16)))
82 {
83     // Validate output
84     validate(CLAccessor(_target), _reference, tolerance_fp16);
85 }
86 
87 TEST_SUITE_END() // FP16
TEST_SUITE(FP32)88 TEST_SUITE(FP32)
89 FIXTURE_DATA_TEST_CASE(RunSmall, CLRsqrtLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), framework::dataset::make("DataType",
90                                                                                                         DataType::F32)))
91 {
92     // Validate output
93     validate(CLAccessor(_target), _reference, tolerance_fp32);
94 }
95 FIXTURE_DATA_TEST_CASE(RunLarge, CLRsqrtLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), framework::dataset::make("DataType",
96                                                                                                       DataType::F32)))
97 {
98     // Validate output
99     validate(CLAccessor(_target), _reference, tolerance_fp32);
100 }
101 
102 TEST_SUITE_END() // FP32
103 TEST_SUITE_END() // Float
104 
105 TEST_SUITE_END() // RsqrtLayer
106 TEST_SUITE_END() // CL
107 } // namespace validation
108 } // namespace test
109 } // namespace arm_compute
110