blob: 368433201b7eda11a25348dbd8339e9750729be7 [file] [log] [blame]
Pablo Tello299025a2017-09-29 11:30:12 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2020 Arm Limited.
Pablo Tello299025a2017-09-29 11:30:12 +01003 *
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"
Pablo Tello181e6512017-11-15 13:28:27 +000025#include "arm_compute/runtime/NEON/functions/NEGEMMLowpAssemblyMatrixMultiplyCore.h"
Gian Marcoe75a02b2017-11-08 12:24:09 +000026#include "arm_compute/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCore.h"
27#include "arm_compute/runtime/NEON/functions/NEGEMMLowpOutputStage.h"
Pablo Tello299025a2017-09-29 11:30:12 +010028#include "arm_compute/runtime/Tensor.h"
29#include "arm_compute/runtime/TensorAllocator.h"
30#include "tests/NEON/Accessor.h"
Gian Marco Iodiceab182122017-10-09 15:05:40 +010031#include "tests/NEON/Helper.h"
Gian Marcoe75a02b2017-11-08 12:24:09 +000032#include "tests/PaddingCalculator.h"
George Wort2d7e6832019-02-22 16:37:41 +000033#include "tests/datasets/GEMMLowpFusedOffsetOutputDataset.h"
Gian Marcofa4cacd2017-10-18 17:05:02 +010034#include "tests/datasets/LargeGEMMLowpDataset.h"
Gian Marcoe75a02b2017-11-08 12:24:09 +000035#include "tests/datasets/ShapeDatasets.h"
Gian Marcofa4cacd2017-10-18 17:05:02 +010036#include "tests/datasets/SmallGEMMLowpDataset.h"
Pablo Tello299025a2017-09-29 11:30:12 +010037#include "tests/framework/Asserts.h"
38#include "tests/framework/Macros.h"
39#include "tests/framework/datasets/Datasets.h"
40#include "tests/validation/Validation.h"
Pablo Tello181e6512017-11-15 13:28:27 +000041#include "tests/validation/fixtures/GEMMLowpAssemblyFixture.h"
Pablo Tello299025a2017-09-29 11:30:12 +010042#include "tests/validation/fixtures/GEMMLowpFixture.h"
43
44namespace arm_compute
45{
46namespace test
47{
48namespace validation
49{
50namespace
51{
Pablo Tello181e6512017-11-15 13:28:27 +000052const auto data_matrix_multiply = framework::dataset::make("M", 12, 20) * framework::dataset::make("N", 12, 20) * framework::dataset::make("K", 16);
Pablo Tello299025a2017-09-29 11:30:12 +010053} // namespace
54
55TEST_SUITE(NEON)
Pablo Tello181e6512017-11-15 13:28:27 +000056TEST_SUITE(ASSEMBLY_MATRIX_MULTIPLY)
Michalis Spyrouf3dfa272017-11-21 17:52:12 +000057
58using NEGEMMAssemblyFixture_S8 = GEMMLowpAssemblyFixture<Tensor, Accessor, NEGEMMLowpAssemblyMatrixMultiplyCore, int8_t>;
59using NEGEMMAssemblyFixture_U8 = GEMMLowpAssemblyFixture<Tensor, Accessor, NEGEMMLowpAssemblyMatrixMultiplyCore, uint8_t>;
60
61TEST_SUITE(S8)
62FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMAssemblyFixture_S8, framework::DatasetMode::PRECOMMIT, data_matrix_multiply)
Pablo Tello181e6512017-11-15 13:28:27 +000063{
64 // Validate output
65 validate(Accessor(_target), _reference);
66}
67TEST_SUITE_END()
68
Michalis Spyrouf3dfa272017-11-21 17:52:12 +000069TEST_SUITE(U8)
70FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMAssemblyFixture_U8, framework::DatasetMode::PRECOMMIT, data_matrix_multiply)
71{
72 // Validate output
73 validate(Accessor(_target), _reference);
74}
75TEST_SUITE_END()
76TEST_SUITE_END()
77
Pablo Tello299025a2017-09-29 11:30:12 +010078TEST_SUITE(GEMMLowp)
Gian Marcoe75a02b2017-11-08 12:24:09 +000079TEST_SUITE(MatrixMultiplyCore)
80using NEGEMMLowpMatrixMultiplyCoreFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<Tensor, Accessor, NEGEMMLowpMatrixMultiplyCore>;
Gian Marcofa4cacd2017-10-18 17:05:02 +010081
Georgios Pinitasa3b1b462017-11-16 19:24:39 +000082// *INDENT-OFF*
83// clang-format off
84DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
85 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), // Input not a multiple of 4
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010086 TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Mismatching data type
Georgios Pinitasa3b1b462017-11-16 19:24:39 +000087 TensorInfo(TensorShape(20U, 13U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), // Invalid dimensions
88 TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), // Invalid dimensions
89 TensorInfo(TensorShape(16U, 32U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)),
90 }),
91 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
92 TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
93 TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
94 TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
95 TensorInfo(TensorShape(64U, 16U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
96 })),
97 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(33U, 13U), 1, DataType::S32),
98 TensorInfo(TensorShape(33U, 13U), 1, DataType::S32),
99 TensorInfo(TensorShape(33U, 13U), 1, DataType::S32),
100 TensorInfo(TensorShape(8U, 11U), 1, DataType::S32),
101 TensorInfo(TensorShape(64U, 32U), 1, DataType::S32),
102 })),
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000103 framework::dataset::make("Expected", { false, false, false, false, true })),
Georgios Pinitasa3b1b462017-11-16 19:24:39 +0000104 a_info, b_info, output_info, expected)
105{
106 // Lock tensors
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000107 Status status = NEGEMMLowpMatrixMultiplyCore::validate(&a_info.clone()->set_is_resizable(false),
108 &b_info.clone()->set_is_resizable(false),
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100109 nullptr,
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000110 &output_info.clone()->set_is_resizable(false));
111 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
Georgios Pinitasa3b1b462017-11-16 19:24:39 +0000112}
113// clang-format on
114// *INDENT-ON*
115
Gian Marcoe75a02b2017-11-08 12:24:09 +0000116FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::ALL, datasets::SmallGEMMLowpDataset())
Pablo Tello299025a2017-09-29 11:30:12 +0100117{
118 // Validate output
Gian Marcofa4cacd2017-10-18 17:05:02 +0100119 validate(Accessor(_target), _reference);
120}
121
Gian Marcoe75a02b2017-11-08 12:24:09 +0000122FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpDataset())
Gian Marcofa4cacd2017-10-18 17:05:02 +0100123{
124 // Validate output
125 validate(Accessor(_target), _reference);
Pablo Tello299025a2017-09-29 11:30:12 +0100126}
Pablo Tello299025a2017-09-29 11:30:12 +0100127
George Wort2d7e6832019-02-22 16:37:41 +0000128using NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture = GEMMLowpMatrixMultiplyCoreFusedOffsetOutputValidationFixture<Tensor, Accessor, NEGEMMLowpMatrixMultiplyCore>;
129TEST_SUITE(FusedOffsetOutput)
Manuel Bottini959c26d2019-12-02 16:22:35 +0000130FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture, framework::DatasetMode::ALL, combine(datasets::SmallGEMMLowpFusedOffsetOutputUint8Dataset(),
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000131 framework::dataset::make("DataType", { DataType::QASYMM8 })))
George Wort2d7e6832019-02-22 16:37:41 +0000132{
133 // Validate output
134 validate(Accessor(_target), _reference);
135}
136
Manuel Bottini959c26d2019-12-02 16:22:35 +0000137FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMLowpFusedOffsetOutputUint8Dataset(),
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000138 framework::dataset::make("DataType", { DataType::QASYMM8 })))
George Wort2d7e6832019-02-22 16:37:41 +0000139{
140 // Validate output
141 validate(Accessor(_target), _reference);
142}
143TEST_SUITE_END() // FusedOffsetOutput
Gian Marcoe75a02b2017-11-08 12:24:09 +0000144TEST_SUITE_END() // MatrixMultiplyCore
145
146TEST_SUITE(OutputStage)
147
Luca Foschiani4b869532020-02-13 15:07:36 +0000148TEST_SUITE(QuantizeDownInt32Scale)
149
150TEST_SUITE(QASYMM8)
Gian Marcoe75a02b2017-11-08 12:24:09 +0000151
Gian Marco05288a22017-11-21 10:57:50 +0000152const 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,
Gian Marco6b77e912017-11-17 09:27:57 +0000153 3)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000154 * framework::dataset::make("min", 0) * framework::dataset::make("max", 255) * framework::dataset::make("addBias", { false, true });
Gian Marco6b77e912017-11-17 09:27:57 +0000155
Gian Marco05288a22017-11-21 10:57:50 +0000156const auto quantize_down_int32_to_uint8_scale_relu_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1,
Gian Marco6b77e912017-11-17 09:27:57 +0000157 2)
158 * framework::dataset::make("result_shift", 2, 3) * framework::dataset::make("min", 0, 2) * framework::dataset::make("max", 171, 174) * framework::dataset::make("addBias", { false, true });
159
Luca Foschiani4b869532020-02-13 15:07:36 +0000160using NEGEMMLowpQuantizeDownInt32ScaleFixture = GEMMLowpQuantizeDownInt32ToUint8ScaleValidationFixture<Tensor, Accessor, NEGEMMLowpOutputStage>;
Gian Marcoe75a02b2017-11-08 12:24:09 +0000161
Gian Marco7f0f7902017-12-07 09:26:56 +0000162// *INDENT-OFF*
163// clang-format off
164DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
165 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
Gian Marco7f0f7902017-12-07 09:26:56 +0000166 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
167 }),
168 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Gian Marco7f0f7902017-12-07 09:26:56 +0000169 TensorInfo(TensorShape(20U), 1, DataType::S32),
170 })),
171 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8),
Gian Marco7f0f7902017-12-07 09:26:56 +0000172 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
173 })),
174 framework::dataset::make("Min",{ 0,
Gian Marco7f0f7902017-12-07 09:26:56 +0000175 13,
176 })),
177 framework::dataset::make("Max",{ 205,
Gian Marco7f0f7902017-12-07 09:26:56 +0000178 180,
179 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000180 framework::dataset::make("Expected", { true, false })),
Gian Marco7f0f7902017-12-07 09:26:56 +0000181 a_info, b_info, output_info, min, max, expected)
182{
Luca Foschiani4b869532020-02-13 15:07:36 +0000183
184 GEMMLowpOutputStageInfo output_stage = GEMMLowpOutputStageInfo();
185 output_stage.type = GEMMLowpOutputStageType::QUANTIZE_DOWN;
186 output_stage.gemmlowp_min_bound = min;
187 output_stage.gemmlowp_max_bound = max;
188 output_stage.output_data_type = DataType::QASYMM8;
189
Gian Marco7f0f7902017-12-07 09:26:56 +0000190 // Lock tensors
Luca Foschiani4b869532020-02-13 15:07:36 +0000191 Status status = NEGEMMLowpOutputStage::validate(&a_info.clone()->set_is_resizable(false),
Gian Marco7f0f7902017-12-07 09:26:56 +0000192 &b_info.clone()->set_is_resizable(false),
193 &output_info.clone()->set_is_resizable(false),
Luca Foschiani4b869532020-02-13 15:07:36 +0000194 output_stage);
Gian Marco7f0f7902017-12-07 09:26:56 +0000195 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
196}
197// clang-format on
198// *INDENT-ON*
199
morgolockf1109542020-09-15 14:33:54 +0100200TEST_CASE(NoPaddingAdded, framework::DatasetMode::PRECOMMIT)
201{
202 Tensor input1 = create_tensor<Tensor>(TensorShape(21U, 13U), DataType::S32);
203 Tensor input2 = create_tensor<Tensor>(TensorShape(21U, 1U), DataType::S32);
204 Tensor output = create_tensor<Tensor>(TensorShape(21U, 13U), DataType::QASYMM8);
205
206 GEMMLowpOutputStageInfo output_stage = GEMMLowpOutputStageInfo();
Michalis Spyroud175ece2020-07-30 23:39:32 +0100207 output_stage.type = GEMMLowpOutputStageType::QUANTIZE_DOWN;
208 output_stage.gemmlowp_min_bound = 0;
209 output_stage.gemmlowp_max_bound = 205;
210 output_stage.output_data_type = DataType::QASYMM8;
morgolockf1109542020-09-15 14:33:54 +0100211
212 NEGEMMLowpOutputStage f;
213 f.configure(&input1, &input2, &output, output_stage);
214
215 // Validate padding is zero
216 validate(input1.info()->padding(), PaddingSize());
217 validate(input2.info()->padding(), PaddingSize());
218 validate(output.info()->padding(), PaddingSize());
219}
220
Luca Foschiani4b869532020-02-13 15:07:36 +0000221FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_cases))
Gian Marcoe75a02b2017-11-08 12:24:09 +0000222{
223 // Validate output
224 validate(Accessor(_target), _reference);
225}
226
Gian Marco6b77e912017-11-17 09:27:57 +0000227TEST_SUITE(BoundedReLu)
Luca Foschiani4b869532020-02-13 15:07:36 +0000228FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_relu_cases))
Gian Marco6b77e912017-11-17 09:27:57 +0000229{
230 // Validate output
231 validate(Accessor(_target), _reference);
232}
Gian Marcoe75a02b2017-11-08 12:24:09 +0000233
Gian Marco6b77e912017-11-17 09:27:57 +0000234TEST_SUITE_END() // BoundedReLu
235
Luca Foschiani4b869532020-02-13 15:07:36 +0000236TEST_SUITE_END() // QASYMM8
237
238TEST_SUITE(QASYMM8_SIGNED)
239
240const 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,
241 3)
242 * framework::dataset::make("min", 0) * framework::dataset::make("max", 0) * framework::dataset::make("addBias", { false, true });
243
244const auto quantize_down_int32_to_int8_scale_relu_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1,
245 2)
246 * framework::dataset::make("result_shift", 2, 3) * framework::dataset::make("min", -100, -98) * framework::dataset::make("max", 71, 74) * framework::dataset::make("addBias", { false, true });
247
248using NEGEMMLowpQuantizeDownInt32ScaleFixture = GEMMLowpQuantizeDownInt32ToInt8ScaleValidationFixture<Tensor, Accessor, NEGEMMLowpOutputStage>;
249
250// *INDENT-OFF*
251// clang-format off
252DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
253 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
254 TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Invalid min and max
255 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
256 }),
257 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
258 TensorInfo(TensorShape(21U), 1, DataType::S32),
259 TensorInfo(TensorShape(20U), 1, DataType::S32),
260 })),
261 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
262 TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
263 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
264 })),
265 framework::dataset::make("Min",{ -10,
266 -200,
267 -113,
268 })),
269 framework::dataset::make("Max",{ 105,
270 300,
271 -18,
272 })),
273 framework::dataset::make("Expected", { true, false, false })),
274 a_info, b_info, output_info, min, max, expected)
275{
276 GEMMLowpOutputStageInfo output_stage = GEMMLowpOutputStageInfo();
277 output_stage.type = GEMMLowpOutputStageType::QUANTIZE_DOWN;
278 output_stage.gemmlowp_min_bound = min;
279 output_stage.gemmlowp_max_bound = max;
280 output_stage.output_data_type = DataType::QASYMM8_SIGNED;
281
282 // Lock tensors
283 Status status = NEGEMMLowpOutputStage::validate(&a_info.clone()->set_is_resizable(false),
284 &b_info.clone()->set_is_resizable(false),
285 &output_info.clone()->set_is_resizable(false),
286 output_stage);
287 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
288}
289// clang-format on
290// *INDENT-ON*
291
292FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_int8_scale_cases))
293{
294 // Validate output
295 validate(Accessor(_target), _reference);
296}
297
298TEST_SUITE(BoundedReLu)
299FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_int8_scale_relu_cases))
300{
301 // Validate output
302 validate(Accessor(_target), _reference);
303}
304
305TEST_SUITE_END() // BoundedReLu
306
307TEST_SUITE_END() // QASYMM8_SIGNED
308
309TEST_SUITE_END() // QuantizeDownInt32Scale
Gian Marco58c57942017-11-28 09:10:03 +0000310
311TEST_SUITE(QuantizeDownInt32ToUint8ScaleByFixedPoint)
312
313const auto quantize_down_int32_to_uint8_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
314 2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000315 * framework::dataset::make("result_offset_after_shift", 2, 3) * framework::dataset::make("min", 0) * framework::dataset::make("max", 255) * framework::dataset::make("addBias", { false, true });
Gian Marco58c57942017-11-28 09:10:03 +0000316
317const auto quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
318 2)
319 * framework::dataset::make("result_offset_after_shift", 2, 3) * framework::dataset::make("min", 0, 2) * framework::dataset::make("max", 171, 174) * framework::dataset::make("addBias", { false, true });
320
321using NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture =
322 GEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint>;
323
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100324using NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture =
325 GEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint>;
326
Gian Marco7f0f7902017-12-07 09:26:56 +0000327// *INDENT-OFF*
328// clang-format off
329DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
330 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
Gian Marco7f0f7902017-12-07 09:26:56 +0000331 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
332 }),
333 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Gian Marco7f0f7902017-12-07 09:26:56 +0000334 TensorInfo(TensorShape(20U), 1, DataType::S32),
335 })),
336 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8),
Gian Marco7f0f7902017-12-07 09:26:56 +0000337 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
338 })),
339 framework::dataset::make("Min",{ 0,
Gian Marco7f0f7902017-12-07 09:26:56 +0000340 13,
341 })),
342 framework::dataset::make("Max",{ 205,
Gian Marco7f0f7902017-12-07 09:26:56 +0000343 180,
344 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000345 framework::dataset::make("Expected", { true, false })),
Gian Marco7f0f7902017-12-07 09:26:56 +0000346 a_info, b_info, output_info, min, max, expected)
347{
348 // Lock tensors
349 Status status = NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false),
350 &b_info.clone()->set_is_resizable(false),
351 &output_info.clone()->set_is_resizable(false),
352 min,
353 max);
354 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
355}
356// clang-format on
357// *INDENT-ON*
358
Gian Marco58c57942017-11-28 09:10:03 +0000359FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
360 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases))
361{
362 // Validate output
363 validate(Accessor(_target), _reference);
364}
365
366FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
367 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases))
368{
369 // Validate output
370 validate(Accessor(_target), _reference);
371}
372
373TEST_SUITE(BoundedReLu)
374FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
375 quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases))
376{
377 // Validate output
378 validate(Accessor(_target), _reference);
379}
380
381FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
382 quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases))
383{
384 // Validate output
385 validate(Accessor(_target), _reference);
386}
387TEST_SUITE_END() // BoundedReLu
388
389TEST_SUITE_END() // QuantizeDownInt32ToUint8ScaleByFixedPoint
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100390
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000391TEST_SUITE(QuantizeDownInt32ToInt8ScaleByFixedPoint)
392
393const auto quantize_down_int32_to_int8_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
394 2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000395 * framework::dataset::make("result_offset_after_shift", 2, 3) * framework::dataset::make("min", -128) * framework::dataset::make("max", 128) * framework::dataset::make("addBias", { false, true });
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000396
397const auto quantize_down_int32_to_int8_scale_by_fixedpoint_relu_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
398 2)
399 * framework::dataset::make("result_offset_after_shift", 2, 3) * framework::dataset::make("min", -2, 0) * framework::dataset::make("max", 1, 3) * framework::dataset::make("addBias", { false, true });
400
401using NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture =
402 GEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint>;
403
404// *INDENT-OFF*
405// clang-format off
406DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
407 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::F32), // Invalid input data type
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000408 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
409 TensorInfo(TensorShape(21U, 13U), 1, DataType::S32),
410 }),
411 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000412 TensorInfo(TensorShape(20U), 1, DataType::S32),
413 TensorInfo(TensorShape(21U), 1, DataType::S32),
414 })),
415 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000416 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
417 TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
418 })),
419 framework::dataset::make("Min",{ -110,
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000420 -113,
421 -113,
422 })),
423 framework::dataset::make("Max",{ 87,
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000424 97,
425 97,
426 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000427 framework::dataset::make("Expected", { false, false, true })),
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000428 a_info, b_info, output_info, min, max, expected)
429{
430 // Lock tensors
431 Status status = NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false),
432 &b_info.clone()->set_is_resizable(false),
433 &output_info.clone()->set_is_resizable(false),
434 min,
435 max);
436 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
437}
438// clang-format on
439// *INDENT-ON*
440
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000441FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
442 quantize_down_int32_to_int8_scale_by_fixedpoint_cases))
443{
444 // Validate output
445 validate(Accessor(_target), _reference);
446}
447
448TEST_SUITE(BoundedReLu)
449FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
450 quantize_down_int32_to_int8_scale_by_fixedpoint_relu_cases))
451{
452 // Validate output
453 validate(Accessor(_target), _reference);
454}
455TEST_SUITE_END() // BoundedReLu
456TEST_SUITE_END() // QuantizeDownInt32ToInt8ScaleByFixedPoint
457
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100458TEST_SUITE(QuantizeDownInt32ToInt16ScaleByFixedPoint)
459
460const auto quantize_down_int32_to_int16_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
461 2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000462 * framework::dataset::make("min", -32768) * framework::dataset::make("max", 32767) * framework::dataset::make("addBias", { false, true });
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100463
464const auto quantize_down_int32_to_int16_scale_by_fixedpoint_relu_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
465 2)
466 * framework::dataset::make("min", -2, 0) * framework::dataset::make("max", 1, 3) * framework::dataset::make("addBias", { false, true });
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000467const auto quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_cases = framework::dataset::make("result_fixedpoint_multiplier", 1073741823,
468 1073741825)
469 * framework::dataset::make("result_shift", -3,
470 -2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000471 * framework::dataset::make("min", -32768) * framework::dataset::make("max", 32767) * framework::dataset::make("addBias", { false, true });
Manuel Bottini07263982019-10-17 18:37:26 +0100472
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000473const auto quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_relu_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600,
474 254601602)
475 * framework::dataset::make("result_shift", -3,
476 -1)
477 * framework::dataset::make("min", -2, 0) * framework::dataset::make("max", 1, 3) * framework::dataset::make("addBias", { false, true });
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100478
479using NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture =
480 GEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint>;
481
482// *INDENT-OFF*
483// clang-format off
484DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
485 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100486 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
487 }),
488 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100489 TensorInfo(TensorShape(20U), 1, DataType::S32),
490 })),
491 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QSYMM16),
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100492 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
493 })),
494 framework::dataset::make("Min",{ -205,
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100495 -180,
496 })),
497 framework::dataset::make("Max",{ 205,
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100498 180,
499 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000500 framework::dataset::make("Expected", { true, false })),
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100501 a_info, b_info, output_info, min, max, expected)
502{
503 // Lock tensors
504 Status status = NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false),
505 &b_info.clone()->set_is_resizable(false),
506 &output_info.clone()->set_is_resizable(false),
507 min,
508 max);
509 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
510}
511// clang-format on
512// *INDENT-ON*
513
Manuel Bottini07263982019-10-17 18:37:26 +0100514TEST_SUITE(NoRelu)
515TEST_SUITE(MultSmallerEq1)
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100516FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
517 quantize_down_int32_to_int16_scale_by_fixedpoint_cases))
518{
519 // Validate output
520 validate(Accessor(_target), _reference);
521}
Manuel Bottini07263982019-10-17 18:37:26 +0100522TEST_SUITE_END() // MultSmallerEq1
523TEST_SUITE(MultGreater1)
524FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
525 quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_cases))
526{
527 // Validate output
528 validate(Accessor(_target), _reference);
529}
530TEST_SUITE_END() // MultGreater1
531TEST_SUITE_END() // NoRelu
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100532TEST_SUITE(BoundedReLu)
Manuel Bottini07263982019-10-17 18:37:26 +0100533TEST_SUITE(MultSmallerEq1)
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100534FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
535 quantize_down_int32_to_int16_scale_by_fixedpoint_relu_cases))
536{
537 // Validate output
538 validate(Accessor(_target), _reference);
539}
Manuel Bottini07263982019-10-17 18:37:26 +0100540TEST_SUITE_END() // MultSmallerEq1
541TEST_SUITE(MultGreater1)
542FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
543 quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_relu_cases))
544{
545 // Validate output
546 validate(Accessor(_target), _reference);
547}
548TEST_SUITE_END() // MultGreater1
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100549TEST_SUITE_END() // BoundedReLu
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100550TEST_SUITE_END() // QuantizeDownInt32ToInt16ScaleByFixedPoint
Gian Marcoe75a02b2017-11-08 12:24:09 +0000551TEST_SUITE_END() // OutputStage
Gian Marcoe75a02b2017-11-08 12:24:09 +0000552TEST_SUITE_END() // GEMMLowp
553TEST_SUITE_END() // NEON
Pablo Tello299025a2017-09-29 11:30:12 +0100554} // namespace validation
555} // namespace test
556} // namespace arm_compute