xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/CL/Range.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
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/CLRange.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/RangeFixture.h"
37 
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 namespace
45 {
46 constexpr RelativeTolerance<float> tolerance(0.01f);
47 constexpr AbsoluteTolerance<float> abs_tolerance(0.02f);
48 const auto                         start_dataset          = framework::dataset::make("Start", { float(3), float(-17), float(16) });
49 const auto                         unsigned_start_dataset = framework::dataset::make("Start", { float(3), float(16) });
50 const auto                         float_step_dataset     = framework::dataset::make("Step", { float(1), float(-0.2f), float(0.2), float(12.2), float(-12.2), float(-1.2), float(-3), float(3) });
51 const auto                         step_dataset           = framework::dataset::make("Step", { float(1), float(12), float(-12), float(-1), float(-3), float(3) });
52 const auto                         unsigned_step_dataset  = framework::dataset::make("Step", { float(1), float(12), float(3) });
53 } // namespace
54 
55 TEST_SUITE(CL)
TEST_SUITE(Range)56 TEST_SUITE(Range)
57 
58 // *INDENT-OFF*
59 // clang-format off
60 
61 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
62                framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
63                                                         TensorInfo(TensorShape(32U), 1, DataType::U8),
64                                                         TensorInfo(TensorShape(27U), 1, DataType::U8),
65                                                         TensorInfo(TensorShape(32U), 1, DataType::U8),
66                                                         TensorInfo(TensorShape(32U), 1, DataType::F32),
67                                                         TensorInfo(TensorShape(27U), 1, DataType::U8),
68                                                         TensorInfo(TensorShape(27U), 1, DataType::U8),
69                                                         TensorInfo(TensorShape(10U), 1, DataType::U8),
70                                                       }),
71                framework::dataset::make("Start",{ 0.0f, 15.0f, 1500.0f, 100.0f, -15.0f, 0.2f , 2.0f , 10.0f})),
72                framework::dataset::make("End",{ 100.0f, 15.0f, 2500.0f, -1000.0f, 15.0f, 10.0f, 10.0f,100.0f })),
73                framework::dataset::make("Step",{ 100.0f, 15.0f, 10.0f, 100.0f, -15.0f, 1.0f, 0.0f, 10.0f })),
74                framework::dataset::make("Expected", { false, //1-D tensor expected
75                                                     false, //start == end
76                                                     false, //output vector size insufficient
77                                                     false, //sign of step incorrect
78                                                     false, //sign of step incorrect
79                                                     false, //data type incompatible
80                                                     false, //step = 0
81                                                     true,
82                                                     })),
83                output_info, start, end, step, expected)
84 {
85     ARM_COMPUTE_EXPECT(bool(CLRange::validate(&output_info, start, end, step)) == expected, framework::LogLevel::ERRORS);
86 }
87 // clang-format on
88 // *INDENT-ON*
89 
90 template <typename T>
91 using CLRangeFixture = RangeFixture<CLTensor, CLAccessor, CLRange, T>;
92 
93 TEST_SUITE(U8)
94 FIXTURE_DATA_TEST_CASE(RunSmall, CLRangeFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
95                                                                                                                  framework::dataset::make("DataType", DataType::U8),
96                                                                                                                  unsigned_start_dataset),
97                                                                                                              unsigned_step_dataset),
98                                                                                                      framework::dataset::make("QuantizationInfo", { QuantizationInfo() })))
99 {
100     // Validate output
101     validate(CLAccessor(_target), _reference, tolerance, 0.f, abs_tolerance);
102 }
103 TEST_SUITE_END() //U8
104 
TEST_SUITE(Quantized)105 TEST_SUITE(Quantized)
106 TEST_SUITE(QASYMM8)
107 
108 FIXTURE_DATA_TEST_CASE(RunSmall, CLRangeFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
109                                                                                                                  framework::dataset::make("DataType", DataType::QASYMM8),
110                                                                                                                  start_dataset),
111                                                                                                              step_dataset),
112                                                                                                      framework::dataset::make("QuantizationInfo", { QuantizationInfo(0.3457f, 120.0f) })))
113 {
114     // Validate output
115     validate(CLAccessor(_target), _reference, tolerance, 0.f, abs_tolerance);
116 }
117 TEST_SUITE_END() //QASYMM8
TEST_SUITE_END()118 TEST_SUITE_END() //Quantized
119 
120 TEST_SUITE(S16)
121 FIXTURE_DATA_TEST_CASE(RunSmall, CLRangeFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
122                                                                                                                  framework::dataset::make("DataType", DataType::S16),
123                                                                                                                  start_dataset),
124                                                                                                              step_dataset),
125                                                                                                      framework::dataset::make("QuantizationInfo", { QuantizationInfo() })))
126 {
127     // Validate output
128     validate(CLAccessor(_target), _reference, tolerance, 0.f, abs_tolerance);
129 }
130 TEST_SUITE_END() //S16
131 
TEST_SUITE(Float)132 TEST_SUITE(Float)
133 TEST_SUITE(FP16)
134 FIXTURE_DATA_TEST_CASE(RunSmall, CLRangeFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
135                                                                                                               framework::dataset::make("DataType", DataType::F16),
136                                                                                                               start_dataset),
137                                                                                                           float_step_dataset),
138                                                                                                   framework::dataset::make("QuantizationInfo", { QuantizationInfo() })))
139 {
140     // Validate output
141     validate(CLAccessor(_target), _reference, tolerance, 0.f, abs_tolerance);
142 }
143 TEST_SUITE_END() //FP16
144 
TEST_SUITE(FP32)145 TEST_SUITE(FP32)
146 FIXTURE_DATA_TEST_CASE(RunSmall, CLRangeFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(
147                                                                                                                framework::dataset::make("DataType", DataType::F32),
148                                                                                                                start_dataset),
149                                                                                                            float_step_dataset),
150                                                                                                    framework::dataset::make("QuantizationInfo", { QuantizationInfo() })))
151 {
152     // Validate output
153     validate(CLAccessor(_target), _reference, tolerance, 0.f, abs_tolerance);
154 }
155 TEST_SUITE_END() //FP32
156 TEST_SUITE_END() //Float
157 
158 TEST_SUITE_END() //Range
159 TEST_SUITE_END() //CL
160 } // namespace validation
161 } // namespace test
162 } // namespace arm_compute
163