blob: 04282c2c3c86c77dd24a78eaea68384f5e357e03 [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"
Gian Marcoe75a02b2017-11-08 12:24:09 +000025#include "arm_compute/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCore.h"
26#include "arm_compute/runtime/NEON/functions/NEGEMMLowpOutputStage.h"
Pablo Tello299025a2017-09-29 11:30:12 +010027#include "arm_compute/runtime/Tensor.h"
28#include "arm_compute/runtime/TensorAllocator.h"
29#include "tests/NEON/Accessor.h"
Gian Marco Iodiceab182122017-10-09 15:05:40 +010030#include "tests/NEON/Helper.h"
Gian Marcoe75a02b2017-11-08 12:24:09 +000031#include "tests/PaddingCalculator.h"
George Wort2d7e6832019-02-22 16:37:41 +000032#include "tests/datasets/GEMMLowpFusedOffsetOutputDataset.h"
Gian Marcofa4cacd2017-10-18 17:05:02 +010033#include "tests/datasets/LargeGEMMLowpDataset.h"
Gian Marcoe75a02b2017-11-08 12:24:09 +000034#include "tests/datasets/ShapeDatasets.h"
Gian Marcofa4cacd2017-10-18 17:05:02 +010035#include "tests/datasets/SmallGEMMLowpDataset.h"
Pablo Tello299025a2017-09-29 11:30:12 +010036#include "tests/framework/Asserts.h"
37#include "tests/framework/Macros.h"
38#include "tests/framework/datasets/Datasets.h"
39#include "tests/validation/Validation.h"
Pablo Tello181e6512017-11-15 13:28:27 +000040#include "tests/validation/fixtures/GEMMLowpAssemblyFixture.h"
Pablo Tello299025a2017-09-29 11:30:12 +010041#include "tests/validation/fixtures/GEMMLowpFixture.h"
42
43namespace arm_compute
44{
45namespace test
46{
47namespace validation
48{
49namespace
50{
Pablo Tello181e6512017-11-15 13:28:27 +000051const 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 +010052} // namespace
53
54TEST_SUITE(NEON)
55TEST_SUITE(GEMMLowp)
Gian Marcoe75a02b2017-11-08 12:24:09 +000056TEST_SUITE(MatrixMultiplyCore)
57using NEGEMMLowpMatrixMultiplyCoreFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<Tensor, Accessor, NEGEMMLowpMatrixMultiplyCore>;
Gian Marcofa4cacd2017-10-18 17:05:02 +010058
morgolock4adaddb2020-09-29 14:24:32 +010059DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallGEMMLowpDataset(), datasets::LargeGEMMLowpDataset()),
60 shape_a, shape_b, shape_c, a_offset, b_offset)
61{
62 // Create tensors
63 Tensor a = create_tensor<Tensor>(shape_a, DataType::QASYMM8);
64 Tensor b = create_tensor<Tensor>(shape_b, DataType::QASYMM8);
65 Tensor c = create_tensor<Tensor>(shape_c, DataType::S32);
66
67 a.info()->set_quantization_info(QuantizationInfo(1.0f / 255, a_offset));
68 b.info()->set_quantization_info(QuantizationInfo(1.0f / 255, b_offset));
69
70 ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS);
71 ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS);
72 ARM_COMPUTE_EXPECT(c.info()->is_resizable(), framework::LogLevel::ERRORS);
73
74 // Create and configure function
75 NEGEMMLowpMatrixMultiplyCore gemmlowp_mm;
76 gemmlowp_mm.configure(&a, &b, nullptr, &c);
77
78 // Validate padding is zero
79 validate(a.info()->padding(), PaddingSize());
80 validate(b.info()->padding(), PaddingSize());
81 validate(c.info()->padding(), PaddingSize());
82}
83
Georgios Pinitasa3b1b462017-11-16 19:24:39 +000084// *INDENT-OFF*
85// clang-format off
86DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
87 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 +010088 TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Mismatching data type
Georgios Pinitasa3b1b462017-11-16 19:24:39 +000089 TensorInfo(TensorShape(20U, 13U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), // Invalid dimensions
90 TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), // Invalid dimensions
91 TensorInfo(TensorShape(16U, 32U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)),
92 }),
93 framework::dataset::make("InputBInfo",{ 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(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
96 TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
97 TensorInfo(TensorShape(64U, 16U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
98 })),
99 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(33U, 13U), 1, DataType::S32),
100 TensorInfo(TensorShape(33U, 13U), 1, DataType::S32),
101 TensorInfo(TensorShape(33U, 13U), 1, DataType::S32),
102 TensorInfo(TensorShape(8U, 11U), 1, DataType::S32),
103 TensorInfo(TensorShape(64U, 32U), 1, DataType::S32),
104 })),
morgolock4adaddb2020-09-29 14:24:32 +0100105 framework::dataset::make("Expected", { true, false, false, false, true })),
Georgios Pinitasa3b1b462017-11-16 19:24:39 +0000106 a_info, b_info, output_info, expected)
107{
108 // Lock tensors
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000109 Status status = NEGEMMLowpMatrixMultiplyCore::validate(&a_info.clone()->set_is_resizable(false),
110 &b_info.clone()->set_is_resizable(false),
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100111 nullptr,
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000112 &output_info.clone()->set_is_resizable(false));
113 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
Georgios Pinitasa3b1b462017-11-16 19:24:39 +0000114}
115// clang-format on
116// *INDENT-ON*
117
Gian Marcoe75a02b2017-11-08 12:24:09 +0000118FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::ALL, datasets::SmallGEMMLowpDataset())
Pablo Tello299025a2017-09-29 11:30:12 +0100119{
120 // Validate output
Gian Marcofa4cacd2017-10-18 17:05:02 +0100121 validate(Accessor(_target), _reference);
122}
123
Gian Marcoe75a02b2017-11-08 12:24:09 +0000124FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpDataset())
Gian Marcofa4cacd2017-10-18 17:05:02 +0100125{
126 // Validate output
127 validate(Accessor(_target), _reference);
Pablo Tello299025a2017-09-29 11:30:12 +0100128}
Pablo Tello299025a2017-09-29 11:30:12 +0100129
George Wort2d7e6832019-02-22 16:37:41 +0000130using NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture = GEMMLowpMatrixMultiplyCoreFusedOffsetOutputValidationFixture<Tensor, Accessor, NEGEMMLowpMatrixMultiplyCore>;
131TEST_SUITE(FusedOffsetOutput)
Manuel Bottini959c26d2019-12-02 16:22:35 +0000132FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture, framework::DatasetMode::ALL, combine(datasets::SmallGEMMLowpFusedOffsetOutputUint8Dataset(),
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000133 framework::dataset::make("DataType", { DataType::QASYMM8 })))
George Wort2d7e6832019-02-22 16:37:41 +0000134{
135 // Validate output
136 validate(Accessor(_target), _reference);
137}
138
Manuel Bottini959c26d2019-12-02 16:22:35 +0000139FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMLowpFusedOffsetOutputUint8Dataset(),
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000140 framework::dataset::make("DataType", { DataType::QASYMM8 })))
George Wort2d7e6832019-02-22 16:37:41 +0000141{
142 // Validate output
143 validate(Accessor(_target), _reference);
144}
145TEST_SUITE_END() // FusedOffsetOutput
Gian Marcoe75a02b2017-11-08 12:24:09 +0000146TEST_SUITE_END() // MatrixMultiplyCore
147
148TEST_SUITE(OutputStage)
149
Luca Foschiani4b869532020-02-13 15:07:36 +0000150TEST_SUITE(QuantizeDownInt32Scale)
151
152TEST_SUITE(QASYMM8)
Gian Marcoe75a02b2017-11-08 12:24:09 +0000153
Gian Marco05288a22017-11-21 10:57:50 +0000154const 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 +0000155 3)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000156 * framework::dataset::make("min", 0) * framework::dataset::make("max", 255) * framework::dataset::make("addBias", { false, true });
Gian Marco6b77e912017-11-17 09:27:57 +0000157
Gian Marco05288a22017-11-21 10:57:50 +0000158const 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 +0000159 2)
160 * 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 });
161
Luca Foschiani4b869532020-02-13 15:07:36 +0000162using NEGEMMLowpQuantizeDownInt32ScaleFixture = GEMMLowpQuantizeDownInt32ToUint8ScaleValidationFixture<Tensor, Accessor, NEGEMMLowpOutputStage>;
Gian Marcoe75a02b2017-11-08 12:24:09 +0000163
Gian Marco7f0f7902017-12-07 09:26:56 +0000164// *INDENT-OFF*
165// clang-format off
166DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
167 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
Gian Marco7f0f7902017-12-07 09:26:56 +0000168 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
169 }),
170 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Gian Marco7f0f7902017-12-07 09:26:56 +0000171 TensorInfo(TensorShape(20U), 1, DataType::S32),
172 })),
173 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8),
Gian Marco7f0f7902017-12-07 09:26:56 +0000174 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
175 })),
176 framework::dataset::make("Min",{ 0,
Gian Marco7f0f7902017-12-07 09:26:56 +0000177 13,
178 })),
179 framework::dataset::make("Max",{ 205,
Gian Marco7f0f7902017-12-07 09:26:56 +0000180 180,
181 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000182 framework::dataset::make("Expected", { true, false })),
Gian Marco7f0f7902017-12-07 09:26:56 +0000183 a_info, b_info, output_info, min, max, expected)
184{
Luca Foschiani4b869532020-02-13 15:07:36 +0000185
186 GEMMLowpOutputStageInfo output_stage = GEMMLowpOutputStageInfo();
187 output_stage.type = GEMMLowpOutputStageType::QUANTIZE_DOWN;
188 output_stage.gemmlowp_min_bound = min;
189 output_stage.gemmlowp_max_bound = max;
190 output_stage.output_data_type = DataType::QASYMM8;
191
Gian Marco7f0f7902017-12-07 09:26:56 +0000192 // Lock tensors
Luca Foschiani4b869532020-02-13 15:07:36 +0000193 Status status = NEGEMMLowpOutputStage::validate(&a_info.clone()->set_is_resizable(false),
Gian Marco7f0f7902017-12-07 09:26:56 +0000194 &b_info.clone()->set_is_resizable(false),
195 &output_info.clone()->set_is_resizable(false),
Luca Foschiani4b869532020-02-13 15:07:36 +0000196 output_stage);
Gian Marco7f0f7902017-12-07 09:26:56 +0000197 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
198}
199// clang-format on
200// *INDENT-ON*
201
morgolockf1109542020-09-15 14:33:54 +0100202TEST_CASE(NoPaddingAdded, framework::DatasetMode::PRECOMMIT)
203{
204 Tensor input1 = create_tensor<Tensor>(TensorShape(21U, 13U), DataType::S32);
205 Tensor input2 = create_tensor<Tensor>(TensorShape(21U, 1U), DataType::S32);
206 Tensor output = create_tensor<Tensor>(TensorShape(21U, 13U), DataType::QASYMM8);
207
208 GEMMLowpOutputStageInfo output_stage = GEMMLowpOutputStageInfo();
Michalis Spyroud175ece2020-07-30 23:39:32 +0100209 output_stage.type = GEMMLowpOutputStageType::QUANTIZE_DOWN;
210 output_stage.gemmlowp_min_bound = 0;
211 output_stage.gemmlowp_max_bound = 205;
212 output_stage.output_data_type = DataType::QASYMM8;
morgolockf1109542020-09-15 14:33:54 +0100213
214 NEGEMMLowpOutputStage f;
215 f.configure(&input1, &input2, &output, output_stage);
216
217 // Validate padding is zero
218 validate(input1.info()->padding(), PaddingSize());
219 validate(input2.info()->padding(), PaddingSize());
220 validate(output.info()->padding(), PaddingSize());
221}
222
Luca Foschiani4b869532020-02-13 15:07:36 +0000223FIXTURE_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 +0000224{
225 // Validate output
226 validate(Accessor(_target), _reference);
227}
228
Gian Marco6b77e912017-11-17 09:27:57 +0000229TEST_SUITE(BoundedReLu)
Luca Foschiani4b869532020-02-13 15:07:36 +0000230FIXTURE_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 +0000231{
232 // Validate output
233 validate(Accessor(_target), _reference);
234}
Gian Marcoe75a02b2017-11-08 12:24:09 +0000235
Gian Marco6b77e912017-11-17 09:27:57 +0000236TEST_SUITE_END() // BoundedReLu
237
Luca Foschiani4b869532020-02-13 15:07:36 +0000238TEST_SUITE_END() // QASYMM8
239
240TEST_SUITE(QASYMM8_SIGNED)
241
242const 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,
243 3)
244 * framework::dataset::make("min", 0) * framework::dataset::make("max", 0) * framework::dataset::make("addBias", { false, true });
245
246const auto quantize_down_int32_to_int8_scale_relu_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1,
247 2)
248 * 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 });
249
250using NEGEMMLowpQuantizeDownInt32ScaleFixture = GEMMLowpQuantizeDownInt32ToInt8ScaleValidationFixture<Tensor, Accessor, NEGEMMLowpOutputStage>;
251
252// *INDENT-OFF*
253// clang-format off
254DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
255 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
256 TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Invalid min and max
257 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
258 }),
259 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
260 TensorInfo(TensorShape(21U), 1, DataType::S32),
261 TensorInfo(TensorShape(20U), 1, DataType::S32),
262 })),
263 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
264 TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
265 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
266 })),
267 framework::dataset::make("Min",{ -10,
268 -200,
269 -113,
270 })),
271 framework::dataset::make("Max",{ 105,
272 300,
273 -18,
274 })),
275 framework::dataset::make("Expected", { true, false, false })),
276 a_info, b_info, output_info, min, max, expected)
277{
278 GEMMLowpOutputStageInfo output_stage = GEMMLowpOutputStageInfo();
279 output_stage.type = GEMMLowpOutputStageType::QUANTIZE_DOWN;
280 output_stage.gemmlowp_min_bound = min;
281 output_stage.gemmlowp_max_bound = max;
282 output_stage.output_data_type = DataType::QASYMM8_SIGNED;
283
284 // Lock tensors
285 Status status = NEGEMMLowpOutputStage::validate(&a_info.clone()->set_is_resizable(false),
286 &b_info.clone()->set_is_resizable(false),
287 &output_info.clone()->set_is_resizable(false),
288 output_stage);
289 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
290}
291// clang-format on
292// *INDENT-ON*
293
294FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_int8_scale_cases))
295{
296 // Validate output
297 validate(Accessor(_target), _reference);
298}
299
300TEST_SUITE(BoundedReLu)
301FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_int8_scale_relu_cases))
302{
303 // Validate output
304 validate(Accessor(_target), _reference);
305}
306
307TEST_SUITE_END() // BoundedReLu
308
309TEST_SUITE_END() // QASYMM8_SIGNED
310
311TEST_SUITE_END() // QuantizeDownInt32Scale
Gian Marco58c57942017-11-28 09:10:03 +0000312
313TEST_SUITE(QuantizeDownInt32ToUint8ScaleByFixedPoint)
314
315const auto quantize_down_int32_to_uint8_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
316 2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000317 * 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 +0000318
319const 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,
320 2)
321 * 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 });
322
323using NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture =
324 GEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint>;
325
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100326using NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture =
327 GEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint>;
328
Gian Marco7f0f7902017-12-07 09:26:56 +0000329// *INDENT-OFF*
330// clang-format off
331DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
332 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
Gian Marco7f0f7902017-12-07 09:26:56 +0000333 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
334 }),
335 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Gian Marco7f0f7902017-12-07 09:26:56 +0000336 TensorInfo(TensorShape(20U), 1, DataType::S32),
337 })),
338 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8),
Gian Marco7f0f7902017-12-07 09:26:56 +0000339 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
340 })),
341 framework::dataset::make("Min",{ 0,
Gian Marco7f0f7902017-12-07 09:26:56 +0000342 13,
343 })),
344 framework::dataset::make("Max",{ 205,
Gian Marco7f0f7902017-12-07 09:26:56 +0000345 180,
346 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000347 framework::dataset::make("Expected", { true, false })),
Gian Marco7f0f7902017-12-07 09:26:56 +0000348 a_info, b_info, output_info, min, max, expected)
349{
350 // Lock tensors
351 Status status = NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false),
352 &b_info.clone()->set_is_resizable(false),
353 &output_info.clone()->set_is_resizable(false),
354 min,
355 max);
356 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
357}
358// clang-format on
359// *INDENT-ON*
360
Gian Marco58c57942017-11-28 09:10:03 +0000361FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
362 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases))
363{
364 // Validate output
365 validate(Accessor(_target), _reference);
366}
367
368FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
369 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases))
370{
371 // Validate output
372 validate(Accessor(_target), _reference);
373}
374
375TEST_SUITE(BoundedReLu)
376FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
377 quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases))
378{
379 // Validate output
380 validate(Accessor(_target), _reference);
381}
382
383FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
384 quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases))
385{
386 // Validate output
387 validate(Accessor(_target), _reference);
388}
389TEST_SUITE_END() // BoundedReLu
390
391TEST_SUITE_END() // QuantizeDownInt32ToUint8ScaleByFixedPoint
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100392
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000393TEST_SUITE(QuantizeDownInt32ToInt8ScaleByFixedPoint)
394
395const auto quantize_down_int32_to_int8_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
396 2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000397 * 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 +0000398
399const 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,
400 2)
401 * 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 });
402
403using NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture =
404 GEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint>;
405
406// *INDENT-OFF*
407// clang-format off
408DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
409 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::F32), // Invalid input data type
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000410 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
411 TensorInfo(TensorShape(21U, 13U), 1, DataType::S32),
412 }),
413 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000414 TensorInfo(TensorShape(20U), 1, DataType::S32),
415 TensorInfo(TensorShape(21U), 1, DataType::S32),
416 })),
417 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000418 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
419 TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
420 })),
421 framework::dataset::make("Min",{ -110,
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000422 -113,
423 -113,
424 })),
425 framework::dataset::make("Max",{ 87,
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000426 97,
427 97,
428 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000429 framework::dataset::make("Expected", { false, false, true })),
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000430 a_info, b_info, output_info, min, max, expected)
431{
432 // Lock tensors
433 Status status = NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false),
434 &b_info.clone()->set_is_resizable(false),
435 &output_info.clone()->set_is_resizable(false),
436 min,
437 max);
438 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
439}
440// clang-format on
441// *INDENT-ON*
442
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000443FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
444 quantize_down_int32_to_int8_scale_by_fixedpoint_cases))
445{
446 // Validate output
447 validate(Accessor(_target), _reference);
448}
449
450TEST_SUITE(BoundedReLu)
451FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
452 quantize_down_int32_to_int8_scale_by_fixedpoint_relu_cases))
453{
454 // Validate output
455 validate(Accessor(_target), _reference);
456}
457TEST_SUITE_END() // BoundedReLu
458TEST_SUITE_END() // QuantizeDownInt32ToInt8ScaleByFixedPoint
459
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100460TEST_SUITE(QuantizeDownInt32ToInt16ScaleByFixedPoint)
461
462const auto quantize_down_int32_to_int16_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
463 2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000464 * framework::dataset::make("min", -32768) * framework::dataset::make("max", 32767) * framework::dataset::make("addBias", { false, true });
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100465
466const 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,
467 2)
468 * 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 +0000469const auto quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_cases = framework::dataset::make("result_fixedpoint_multiplier", 1073741823,
470 1073741825)
471 * framework::dataset::make("result_shift", -3,
472 -2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000473 * framework::dataset::make("min", -32768) * framework::dataset::make("max", 32767) * framework::dataset::make("addBias", { false, true });
Manuel Bottini07263982019-10-17 18:37:26 +0100474
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000475const auto quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_relu_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600,
476 254601602)
477 * framework::dataset::make("result_shift", -3,
478 -1)
479 * 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 +0100480
481using NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture =
482 GEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint>;
483
484// *INDENT-OFF*
485// clang-format off
486DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
487 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 +0100488 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
489 }),
490 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100491 TensorInfo(TensorShape(20U), 1, DataType::S32),
492 })),
493 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QSYMM16),
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100494 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
495 })),
496 framework::dataset::make("Min",{ -205,
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100497 -180,
498 })),
499 framework::dataset::make("Max",{ 205,
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100500 180,
501 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000502 framework::dataset::make("Expected", { true, false })),
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100503 a_info, b_info, output_info, min, max, expected)
504{
505 // Lock tensors
506 Status status = NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false),
507 &b_info.clone()->set_is_resizable(false),
508 &output_info.clone()->set_is_resizable(false),
509 min,
510 max);
511 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
512}
513// clang-format on
514// *INDENT-ON*
515
Manuel Bottini07263982019-10-17 18:37:26 +0100516TEST_SUITE(NoRelu)
517TEST_SUITE(MultSmallerEq1)
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100518FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
519 quantize_down_int32_to_int16_scale_by_fixedpoint_cases))
520{
521 // Validate output
522 validate(Accessor(_target), _reference);
523}
Manuel Bottini07263982019-10-17 18:37:26 +0100524TEST_SUITE_END() // MultSmallerEq1
525TEST_SUITE(MultGreater1)
526FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
527 quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_cases))
528{
529 // Validate output
530 validate(Accessor(_target), _reference);
531}
532TEST_SUITE_END() // MultGreater1
533TEST_SUITE_END() // NoRelu
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100534TEST_SUITE(BoundedReLu)
Manuel Bottini07263982019-10-17 18:37:26 +0100535TEST_SUITE(MultSmallerEq1)
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100536FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
537 quantize_down_int32_to_int16_scale_by_fixedpoint_relu_cases))
538{
539 // Validate output
540 validate(Accessor(_target), _reference);
541}
Manuel Bottini07263982019-10-17 18:37:26 +0100542TEST_SUITE_END() // MultSmallerEq1
543TEST_SUITE(MultGreater1)
544FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
545 quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_relu_cases))
546{
547 // Validate output
548 validate(Accessor(_target), _reference);
549}
550TEST_SUITE_END() // MultGreater1
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100551TEST_SUITE_END() // BoundedReLu
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100552TEST_SUITE_END() // QuantizeDownInt32ToInt16ScaleByFixedPoint
Gian Marcoe75a02b2017-11-08 12:24:09 +0000553TEST_SUITE_END() // OutputStage
Gian Marcoe75a02b2017-11-08 12:24:09 +0000554TEST_SUITE_END() // GEMMLowp
555TEST_SUITE_END() // NEON
Pablo Tello299025a2017-09-29 11:30:12 +0100556} // namespace validation
557} // namespace test
558} // namespace arm_compute