blob: 9fe7e55de7c33872664594d7136e7afc3f5d7a49 [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
morgolock4adaddb2020-09-29 14:24:32 +010082DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallGEMMLowpDataset(), datasets::LargeGEMMLowpDataset()),
83 shape_a, shape_b, shape_c, a_offset, b_offset)
84{
85 // Create tensors
86 Tensor a = create_tensor<Tensor>(shape_a, DataType::QASYMM8);
87 Tensor b = create_tensor<Tensor>(shape_b, DataType::QASYMM8);
88 Tensor c = create_tensor<Tensor>(shape_c, DataType::S32);
89
90 a.info()->set_quantization_info(QuantizationInfo(1.0f / 255, a_offset));
91 b.info()->set_quantization_info(QuantizationInfo(1.0f / 255, b_offset));
92
93 ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS);
94 ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS);
95 ARM_COMPUTE_EXPECT(c.info()->is_resizable(), framework::LogLevel::ERRORS);
96
97 // Create and configure function
98 NEGEMMLowpMatrixMultiplyCore gemmlowp_mm;
99 gemmlowp_mm.configure(&a, &b, nullptr, &c);
100
101 // Validate padding is zero
102 validate(a.info()->padding(), PaddingSize());
103 validate(b.info()->padding(), PaddingSize());
104 validate(c.info()->padding(), PaddingSize());
105}
106
Georgios Pinitasa3b1b462017-11-16 19:24:39 +0000107// *INDENT-OFF*
108// clang-format off
109DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
110 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 +0100111 TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Mismatching data type
Georgios Pinitasa3b1b462017-11-16 19:24:39 +0000112 TensorInfo(TensorShape(20U, 13U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), // Invalid dimensions
113 TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), // Invalid dimensions
114 TensorInfo(TensorShape(16U, 32U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)),
115 }),
116 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
117 TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
118 TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
119 TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
120 TensorInfo(TensorShape(64U, 16U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
121 })),
122 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(33U, 13U), 1, DataType::S32),
123 TensorInfo(TensorShape(33U, 13U), 1, DataType::S32),
124 TensorInfo(TensorShape(33U, 13U), 1, DataType::S32),
125 TensorInfo(TensorShape(8U, 11U), 1, DataType::S32),
126 TensorInfo(TensorShape(64U, 32U), 1, DataType::S32),
127 })),
morgolock4adaddb2020-09-29 14:24:32 +0100128 framework::dataset::make("Expected", { true, false, false, false, true })),
Georgios Pinitasa3b1b462017-11-16 19:24:39 +0000129 a_info, b_info, output_info, expected)
130{
131 // Lock tensors
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000132 Status status = NEGEMMLowpMatrixMultiplyCore::validate(&a_info.clone()->set_is_resizable(false),
133 &b_info.clone()->set_is_resizable(false),
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100134 nullptr,
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000135 &output_info.clone()->set_is_resizable(false));
136 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
Georgios Pinitasa3b1b462017-11-16 19:24:39 +0000137}
138// clang-format on
139// *INDENT-ON*
140
Gian Marcoe75a02b2017-11-08 12:24:09 +0000141FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::ALL, datasets::SmallGEMMLowpDataset())
Pablo Tello299025a2017-09-29 11:30:12 +0100142{
143 // Validate output
Gian Marcofa4cacd2017-10-18 17:05:02 +0100144 validate(Accessor(_target), _reference);
145}
146
Gian Marcoe75a02b2017-11-08 12:24:09 +0000147FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpDataset())
Gian Marcofa4cacd2017-10-18 17:05:02 +0100148{
149 // Validate output
150 validate(Accessor(_target), _reference);
Pablo Tello299025a2017-09-29 11:30:12 +0100151}
Pablo Tello299025a2017-09-29 11:30:12 +0100152
George Wort2d7e6832019-02-22 16:37:41 +0000153using NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture = GEMMLowpMatrixMultiplyCoreFusedOffsetOutputValidationFixture<Tensor, Accessor, NEGEMMLowpMatrixMultiplyCore>;
154TEST_SUITE(FusedOffsetOutput)
Manuel Bottini959c26d2019-12-02 16:22:35 +0000155FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture, framework::DatasetMode::ALL, combine(datasets::SmallGEMMLowpFusedOffsetOutputUint8Dataset(),
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000156 framework::dataset::make("DataType", { DataType::QASYMM8 })))
George Wort2d7e6832019-02-22 16:37:41 +0000157{
158 // Validate output
159 validate(Accessor(_target), _reference);
160}
161
Manuel Bottini959c26d2019-12-02 16:22:35 +0000162FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMLowpFusedOffsetOutputUint8Dataset(),
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000163 framework::dataset::make("DataType", { DataType::QASYMM8 })))
George Wort2d7e6832019-02-22 16:37:41 +0000164{
165 // Validate output
166 validate(Accessor(_target), _reference);
167}
168TEST_SUITE_END() // FusedOffsetOutput
Gian Marcoe75a02b2017-11-08 12:24:09 +0000169TEST_SUITE_END() // MatrixMultiplyCore
170
171TEST_SUITE(OutputStage)
172
Luca Foschiani4b869532020-02-13 15:07:36 +0000173TEST_SUITE(QuantizeDownInt32Scale)
174
175TEST_SUITE(QASYMM8)
Gian Marcoe75a02b2017-11-08 12:24:09 +0000176
Gian Marco05288a22017-11-21 10:57:50 +0000177const 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 +0000178 3)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000179 * framework::dataset::make("min", 0) * framework::dataset::make("max", 255) * framework::dataset::make("addBias", { false, true });
Gian Marco6b77e912017-11-17 09:27:57 +0000180
Gian Marco05288a22017-11-21 10:57:50 +0000181const 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 +0000182 2)
183 * 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 });
184
Luca Foschiani4b869532020-02-13 15:07:36 +0000185using NEGEMMLowpQuantizeDownInt32ScaleFixture = GEMMLowpQuantizeDownInt32ToUint8ScaleValidationFixture<Tensor, Accessor, NEGEMMLowpOutputStage>;
Gian Marcoe75a02b2017-11-08 12:24:09 +0000186
Gian Marco7f0f7902017-12-07 09:26:56 +0000187// *INDENT-OFF*
188// clang-format off
189DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
190 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
Gian Marco7f0f7902017-12-07 09:26:56 +0000191 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
192 }),
193 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Gian Marco7f0f7902017-12-07 09:26:56 +0000194 TensorInfo(TensorShape(20U), 1, DataType::S32),
195 })),
196 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8),
Gian Marco7f0f7902017-12-07 09:26:56 +0000197 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
198 })),
199 framework::dataset::make("Min",{ 0,
Gian Marco7f0f7902017-12-07 09:26:56 +0000200 13,
201 })),
202 framework::dataset::make("Max",{ 205,
Gian Marco7f0f7902017-12-07 09:26:56 +0000203 180,
204 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000205 framework::dataset::make("Expected", { true, false })),
Gian Marco7f0f7902017-12-07 09:26:56 +0000206 a_info, b_info, output_info, min, max, expected)
207{
Luca Foschiani4b869532020-02-13 15:07:36 +0000208
209 GEMMLowpOutputStageInfo output_stage = GEMMLowpOutputStageInfo();
210 output_stage.type = GEMMLowpOutputStageType::QUANTIZE_DOWN;
211 output_stage.gemmlowp_min_bound = min;
212 output_stage.gemmlowp_max_bound = max;
213 output_stage.output_data_type = DataType::QASYMM8;
214
Gian Marco7f0f7902017-12-07 09:26:56 +0000215 // Lock tensors
Luca Foschiani4b869532020-02-13 15:07:36 +0000216 Status status = NEGEMMLowpOutputStage::validate(&a_info.clone()->set_is_resizable(false),
Gian Marco7f0f7902017-12-07 09:26:56 +0000217 &b_info.clone()->set_is_resizable(false),
218 &output_info.clone()->set_is_resizable(false),
Luca Foschiani4b869532020-02-13 15:07:36 +0000219 output_stage);
Gian Marco7f0f7902017-12-07 09:26:56 +0000220 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
221}
222// clang-format on
223// *INDENT-ON*
224
morgolockf1109542020-09-15 14:33:54 +0100225TEST_CASE(NoPaddingAdded, framework::DatasetMode::PRECOMMIT)
226{
227 Tensor input1 = create_tensor<Tensor>(TensorShape(21U, 13U), DataType::S32);
228 Tensor input2 = create_tensor<Tensor>(TensorShape(21U, 1U), DataType::S32);
229 Tensor output = create_tensor<Tensor>(TensorShape(21U, 13U), DataType::QASYMM8);
230
231 GEMMLowpOutputStageInfo output_stage = GEMMLowpOutputStageInfo();
Michalis Spyroud175ece2020-07-30 23:39:32 +0100232 output_stage.type = GEMMLowpOutputStageType::QUANTIZE_DOWN;
233 output_stage.gemmlowp_min_bound = 0;
234 output_stage.gemmlowp_max_bound = 205;
235 output_stage.output_data_type = DataType::QASYMM8;
morgolockf1109542020-09-15 14:33:54 +0100236
237 NEGEMMLowpOutputStage f;
238 f.configure(&input1, &input2, &output, output_stage);
239
240 // Validate padding is zero
241 validate(input1.info()->padding(), PaddingSize());
242 validate(input2.info()->padding(), PaddingSize());
243 validate(output.info()->padding(), PaddingSize());
244}
245
Luca Foschiani4b869532020-02-13 15:07:36 +0000246FIXTURE_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 +0000247{
248 // Validate output
249 validate(Accessor(_target), _reference);
250}
251
Gian Marco6b77e912017-11-17 09:27:57 +0000252TEST_SUITE(BoundedReLu)
Luca Foschiani4b869532020-02-13 15:07:36 +0000253FIXTURE_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 +0000254{
255 // Validate output
256 validate(Accessor(_target), _reference);
257}
Gian Marcoe75a02b2017-11-08 12:24:09 +0000258
Gian Marco6b77e912017-11-17 09:27:57 +0000259TEST_SUITE_END() // BoundedReLu
260
Luca Foschiani4b869532020-02-13 15:07:36 +0000261TEST_SUITE_END() // QASYMM8
262
263TEST_SUITE(QASYMM8_SIGNED)
264
265const 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,
266 3)
267 * framework::dataset::make("min", 0) * framework::dataset::make("max", 0) * framework::dataset::make("addBias", { false, true });
268
269const auto quantize_down_int32_to_int8_scale_relu_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1,
270 2)
271 * 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 });
272
273using NEGEMMLowpQuantizeDownInt32ScaleFixture = GEMMLowpQuantizeDownInt32ToInt8ScaleValidationFixture<Tensor, Accessor, NEGEMMLowpOutputStage>;
274
275// *INDENT-OFF*
276// clang-format off
277DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
278 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
279 TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Invalid min and max
280 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
281 }),
282 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
283 TensorInfo(TensorShape(21U), 1, DataType::S32),
284 TensorInfo(TensorShape(20U), 1, DataType::S32),
285 })),
286 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
287 TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
288 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
289 })),
290 framework::dataset::make("Min",{ -10,
291 -200,
292 -113,
293 })),
294 framework::dataset::make("Max",{ 105,
295 300,
296 -18,
297 })),
298 framework::dataset::make("Expected", { true, false, false })),
299 a_info, b_info, output_info, min, max, expected)
300{
301 GEMMLowpOutputStageInfo output_stage = GEMMLowpOutputStageInfo();
302 output_stage.type = GEMMLowpOutputStageType::QUANTIZE_DOWN;
303 output_stage.gemmlowp_min_bound = min;
304 output_stage.gemmlowp_max_bound = max;
305 output_stage.output_data_type = DataType::QASYMM8_SIGNED;
306
307 // Lock tensors
308 Status status = NEGEMMLowpOutputStage::validate(&a_info.clone()->set_is_resizable(false),
309 &b_info.clone()->set_is_resizable(false),
310 &output_info.clone()->set_is_resizable(false),
311 output_stage);
312 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
313}
314// clang-format on
315// *INDENT-ON*
316
317FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_int8_scale_cases))
318{
319 // Validate output
320 validate(Accessor(_target), _reference);
321}
322
323TEST_SUITE(BoundedReLu)
324FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_int8_scale_relu_cases))
325{
326 // Validate output
327 validate(Accessor(_target), _reference);
328}
329
330TEST_SUITE_END() // BoundedReLu
331
332TEST_SUITE_END() // QASYMM8_SIGNED
333
334TEST_SUITE_END() // QuantizeDownInt32Scale
Gian Marco58c57942017-11-28 09:10:03 +0000335
336TEST_SUITE(QuantizeDownInt32ToUint8ScaleByFixedPoint)
337
338const auto quantize_down_int32_to_uint8_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
339 2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000340 * 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 +0000341
342const 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,
343 2)
344 * 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 });
345
346using NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture =
347 GEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint>;
348
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100349using NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture =
350 GEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint>;
351
Gian Marco7f0f7902017-12-07 09:26:56 +0000352// *INDENT-OFF*
353// clang-format off
354DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
355 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
Gian Marco7f0f7902017-12-07 09:26:56 +0000356 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
357 }),
358 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Gian Marco7f0f7902017-12-07 09:26:56 +0000359 TensorInfo(TensorShape(20U), 1, DataType::S32),
360 })),
361 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8),
Gian Marco7f0f7902017-12-07 09:26:56 +0000362 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
363 })),
364 framework::dataset::make("Min",{ 0,
Gian Marco7f0f7902017-12-07 09:26:56 +0000365 13,
366 })),
367 framework::dataset::make("Max",{ 205,
Gian Marco7f0f7902017-12-07 09:26:56 +0000368 180,
369 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000370 framework::dataset::make("Expected", { true, false })),
Gian Marco7f0f7902017-12-07 09:26:56 +0000371 a_info, b_info, output_info, min, max, expected)
372{
373 // Lock tensors
374 Status status = NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false),
375 &b_info.clone()->set_is_resizable(false),
376 &output_info.clone()->set_is_resizable(false),
377 min,
378 max);
379 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
380}
381// clang-format on
382// *INDENT-ON*
383
Gian Marco58c57942017-11-28 09:10:03 +0000384FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
385 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases))
386{
387 // Validate output
388 validate(Accessor(_target), _reference);
389}
390
391FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
392 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases))
393{
394 // Validate output
395 validate(Accessor(_target), _reference);
396}
397
398TEST_SUITE(BoundedReLu)
399FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
400 quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases))
401{
402 // Validate output
403 validate(Accessor(_target), _reference);
404}
405
406FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
407 quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases))
408{
409 // Validate output
410 validate(Accessor(_target), _reference);
411}
412TEST_SUITE_END() // BoundedReLu
413
414TEST_SUITE_END() // QuantizeDownInt32ToUint8ScaleByFixedPoint
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100415
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000416TEST_SUITE(QuantizeDownInt32ToInt8ScaleByFixedPoint)
417
418const auto quantize_down_int32_to_int8_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
419 2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000420 * 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 +0000421
422const 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,
423 2)
424 * 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 });
425
426using NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture =
427 GEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint>;
428
429// *INDENT-OFF*
430// clang-format off
431DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
432 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::F32), // Invalid input data type
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000433 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
434 TensorInfo(TensorShape(21U, 13U), 1, DataType::S32),
435 }),
436 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000437 TensorInfo(TensorShape(20U), 1, DataType::S32),
438 TensorInfo(TensorShape(21U), 1, DataType::S32),
439 })),
440 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000441 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
442 TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
443 })),
444 framework::dataset::make("Min",{ -110,
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000445 -113,
446 -113,
447 })),
448 framework::dataset::make("Max",{ 87,
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000449 97,
450 97,
451 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000452 framework::dataset::make("Expected", { false, false, true })),
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000453 a_info, b_info, output_info, min, max, expected)
454{
455 // Lock tensors
456 Status status = NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false),
457 &b_info.clone()->set_is_resizable(false),
458 &output_info.clone()->set_is_resizable(false),
459 min,
460 max);
461 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
462}
463// clang-format on
464// *INDENT-ON*
465
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000466FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
467 quantize_down_int32_to_int8_scale_by_fixedpoint_cases))
468{
469 // Validate output
470 validate(Accessor(_target), _reference);
471}
472
473TEST_SUITE(BoundedReLu)
474FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
475 quantize_down_int32_to_int8_scale_by_fixedpoint_relu_cases))
476{
477 // Validate output
478 validate(Accessor(_target), _reference);
479}
480TEST_SUITE_END() // BoundedReLu
481TEST_SUITE_END() // QuantizeDownInt32ToInt8ScaleByFixedPoint
482
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100483TEST_SUITE(QuantizeDownInt32ToInt16ScaleByFixedPoint)
484
485const auto quantize_down_int32_to_int16_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
486 2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000487 * framework::dataset::make("min", -32768) * framework::dataset::make("max", 32767) * framework::dataset::make("addBias", { false, true });
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100488
489const 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,
490 2)
491 * 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 +0000492const auto quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_cases = framework::dataset::make("result_fixedpoint_multiplier", 1073741823,
493 1073741825)
494 * framework::dataset::make("result_shift", -3,
495 -2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000496 * framework::dataset::make("min", -32768) * framework::dataset::make("max", 32767) * framework::dataset::make("addBias", { false, true });
Manuel Bottini07263982019-10-17 18:37:26 +0100497
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000498const auto quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_relu_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600,
499 254601602)
500 * framework::dataset::make("result_shift", -3,
501 -1)
502 * 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 +0100503
504using NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture =
505 GEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint>;
506
507// *INDENT-OFF*
508// clang-format off
509DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
510 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 +0100511 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
512 }),
513 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100514 TensorInfo(TensorShape(20U), 1, DataType::S32),
515 })),
516 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QSYMM16),
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100517 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
518 })),
519 framework::dataset::make("Min",{ -205,
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100520 -180,
521 })),
522 framework::dataset::make("Max",{ 205,
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100523 180,
524 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000525 framework::dataset::make("Expected", { true, false })),
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100526 a_info, b_info, output_info, min, max, expected)
527{
528 // Lock tensors
529 Status status = NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false),
530 &b_info.clone()->set_is_resizable(false),
531 &output_info.clone()->set_is_resizable(false),
532 min,
533 max);
534 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
535}
536// clang-format on
537// *INDENT-ON*
538
Manuel Bottini07263982019-10-17 18:37:26 +0100539TEST_SUITE(NoRelu)
540TEST_SUITE(MultSmallerEq1)
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100541FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
542 quantize_down_int32_to_int16_scale_by_fixedpoint_cases))
543{
544 // Validate output
545 validate(Accessor(_target), _reference);
546}
Manuel Bottini07263982019-10-17 18:37:26 +0100547TEST_SUITE_END() // MultSmallerEq1
548TEST_SUITE(MultGreater1)
549FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
550 quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_cases))
551{
552 // Validate output
553 validate(Accessor(_target), _reference);
554}
555TEST_SUITE_END() // MultGreater1
556TEST_SUITE_END() // NoRelu
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100557TEST_SUITE(BoundedReLu)
Manuel Bottini07263982019-10-17 18:37:26 +0100558TEST_SUITE(MultSmallerEq1)
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100559FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
560 quantize_down_int32_to_int16_scale_by_fixedpoint_relu_cases))
561{
562 // Validate output
563 validate(Accessor(_target), _reference);
564}
Manuel Bottini07263982019-10-17 18:37:26 +0100565TEST_SUITE_END() // MultSmallerEq1
566TEST_SUITE(MultGreater1)
567FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
568 quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_relu_cases))
569{
570 // Validate output
571 validate(Accessor(_target), _reference);
572}
573TEST_SUITE_END() // MultGreater1
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100574TEST_SUITE_END() // BoundedReLu
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100575TEST_SUITE_END() // QuantizeDownInt32ToInt16ScaleByFixedPoint
Gian Marcoe75a02b2017-11-08 12:24:09 +0000576TEST_SUITE_END() // OutputStage
Gian Marcoe75a02b2017-11-08 12:24:09 +0000577TEST_SUITE_END() // GEMMLowp
578TEST_SUITE_END() // NEON
Pablo Tello299025a2017-09-29 11:30:12 +0100579} // namespace validation
580} // namespace test
581} // namespace arm_compute