xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/CL/Col2Im.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1*c217d954SCole Faust /*
2*c217d954SCole Faust  * Copyright (c) 2018-2021 Arm Limited.
3*c217d954SCole Faust  *
4*c217d954SCole Faust  * SPDX-License-Identifier: MIT
5*c217d954SCole Faust  *
6*c217d954SCole Faust  * Permission is hereby granted, free of charge, to any person obtaining a copy
7*c217d954SCole Faust  * of this software and associated documentation files (the "Software"), to
8*c217d954SCole Faust  * deal in the Software without restriction, including without limitation the
9*c217d954SCole Faust  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10*c217d954SCole Faust  * sell copies of the Software, and to permit persons to whom the Software is
11*c217d954SCole Faust  * furnished to do so, subject to the following conditions:
12*c217d954SCole Faust  *
13*c217d954SCole Faust  * The above copyright notice and this permission notice shall be included in all
14*c217d954SCole Faust  * copies or substantial portions of the Software.
15*c217d954SCole Faust  *
16*c217d954SCole Faust  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*c217d954SCole Faust  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*c217d954SCole Faust  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19*c217d954SCole Faust  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20*c217d954SCole Faust  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21*c217d954SCole Faust  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22*c217d954SCole Faust  * SOFTWARE.
23*c217d954SCole Faust  */
24*c217d954SCole Faust #include "arm_compute/core/Types.h"
25*c217d954SCole Faust #include "src/gpu/cl/kernels/ClCol2ImKernel.h"
26*c217d954SCole Faust #include "tests/CL/CLAccessor.h"
27*c217d954SCole Faust #include "tests/CL/Helper.h"
28*c217d954SCole Faust #include "tests/framework/Asserts.h"
29*c217d954SCole Faust #include "tests/framework/Macros.h"
30*c217d954SCole Faust #include "tests/framework/datasets/Datasets.h"
31*c217d954SCole Faust #include "tests/validation/Validation.h"
32*c217d954SCole Faust #include "tests/validation/fixtures/Col2ImFixture.h"
33*c217d954SCole Faust 
34*c217d954SCole Faust namespace arm_compute
35*c217d954SCole Faust {
36*c217d954SCole Faust namespace test
37*c217d954SCole Faust {
38*c217d954SCole Faust namespace validation
39*c217d954SCole Faust {
40*c217d954SCole Faust TEST_SUITE(CL)
41*c217d954SCole Faust TEST_SUITE(Col2Im)
42*c217d954SCole Faust 
43*c217d954SCole Faust using ClCol2Im = ClSynthetizeOperatorWithBorder<opencl::kernels::ClCol2ImKernel>;
44*c217d954SCole Faust 
45*c217d954SCole Faust /** Negative tests
46*c217d954SCole Faust  *
47*c217d954SCole Faust  * A series of validation tests on configurations which according to the API specification
48*c217d954SCole Faust  * the function should fail against.
49*c217d954SCole Faust  *
50*c217d954SCole Faust  * Checks performed in order:
51*c217d954SCole Faust  *     - Pass unsupported data type for input
52*c217d954SCole Faust  *     - Pass NHWC as output data layout
53*c217d954SCole Faust  *     - Pass an invalid output shape
54*c217d954SCole Faust  */
TEST_CASE(Negative,framework::DatasetMode::ALL)55*c217d954SCole Faust TEST_CASE(Negative, framework::DatasetMode::ALL)
56*c217d954SCole Faust {
57*c217d954SCole Faust     // Unsupported data type
58*c217d954SCole Faust     {
59*c217d954SCole Faust         const auto input     = TensorInfo(TensorShape(10U, 12U, 1U, 2U), 1, DataType::SIZET);
60*c217d954SCole Faust         const auto output    = TensorInfo(TensorShape(3U, 4U, 10U, 1U, 2U), 1, DataType::F32);
61*c217d954SCole Faust         const auto conv_size = Size2D(3, 4);
62*c217d954SCole Faust         const auto status    = opencl::kernels::ClCol2ImKernel::validate(&input, &output, conv_size);
63*c217d954SCole Faust         ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
64*c217d954SCole Faust     }
65*c217d954SCole Faust 
66*c217d954SCole Faust     // NHWC as output data layout
67*c217d954SCole Faust     {
68*c217d954SCole Faust         const auto input     = TensorInfo(TensorShape(10U, 12U, 1U, 2U), 1, DataType::F32);
69*c217d954SCole Faust         const auto output    = TensorInfo(TensorShape(3U, 4U, 10U, 1U, 2U), 1, DataType::F32, DataLayout::NHWC);
70*c217d954SCole Faust         const auto conv_size = Size2D(3, 4);
71*c217d954SCole Faust         const auto status    = opencl::kernels::ClCol2ImKernel::validate(&input, &output, conv_size);
72*c217d954SCole Faust         ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
73*c217d954SCole Faust     }
74*c217d954SCole Faust 
75*c217d954SCole Faust     // Invalid output size
76*c217d954SCole Faust     {
77*c217d954SCole Faust         const auto input     = TensorInfo(TensorShape(10U, 12U, 1U, 2U), 1, DataType::F32);
78*c217d954SCole Faust         const auto output    = TensorInfo(TensorShape(3U, 4U, 10U, 2U, 2U), 1, DataType::F32);
79*c217d954SCole Faust         const auto conv_size = Size2D(3, 4);
80*c217d954SCole Faust         const auto status    = opencl::kernels::ClCol2ImKernel::validate(&input, &output, conv_size);
81*c217d954SCole Faust         ARM_COMPUTE_EXPECT(bool(status) == false, framework::LogLevel::ERRORS);
82*c217d954SCole Faust     }
83*c217d954SCole Faust }
84*c217d954SCole Faust 
85*c217d954SCole Faust template <typename T>
86*c217d954SCole Faust using ClCol2ImFixture = Col2ImOpValidationFixture<CLTensor, CLAccessor, ClCol2Im, T, true>;
87*c217d954SCole Faust 
88*c217d954SCole Faust /** Test kernel for single-precision floating point
89*c217d954SCole Faust  *
90*c217d954SCole Faust  * @note 8 elements processed per iteration
91*c217d954SCole Faust  *
92*c217d954SCole Faust  * Three main tests will be run:
93*c217d954SCole Faust  *  - Channels are multiple of elements processed
94*c217d954SCole Faust  *  - Channels larger and non multiple of elements used
95*c217d954SCole Faust  *  - Channels smaller and not multiple of elements used
96*c217d954SCole Faust  *
97*c217d954SCole Faust  *  The above will be repeated with a different group size
98*c217d954SCole Faust  *
99*c217d954SCole Faust  *  Kernel tested col2im
100*c217d954SCole Faust  */
101*c217d954SCole Faust FIXTURE_DATA_TEST_CASE(FP32,
102*c217d954SCole Faust                        ClCol2ImFixture<float>,
103*c217d954SCole Faust                        framework::DatasetMode::ALL,
104*c217d954SCole Faust                        combine(combine(combine(combine(
105*c217d954SCole Faust                                                    framework::dataset::make("InputShape", { TensorShape(8U, 16U, 3U, 1U), TensorShape(17U, 16U, 3U, 1U), TensorShape(7U, 16U, 3U, 1U) }),
106*c217d954SCole Faust                                                    framework::dataset::make("ConvolvedWidth", 4)),
107*c217d954SCole Faust                                                framework::dataset::make("ConvolvedHeight", 4)),
108*c217d954SCole Faust                                        framework::dataset::make("Groups", { 1, 3 })),
109*c217d954SCole Faust                                framework::dataset::make("DataType", DataType::F32)))
110*c217d954SCole Faust {
111*c217d954SCole Faust     // Validate output
112*c217d954SCole Faust     validate(CLAccessor(_target), _reference);
113*c217d954SCole Faust }
114*c217d954SCole Faust 
115*c217d954SCole Faust /** Test kernel for half-precision floating point
116*c217d954SCole Faust  *
117*c217d954SCole Faust  * @note 8 elements processed per iteration
118*c217d954SCole Faust  *
119*c217d954SCole Faust  * One main tests will be run:
120*c217d954SCole Faust  *  - Channels larger and non multiple of elements used
121*c217d954SCole Faust  *
122*c217d954SCole Faust  *  We just need to test the difference in the data type size.
123*c217d954SCole Faust  *  Any other issues can be identified by the main FP32 tests
124*c217d954SCole Faust  *
125*c217d954SCole Faust  *  Kernel tested col2im
126*c217d954SCole Faust  */
127*c217d954SCole Faust FIXTURE_DATA_TEST_CASE(F16,
128*c217d954SCole Faust                        ClCol2ImFixture<half>,
129*c217d954SCole Faust                        framework::DatasetMode::ALL,
130*c217d954SCole Faust                        combine(combine(combine(combine(
131*c217d954SCole Faust                                                    framework::dataset::make("InputShape", TensorShape(17U, 16U, 3U, 1U)),
132*c217d954SCole Faust                                                    framework::dataset::make("ConvolvedWidth", 4)),
133*c217d954SCole Faust                                                framework::dataset::make("ConvolvedHeight", 4)),
134*c217d954SCole Faust                                        framework::dataset::make("Groups", 3)),
135*c217d954SCole Faust                                framework::dataset::make("DataType", DataType::F16)))
136*c217d954SCole Faust {
137*c217d954SCole Faust     // Validate output
138*c217d954SCole Faust     validate(CLAccessor(_target), _reference);
139*c217d954SCole Faust }
140*c217d954SCole Faust 
141*c217d954SCole Faust /** Test kernel for unsigned asymmetric quantized type
142*c217d954SCole Faust  *
143*c217d954SCole Faust  * @note 8 elements processed per iteration
144*c217d954SCole Faust  *
145*c217d954SCole Faust  * One main tests will be run:
146*c217d954SCole Faust  *  - Channels larger and non multiple of elements used
147*c217d954SCole Faust  *
148*c217d954SCole Faust  *  We just need to test the difference in the data type size.
149*c217d954SCole Faust  *  Any other issues can be identified by the main FP32 tests
150*c217d954SCole Faust  *
151*c217d954SCole Faust  *  Kernel tested col2im
152*c217d954SCole Faust  */
153*c217d954SCole Faust FIXTURE_DATA_TEST_CASE(QASYMM8,
154*c217d954SCole Faust                        ClCol2ImFixture<uint8_t>,
155*c217d954SCole Faust                        framework::DatasetMode::ALL,
156*c217d954SCole Faust                        combine(combine(combine(combine(
157*c217d954SCole Faust                                                    framework::dataset::make("InputShape", TensorShape(17U, 16U, 3U, 1U)),
158*c217d954SCole Faust                                                    framework::dataset::make("ConvolvedWidth", 4)),
159*c217d954SCole Faust                                                framework::dataset::make("ConvolvedHeight", 4)),
160*c217d954SCole Faust                                        framework::dataset::make("Groups", 3)),
161*c217d954SCole Faust                                framework::dataset::make("DataType", DataType::QASYMM8)))
162*c217d954SCole Faust {
163*c217d954SCole Faust     // Validate output
164*c217d954SCole Faust     validate(CLAccessor(_target), _reference);
165*c217d954SCole Faust }
166*c217d954SCole Faust 
167*c217d954SCole Faust TEST_SUITE_END() // CL
168*c217d954SCole Faust TEST_SUITE_END() // Col2Im
169*c217d954SCole Faust } // namespace validation
170*c217d954SCole Faust } // namespace test
171*c217d954SCole Faust } // namespace arm_compute
172