xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/CL/DepthConvertLayer.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2017-2021 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/CLDepthConvertLayer.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/DepthConvertLayerFixture.h"
37 
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 namespace
45 {
46 /** Input data sets **/
47 const auto DepthConvertLayerU8toU16Dataset   = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U16));
48 const auto DepthConvertLayerU8toS16Dataset   = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::S16));
49 const auto DepthConvertLayerU8toS32Dataset   = combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::S32));
50 const auto DepthConvertLayerU16toU8Dataset   = combine(framework::dataset::make("DataType", DataType::U16), framework::dataset::make("DataType", DataType::U8));
51 const auto DepthConvertLayerU16toU32Dataset  = combine(framework::dataset::make("DataType", DataType::U16), framework::dataset::make("DataType", DataType::U32));
52 const auto DepthConvertLayerS16toU8Dataset   = combine(framework::dataset::make("DataType", DataType::S16), framework::dataset::make("DataType", DataType::U8));
53 const auto DepthConvertLayerS16toS32Dataset  = combine(framework::dataset::make("DataType", DataType::S16), framework::dataset::make("DataType", DataType::S32));
54 const auto DepthConvertLayerF16toF32Dataset  = combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F32));
55 const auto DepthConvertLayerF32toF16Dataset  = combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F16));
56 const auto DepthConvertLayerZeroShiftDataset = framework::dataset::make("Shift", 0);
57 } // namespace
58 
59 TEST_SUITE(CL)
TEST_SUITE(DepthConvertLayer)60 TEST_SUITE(DepthConvertLayer)
61 
62 // *INDENT-OFF*
63 // clang-format off
64 DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
65                framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QASYMM8), // Support upcasting from QASYMM8 to S16
66                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),      // Invalid data type combination
67                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),      // Mismatching shapes
68                                                        TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),      // Invalid shift
69                                                        TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32),     // Shift non zero and FP
70                                                        TensorInfo(TensorShape(32U, 32U, 2U), 1, DataType::U8),      // Valid
71                                                      }),
72                framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
73                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
74                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
75                                                        TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
76                                                        TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16),
77                                                        TensorInfo(TensorShape(32U, 32U, 2U), 1, DataType::U16),
78                                                      })),
79                framework::dataset::make("Policy",{ ConvertPolicy::WRAP,
80                                                    ConvertPolicy::WRAP,
81                                                    ConvertPolicy::WRAP,
82                                                    ConvertPolicy::WRAP,
83                                                    ConvertPolicy::WRAP,
84                                                    ConvertPolicy::WRAP,
85                                                      })),
86                framework::dataset::make("Shift",{ 0, 0, 0, 1, 1, 0, })),
87                framework::dataset::make("Expected", { true, false, false, false, false, true})),
88                input_info, output_info, policy, shift, expected)
89 {
90     ARM_COMPUTE_EXPECT(bool(CLDepthConvertLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), policy, shift)) == expected, framework::LogLevel::ERRORS);
91 }
92 // clang-format on
93 // *INDENT-ON*
94 
95 template <typename T>
96 using CLDepthConvertLayerToU16Fixture = DepthConvertLayerValidationFixture<CLTensor, CLAccessor, CLDepthConvertLayer, T, uint16_t>;
97 template <typename T>
98 using CLDepthConvertLayerToS16Fixture = DepthConvertLayerValidationFixture<CLTensor, CLAccessor, CLDepthConvertLayer, T, int16_t>;
99 template <typename T>
100 using CLDepthConvertLayerToS32Fixture = DepthConvertLayerValidationFixture<CLTensor, CLAccessor, CLDepthConvertLayer, T, int32_t>;
101 template <typename T>
102 using CLDepthConvertLayerToU8Fixture = DepthConvertLayerValidationFixture<CLTensor, CLAccessor, CLDepthConvertLayer, T, uint8_t>;
103 template <typename T>
104 using CLDepthConvertLayerToU32Fixture = DepthConvertLayerValidationFixture<CLTensor, CLAccessor, CLDepthConvertLayer, T, uint32_t>;
105 template <typename T>
106 using CLDepthConvertLayerToF16Fixture = DepthConvertLayerValidationFixture<CLTensor, CLAccessor, CLDepthConvertLayer, T, half>;
107 template <typename T>
108 using CLDepthConvertLayerToF32Fixture = DepthConvertLayerValidationFixture<CLTensor, CLAccessor, CLDepthConvertLayer, T, float>;
109 
110 TEST_SUITE(U8_to_U16)
111 FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthConvertLayerToU16Fixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), DepthConvertLayerU8toU16Dataset),
112                                                                                                                       framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
113                                                                                                                       DepthConvertLayerZeroShiftDataset))
114 {
115     // Validate output
116     validate(CLAccessor(_target), _reference);
117 }
118 
119 FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthConvertLayerToU16Fixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), DepthConvertLayerU8toU16Dataset),
120                                                                                                                     framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
121                                                                                                                     DepthConvertLayerZeroShiftDataset))
122 {
123     // Validate output
124     validate(CLAccessor(_target), _reference);
125 }
126 TEST_SUITE_END() // U8_to_U16
127 
TEST_SUITE(U8_to_S16)128 TEST_SUITE(U8_to_S16)
129 FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthConvertLayerToS16Fixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), DepthConvertLayerU8toS16Dataset),
130                                                                                                                       framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
131                                                                                                                       DepthConvertLayerZeroShiftDataset))
132 {
133     // Validate output
134     validate(CLAccessor(_target), _reference);
135 }
136 
137 FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthConvertLayerToS16Fixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), DepthConvertLayerU8toS16Dataset),
138                                                                                                                     framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
139                                                                                                                     DepthConvertLayerZeroShiftDataset))
140 {
141     // Validate output
142     validate(CLAccessor(_target), _reference);
143 }
144 TEST_SUITE_END() // U8_to_S16
TEST_SUITE(U8_to_S32)145 TEST_SUITE(U8_to_S32)
146 FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthConvertLayerToS32Fixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), DepthConvertLayerU8toS32Dataset),
147                                                                                                                       framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
148                                                                                                                       DepthConvertLayerZeroShiftDataset))
149 {
150     // Validate output
151     validate(CLAccessor(_target), _reference);
152 }
153 
154 FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthConvertLayerToS32Fixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), DepthConvertLayerU8toS32Dataset),
155                                                                                                                     framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
156                                                                                                                     DepthConvertLayerZeroShiftDataset))
157 {
158     // Validate output
159     validate(CLAccessor(_target), _reference);
160 }
161 TEST_SUITE_END() // U8_to_S32
162 
TEST_SUITE(U16_to_U8)163 TEST_SUITE(U16_to_U8)
164 FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthConvertLayerToU8Fixture<uint16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), DepthConvertLayerU16toU8Dataset),
165                                                                                                                       framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
166                                                                                                                       DepthConvertLayerZeroShiftDataset))
167 {
168     // Validate output
169     validate(CLAccessor(_target), _reference);
170 }
171 FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthConvertLayerToU8Fixture<uint16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), DepthConvertLayerU16toU8Dataset),
172                                                                                                                     framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
173                                                                                                                     DepthConvertLayerZeroShiftDataset))
174 {
175     // Validate output
176     validate(CLAccessor(_target), _reference);
177 }
178 TEST_SUITE_END() // U16_to_U8
179 
TEST_SUITE(U16_to_U32)180 TEST_SUITE(U16_to_U32)
181 FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthConvertLayerToU32Fixture<uint16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), DepthConvertLayerU16toU32Dataset),
182                                                                                                                        framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
183                                                                                                                        DepthConvertLayerZeroShiftDataset))
184 {
185     // Validate output
186     validate(CLAccessor(_target), _reference);
187 }
188 FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthConvertLayerToU32Fixture<uint16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), DepthConvertLayerU16toU32Dataset),
189                                                                                                                      framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
190                                                                                                                      DepthConvertLayerZeroShiftDataset))
191 {
192     // Validate output
193     validate(CLAccessor(_target), _reference);
194 }
195 TEST_SUITE_END() // U16_to_U32
196 
TEST_SUITE(S16_to_U8)197 TEST_SUITE(S16_to_U8)
198 FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthConvertLayerToU8Fixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), DepthConvertLayerS16toU8Dataset),
199                                                                                                                      framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
200                                                                                                                      DepthConvertLayerZeroShiftDataset))
201 {
202     // Validate output
203     validate(CLAccessor(_target), _reference);
204 }
205 FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthConvertLayerToU8Fixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), DepthConvertLayerS16toU8Dataset),
206                                                                                                                    framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
207                                                                                                                    DepthConvertLayerZeroShiftDataset))
208 {
209     // Validate output
210     validate(CLAccessor(_target), _reference);
211 }
212 TEST_SUITE_END() // S16_to_U8
213 
TEST_SUITE(S16_to_S32)214 TEST_SUITE(S16_to_S32)
215 FIXTURE_DATA_TEST_CASE(RunSmall, CLDepthConvertLayerToS32Fixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), DepthConvertLayerS16toS32Dataset),
216                                                                                                                       framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
217                                                                                                                       DepthConvertLayerZeroShiftDataset))
218 {
219     // Validate output
220     validate(CLAccessor(_target), _reference);
221 }
222 FIXTURE_DATA_TEST_CASE(RunLarge, CLDepthConvertLayerToS32Fixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), DepthConvertLayerS16toS32Dataset),
223                                                                                                                     framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
224                                                                                                                     DepthConvertLayerZeroShiftDataset))
225 {
226     // Validate output
227     validate(CLAccessor(_target), _reference);
228 }
229 TEST_SUITE_END() // S16_to_S32
230 
231 TEST_SUITE_END() // DepthConvertLayer
232 TEST_SUITE_END() // CL
233 } // namespace validation
234 } // namespace test
235 } // namespace arm_compute
236