• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/core/utils/misc/ShapeCalculator.h"
26 #include "src/core/CL/kernels/CLGEMMLowpMatrixMultiplyReshapedKernel.h"
27 #include "src/core/CL/kernels/CLGEMMReshapeLHSMatrixKernel.h"
28 #include "src/core/CL/kernels/CLGEMMReshapeRHSMatrixKernel.h"
29 #include "tests/CL/CLAccessor.h"
30 #include "tests/CL/Helper.h"
31 #include "tests/framework/Asserts.h"
32 #include "tests/framework/Macros.h"
33 #include "tests/framework/datasets/Datasets.h"
34 #include "tests/validation/Validation.h"
35 #include "tests/validation/fixtures/GEMMLowpFixture.h"
36 
37 namespace arm_compute
38 {
39 namespace test
40 {
41 namespace validation
42 {
43 using namespace arm_compute::misc::shape_calculator;
44 
45 // Create function for CLGEMMReshapeLHSMatrixKernel
46 using CLGEMMReshapeLHSMatrix = CLSynthetizeFunction<CLGEMMReshapeLHSMatrixKernel>;
47 
48 // Create function for CLGEMMReshapeRHSMatrixKernel
49 using CLGEMMReshapeRHSMatrix = CLSynthetizeFunction<CLGEMMReshapeRHSMatrixKernel>;
50 
51 // Create function for CLGEMMMatrixMultiplyReshapedKernel
52 using CLGEMMLowpMatrixMultiplyReshaped = CLSynthetizeFunction<CLGEMMLowpMatrixMultiplyReshapedKernel>;
53 
54 // Fixture for CLGEMMLowpMatrixMultiplyReshaped
55 using CLGEMMLowpMatrixMultiplyReshapedFixture = GEMMLowpMatrixMultiplyReshapedValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeLHSMatrix, CLGEMMReshapeRHSMatrix, CLGEMMLowpMatrixMultiplyReshaped>;
56 
57 // Fixture for CLGEMMMatrixMultiplyReshaped3D
58 using CLGEMMLowpMatrixMultiplyReshaped3DFixture =
59     GEMMLowpMatrixMultiplyReshaped3DValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeLHSMatrix, CLGEMMReshapeRHSMatrix, CLGEMMLowpMatrixMultiplyReshaped>;
60 
61 namespace
62 {
63 // *INDENT-OFF*
64 // clang-format off
65 /** M values to test */
66 const auto m_values = framework::dataset::make("M", 37);
67 
68 /** M_W values to test */
69 const auto m_w_values = framework::dataset::make("M_W", 5);
70 
71 /** M_H values to test */
72 const auto m_h_values = framework::dataset::make("M_H", 7);
73 
74 /** N values to test */
75 const auto n_values = framework::dataset::make("N", 51);
76 
77 /** K values to test */
78 const auto k_values = framework::dataset::make("K", 23);
79 
80 /** Batch size values to test */
81 const auto b_values = framework::dataset::make("batch_size", 1, 3);
82 
83 /** M0 values to test - Precommit */
84 const auto m0_values_precommit_1 = framework::dataset::make("M0", { 4 });
85 const auto m0_values_precommit_2 = framework::dataset::make("M0", { 6 });
86 
87 /** N0 values to test - Precommit */
88 const auto n0_values_precommit = framework::dataset::make("N0", { 4 });
89 
90 /** K0 values to test - Precommit */
91 const auto k0_values_precommit = framework::dataset::make("K0", { 16 });
92 
93 /** V0 values to test - Precommit */
94 const auto v0_values_precommit = framework::dataset::make("V0", 1, 3);
95 
96 /** H0 values to test - Precommit */
97 const auto h0_values_precommit = framework::dataset::make("H0", 1, 3);
98 
99 /** M0 values to test - Nightly */
100 const auto m0_values_nightly = framework::dataset::make("M0", 2, 7);
101 
102 /** N0 values to test - Nightly */
103 const auto n0_values_nightly = framework::dataset::make("N0", { 2, 3, 4, 8 });
104 
105 /** K0 values to test - Nightly */
106 const auto k0_values_nightly = framework::dataset::make("K0", { 2, 3, 4, 8, 16 });
107 
108 /** V0 values to test - Nightly */
109 const auto v0_values_nightly = framework::dataset::make("V0", 1, 4);
110 
111 /** H0 values to test - Nightly */
112 const auto h0_values_nightly = framework::dataset::make("H0", 1, 4);
113 
114 /** Interleave values to test with LHS matrix */
115 const auto i_values_lhs = framework::dataset::make("interleave_lhs", { true, false });
116 
117 /** Interleave values to test with RHS matrix */
118 const auto i_values_rhs = framework::dataset::make("interleave_rhs", { true, false });
119 } // namespace
120 
121 TEST_SUITE(CL)
TEST_SUITE(GEMMLowpMatrixMultiplyReshaped)122 TEST_SUITE(GEMMLowpMatrixMultiplyReshaped)
123 
124 TEST_SUITE(QUANTIZED)
125 
126 TEST_SUITE(QASYMM8)
127 FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyReshapedFixture, framework::DatasetMode::ALL,
128                 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
129                                                                    m_values,
130                                                                    n_values),
131                                                                    k_values),
132                                                                    b_values),
133                                                                    m0_values_precommit_1),
134                                                                    n0_values_precommit),
135                                                                    k0_values_precommit),
136                                                                    v0_values_precommit),
137                                                                    h0_values_precommit),
138                                                                    i_values_lhs),
139                                                                    i_values_rhs),
140                                                                    framework::dataset::make("DataType", { DataType::QASYMM8 })))
141 {
142     // Validate output
143     validate(CLAccessor(_target), _reference);
144 }
145 
146 FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyReshapedFixture, framework::DatasetMode::DISABLED,
147                 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
148                                                                    m_values,
149                                                                    n_values),
150                                                                    k_values),
151                                                                    b_values),
152                                                                    m0_values_nightly),
153                                                                    n0_values_nightly),
154                                                                    k0_values_nightly),
155                                                                    v0_values_nightly),
156                                                                    h0_values_nightly),
157                                                                    i_values_lhs),
158                                                                    i_values_rhs),
159                                                                    framework::dataset::make("DataType", { DataType::QASYMM8 })))
160 {
161     // Validate output
162     validate(CLAccessor(_target), _reference);
163 }
164 
165 FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMLowpMatrixMultiplyReshaped3DFixture, framework::DatasetMode::ALL,
166                 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
167                                                                    m_w_values,
168                                                                    m_h_values),
169                                                                    n_values),
170                                                                    k_values),
171                                                                    b_values),
172                                                                    m0_values_precommit_1),
173                                                                    n0_values_precommit),
174                                                                    k0_values_precommit),
175                                                                    v0_values_precommit),
176                                                                    h0_values_precommit),
177                                                                    i_values_lhs),
178                                                                    i_values_rhs),
179                                                                    framework::dataset::make("DataType", { DataType::QASYMM8 })))
180 {
181     // Validate output
182     validate(CLAccessor(_target), _reference);
183 }
184 
185 FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMLowpMatrixMultiplyReshaped3DFixture, framework::DatasetMode::DISABLED,
186                 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
187                                                                    m_w_values,
188                                                                    m_h_values),
189                                                                    n_values),
190                                                                    k_values),
191                                                                    b_values),
192                                                                    m0_values_nightly),
193                                                                    n0_values_nightly),
194                                                                    k0_values_nightly),
195                                                                    v0_values_nightly),
196                                                                    h0_values_nightly),
197                                                                    i_values_lhs),
198                                                                    i_values_rhs),
199                                                                    framework::dataset::make("DataType", { DataType::QASYMM8 })))
200 {
201     // Validate output
202     validate(CLAccessor(_target), _reference);
203 }
204 TEST_SUITE_END() // QASYMM8
205 
TEST_SUITE(QASYMM8_SIGNED)206 TEST_SUITE(QASYMM8_SIGNED)
207 FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyReshapedFixture, framework::DatasetMode::ALL,
208                 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
209                                                                    m_values,
210                                                                    n_values),
211                                                                    k_values),
212                                                                    b_values),
213                                                                    m0_values_precommit_2),
214                                                                    n0_values_precommit),
215                                                                    k0_values_precommit),
216                                                                    v0_values_precommit),
217                                                                    h0_values_precommit),
218                                                                    i_values_lhs),
219                                                                    i_values_rhs),
220                                                                    framework::dataset::make("DataType", { DataType::QASYMM8_SIGNED })))
221 {
222     // Validate output
223     validate(CLAccessor(_target), _reference);
224 }
225 FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMLowpMatrixMultiplyReshaped3DFixture, framework::DatasetMode::ALL,
226                 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(
227                                                                    m_w_values,
228                                                                    m_h_values),
229                                                                    n_values),
230                                                                    k_values),
231                                                                    b_values),
232                                                                    m0_values_precommit_2),
233                                                                    n0_values_precommit),
234                                                                    k0_values_precommit),
235                                                                    v0_values_precommit),
236                                                                    h0_values_precommit),
237                                                                    i_values_lhs),
238                                                                    i_values_rhs),
239                                                                    framework::dataset::make("DataType", { DataType::QASYMM8_SIGNED })))
240 {
241     // Validate output
242     validate(CLAccessor(_target), _reference);
243 }
244 TEST_SUITE_END() // QASYMM8_SIGNED
245 
246 TEST_SUITE_END() // QUANTIZED
247 TEST_SUITE_END() // GEMMLowpMatrixMultiplyReshaped
248 TEST_SUITE_END() // CL
249 } // namespace validation
250 } // namespace test
251 } // namespace arm_compute
252