xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/CL/Col2Im.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2018-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 "src/gpu/cl/kernels/ClCol2ImKernel.h"
26 #include "tests/CL/CLAccessor.h"
27 #include "tests/CL/Helper.h"
28 #include "tests/framework/Asserts.h"
29 #include "tests/framework/Macros.h"
30 #include "tests/framework/datasets/Datasets.h"
31 #include "tests/validation/Validation.h"
32 #include "tests/validation/fixtures/Col2ImFixture.h"
33 
34 namespace arm_compute
35 {
36 namespace test
37 {
38 namespace validation
39 {
40 TEST_SUITE(CL)
41 TEST_SUITE(Col2Im)
42 
43 using ClCol2Im = ClSynthetizeOperatorWithBorder<opencl::kernels::ClCol2ImKernel>;
44 
45 /** Negative tests
46  *
47  * A series of validation tests on configurations which according to the API specification
48  * the function should fail against.
49  *
50  * Checks performed in order:
51  *     - Pass unsupported data type for input
52  *     - Pass NHWC as output data layout
53  *     - Pass an invalid output shape
54  */
TEST_CASE(Negative,framework::DatasetMode::ALL)55 TEST_CASE(Negative, framework::DatasetMode::ALL)
56 {
57     // Unsupported data type
58     {
59         const auto input     = TensorInfo(TensorShape(10U, 12U, 1U, 2U), 1, DataType::SIZET);
60         const auto output    = TensorInfo(TensorShape(3U, 4U, 10U, 1U, 2U), 1, DataType::F32);
61         const auto conv_size = Size2D(3, 4);
62         const auto status    = opencl::kernels::ClCol2ImKernel::validate(&input, &output, conv_size);
63         ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
64     }
65 
66     // NHWC as output data layout
67     {
68         const auto input     = TensorInfo(TensorShape(10U, 12U, 1U, 2U), 1, DataType::F32);
69         const auto output    = TensorInfo(TensorShape(3U, 4U, 10U, 1U, 2U), 1, DataType::F32, DataLayout::NHWC);
70         const auto conv_size = Size2D(3, 4);
71         const auto status    = opencl::kernels::ClCol2ImKernel::validate(&input, &output, conv_size);
72         ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
73     }
74 
75     // Invalid output size
76     {
77         const auto input     = TensorInfo(TensorShape(10U, 12U, 1U, 2U), 1, DataType::F32);
78         const auto output    = TensorInfo(TensorShape(3U, 4U, 10U, 2U, 2U), 1, DataType::F32);
79         const auto conv_size = Size2D(3, 4);
80         const auto status    = opencl::kernels::ClCol2ImKernel::validate(&input, &output, conv_size);
81         ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
82     }
83 }
84 
85 template <typename T>
86 using ClCol2ImFixture = Col2ImOpValidationFixture<CLTensor, CLAccessor, ClCol2Im, T, true>;
87 
88 /** Test kernel for single-precision floating point
89  *
90  * @note 8 elements processed per iteration
91  *
92  * Three main tests will be run:
93  *  - Channels are multiple of elements processed
94  *  - Channels larger and non multiple of elements used
95  *  - Channels smaller and not multiple of elements used
96  *
97  *  The above will be repeated with a different group size
98  *
99  *  Kernel tested col2im
100  */
101 FIXTURE_DATA_TEST_CASE(FP32,
102                        ClCol2ImFixture<float>,
103                        framework::DatasetMode::ALL,
104                        combine(combine(combine(combine(
105                                                    framework::dataset::make("InputShape", { TensorShape(8U, 16U, 3U, 1U), TensorShape(17U, 16U, 3U, 1U), TensorShape(7U, 16U, 3U, 1U) }),
106                                                    framework::dataset::make("ConvolvedWidth", 4)),
107                                                framework::dataset::make("ConvolvedHeight", 4)),
108                                        framework::dataset::make("Groups", { 1, 3 })),
109                                framework::dataset::make("DataType", DataType::F32)))
110 {
111     // Validate output
112     validate(CLAccessor(_target), _reference);
113 }
114 
115 /** Test kernel for half-precision floating point
116  *
117  * @note 8 elements processed per iteration
118  *
119  * One main tests will be run:
120  *  - Channels larger and non multiple of elements used
121  *
122  *  We just need to test the difference in the data type size.
123  *  Any other issues can be identified by the main FP32 tests
124  *
125  *  Kernel tested col2im
126  */
127 FIXTURE_DATA_TEST_CASE(F16,
128                        ClCol2ImFixture<half>,
129                        framework::DatasetMode::ALL,
130                        combine(combine(combine(combine(
131                                                    framework::dataset::make("InputShape", TensorShape(17U, 16U, 3U, 1U)),
132                                                    framework::dataset::make("ConvolvedWidth", 4)),
133                                                framework::dataset::make("ConvolvedHeight", 4)),
134                                        framework::dataset::make("Groups", 3)),
135                                framework::dataset::make("DataType", DataType::F16)))
136 {
137     // Validate output
138     validate(CLAccessor(_target), _reference);
139 }
140 
141 /** Test kernel for unsigned asymmetric quantized type
142  *
143  * @note 8 elements processed per iteration
144  *
145  * One main tests will be run:
146  *  - Channels larger and non multiple of elements used
147  *
148  *  We just need to test the difference in the data type size.
149  *  Any other issues can be identified by the main FP32 tests
150  *
151  *  Kernel tested col2im
152  */
153 FIXTURE_DATA_TEST_CASE(QASYMM8,
154                        ClCol2ImFixture<uint8_t>,
155                        framework::DatasetMode::ALL,
156                        combine(combine(combine(combine(
157                                                    framework::dataset::make("InputShape", TensorShape(17U, 16U, 3U, 1U)),
158                                                    framework::dataset::make("ConvolvedWidth", 4)),
159                                                framework::dataset::make("ConvolvedHeight", 4)),
160                                        framework::dataset::make("Groups", 3)),
161                                framework::dataset::make("DataType", DataType::QASYMM8)))
162 {
163     // Validate output
164     validate(CLAccessor(_target), _reference);
165 }
166 
167 TEST_SUITE_END() // CL
168 TEST_SUITE_END() // Col2Im
169 } // namespace validation
170 } // namespace test
171 } // namespace arm_compute
172