blob: 2f604c95eacb1acf102fce0973922cc21ad3fa1e [file] [log] [blame]
Pablo Tello299025a2017-09-29 11:30:12 +01001/*
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +00002 * Copyright (c) 2017-2019 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)
150FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture, framework::DatasetMode::ALL, datasets::SmallGEMMLowpFusedOffsetOutputDataset())
151{
152 // Validate output
153 validate(Accessor(_target), _reference);
154}
155
156FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpFusedOffsetOutputDataset())
157{
158 // Validate output
159 validate(Accessor(_target), _reference);
160}
161TEST_SUITE_END() // FusedOffsetOutput
Gian Marcoe75a02b2017-11-08 12:24:09 +0000162TEST_SUITE_END() // MatrixMultiplyCore
163
164TEST_SUITE(OutputStage)
165
166TEST_SUITE(QuantizeDownInt32ToUint8Scale)
167
Gian Marco05288a22017-11-21 10:57:50 +0000168const 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 +0000169 3)
170 * framework::dataset::make("min", 0) * framework::dataset::make("max", 0) * framework::dataset::make("addBias", { false, true });
171
Gian Marco05288a22017-11-21 10:57:50 +0000172const 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 +0000173 2)
174 * 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 });
175
Gian Marcoe75a02b2017-11-08 12:24:09 +0000176using NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture = GEMMLowpQuantizeDownInt32ToUint8ScaleValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToUint8Scale>;
177
Gian Marco7f0f7902017-12-07 09:26:56 +0000178// *INDENT-OFF*
179// clang-format off
180DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
181 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
182 TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Invalid min and max
183 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
184 }),
185 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
186 TensorInfo(TensorShape(21U), 1, DataType::S32),
187 TensorInfo(TensorShape(20U), 1, DataType::S32),
188 })),
189 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8),
190 TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8),
191 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
192 })),
193 framework::dataset::make("Min",{ 0,
194 8,
195 13,
196 })),
197 framework::dataset::make("Max",{ 205,
198 300,
199 180,
200 })),
201 framework::dataset::make("Expected", { true, false, false })),
202 a_info, b_info, output_info, min, max, expected)
203{
204 // Lock tensors
205 Status status = NEGEMMLowpQuantizeDownInt32ToUint8Scale::validate(&a_info.clone()->set_is_resizable(false),
206 &b_info.clone()->set_is_resizable(false),
207 &output_info.clone()->set_is_resizable(false),
208 min,
209 max);
210 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
211}
212// clang-format on
213// *INDENT-ON*
214
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +0000215DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_cases),
Gian Marco6b77e912017-11-17 09:27:57 +0000216 shape, result_offset, result_mult_int, result_shift, min, max, add_bias)
Gian Marcoe75a02b2017-11-08 12:24:09 +0000217{
Gian Marco6b77e912017-11-17 09:27:57 +0000218 TensorShape shape_bias(shape[0]);
219
Gian Marcoe75a02b2017-11-08 12:24:09 +0000220 // Create tensors
Gian Marco6b77e912017-11-17 09:27:57 +0000221 Tensor in = create_tensor<Tensor>(shape, DataType::S32);
222 Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32);
223 Tensor out = create_tensor<Tensor>(shape, DataType::QASYMM8);
Gian Marcoe75a02b2017-11-08 12:24:09 +0000224
225 ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS);
Gian Marco6b77e912017-11-17 09:27:57 +0000226 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
Gian Marcoe75a02b2017-11-08 12:24:09 +0000227 ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS);
228
229 // Create and configure function
230 NEGEMMLowpQuantizeDownInt32ToUint8Scale output_stage;
Gian Marco6b77e912017-11-17 09:27:57 +0000231 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 +0000232
Gian Marco6b77e912017-11-17 09:27:57 +0000233 // Validate valid region input and output
Gian Marcoe75a02b2017-11-08 12:24:09 +0000234 const ValidRegion valid_region = shape_to_valid_region(shape);
235 validate(in.info()->valid_region(), valid_region);
236 validate(out.info()->valid_region(), valid_region);
237
Gian Marco6b77e912017-11-17 09:27:57 +0000238 // Validate valid region bias
239 if(add_bias)
240 {
241 const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias);
242 validate(bias.info()->valid_region(), valid_region_bias);
243 }
244
Gian Marcoe75a02b2017-11-08 12:24:09 +0000245 // Validate padding
Gian Marco7f0f7902017-12-07 09:26:56 +0000246 const PaddingSize padding(0);
Gian Marcoe75a02b2017-11-08 12:24:09 +0000247 validate(in.info()->padding(), padding);
248 validate(out.info()->padding(), padding);
Gian Marco6b77e912017-11-17 09:27:57 +0000249
250 if(add_bias)
251 {
252 validate(bias.info()->padding(), padding);
253 }
Gian Marcoe75a02b2017-11-08 12:24:09 +0000254}
255
256FIXTURE_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 +0100257{
258 // Validate output
Gian Marcofa4cacd2017-10-18 17:05:02 +0100259 validate(Accessor(_target), _reference);
Pablo Tellobf2fb952017-09-29 16:43:25 +0100260}
Pablo Tello6ff12a02017-11-02 16:09:35 +0000261
Gian Marcoe75a02b2017-11-08 12:24:09 +0000262FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), quantize_down_int32_to_uint8_scale_cases))
263{
264 // Validate output
265 validate(Accessor(_target), _reference);
266}
267
Gian Marco6b77e912017-11-17 09:27:57 +0000268TEST_SUITE(BoundedReLu)
269FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_relu_cases))
270{
271 // Validate output
272 validate(Accessor(_target), _reference);
273}
Gian Marcoe75a02b2017-11-08 12:24:09 +0000274
Gian Marco6b77e912017-11-17 09:27:57 +0000275FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), quantize_down_int32_to_uint8_scale_relu_cases))
276{
277 // Validate output
278 validate(Accessor(_target), _reference);
279}
280TEST_SUITE_END() // BoundedReLu
281
Gian Marco6b77e912017-11-17 09:27:57 +0000282TEST_SUITE_END() // QuantizeDownInt32ToUint8Scale
Gian Marco58c57942017-11-28 09:10:03 +0000283
284TEST_SUITE(QuantizeDownInt32ToUint8ScaleByFixedPoint)
285
286const auto quantize_down_int32_to_uint8_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
287 2)
288 * framework::dataset::make("result_offset_after_shift", 2, 3) * framework::dataset::make("min", 0) * framework::dataset::make("max", 0) * framework::dataset::make("addBias", { false, true });
289
290const 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,
291 2)
292 * 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 });
293
294using NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture =
295 GEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint>;
296
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100297using NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture =
298 GEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint>;
299
Gian Marco7f0f7902017-12-07 09:26:56 +0000300// *INDENT-OFF*
301// clang-format off
302DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
303 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
304 TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Invalid min and max
305 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
306 }),
307 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
308 TensorInfo(TensorShape(21U), 1, DataType::S32),
309 TensorInfo(TensorShape(20U), 1, DataType::S32),
310 })),
311 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8),
312 TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8),
313 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
314 })),
315 framework::dataset::make("Min",{ 0,
316 8,
317 13,
318 })),
319 framework::dataset::make("Max",{ 205,
320 300,
321 180,
322 })),
323 framework::dataset::make("Expected", { true, false, false })),
324 a_info, b_info, output_info, min, max, expected)
325{
326 // Lock tensors
327 Status status = NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false),
328 &b_info.clone()->set_is_resizable(false),
329 &output_info.clone()->set_is_resizable(false),
330 min,
331 max);
332 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
333}
334// clang-format on
335// *INDENT-ON*
336
Michalis Spyrou5c9f0c42019-01-16 14:48:48 +0000337DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
Gian Marco58c57942017-11-28 09:10:03 +0000338 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases),
339 shape, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max, add_bias)
340{
341 TensorShape shape_bias(shape[0]);
342
343 // Create tensors
344 Tensor in = create_tensor<Tensor>(shape, DataType::S32);
345 Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32);
346 Tensor out = create_tensor<Tensor>(shape, DataType::QASYMM8);
347
348 ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS);
349 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
350 ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS);
351
352 // Create and configure function
353 NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint output_stage;
354 output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max);
355
356 // Validate valid region input and output
357 const ValidRegion valid_region = shape_to_valid_region(shape);
358 validate(in.info()->valid_region(), valid_region);
359 validate(out.info()->valid_region(), valid_region);
360
361 // Validate valid region bias
362 if(add_bias)
363 {
364 const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias);
365 validate(bias.info()->valid_region(), valid_region_bias);
366 }
367
368 // Validate padding
Gian Marco7f0f7902017-12-07 09:26:56 +0000369 const PaddingSize padding(0);
Gian Marco58c57942017-11-28 09:10:03 +0000370 validate(in.info()->padding(), padding);
371 validate(out.info()->padding(), padding);
372
373 if(add_bias)
374 {
375 validate(bias.info()->padding(), padding);
376 }
377}
378
379FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
380 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases))
381{
382 // Validate output
383 validate(Accessor(_target), _reference);
384}
385
386FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
387 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases))
388{
389 // Validate output
390 validate(Accessor(_target), _reference);
391}
392
393TEST_SUITE(BoundedReLu)
394FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
395 quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases))
396{
397 // Validate output
398 validate(Accessor(_target), _reference);
399}
400
401FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
402 quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases))
403{
404 // Validate output
405 validate(Accessor(_target), _reference);
406}
407TEST_SUITE_END() // BoundedReLu
408
409TEST_SUITE_END() // QuantizeDownInt32ToUint8ScaleByFixedPoint
Gian Marco Iodicebc415af2019-06-13 15:58:32 +0100410
411TEST_SUITE(QuantizeDownInt32ToInt16ScaleByFixedPoint)
412
413const auto quantize_down_int32_to_int16_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
414 2)
415 * framework::dataset::make("min", 0) * framework::dataset::make("max", 0) * framework::dataset::make("addBias", { false, true });
416
417const 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,
418 2)
419 * framework::dataset::make("min", -2, 0) * framework::dataset::make("max", 1, 3) * framework::dataset::make("addBias", { false, true });
420
421using NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture =
422 GEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint>;
423
424// *INDENT-OFF*
425// clang-format off
426DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
427 framework::dataset::make("InputAInfo", { TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Input not a multiple of 16
428 TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Invalid min and max
429 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32), // Wrong output data type
430 }),
431 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(21U), 1, DataType::S32),
432 TensorInfo(TensorShape(21U), 1, DataType::S32),
433 TensorInfo(TensorShape(20U), 1, DataType::S32),
434 })),
435 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(21U, 13U), 1, DataType::QSYMM16),
436 TensorInfo(TensorShape(21U, 13U), 1, DataType::QSYMM16),
437 TensorInfo(TensorShape(20U, 13U), 1, DataType::S32),
438 })),
439 framework::dataset::make("Min",{ -205,
440 -60000,
441 -180,
442 })),
443 framework::dataset::make("Max",{ 205,
444 60000,
445 180,
446 })),
447 framework::dataset::make("Expected", { true, false, false })),
448 a_info, b_info, output_info, min, max, expected)
449{
450 // Lock tensors
451 Status status = NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint::validate(&a_info.clone()->set_is_resizable(false),
452 &b_info.clone()->set_is_resizable(false),
453 &output_info.clone()->set_is_resizable(false),
454 min,
455 max);
456 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
457}
458// clang-format on
459// *INDENT-ON*
460
461DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
462 quantize_down_int32_to_int16_scale_by_fixedpoint_cases),
463 shape, result_fixedpoint_multiplier, result_shift, min, max, add_bias)
464{
465 TensorShape shape_bias(shape[0]);
466
467 // Create tensors
468 Tensor in = create_tensor<Tensor>(shape, DataType::S32);
469 Tensor bias = create_tensor<Tensor>(shape_bias, DataType::S32);
470 Tensor out = create_tensor<Tensor>(shape, DataType::QSYMM16);
471
472 ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS);
473 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
474 ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS);
475
476 // Create and configure function
477 NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPoint output_stage;
478 output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_fixedpoint_multiplier, result_shift, min, max);
479
480 // Validate valid region input and output
481 const ValidRegion valid_region = shape_to_valid_region(shape);
482 validate(in.info()->valid_region(), valid_region);
483 validate(out.info()->valid_region(), valid_region);
484
485 // Validate valid region bias
486 if(add_bias)
487 {
488 const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias);
489 validate(bias.info()->valid_region(), valid_region_bias);
490 }
491
492 // Validate padding
493 const PaddingSize padding(0);
494 validate(in.info()->padding(), padding);
495 validate(out.info()->padding(), padding);
496
497 if(add_bias)
498 {
499 validate(bias.info()->padding(), padding);
500 }
501}
502
503FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
504 quantize_down_int32_to_int16_scale_by_fixedpoint_cases))
505{
506 // Validate output
507 validate(Accessor(_target), _reference);
508}
509
510TEST_SUITE(BoundedReLu)
511FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToInt16ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
512 quantize_down_int32_to_int16_scale_by_fixedpoint_relu_cases))
513{
514 // Validate output
515 validate(Accessor(_target), _reference);
516}
517TEST_SUITE_END() // BoundedReLu
518
519TEST_SUITE_END() // QuantizeDownInt32ToInt16ScaleByFixedPoint
520
Gian Marcoe75a02b2017-11-08 12:24:09 +0000521TEST_SUITE_END() // OutputStage
522
523TEST_SUITE_END() // GEMMLowp
524TEST_SUITE_END() // NEON
Pablo Tello299025a2017-09-29 11:30:12 +0100525} // namespace validation
526} // namespace test
527} // namespace arm_compute