xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/CL/GEMMReshapeLHSMatrix.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 "arm_compute/core/utils/misc/ShapeCalculator.h"
26 #include "arm_compute/runtime/CL/CLTensor.h"
27 #include "arm_compute/runtime/CL/CLTensorAllocator.h"
28 #include "src/gpu/cl/kernels/ClGemmReshapeLhsMatrixKernel.h"
29 #include "tests/CL/CLAccessor.h"
30 #include "tests/CL/Helper.h"
31 #include "tests/PaddingCalculator.h"
32 #include "tests/datasets/ShapeDatasets.h"
33 #include "tests/framework/Asserts.h"
34 #include "tests/framework/Macros.h"
35 #include "tests/framework/datasets/Datasets.h"
36 #include "tests/validation/Validation.h"
37 #include "tests/validation/fixtures/GEMMReshapeLHSMatrixFixture.h"
38 
39 namespace arm_compute
40 {
41 namespace test
42 {
43 namespace validation
44 {
45 using namespace arm_compute::misc::shape_calculator;
46 using namespace arm_compute::opencl::kernels;
47 
48 // Initialize the output tensor with zero and fill the border with zero
49 using CLGEMMReshapeLHSMatrix = CLSynthetizeOperatorInitOutputWithZeroAndWithZeroConstantBorder<ClGemmReshapeLhsMatrixKernel, 16>;
50 
51 template <typename T>
52 using CLGEMMReshapeLHSMatrixFixture = GEMMReshapeLHSMatrixValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeLHSMatrix, T, false>;
53 
54 // Fixture to use when the input has to be reinterpreted as 3D
55 template <typename T>
56 using CLGEMMReshapeLHSMatrix3DFixture = GEMMReshapeLHSMatrixValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeLHSMatrix, T, true>;
57 
58 // *INDENT-OFF*
59 // clang-format off
60 /** Data types */
61 
62 namespace
63 {
64 /** Batch size values to test */
65 const auto b_values = framework::dataset::make("batchsize", 1, 3);
66 
67 /** M0 values to test */
68 const auto m0_values_s32 = framework::dataset::make("M0", { 2, 3 });
69 const auto m0_values_s16 = framework::dataset::make("M0", { 4 });
70 const auto m0_values_s16_nt = framework::dataset::make("M0", { 5 });
71 const auto m0_values_s8_nt = framework::dataset::make("M0", { 6,7 });
72 const auto m0_values_s8 = framework::dataset::make("M0", { 8 });
73 
74 /** K0 values to test */
75 const auto k0_values_s32 = framework::dataset::make("K0", { 2, 3 });
76 const auto k0_values_s16 = framework::dataset::make("K0", { 4, 8 });
77 const auto k0_values_s8 = framework::dataset::make("K0", { 16 });
78 
79 /** V0 values to test */
80 const auto v0_values = framework::dataset::make("V0", 1, 4);
81 
82 /** Interleave values to test */
83 const auto i_values = framework::dataset::make("interleave", { true, false });
84 
85 /** Transpose values to test */
86 const auto t_values = framework::dataset::make("transpose", { true, false });
87 
88 } // namespace
89 
90 TEST_SUITE(CL)
TEST_SUITE(GEMMReshapeLHSMatrix)91 TEST_SUITE(GEMMReshapeLHSMatrix)
92 
93 FIXTURE_DATA_TEST_CASE(S32, CLGEMMReshapeLHSMatrixFixture<int>, framework::DatasetMode::ALL,
94                 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
95                                                                    b_values),
96                                                                    framework::dataset::make("DataType", DataType::S32)),
97                                                                    m0_values_s32),
98                                                                    k0_values_s32),
99                                                                    v0_values),
100                                                                    i_values),
101                                                                    t_values))
102 {
103     // Validate output
104     validate(CLAccessor(_target), _reference);
105 }
106 
107 FIXTURE_DATA_TEST_CASE(S16, CLGEMMReshapeLHSMatrixFixture<short>, framework::DatasetMode::ALL,
108                 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
109                                                                    b_values),
110                                                                    framework::dataset::make("DataType", DataType::S16)),
111                                                                    m0_values_s16),
112                                                                    k0_values_s16),
113                                                                    v0_values),
114                                                                    i_values),
115                                                                    t_values))
116 {
117     // Validate output
118     validate(CLAccessor(_target), _reference);
119 }
120 
121 FIXTURE_DATA_TEST_CASE(S8, CLGEMMReshapeLHSMatrixFixture<char>, framework::DatasetMode::ALL,
122                 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
123                                                                    b_values),
124                                                                    framework::dataset::make("DataType", DataType::S8)),
125                                                                    m0_values_s8),
126                                                                    k0_values_s8),
127                                                                    v0_values),
128                                                                    i_values),
129                                                                    t_values))
130 {
131     // Validate output
132     validate(CLAccessor(_target), _reference);
133 }
134 
135 TEST_SUITE(NotTransposed)
136 FIXTURE_DATA_TEST_CASE(S16, CLGEMMReshapeLHSMatrixFixture<short>, framework::DatasetMode::ALL,
137                 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
138                                                                    b_values),
139                                                                    framework::dataset::make("DataType", DataType::S16)),
140                                                                    m0_values_s16_nt),
141                                                                    k0_values_s16),
142                                                                    v0_values),
143                                                                    i_values),
144                                                                    framework::dataset::make("transpose", { false })))
145 {
146     // Validate output
147     validate(CLAccessor(_target), _reference);
148 }
149 
150 FIXTURE_DATA_TEST_CASE(S8, CLGEMMReshapeLHSMatrixFixture<char>, framework::DatasetMode::ALL,
151                 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
152                                                                    b_values),
153                                                                    framework::dataset::make("DataType", DataType::S8)),
154                                                                    m0_values_s8_nt),
155                                                                    k0_values_s8),
156                                                                    v0_values),
157                                                                    i_values),
158                                                                    framework::dataset::make("transpose", { false })))
159 {
160     // Validate output
161     validate(CLAccessor(_target), _reference);
162 }
163 
164 TEST_SUITE_END()
165 
TEST_SUITE(ReinterpretInputAs3D)166 TEST_SUITE(ReinterpretInputAs3D)
167 FIXTURE_DATA_TEST_CASE(S32, CLGEMMReshapeLHSMatrix3DFixture<int>, framework::DatasetMode::ALL,
168                 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(),
169                                                                    b_values),
170                                                                    framework::dataset::make("DataType", DataType::S32)),
171                                                                    m0_values_s32),
172                                                                    k0_values_s32),
173                                                                    v0_values),
174                                                                    i_values),
175                                                                    t_values))
176 {
177     // Validate output
178     validate(CLAccessor(_target), _reference);
179 }
180 
181 FIXTURE_DATA_TEST_CASE(S16, CLGEMMReshapeLHSMatrix3DFixture<short>, framework::DatasetMode::ALL,
182                 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(),
183                                                                    b_values),
184                                                                    framework::dataset::make("DataType", DataType::S16)),
185                                                                    m0_values_s16),
186                                                                    k0_values_s16),
187                                                                    v0_values),
188                                                                    i_values),
189                                                                    t_values))
190 {
191     // Validate output
192     validate(CLAccessor(_target), _reference);
193 }
194 
195 FIXTURE_DATA_TEST_CASE(S8, CLGEMMReshapeLHSMatrix3DFixture<char>, framework::DatasetMode::ALL,
196                 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(),
197                                                                    b_values),
198                                                                    framework::dataset::make("DataType", DataType::S8)),
199                                                                    m0_values_s8),
200                                                                    k0_values_s8),
201                                                                    v0_values),
202                                                                    i_values),
203                                                                    t_values))
204 {
205     // Validate output
206     validate(CLAccessor(_target), _reference);
207 }
208 TEST_SUITE_END() // ReinterpretInputAs3D
209 TEST_SUITE_END() // GEMMReshapeLHSMatrix
210 TEST_SUITE_END() // CL
211 } // namespace validation
212 } // namespace test
213 } // namespace arm_compute
214