blob: de30bd5451db814fc4cd570dbcc5e5259c149555 [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
168TEST_SUITE(QuantizeDownInt32ToUint8Scale)
169
Gian Marco05288a22017-11-21 10:57:50 +0000170const 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 +0000171 3)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000172 * framework::dataset::make("min", 0) * framework::dataset::make("max", 255) * framework::dataset::make("addBias", { false, true });
Gian Marco6b77e912017-11-17 09:27:57 +0000173
Gian Marco05288a22017-11-21 10:57:50 +0000174const 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 +0000175 2)
176 * 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 });
177
Gian Marcoe75a02b2017-11-08 12:24:09 +0000178using NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture = GEMMLowpQuantizeDownInt32ToUint8ScaleValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToUint8Scale>;
179
Gian Marco7f0f7902017-12-07 09:26:56 +0000180// *INDENT-OFF*
181// clang-format off
182DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
183 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
Gian Marco7f0f7902017-12-07 09:26:56 +0000184 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
185 }),
186 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Gian Marco7f0f7902017-12-07 09:26:56 +0000187 TensorInfo(TensorShape(20U), 1, DataType::S32),
188 })),
189 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8),
Gian Marco7f0f7902017-12-07 09:26:56 +0000190 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
191 })),
192 framework::dataset::make("Min",{ 0,
Gian Marco7f0f7902017-12-07 09:26:56 +0000193 13,
194 })),
195 framework::dataset::make("Max",{ 205,
Gian Marco7f0f7902017-12-07 09:26:56 +0000196 180,
197 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000198 framework::dataset::make("Expected", { true, false })),
Gian Marco7f0f7902017-12-07 09:26:56 +0000199 a_info, b_info, output_info, min, max, expected)
200{
201 // Lock tensors
202 Status status = NEGEMMLowpQuantizeDownInt32ToUint8Scale::validate(&a_info.clone()->set_is_resizable(false),
203 &b_info.clone()->set_is_resizable(false),
204 &output_info.clone()->set_is_resizable(false),
205 min,
206 max);
207 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
208}
209// clang-format on
210// *INDENT-ON*
211
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +0000212DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_cases),
Gian Marco6b77e912017-11-17 09:27:57 +0000213 shape, result_offset, result_mult_int, result_shift, min, max, add_bias)
Gian Marcoe75a02b2017-11-08 12:24:09 +0000214{
Gian Marco6b77e912017-11-17 09:27:57 +0000215 TensorShape shape_bias(shape[0]);
216
Gian Marcoe75a02b2017-11-08 12:24:09 +0000217 // Create tensors
Gian Marco6b77e912017-11-17 09:27:57 +0000218 Tensor in = create_tensor<Tensor>(shape, DataType::S32);
219 Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32);
220 Tensor out = create_tensor<Tensor>(shape, DataType::QASYMM8);
Gian Marcoe75a02b2017-11-08 12:24:09 +0000221
222 ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS);
Gian Marco6b77e912017-11-17 09:27:57 +0000223 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
Gian Marcoe75a02b2017-11-08 12:24:09 +0000224 ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS);
225
226 // Create and configure function
227 NEGEMMLowpQuantizeDownInt32ToUint8Scale output_stage;
Gian Marco6b77e912017-11-17 09:27:57 +0000228 output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_offset, result_mult_int, result_shift, min, max);
Gian Marcoe75a02b2017-11-08 12:24:09 +0000229
Gian Marco6b77e912017-11-17 09:27:57 +0000230 // Validate valid region input and output
Gian Marcoe75a02b2017-11-08 12:24:09 +0000231 const ValidRegion valid_region = shape_to_valid_region(shape);
232 validate(in.info()->valid_region(), valid_region);
233 validate(out.info()->valid_region(), valid_region);
234
Gian Marco6b77e912017-11-17 09:27:57 +0000235 // Validate valid region bias
236 if(add_bias)
237 {
238 const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias);
239 validate(bias.info()->valid_region(), valid_region_bias);
240 }
241
Gian Marcoe75a02b2017-11-08 12:24:09 +0000242 // Validate padding
Gian Marco7f0f7902017-12-07 09:26:56 +0000243 const PaddingSize padding(0);
Gian Marcoe75a02b2017-11-08 12:24:09 +0000244 validate(in.info()->padding(), padding);
245 validate(out.info()->padding(), padding);
Gian Marco6b77e912017-11-17 09:27:57 +0000246
247 if(add_bias)
248 {
249 validate(bias.info()->padding(), padding);
250 }
Gian Marcoe75a02b2017-11-08 12:24:09 +0000251}
252
253FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_cases))
Pablo Tellobf2fb952017-09-29 16:43:25 +0100254{
255 // Validate output
Gian Marcofa4cacd2017-10-18 17:05:02 +0100256 validate(Accessor(_target), _reference);
Pablo Tellobf2fb952017-09-29 16:43:25 +0100257}
Pablo Tello6ff12a02017-11-02 16:09:35 +0000258
Gian Marcoe75a02b2017-11-08 12:24:09 +0000259FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), quantize_down_int32_to_uint8_scale_cases))
260{
261 // Validate output
262 validate(Accessor(_target), _reference);
263}
264
Gian Marco6b77e912017-11-17 09:27:57 +0000265TEST_SUITE(BoundedReLu)
266FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_relu_cases))
267{
268 // Validate output
269 validate(Accessor(_target), _reference);
270}
Gian Marcoe75a02b2017-11-08 12:24:09 +0000271
Gian Marco6b77e912017-11-17 09:27:57 +0000272FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), quantize_down_int32_to_uint8_scale_relu_cases))
273{
274 // Validate output
275 validate(Accessor(_target), _reference);
276}
277TEST_SUITE_END() // BoundedReLu
278
Gian Marco6b77e912017-11-17 09:27:57 +0000279TEST_SUITE_END() // QuantizeDownInt32ToUint8Scale
Gian Marco58c57942017-11-28 09:10:03 +0000280
281TEST_SUITE(QuantizeDownInt32ToUint8ScaleByFixedPoint)
282
283const auto quantize_down_int32_to_uint8_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
284 2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000285 * 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 +0000286
287const 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,
288 2)
289 * 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 });
290
291using NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture =
292 GEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint>;
293
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100294using NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture =
295 GEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint>;
296
Gian Marco7f0f7902017-12-07 09:26:56 +0000297// *INDENT-OFF*
298// clang-format off
299DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
300 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
Gian Marco7f0f7902017-12-07 09:26:56 +0000301 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
302 }),
303 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Gian Marco7f0f7902017-12-07 09:26:56 +0000304 TensorInfo(TensorShape(20U), 1, DataType::S32),
305 })),
306 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8),
Gian Marco7f0f7902017-12-07 09:26:56 +0000307 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
308 })),
309 framework::dataset::make("Min",{ 0,
Gian Marco7f0f7902017-12-07 09:26:56 +0000310 13,
311 })),
312 framework::dataset::make("Max",{ 205,
Gian Marco7f0f7902017-12-07 09:26:56 +0000313 180,
314 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000315 framework::dataset::make("Expected", { true, false })),
Gian Marco7f0f7902017-12-07 09:26:56 +0000316 a_info, b_info, output_info, min, max, expected)
317{
318 // Lock tensors
319 Status status = NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false),
320 &b_info.clone()->set_is_resizable(false),
321 &output_info.clone()->set_is_resizable(false),
322 min,
323 max);
324 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
325}
326// clang-format on
327// *INDENT-ON*
328
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +0000329DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
Gian Marco58c57942017-11-28 09:10:03 +0000330 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases),
331 shape, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max, add_bias)
332{
333 TensorShape shape_bias(shape[0]);
334
335 // Create tensors
336 Tensor in = create_tensor<Tensor>(shape, DataType::S32);
337 Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32);
338 Tensor out = create_tensor<Tensor>(shape, DataType::QASYMM8);
339
340 ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS);
341 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
342 ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS);
343
344 // Create and configure function
345 NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint output_stage;
346 output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max);
347
348 // Validate valid region input and output
349 const ValidRegion valid_region = shape_to_valid_region(shape);
350 validate(in.info()->valid_region(), valid_region);
351 validate(out.info()->valid_region(), valid_region);
352
353 // Validate valid region bias
354 if(add_bias)
355 {
356 const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias);
357 validate(bias.info()->valid_region(), valid_region_bias);
358 }
359
360 // Validate padding
Gian Marco7f0f7902017-12-07 09:26:56 +0000361 const PaddingSize padding(0);
Gian Marco58c57942017-11-28 09:10:03 +0000362 validate(in.info()->padding(), padding);
363 validate(out.info()->padding(), padding);
364
365 if(add_bias)
366 {
367 validate(bias.info()->padding(), padding);
368 }
369}
370
371FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
372 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases))
373{
374 // Validate output
375 validate(Accessor(_target), _reference);
376}
377
378FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
379 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases))
380{
381 // Validate output
382 validate(Accessor(_target), _reference);
383}
384
385TEST_SUITE(BoundedReLu)
386FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
387 quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases))
388{
389 // Validate output
390 validate(Accessor(_target), _reference);
391}
392
393FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
394 quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases))
395{
396 // Validate output
397 validate(Accessor(_target), _reference);
398}
399TEST_SUITE_END() // BoundedReLu
400
401TEST_SUITE_END() // QuantizeDownInt32ToUint8ScaleByFixedPoint
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100402
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000403TEST_SUITE(QuantizeDownInt32ToInt8ScaleByFixedPoint)
404
405const auto quantize_down_int32_to_int8_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
406 2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000407 * 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 +0000408
409const 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,
410 2)
411 * 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 });
412
413using NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture =
414 GEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint>;
415
416// *INDENT-OFF*
417// clang-format off
418DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
419 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::F32), // Invalid input data type
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000420 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
421 TensorInfo(TensorShape(21U, 13U), 1, DataType::S32),
422 }),
423 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000424 TensorInfo(TensorShape(20U), 1, DataType::S32),
425 TensorInfo(TensorShape(21U), 1, DataType::S32),
426 })),
427 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000428 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
429 TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8_SIGNED),
430 })),
431 framework::dataset::make("Min",{ -110,
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000432 -113,
433 -113,
434 })),
435 framework::dataset::make("Max",{ 87,
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000436 97,
437 97,
438 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000439 framework::dataset::make("Expected", { false, false, true })),
Georgios Pinitas448a81f2019-11-21 14:10:25 +0000440 a_info, b_info, output_info, min, max, expected)
441{
442 // Lock tensors
443 Status status = NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false),
444 &b_info.clone()->set_is_resizable(false),
445 &output_info.clone()->set_is_resizable(false),
446 min,
447 max);
448 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
449}
450// clang-format on
451// *INDENT-ON*
452
453DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
454 quantize_down_int32_to_int8_scale_by_fixedpoint_cases),
455 shape, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max, add_bias)
456{
457 TensorShape shape_bias(shape[0]);
458
459 // Create tensors
460 Tensor in = create_tensor<Tensor>(shape, DataType::S32);
461 Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32);
462 Tensor out = create_tensor<Tensor>(shape, DataType::QASYMM8_SIGNED);
463
464 ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS);
465 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
466 ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS);
467
468 // Create and configure function
469 NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPoint output_stage;
470 output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max);
471
472 // Validate valid region input and output
473 const ValidRegion valid_region = shape_to_valid_region(shape);
474 validate(in.info()->valid_region(), valid_region);
475 validate(out.info()->valid_region(), valid_region);
476
477 // Validate valid region bias
478 if(add_bias)
479 {
480 const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias);
481 validate(bias.info()->valid_region(), valid_region_bias);
482 }
483
484 // Validate padding
485 const PaddingSize padding(0);
486 validate(in.info()->padding(), padding);
487 validate(out.info()->padding(), padding);
488
489 if(add_bias)
490 {
491 validate(bias.info()->padding(), padding);
492 }
493}
494FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
495 quantize_down_int32_to_int8_scale_by_fixedpoint_cases))
496{
497 // Validate output
498 validate(Accessor(_target), _reference);
499}
500
501TEST_SUITE(BoundedReLu)
502FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
503 quantize_down_int32_to_int8_scale_by_fixedpoint_relu_cases))
504{
505 // Validate output
506 validate(Accessor(_target), _reference);
507}
508TEST_SUITE_END() // BoundedReLu
509TEST_SUITE_END() // QuantizeDownInt32ToInt8ScaleByFixedPoint
510
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100511TEST_SUITE(QuantizeDownInt32ToInt16ScaleByFixedPoint)
512
513const auto quantize_down_int32_to_int16_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
514 2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000515 * framework::dataset::make("min", -32768) * framework::dataset::make("max", 32767) * framework::dataset::make("addBias", { false, true });
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100516
517const 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,
518 2)
519 * 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 +0000520const auto quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_cases = framework::dataset::make("result_fixedpoint_multiplier", 1073741823,
521 1073741825)
522 * framework::dataset::make("result_shift", -3,
523 -2)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000524 * framework::dataset::make("min", -32768) * framework::dataset::make("max", 32767) * framework::dataset::make("addBias", { false, true });
Manuel Bottini07263982019-10-17 18:37:26 +0100525
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000526const auto quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_relu_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600,
527 254601602)
528 * framework::dataset::make("result_shift", -3,
529 -1)
530 * 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 +0100531
532using NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture =
533 GEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint>;
534
535// *INDENT-OFF*
536// clang-format off
537DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
538 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 +0100539 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
540 }),
541 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100542 TensorInfo(TensorShape(20U), 1, DataType::S32),
543 })),
544 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QSYMM16),
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100545 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
546 })),
547 framework::dataset::make("Min",{ -205,
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100548 -180,
549 })),
550 framework::dataset::make("Max",{ 205,
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100551 180,
552 })),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000553 framework::dataset::make("Expected", { true, false })),
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100554 a_info, b_info, output_info, min, max, expected)
555{
556 // Lock tensors
557 Status status = NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false),
558 &b_info.clone()->set_is_resizable(false),
559 &output_info.clone()->set_is_resizable(false),
560 min,
561 max);
562 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
563}
564// clang-format on
565// *INDENT-ON*
566
567DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
568 quantize_down_int32_to_int16_scale_by_fixedpoint_cases),
569 shape, result_fixedpoint_multiplier, result_shift, min, max, add_bias)
570{
571 TensorShape shape_bias(shape[0]);
572
573 // Create tensors
574 Tensor in = create_tensor<Tensor>(shape, DataType::S32);
575 Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32);
576 Tensor out = create_tensor<Tensor>(shape, DataType::QSYMM16);
577
578 ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS);
579 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
580 ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS);
581
582 // Create and configure function
583 NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint output_stage;
584 output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_fixedpoint_multiplier, result_shift, min, max);
585
586 // Validate valid region input and output
587 const ValidRegion valid_region = shape_to_valid_region(shape);
588 validate(in.info()->valid_region(), valid_region);
589 validate(out.info()->valid_region(), valid_region);
590
591 // Validate valid region bias
592 if(add_bias)
593 {
594 const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias);
595 validate(bias.info()->valid_region(), valid_region_bias);
596 }
597
598 // Validate padding
599 const PaddingSize padding(0);
600 validate(in.info()->padding(), padding);
601 validate(out.info()->padding(), padding);
602
603 if(add_bias)
604 {
605 validate(bias.info()->padding(), padding);
606 }
607}
Manuel Bottini07263982019-10-17 18:37:26 +0100608TEST_SUITE(NoRelu)
609TEST_SUITE(MultSmallerEq1)
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100610FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
611 quantize_down_int32_to_int16_scale_by_fixedpoint_cases))
612{
613 // Validate output
614 validate(Accessor(_target), _reference);
615}
Manuel Bottini07263982019-10-17 18:37:26 +0100616TEST_SUITE_END() // MultSmallerEq1
617TEST_SUITE(MultGreater1)
618FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
619 quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_cases))
620{
621 // Validate output
622 validate(Accessor(_target), _reference);
623}
624TEST_SUITE_END() // MultGreater1
625TEST_SUITE_END() // NoRelu
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100626TEST_SUITE(BoundedReLu)
Manuel Bottini07263982019-10-17 18:37:26 +0100627TEST_SUITE(MultSmallerEq1)
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100628FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
629 quantize_down_int32_to_int16_scale_by_fixedpoint_relu_cases))
630{
631 // Validate output
632 validate(Accessor(_target), _reference);
633}
Manuel Bottini07263982019-10-17 18:37:26 +0100634TEST_SUITE_END() // MultSmallerEq1
635TEST_SUITE(MultGreater1)
636FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
637 quantize_down_int32_to_int16_scale_by_fixedpoint_multgreat1_relu_cases))
638{
639 // Validate output
640 validate(Accessor(_target), _reference);
641}
642TEST_SUITE_END() // MultGreater1
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100643TEST_SUITE_END() // BoundedReLu
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100644TEST_SUITE_END() // QuantizeDownInt32ToInt16ScaleByFixedPoint
Gian Marcoe75a02b2017-11-08 12:24:09 +0000645TEST_SUITE_END() // OutputStage
Gian Marcoe75a02b2017-11-08 12:24:09 +0000646TEST_SUITE_END() // GEMMLowp
647TEST_SUITE_END() // NEON
Pablo Tello299025a2017-09-29 11:30:12 +0100648} // namespace validation
649} // namespace test
650} // namespace arm_compute