blob: c3747ddd24ac8d85b4bcf347d128d6bb48f7473d [file] [log] [blame]
Pablo Tello299025a2017-09-29 11:30:12 +01001/*
Manuel Bottini959c26d2019-12-02 16:22:35 +00002 * 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
Gian Marcoe75a02b2017-11-08 12:24:09 +000082DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallGEMMLowpDataset(), datasets::LargeGEMMLowpDataset()),
83 shape_a, shape_b, shape_c, a_offset, b_offset)
Gian Marcofa4cacd2017-10-18 17:05:02 +010084{
85 // Create tensors
Gian Marcoe75a02b2017-11-08 12:24:09 +000086 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));
Gian Marcofa4cacd2017-10-18 17:05:02 +010092
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
Gian Marcoe75a02b2017-11-08 12:24:09 +000098 NEGEMMLowpMatrixMultiplyCore gemmlowp_mm;
Gian Marco Iodice4b908652018-10-18 10:21:02 +010099 gemmlowp_mm.configure(&a, &b, nullptr, &c);
Gian Marcofa4cacd2017-10-18 17:05:02 +0100100}
101
Georgios Pinitasa3b1b462017-11-16 19:24:39 +0000102// *INDENT-OFF*
103// clang-format off
104DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
105 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 +0100106 TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Mismatching data type
Georgios Pinitasa3b1b462017-11-16 19:24:39 +0000107 TensorInfo(TensorShape(20U, 13U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), // Invalid dimensions
108 TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), // Invalid dimensions
109 TensorInfo(TensorShape(16U, 32U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)),
110 }),
111 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
112 TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
113 TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
114 TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
115 TensorInfo(TensorShape(64U, 16U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
116 })),
117 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(33U, 13U), 1, DataType::S32),
118 TensorInfo(TensorShape(33U, 13U), 1, DataType::S32),
119 TensorInfo(TensorShape(33U, 13U), 1, DataType::S32),
120 TensorInfo(TensorShape(8U, 11U), 1, DataType::S32),
121 TensorInfo(TensorShape(64U, 32U), 1, DataType::S32),
122 })),
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000123 framework::dataset::make("Expected", { false, false, false, false, true })),
Georgios Pinitasa3b1b462017-11-16 19:24:39 +0000124 a_info, b_info, output_info, expected)
125{
126 // Lock tensors
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000127 Status status = NEGEMMLowpMatrixMultiplyCore::validate(&a_info.clone()->set_is_resizable(false),
128 &b_info.clone()->set_is_resizable(false),
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100129 nullptr,
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000130 &output_info.clone()->set_is_resizable(false));
131 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
Georgios Pinitasa3b1b462017-11-16 19:24:39 +0000132}
133// clang-format on
134// *INDENT-ON*
135
Gian Marcoe75a02b2017-11-08 12:24:09 +0000136FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::ALL, datasets::SmallGEMMLowpDataset())
Pablo Tello299025a2017-09-29 11:30:12 +0100137{
138 // Validate output
Gian Marcofa4cacd2017-10-18 17:05:02 +0100139 validate(Accessor(_target), _reference);
140}
141
Gian Marcoe75a02b2017-11-08 12:24:09 +0000142FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpDataset())
Gian Marcofa4cacd2017-10-18 17:05:02 +0100143{
144 // Validate output
145 validate(Accessor(_target), _reference);
Pablo Tello299025a2017-09-29 11:30:12 +0100146}
Pablo Tello299025a2017-09-29 11:30:12 +0100147
George Wort2d7e6832019-02-22 16:37:41 +0000148using NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture = GEMMLowpMatrixMultiplyCoreFusedOffsetOutputValidationFixture<Tensor, Accessor, NEGEMMLowpMatrixMultiplyCore>;
149TEST_SUITE(FusedOffsetOutput)
Manuel Bottini959c26d2019-12-02 16:22:35 +0000150FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture, framework::DatasetMode::ALL, combine(datasets::SmallGEMMLowpFusedOffsetOutputUint8Dataset(),
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000151 framework::dataset::make("DataType", { DataType::QASYMM8 })))
George Wort2d7e6832019-02-22 16:37:41 +0000152{
153 // Validate output
154 validate(Accessor(_target), _reference);
155}
156
Manuel Bottini959c26d2019-12-02 16:22:35 +0000157FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMLowpFusedOffsetOutputUint8Dataset(),
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000158 framework::dataset::make("DataType", { DataType::QASYMM8 })))
George Wort2d7e6832019-02-22 16:37:41 +0000159{
160 // Validate output
161 validate(Accessor(_target), _reference);
162}
163TEST_SUITE_END() // FusedOffsetOutput
Gian Marcoe75a02b2017-11-08 12:24:09 +0000164TEST_SUITE_END() // MatrixMultiplyCore
165
166TEST_SUITE(OutputStage)
167
Luca Foschiani4b869532020-02-13 15:07:36 +0000168TEST_SUITE(QuantizeDownInt32Scale)
169
170TEST_SUITE(QASYMM8)
Gian Marcoe75a02b2017-11-08 12:24:09 +0000171
Gian Marco05288a22017-11-21 10:57:50 +0000172const 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 +0000173 3)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000174 * framework::dataset::make("min", 0) * framework::dataset::make("max", 255) * framework::dataset::make("addBias", { false, true });
Gian Marco6b77e912017-11-17 09:27:57 +0000175
Gian Marco05288a22017-11-21 10:57:50 +0000176const 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 +0000177 2)
178 * 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 });
179
Luca Foschiani4b869532020-02-13 15:07:36 +0000180using NEGEMMLowpQuantizeDownInt32ScaleFixture = GEMMLowpQuantizeDownInt32ToUint8ScaleValidationFixture<Tensor, Accessor, NEGEMMLowpOutputStage>;
Gian Marcoe75a02b2017-11-08 12:24:09 +0000181
Gian Marco7f0f7902017-12-07 09:26:56 +0000182// *INDENT-OFF*
183// clang-format off
184DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
185 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
Gian Marco7f0f7902017-12-07 09:26:56 +0000186 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
187 }),
188 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Gian Marco7f0f7902017-12-07 09:26:56 +0000189 TensorInfo(TensorShape(20U), 1, DataType::S32),
190 })),
191 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8),
Gian Marco7f0f7902017-12-07 09:26:56 +0000192 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
193 })),
194 framework::dataset::make("Min",{ 0,
Gian Marco7f0f7902017-12-07 09:26:56 +0000195 13,
196 })),
197 framework::dataset::make("Max",{ 205,
Gian Marco7f0f7902017-12-07 09:26:56 +0000198 180,
199 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000200 framework::dataset::make("Expected", { true, false })),
Gian Marco7f0f7902017-12-07 09:26:56 +0000201 a_info, b_info, output_info, min, max, expected)
202{
Luca Foschiani4b869532020-02-13 15:07:36 +0000203
204 GEMMLowpOutputStageInfo output_stage = GEMMLowpOutputStageInfo();
205 output_stage.type = GEMMLowpOutputStageType::QUANTIZE_DOWN;
206 output_stage.gemmlowp_min_bound = min;
207 output_stage.gemmlowp_max_bound = max;
208 output_stage.output_data_type = DataType::QASYMM8;
209
Gian Marco7f0f7902017-12-07 09:26:56 +0000210 // Lock tensors
Luca Foschiani4b869532020-02-13 15:07:36 +0000211 Status status = NEGEMMLowpOutputStage::validate(&a_info.clone()->set_is_resizable(false),
Gian Marco7f0f7902017-12-07 09:26:56 +0000212 &b_info.clone()->set_is_resizable(false),
213 &output_info.clone()->set_is_resizable(false),
Luca Foschiani4b869532020-02-13 15:07:36 +0000214 output_stage);
Gian Marco7f0f7902017-12-07 09:26:56 +0000215 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
216}
217// clang-format on
218// *INDENT-ON*
219
Luca Foschiani4b869532020-02-13 15:07:36 +0000220FIXTURE_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 +0000221{
222 // Validate output
223 validate(Accessor(_target), _reference);
224}
225
Gian Marco6b77e912017-11-17 09:27:57 +0000226TEST_SUITE(BoundedReLu)
Luca Foschiani4b869532020-02-13 15:07:36 +0000227FIXTURE_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 +0000228{
229 // Validate output
230 validate(Accessor(_target), _reference);
231}
Gian Marcoe75a02b2017-11-08 12:24:09 +0000232
Gian Marco6b77e912017-11-17 09:27:57 +0000233TEST_SUITE_END() // BoundedReLu
234
Luca Foschiani4b869532020-02-13 15:07:36 +0000235TEST_SUITE_END() // QASYMM8
236
237TEST_SUITE(QASYMM8_SIGNED)
238
239const 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,
240 3)
241 * framework::dataset::make("min", 0) * framework::dataset::make("max", 0) * framework::dataset::make("addBias", { false, true });
242
243const auto quantize_down_int32_to_int8_scale_relu_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1,
244 2)
245 * 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 });
246
247using NEGEMMLowpQuantizeDownInt32ScaleFixture = GEMMLowpQuantizeDownInt32ToInt8ScaleValidationFixture<Tensor, Accessor, NEGEMMLowpOutputStage>;
248
249// *INDENT-OFF*
250// clang-format off
251DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
252 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
253 TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Invalid min and max
254 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
255 }),
256 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
257 TensorInfo(TensorShape(21U), 1, DataType::S32),
258 TensorInfo(TensorShape(20U), 1, DataType::S32),
259 })),
260 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
261 TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
262 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
263 })),
264 framework::dataset::make("Min",{ -10,
265 -200,
266 -113,
267 })),
268 framework::dataset::make("Max",{ 105,
269 300,
270 -18,
271 })),
272 framework::dataset::make("Expected", { true, false, false })),
273 a_info, b_info, output_info, min, max, expected)
274{
275 GEMMLowpOutputStageInfo output_stage = GEMMLowpOutputStageInfo();
276 output_stage.type = GEMMLowpOutputStageType::QUANTIZE_DOWN;
277 output_stage.gemmlowp_min_bound = min;
278 output_stage.gemmlowp_max_bound = max;
279 output_stage.output_data_type = DataType::QASYMM8_SIGNED;
280
281 // Lock tensors
282 Status status = NEGEMMLowpOutputStage::validate(&a_info.clone()->set_is_resizable(false),
283 &b_info.clone()->set_is_resizable(false),
284 &output_info.clone()->set_is_resizable(false),
285 output_stage);
286 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
287}
288// clang-format on
289// *INDENT-ON*
290
291FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_int8_scale_cases))
292{
293 // Validate output
294 validate(Accessor(_target), _reference);
295}
296
297TEST_SUITE(BoundedReLu)
298FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_int8_scale_relu_cases))
299{
300 // Validate output
301 validate(Accessor(_target), _reference);
302}
303
304TEST_SUITE_END() // BoundedReLu
305
306TEST_SUITE_END() // QASYMM8_SIGNED
307
308TEST_SUITE_END() // QuantizeDownInt32Scale
Gian Marco58c57942017-11-28 09:10:03 +0000309
310TEST_SUITE(QuantizeDownInt32ToUint8ScaleByFixedPoint)
311
312const auto quantize_down_int32_to_uint8_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
313 2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000314 * 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 +0000315
316const 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,
317 2)
318 * 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 });
319
320using NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture =
321 GEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint>;
322
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100323using NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture =
324 GEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint>;
325
Gian Marco7f0f7902017-12-07 09:26:56 +0000326// *INDENT-OFF*
327// clang-format off
328DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
329 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
Gian Marco7f0f7902017-12-07 09:26:56 +0000330 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
331 }),
332 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Gian Marco7f0f7902017-12-07 09:26:56 +0000333 TensorInfo(TensorShape(20U), 1, DataType::S32),
334 })),
335 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8),
Gian Marco7f0f7902017-12-07 09:26:56 +0000336 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
337 })),
338 framework::dataset::make("Min",{ 0,
Gian Marco7f0f7902017-12-07 09:26:56 +0000339 13,
340 })),
341 framework::dataset::make("Max",{ 205,
Gian Marco7f0f7902017-12-07 09:26:56 +0000342 180,
343 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000344 framework::dataset::make("Expected", { true, false })),
Gian Marco7f0f7902017-12-07 09:26:56 +0000345 a_info, b_info, output_info, min, max, expected)
346{
347 // Lock tensors
348 Status status = NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false),
349 &b_info.clone()->set_is_resizable(false),
350 &output_info.clone()->set_is_resizable(false),
351 min,
352 max);
353 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
354}
355// clang-format on
356// *INDENT-ON*
357
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +0000358DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
Gian Marco58c57942017-11-28 09:10:03 +0000359 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases),
360 shape, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max, add_bias)
361{
362 TensorShape shape_bias(shape[0]);
363
364 // Create tensors
365 Tensor in = create_tensor<Tensor>(shape, DataType::S32);
366 Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32);
367 Tensor out = create_tensor<Tensor>(shape, DataType::QASYMM8);
368
369 ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS);
370 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
371 ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS);
372
373 // Create and configure function
374 NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint output_stage;
375 output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max);
376
377 // Validate valid region input and output
378 const ValidRegion valid_region = shape_to_valid_region(shape);
379 validate(in.info()->valid_region(), valid_region);
380 validate(out.info()->valid_region(), valid_region);
381
382 // Validate valid region bias
383 if(add_bias)
384 {
385 const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias);
386 validate(bias.info()->valid_region(), valid_region_bias);
387 }
388
389 // Validate padding
Gian Marco7f0f7902017-12-07 09:26:56 +0000390 const PaddingSize padding(0);
Gian Marco58c57942017-11-28 09:10:03 +0000391 validate(in.info()->padding(), padding);
392 validate(out.info()->padding(), padding);
393
394 if(add_bias)
395 {
396 validate(bias.info()->padding(), padding);
397 }
398}
399
400FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
401 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases))
402{
403 // Validate output
404 validate(Accessor(_target), _reference);
405}
406
407FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
408 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases))
409{
410 // Validate output
411 validate(Accessor(_target), _reference);
412}
413
414TEST_SUITE(BoundedReLu)
415FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
416 quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases))
417{
418 // Validate output
419 validate(Accessor(_target), _reference);
420}
421
422FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
423 quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases))
424{
425 // Validate output
426 validate(Accessor(_target), _reference);
427}
428TEST_SUITE_END() // BoundedReLu
429
430TEST_SUITE_END() // QuantizeDownInt32ToUint8ScaleByFixedPoint
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100431
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000432TEST_SUITE(QuantizeDownInt32ToInt8ScaleByFixedPoint)
433
434const auto quantize_down_int32_to_int8_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
435 2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000436 * 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 +0000437
438const 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,
439 2)
440 * 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 });
441
442using NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture =
443 GEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint>;
444
445// *INDENT-OFF*
446// clang-format off
447DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
448 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::F32), // Invalid input data type
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000449 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
450 TensorInfo(TensorShape(21U, 13U), 1, DataType::S32),
451 }),
452 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000453 TensorInfo(TensorShape(20U), 1, DataType::S32),
454 TensorInfo(TensorShape(21U), 1, DataType::S32),
455 })),
456 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000457 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
458 TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
459 })),
460 framework::dataset::make("Min",{ -110,
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000461 -113,
462 -113,
463 })),
464 framework::dataset::make("Max",{ 87,
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000465 97,
466 97,
467 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000468 framework::dataset::make("Expected", { false, false, true })),
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000469 a_info, b_info, output_info, min, max, expected)
470{
471 // Lock tensors
472 Status status = NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false),
473 &b_info.clone()->set_is_resizable(false),
474 &output_info.clone()->set_is_resizable(false),
475 min,
476 max);
477 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
478}
479// clang-format on
480// *INDENT-ON*
481
482DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
483 quantize_down_int32_to_int8_scale_by_fixedpoint_cases),
484 shape, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max, add_bias)
485{
486 TensorShape shape_bias(shape[0]);
487
488 // Create tensors
489 Tensor in = create_tensor<Tensor>(shape, DataType::S32);
490 Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32);
491 Tensor out = create_tensor<Tensor>(shape, DataType::QASYMM8_SIGNED);
492
493 ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS);
494 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
495 ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS);
496
497 // Create and configure function
498 NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint output_stage;
499 output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max);
500
501 // Validate valid region input and output
502 const ValidRegion valid_region = shape_to_valid_region(shape);
503 validate(in.info()->valid_region(), valid_region);
504 validate(out.info()->valid_region(), valid_region);
505
506 // Validate valid region bias
507 if(add_bias)
508 {
509 const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias);
510 validate(bias.info()->valid_region(), valid_region_bias);
511 }
512
513 // Validate padding
514 const PaddingSize padding(0);
515 validate(in.info()->padding(), padding);
516 validate(out.info()->padding(), padding);
517
518 if(add_bias)
519 {
520 validate(bias.info()->padding(), padding);
521 }
522}
523FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
524 quantize_down_int32_to_int8_scale_by_fixedpoint_cases))
525{
526 // Validate output
527 validate(Accessor(_target), _reference);
528}
529
530TEST_SUITE(BoundedReLu)
531FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
532 quantize_down_int32_to_int8_scale_by_fixedpoint_relu_cases))
533{
534 // Validate output
535 validate(Accessor(_target), _reference);
536}
537TEST_SUITE_END() // BoundedReLu
538TEST_SUITE_END() // QuantizeDownInt32ToInt8ScaleByFixedPoint
539
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100540TEST_SUITE(QuantizeDownInt32ToInt16ScaleByFixedPoint)
541
542const auto quantize_down_int32_to_int16_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
543 2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000544 * framework::dataset::make("min", -32768) * framework::dataset::make("max", 32767) * framework::dataset::make("addBias", { false, true });
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100545
546const 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,
547 2)
548 * 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 +0000549const auto quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_cases = framework::dataset::make("result_fixedpoint_multiplier", 1073741823,
550 1073741825)
551 * framework::dataset::make("result_shift", -3,
552 -2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000553 * framework::dataset::make("min", -32768) * framework::dataset::make("max", 32767) * framework::dataset::make("addBias", { false, true });
Manuel Bottini07263982019-10-17 18:37:26 +0100554
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000555const auto quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_relu_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600,
556 254601602)
557 * framework::dataset::make("result_shift", -3,
558 -1)
559 * 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 +0100560
561using NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture =
562 GEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint>;
563
564// *INDENT-OFF*
565// clang-format off
566DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
567 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 +0100568 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
569 }),
570 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100571 TensorInfo(TensorShape(20U), 1, DataType::S32),
572 })),
573 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QSYMM16),
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100574 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
575 })),
576 framework::dataset::make("Min",{ -205,
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100577 -180,
578 })),
579 framework::dataset::make("Max",{ 205,
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100580 180,
581 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000582 framework::dataset::make("Expected", { true, false })),
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100583 a_info, b_info, output_info, min, max, expected)
584{
585 // Lock tensors
586 Status status = NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false),
587 &b_info.clone()->set_is_resizable(false),
588 &output_info.clone()->set_is_resizable(false),
589 min,
590 max);
591 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
592}
593// clang-format on
594// *INDENT-ON*
595
596DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
597 quantize_down_int32_to_int16_scale_by_fixedpoint_cases),
598 shape, result_fixedpoint_multiplier, result_shift, min, max, add_bias)
599{
600 TensorShape shape_bias(shape[0]);
601
602 // Create tensors
603 Tensor in = create_tensor<Tensor>(shape, DataType::S32);
604 Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32);
605 Tensor out = create_tensor<Tensor>(shape, DataType::QSYMM16);
606
607 ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS);
608 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
609 ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS);
610
611 // Create and configure function
612 NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint output_stage;
613 output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_fixedpoint_multiplier, result_shift, min, max);
614
615 // Validate valid region input and output
616 const ValidRegion valid_region = shape_to_valid_region(shape);
617 validate(in.info()->valid_region(), valid_region);
618 validate(out.info()->valid_region(), valid_region);
619
620 // Validate valid region bias
621 if(add_bias)
622 {
623 const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias);
624 validate(bias.info()->valid_region(), valid_region_bias);
625 }
626
627 // Validate padding
628 const PaddingSize padding(0);
629 validate(in.info()->padding(), padding);
630 validate(out.info()->padding(), padding);
631
632 if(add_bias)
633 {
634 validate(bias.info()->padding(), padding);
635 }
636}
Manuel Bottini07263982019-10-17 18:37:26 +0100637TEST_SUITE(NoRelu)
638TEST_SUITE(MultSmallerEq1)
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100639FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
640 quantize_down_int32_to_int16_scale_by_fixedpoint_cases))
641{
642 // Validate output
643 validate(Accessor(_target), _reference);
644}
Manuel Bottini07263982019-10-17 18:37:26 +0100645TEST_SUITE_END() // MultSmallerEq1
646TEST_SUITE(MultGreater1)
647FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
648 quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_cases))
649{
650 // Validate output
651 validate(Accessor(_target), _reference);
652}
653TEST_SUITE_END() // MultGreater1
654TEST_SUITE_END() // NoRelu
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100655TEST_SUITE(BoundedReLu)
Manuel Bottini07263982019-10-17 18:37:26 +0100656TEST_SUITE(MultSmallerEq1)
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100657FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
658 quantize_down_int32_to_int16_scale_by_fixedpoint_relu_cases))
659{
660 // Validate output
661 validate(Accessor(_target), _reference);
662}
Manuel Bottini07263982019-10-17 18:37:26 +0100663TEST_SUITE_END() // MultSmallerEq1
664TEST_SUITE(MultGreater1)
665FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
666 quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_relu_cases))
667{
668 // Validate output
669 validate(Accessor(_target), _reference);
670}
671TEST_SUITE_END() // MultGreater1
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100672TEST_SUITE_END() // BoundedReLu
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100673TEST_SUITE_END() // QuantizeDownInt32ToInt16ScaleByFixedPoint
Gian Marcoe75a02b2017-11-08 12:24:09 +0000674TEST_SUITE_END() // OutputStage
Gian Marcoe75a02b2017-11-08 12:24:09 +0000675TEST_SUITE_END() // GEMMLowp
676TEST_SUITE_END() // NEON
Pablo Tello299025a2017-09-29 11:30:12 +0100677} // namespace validation
678} // namespace test
679} // namespace arm_compute