1 /*
2 * Copyright (c) 2017-2022 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/CLGEMMLowpMatrixMultiplyCore.h"
28 #include "arm_compute/runtime/CL/functions/CLGEMMLowpOutputStage.h"
29 #include "tests/CL/CLAccessor.h"
30 #include "tests/PaddingCalculator.h"
31 #include "tests/datasets/GEMMLowpFusedOffsetOutputDataset.h"
32 #include "tests/datasets/LargeGEMMLowpDataset.h"
33 #include "tests/datasets/ShapeDatasets.h"
34 #include "tests/datasets/SmallGEMMLowpDataset.h"
35 #include "tests/framework/Asserts.h"
36 #include "tests/framework/Macros.h"
37 #include "tests/framework/datasets/Datasets.h"
38 #include "tests/validation/Validation.h"
39 #include "tests/validation/fixtures/GEMMLowpFixture.h"
40
41 namespace arm_compute
42 {
43 namespace test
44 {
45 namespace validation
46 {
47 namespace
48 {
49 constexpr AbsoluteTolerance<float> tolerance_quant(1); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
50 }
51 TEST_SUITE(CL)
52 TEST_SUITE(GEMMLowp)
53
54 TEST_SUITE(MatrixMultiplyCore)
55 using CLGEMMLowpMatrixMultiplyCoreFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore>;
56 using CLGEMMLowpBatchedMatMulFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore, false, false, true>;
57
FIXTURE_DATA_TEST_CASE(RunSmall,CLGEMMLowpMatrixMultiplyCoreFixture,framework::DatasetMode::ALL,datasets::SmallGEMMLowpDataset ())58 FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::ALL, datasets::SmallGEMMLowpDataset())
59 {
60 // Validate output
61 validate(CLAccessor(_target), _reference);
62 }
63
FIXTURE_DATA_TEST_CASE(RunLarge,CLGEMMLowpMatrixMultiplyCoreFixture,framework::DatasetMode::NIGHTLY,datasets::LargeGEMMLowpDataset ())64 FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpDataset())
65 {
66 // Validate output
67 validate(CLAccessor(_target), _reference);
68 }
69
70 using CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixtureBatchedUnsigned =
71 GEMMLowpMatrixMultiplyCoreFusedOffsetOutputGenericValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore, false, false, uint8_t, uint8_t, true>;
72 TEST_SUITE(BatchedMatMul)
TEST_SUITE(QASYMM8)73 TEST_SUITE(QASYMM8)
74 FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixtureBatchedUnsigned, framework::DatasetMode::ALL,
75 combine(combine(datasets::SmallGEMMLowpFusedBatchedMatMulDatasetUnsigned(),
76 framework::dataset::make("DataType", { DataType::QASYMM8 })),
77 framework::dataset::make("bool", { false })))
78 {
79 validate(CLAccessor(_target), _reference, tolerance_quant);
80 }
81 TEST_SUITE_END() // QASYMM8
82
83 using CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixtureBatchedSigned =
84 GEMMLowpMatrixMultiplyCoreFusedOffsetOutputGenericValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore, false, false, int8_t, int8_t, true>;
85 TEST_SUITE(QASYMM8_SIGNED)
86 FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixtureBatchedSigned, framework::DatasetMode::ALL,
87 combine(combine(datasets::SmallGEMMLowpFusedBatchedMatMulDatasetSigned(),
88 framework::dataset::make("DataType", { DataType::QASYMM8_SIGNED })),
89 framework::dataset::make("bool", { false })))
90 {
91 validate(CLAccessor(_target), _reference, tolerance_quant);
92 }
93 TEST_SUITE_END() // QASYMM8_SIGNED
94 TEST_SUITE_END() // BatchedMatMul
95
96 TEST_SUITE(FusedOffsetOutput)
97 TEST_SUITE(QASYMM8)
98 using CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputUint8Fixture = GEMMLowpMatrixMultiplyCoreFusedOffsetOutputGenericValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore>;
99 FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputUint8Fixture, framework::DatasetMode::ALL, combine(combine(datasets::SmallGEMMLowpFusedOffsetOutputUint8Dataset(),
100 framework::dataset::make("DataType", { DataType::QASYMM8 })),
101 framework::dataset::make("reshape_b_only_on_first_run", { true, false })))
102 {
103 // Validate output
104 validate(CLAccessor(_target), _reference, tolerance_quant);
105 }
106
107 TEST_SUITE(Output3D)
108 using CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputOutput3DUint8Fixture =
109 GEMMLowpMatrixMultiplyCoreFusedOffsetOutputGenericValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore, false, true>;
110 FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputOutput3DUint8Fixture, framework::DatasetMode::ALL,
111 combine(combine(datasets::SmallGEMMLowpFusedOffsetOutputOutput3DUint8Dataset(),
112 framework::dataset::make("DataType", { DataType::QASYMM8 })),
113 framework::dataset::make("reshape_b_only_on_first_run", { true, false })))
114 {
115 // Validate output
116 validate(CLAccessor(_target), _reference, tolerance_quant);
117 }
118 TEST_SUITE_END() // Output3D
119
120 TEST_SUITE(InputOutput3D)
121 using CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputInputOutput3DUint8Fixture =
122 GEMMLowpMatrixMultiplyCoreFusedOffsetOutputGenericValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore, true, true>;
123 FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputInputOutput3DUint8Fixture, framework::DatasetMode::ALL,
124 combine(combine(datasets::SmallGEMMLowpFusedOffsetOutputInputOutput3DUint8Dataset(),
125 framework::dataset::make("DataType", { DataType::QASYMM8 })),
126 framework::dataset::make("reshape_b_only_on_first_run", { true, false })))
127 {
128 // Validate output
129 validate(CLAccessor(_target), _reference, tolerance_quant);
130 }
131 TEST_SUITE_END() // InputOutput3D
132
133 FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputUint8Fixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMLowpFusedOffsetOutputUint8Dataset(),
134 framework::dataset::make("DataType", { DataType::QASYMM8 })),
135 framework::dataset::make("reshape_b_only_on_first_run", { true, false })))
136 {
137 // Validate output
138 validate(CLAccessor(_target), _reference, tolerance_quant);
139 }
140 TEST_SUITE_END() // QASYMM8
141 TEST_SUITE(QASYMM8_SIGNED)
142 using CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputInt8Fixture =
143 GEMMLowpMatrixMultiplyCoreFusedOffsetOutputValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore, false, false, int8_t, int8_t>;
144 FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreFusedOffsetOutputInt8Fixture, framework::DatasetMode::ALL, combine(datasets::SmallGEMMLowpFusedOffsetOutputInt8Dataset(),
145 framework::dataset::make("DataType", { DataType::QASYMM8_SIGNED })))
146 {
147 // Validate output
148 validate(CLAccessor(_target), _reference, tolerance_quant);
149 }
150 TEST_SUITE_END() // QASYMM8_SIGNED
151 TEST_SUITE_END() // FusedOffsetOutput
152
153 TEST_SUITE(Output3D)
154 using CLGEMMLowpMatrixMultiplyCoreOutput3DFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore, false, true>;
FIXTURE_DATA_TEST_CASE(RunSmall,CLGEMMLowpMatrixMultiplyCoreOutput3DFixture,framework::DatasetMode::PRECOMMIT,datasets::SmallGEMMLowpOutput3DDataset ())155 FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreOutput3DFixture, framework::DatasetMode::PRECOMMIT, datasets::SmallGEMMLowpOutput3DDataset())
156 {
157 // Validate output
158 validate(CLAccessor(_target), _reference);
159 }
FIXTURE_DATA_TEST_CASE(RunLarge,CLGEMMLowpMatrixMultiplyCoreOutput3DFixture,framework::DatasetMode::NIGHTLY,datasets::LargeGEMMLowpOutput3DDataset ())160 FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyCoreOutput3DFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpOutput3DDataset())
161 {
162 // Validate output
163 validate(CLAccessor(_target), _reference);
164 }
165 TEST_SUITE_END() // Output3D
166
167 TEST_SUITE(InputOutput3D)
168 using CLGEMMLowpMatrixMultiplyCoreInputOutput3DFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore, true, true>;
FIXTURE_DATA_TEST_CASE(RunSmall,CLGEMMLowpMatrixMultiplyCoreInputOutput3DFixture,framework::DatasetMode::PRECOMMIT,datasets::SmallGEMMLowpInputOutput3DDataset ())169 FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreInputOutput3DFixture, framework::DatasetMode::PRECOMMIT, datasets::SmallGEMMLowpInputOutput3DDataset())
170 {
171 // Validate output
172 validate(CLAccessor(_target), _reference);
173 }
FIXTURE_DATA_TEST_CASE(RunLarge,CLGEMMLowpMatrixMultiplyCoreInputOutput3DFixture,framework::DatasetMode::NIGHTLY,datasets::LargeGEMMLowpInputOutput3DDataset ())174 FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyCoreInputOutput3DFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpInputOutput3DDataset())
175 {
176 // Validate output
177 validate(CLAccessor(_target), _reference);
178 }
179 TEST_SUITE_END() // InputOutput3D
180 TEST_SUITE_END() // MatrixMultiplyCore
181
182 TEST_SUITE(OutputStage)
183
184 TEST_SUITE(QuantizeDownInt32Scale)
185
186 TEST_SUITE(QASYMM8)
187
188 const auto quantize_down_int32_to_uint8_scale_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1, 2) * framework::dataset::make("result_shift", 2,
189 3)
190 * framework::dataset::make("min", 0) * framework::dataset::make("max", 255) * framework::dataset::make("addBias", { false, true });
191
192 const auto quantize_down_int32_to_uint8_scale_relu_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1,
193 2)
194 * framework::dataset::make("result_shift", 2, 3) * framework::dataset::make("min", 0, 2) * framework::dataset::make("max", 171, 173) * framework::dataset::make("addBias", { false, true });
195
196 using CLGEMMLowpQuantizeDownInt32ScaleFixture = GEMMLowpQuantizeDownInt32ToUint8ScaleValidationFixture<CLTensor, CLAccessor, CLGEMMLowpOutputStage>;
197
FIXTURE_DATA_TEST_CASE(RunSmall,CLGEMMLowpQuantizeDownInt32ScaleFixture,framework::DatasetMode::ALL,combine (datasets::SmallShapes (),quantize_down_int32_to_uint8_scale_cases))198 FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_cases))
199 {
200 // Validate output
201 validate(CLAccessor(_target), _reference);
202 }
203
204 TEST_SUITE(BoundedReLu)
FIXTURE_DATA_TEST_CASE(RunSmall,CLGEMMLowpQuantizeDownInt32ScaleFixture,framework::DatasetMode::ALL,combine (datasets::SmallShapes (),quantize_down_int32_to_uint8_scale_relu_cases))205 FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_relu_cases))
206 {
207 // Validate output
208 validate(CLAccessor(_target), _reference);
209 }
210
211 TEST_SUITE_END() // BoundedReLu
212 TEST_SUITE_END() // QASYMM8
213
214 TEST_SUITE(QASYMM8_SIGNED)
215
216 const auto quantize_down_int32_to_int8_scale_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1, 2) * framework::dataset::make("result_shift", 2,
217 3)
218 * framework::dataset::make("min", -128) * framework::dataset::make("max", 127) * framework::dataset::make("addBias", { false, true });
219
220 const auto quantize_down_int32_to_int8_scale_relu_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1,
221 2)
222 * framework::dataset::make("result_shift", 2, 3) * framework::dataset::make("min", -100, -98) * framework::dataset::make("max", 71, 73) * framework::dataset::make("addBias", { false, true });
223
224 using CLGEMMLowpQuantizeDownInt32ScaleFixture = GEMMLowpQuantizeDownInt32ToInt8ScaleValidationFixture<CLTensor, CLAccessor, CLGEMMLowpOutputStage>;
225
FIXTURE_DATA_TEST_CASE(RunSmall,CLGEMMLowpQuantizeDownInt32ScaleFixture,framework::DatasetMode::ALL,combine (datasets::SmallShapes (),quantize_down_int32_to_int8_scale_cases))226 FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_int8_scale_cases))
227 {
228 // Validate output
229 validate(CLAccessor(_target), _reference);
230 }
231
232 TEST_SUITE(BoundedReLu)
FIXTURE_DATA_TEST_CASE(RunSmall,CLGEMMLowpQuantizeDownInt32ScaleFixture,framework::DatasetMode::ALL,combine (datasets::SmallShapes (),quantize_down_int32_to_int8_scale_relu_cases))233 FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_int8_scale_relu_cases))
234 {
235 // Validate output
236 validate(CLAccessor(_target), _reference);
237 }
238
239 TEST_SUITE_END() // BoundedReLu
240 TEST_SUITE_END() // QASYMM8_SIGNED
241 TEST_SUITE_END() // QuantizeDownInt32Scale
242
243 TEST_SUITE(QuantizeDownInt32ScaleByFloat)
244
245 TEST_SUITE(QASYMM8)
246 using CLGEMMLowpQuantizeDownInt32ScaleByFloatFixture =
247 GEMMLowpQuantizeDownInt32ScaleByFloatValidationFixture<CLTensor, CLAccessor, CLGEMMLowpOutputStage, uint8_t>;
248
249 FIXTURE_DATA_TEST_CASE(RunTiny, CLGEMMLowpQuantizeDownInt32ScaleByFloatFixture, framework::DatasetMode::ALL,
250 combine(combine(combine(combine(combine(combine(framework::dataset::make("DataType", DataType::QASYMM8),
251 datasets::TinyShapes()),
252 framework::dataset::make("result_real_multiplier", 0.33f)),
253 framework::dataset::make("result_offset", 2, 3)),
254 framework::dataset::make("min", 0)),
255 framework::dataset::make("max", 255)),
256 framework::dataset::make("addBias", { false, true })))
257 {
258 // Validate output
259 validate(CLAccessor(_target), _reference);
260 }
261 TEST_SUITE_END() // QASYMM8
262
263 TEST_SUITE(QASYMM8_SIGNED)
264 using CLGEMMLowpQuantizeDownInt32ScaleByFloatFixture_Signed =
265 GEMMLowpQuantizeDownInt32ScaleByFloatValidationFixture<CLTensor, CLAccessor, CLGEMMLowpOutputStage, int8_t>;
266 FIXTURE_DATA_TEST_CASE(RunTiny, CLGEMMLowpQuantizeDownInt32ScaleByFloatFixture_Signed, framework::DatasetMode::ALL,
267 combine(combine(combine(combine(combine(combine(framework::dataset::make("DataType", DataType::QASYMM8_SIGNED),
268 datasets::TinyShapes()),
269 framework::dataset::make("result_real_multiplier", 0.33f)),
270 framework::dataset::make("result_offset", 2, 3)),
271 framework::dataset::make("min", -128)),
272 framework::dataset::make("max", 127)),
273 framework::dataset::make("addBias", { false, true })))
274 {
275 // Validate output
276 validate(CLAccessor(_target), _reference);
277 }
278 TEST_SUITE_END() // QASYMM8_SIGNED
279
280 TEST_SUITE_END() // QuantizeDownInt32ScaleByFloat
281
282 TEST_SUITE_END() // OutputStage
283 TEST_SUITE_END() // GEMMLowp
284 TEST_SUITE_END() // CL
285 } // namespace validation
286 } // namespace test
287 } // namespace arm_compute
288