xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/CL/CropResize.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2019-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/CLCropResize.h"
28 #include "tests/CL/CLAccessor.h"
29 #include "tests/datasets/CropResizeDataset.h"
30 #include "tests/framework/Asserts.h"
31 #include "tests/framework/Macros.h"
32 #include "tests/framework/datasets/Datasets.h"
33 #include "tests/validation/Validation.h"
34 #include "tests/validation/fixtures/CropResizeFixture.h"
35 
36 namespace arm_compute
37 {
38 namespace test
39 {
40 namespace validation
41 {
42 TEST_SUITE(CL)
43 TEST_SUITE(CropResize)
44 
45 RelativeTolerance<float> tolerance_fp32(0.001f);
46 
47 template <typename T>
48 using CLCropResizeFixture = CropResizeFixture<CLTensor, CLAccessor, CLCropResize, T>;
49 
50 // *INDENT-OFF*
51 // clang-format off
52 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
53                framework::dataset::make("InputInfo", { TensorInfo(TensorShape(15U, 30U, 40U, 10U), 1, DataType::S32),
54                                                        TensorInfo(TensorShape(15U, 30U, 40U, 10U), 1, DataType::S32), // Invalid box_ind shape.
55                                                        TensorInfo(TensorShape(15U, 30U, 40U, 10U), 1, DataType::S32), // Invalid output shape.
56                                                        TensorInfo(TensorShape(15U, 30U, 40U, 10U), 1, DataType::S32), // Invalid output data type.
57                                                        TensorInfo(TensorShape(15U, 30U, 40U, 10U), 1, DataType::S32), // Invalid output shape.
58                                                        TensorInfo(TensorShape(15U, 30U, 40U, 10U), 1, DataType::S32), // Invalid boxes shape.
59                                                      }),
60                framework::dataset::make("BoxesInfo",{  TensorInfo(TensorShape(4, 20), 1, DataType::F32),
61                                                        TensorInfo(TensorShape(4, 20), 1, DataType::F32),
62                                                        TensorInfo(TensorShape(4, 20), 1, DataType::F32),
63                                                        TensorInfo(TensorShape(4, 20), 1, DataType::F32),
64                                                        TensorInfo(TensorShape(4, 20), 1, DataType::F32),
65                                                        TensorInfo(TensorShape(3, 20), 1, DataType::F32),
66                                                      })),
67                framework::dataset::make("BoxIndInfo",{ TensorInfo(TensorShape(20), 1, DataType::S32),
68                                                        TensorInfo(TensorShape(10), 1, DataType::S32),
69                                                        TensorInfo(TensorShape(20), 1, DataType::S32),
70                                                        TensorInfo(TensorShape(20), 1, DataType::S32),
71                                                        TensorInfo(TensorShape(20), 1, DataType::S32),
72                                                        TensorInfo(TensorShape(20), 1, DataType::S32),
73                                                      })),
74                framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(15U, 5, 5, 20U), 1, DataType::F32),
75                                                        TensorInfo(TensorShape(15U, 5, 5, 20U), 1, DataType::F32),
76                                                        TensorInfo(TensorShape(15U, 5, 5, 10U), 1, DataType::F32),
77                                                        TensorInfo(TensorShape(15U, 5, 5, 20U), 1, DataType::S32),
78                                                        TensorInfo(TensorShape(5U, 5, 5, 20U), 1, DataType::F32),
79                                                        TensorInfo(TensorShape(15U, 5, 5, 20U), 1, DataType::F32),
80                                                      })),
81                framework::dataset::make("Expected", { true, false, false, false, false, false})),
82                input, boxes, box_ind, output, expected)
83 {
84     ARM_COMPUTE_EXPECT(bool(CLCropResize::validate(&input.clone()->set_data_layout(DataLayout::NHWC).set_is_resizable(false),
85                                                    &boxes.clone()->set_is_resizable(false),
86                                                    &box_ind.clone()->set_is_resizable(false),
87                                                    &output.clone()->set_data_layout(DataLayout::NHWC).set_is_resizable(false),
88                                                    Coordinates2D{ 5, 5 }, InterpolationPolicy::BILINEAR, 100)) == expected, framework::LogLevel::ERRORS);
89 }
90 // clang-format on
91 // *INDENT-ON*
92 
93 TEST_SUITE(Float)
94 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
TEST_SUITE(F16)95 TEST_SUITE(F16)
96 FIXTURE_DATA_TEST_CASE(RunSmall,
97                        CLCropResizeFixture<half>,
98                        framework::DatasetMode::PRECOMMIT,
99                        combine(datasets::SmallCropResizeDataset(),
100                                combine(framework::dataset::make("IsOutOfBounds", { true, false }),
101                                        framework::dataset::make("DataType", DataType::F16))))
102 {
103     // Validate output
104     validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
105 }
106 TEST_SUITE_END() // F16
107 #endif           /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
108 
TEST_SUITE(F32)109 TEST_SUITE(F32)
110 FIXTURE_DATA_TEST_CASE(RunSmall,
111                        CLCropResizeFixture<float>,
112                        framework::DatasetMode::PRECOMMIT,
113                        combine(datasets::SmallCropResizeDataset(),
114                                combine(framework::dataset::make("IsOutOfBounds", { true, false }),
115                                        framework::dataset::make("DataType", DataType::F32))))
116 {
117     // Validate output
118     validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
119 }
120 TEST_SUITE_END() // F32
TEST_SUITE_END()121 TEST_SUITE_END() // Float
122 
123 TEST_SUITE(U8)
124 FIXTURE_DATA_TEST_CASE(RunSmall,
125                        CLCropResizeFixture<uint8_t>,
126                        framework::DatasetMode::PRECOMMIT,
127                        combine(datasets::SmallCropResizeDataset(),
128                                combine(framework::dataset::make("IsOutOfBounds", { true, false }),
129                                        framework::dataset::make("DataType", DataType::U8))))
130 {
131     // Validate output
132     validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
133 }
134 TEST_SUITE_END() // U8
135 
TEST_SUITE(U16)136 TEST_SUITE(U16)
137 FIXTURE_DATA_TEST_CASE(RunSmall,
138                        CLCropResizeFixture<uint16_t>,
139                        framework::DatasetMode::PRECOMMIT,
140                        combine(datasets::SmallCropResizeDataset(),
141                                combine(framework::dataset::make("IsOutOfBounds", { true, false }),
142                                        framework::dataset::make("DataType", DataType::U16))))
143 {
144     // Validate output
145     validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
146 }
147 TEST_SUITE_END() // U16
148 
TEST_SUITE(S16)149 TEST_SUITE(S16)
150 FIXTURE_DATA_TEST_CASE(RunSmall,
151                        CLCropResizeFixture<int16_t>,
152                        framework::DatasetMode::PRECOMMIT,
153                        combine(datasets::SmallCropResizeDataset(),
154                                combine(framework::dataset::make("IsOutOfBounds", { true, false }),
155                                        framework::dataset::make("DataType", DataType::S16))))
156 {
157     // Validate output
158     validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
159 }
160 TEST_SUITE_END() // S16
161 
TEST_SUITE(U32)162 TEST_SUITE(U32)
163 FIXTURE_DATA_TEST_CASE(RunSmall,
164                        CLCropResizeFixture<uint32_t>,
165                        framework::DatasetMode::PRECOMMIT,
166                        combine(datasets::SmallCropResizeDataset(),
167                                combine(framework::dataset::make("IsOutOfBounds", { true, false }),
168                                        framework::dataset::make("DataType", DataType::U32))))
169 {
170     // Validate output
171     validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
172 }
173 TEST_SUITE_END() // U32
174 
TEST_SUITE(S32)175 TEST_SUITE(S32)
176 FIXTURE_DATA_TEST_CASE(RunSmall,
177                        CLCropResizeFixture<int32_t>,
178                        framework::DatasetMode::PRECOMMIT,
179                        combine(datasets::SmallCropResizeDataset(),
180                                combine(framework::dataset::make("IsOutOfBounds", { true, false }),
181                                        framework::dataset::make("DataType", DataType::S32))))
182 {
183     // Validate output
184     validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
185 }
186 TEST_SUITE_END() // S32
187 
188 TEST_SUITE_END() // CropResize
189 TEST_SUITE_END() // CL
190 } // namespace validation
191 } // namespace test
192 } // namespace arm_compute
193