blob: 08641dbaa3185d202dc0fef0298081974bce1b62 [file] [log] [blame]
Gian Marco05288a22017-11-21 10:57:50 +00001/*
Michalis Spyrou80943252019-01-10 17:19:50 +00002 * Copyright (c) 2017-2019 ARM Limited.
Gian Marco05288a22017-11-21 10:57:50 +00003 *
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"
25#include "arm_compute/runtime/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
27#include "arm_compute/runtime/CL/functions/CLGEMMLowpMatrixMultiplyCore.h"
28#include "arm_compute/runtime/CL/functions/CLGEMMLowpOutputStage.h"
29#include "tests/CL/CLAccessor.h"
30#include "tests/PaddingCalculator.h"
31#include "tests/datasets/LargeGEMMLowpDataset.h"
32#include "tests/datasets/ShapeDatasets.h"
33#include "tests/datasets/SmallGEMMLowpDataset.h"
34#include "tests/framework/Asserts.h"
35#include "tests/framework/Macros.h"
36#include "tests/framework/datasets/Datasets.h"
37#include "tests/validation/Validation.h"
38#include "tests/validation/fixtures/GEMMLowpFixture.h"
39
40namespace arm_compute
41{
42namespace test
43{
44namespace validation
45{
46TEST_SUITE(CL)
47TEST_SUITE(GEMMLowp)
48
49TEST_SUITE(MatrixMultiplyCore)
Georgios Pinitasebf6b8a2018-09-24 16:31:08 +010050
Gian Marco05288a22017-11-21 10:57:50 +000051using CLGEMMLowpMatrixMultiplyCoreFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore>;
52
Michalis Spyrou80943252019-01-10 17:19:50 +000053DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallGEMMLowpDataset(),
Gian Marco05288a22017-11-21 10:57:50 +000054 shape_a, shape_b, shape_c, a_offset, b_offset)
55{
56 // Create tensors
57 CLTensor a = create_tensor<CLTensor>(shape_a, DataType::QASYMM8);
58 CLTensor b = create_tensor<CLTensor>(shape_b, DataType::QASYMM8);
59 CLTensor c = create_tensor<CLTensor>(shape_c, DataType::S32);
60
61 a.info()->set_quantization_info(QuantizationInfo(1.0f / 255, a_offset));
62 b.info()->set_quantization_info(QuantizationInfo(1.0f / 255, b_offset));
63
64 ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS);
65 ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS);
66 ARM_COMPUTE_EXPECT(c.info()->is_resizable(), framework::LogLevel::ERRORS);
67
68 // Create and configure function
69 CLGEMMLowpMatrixMultiplyCore gemmlowp_mm;
Gian Marco Iodice4b908652018-10-18 10:21:02 +010070 // TODO (giaiod01) COMPMID-1672 - Extending the test to validate add bias in offset contribution
71 gemmlowp_mm.configure(&a, &b, nullptr, &c);
Gian Marco05288a22017-11-21 10:57:50 +000072}
73
74FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::ALL, datasets::SmallGEMMLowpDataset())
75{
76 // Validate output
77 validate(CLAccessor(_target), _reference);
78}
79
80FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpDataset())
81{
82 // Validate output
83 validate(CLAccessor(_target), _reference);
84}
85
Georgios Pinitasebf6b8a2018-09-24 16:31:08 +010086TEST_SUITE(Output3D)
87using CLGEMMLowpMatrixMultiplyCoreOutput3DFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore, false, true>;
88FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreOutput3DFixture, framework::DatasetMode::PRECOMMIT, datasets::SmallGEMMLowpOutput3DDataset())
89{
90 // Validate output
91 validate(CLAccessor(_target), _reference);
92}
93FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyCoreOutput3DFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpOutput3DDataset())
94{
95 // Validate output
96 validate(CLAccessor(_target), _reference);
97}
98TEST_SUITE_END() // Output3D
99
100TEST_SUITE(InputOutput3D)
101using CLGEMMLowpMatrixMultiplyCoreInputOutput3DFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore, true, true>;
102FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreInputOutput3DFixture, framework::DatasetMode::PRECOMMIT, datasets::SmallGEMMLowpInputOutput3DDataset())
103{
104 // Validate output
105 validate(CLAccessor(_target), _reference);
106}
107FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyCoreInputOutput3DFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpInputOutput3DDataset())
108{
109 // Validate output
110 validate(CLAccessor(_target), _reference);
111}
112TEST_SUITE_END() // InputOutput3D
Gian Marco05288a22017-11-21 10:57:50 +0000113TEST_SUITE_END() // MatrixMultiplyCore
114
115TEST_SUITE(OutputStage)
116TEST_SUITE(QuantizeDownInt32ToUint8Scale)
117
118const 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,
119 3)
120 * framework::dataset::make("min", 0) * framework::dataset::make("max", 0) * framework::dataset::make("addBias", { false, true });
121
122const auto quantize_down_int32_to_uint8_scale_relu_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1,
123 2)
124 * framework::dataset::make("result_shift", 2, 3) * framework::dataset::make("min", 0, 2) * framework::dataset::make("max", 171, 173) * framework::dataset::make("addBias", { false, true });
125
126using CLGEMMLowpQuantizeDownInt32ToUint8ScaleFixture = GEMMLowpQuantizeDownInt32ToUint8ScaleValidationFixture<CLTensor, CLAccessor, CLGEMMLowpQuantizeDownInt32ToUint8Scale>;
127
Michalis Spyrou80943252019-01-10 17:19:50 +0000128DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_cases),
Gian Marco05288a22017-11-21 10:57:50 +0000129 shape, result_offset, result_mult_int, result_shift, min, max, add_bias)
130{
131 TensorShape shape_bias(shape[0]);
132
133 // Create tensors
134 CLTensor in = create_tensor<CLTensor>(shape, DataType::S32);
135 CLTensor bias = create_tensor<CLTensor>(shape_bias, DataType::S32);
136 CLTensor out = create_tensor<CLTensor>(shape, DataType::QASYMM8);
137
138 ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS);
139 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
140 ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS);
141
142 // Create and configure function
143 CLGEMMLowpQuantizeDownInt32ToUint8Scale output_stage;
144 output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_offset, result_mult_int, result_shift, min, max);
145
146 // Validate valid region input and output
147 const ValidRegion valid_region = shape_to_valid_region(shape);
148 validate(in.info()->valid_region(), valid_region);
149 validate(out.info()->valid_region(), valid_region);
150
151 // Validate valid region bias
152 if(add_bias)
153 {
154 const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias);
155 validate(bias.info()->valid_region(), valid_region_bias);
156 }
157
158 // Validate padding
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100159 const PaddingSize padding = PaddingCalculator(shape.x(), 4).required_padding();
Gian Marco05288a22017-11-21 10:57:50 +0000160 validate(in.info()->padding(), padding);
161 validate(out.info()->padding(), padding);
162
163 if(add_bias)
164 {
165 validate(bias.info()->padding(), padding);
166 }
167}
168
Gian Marco58c57942017-11-28 09:10:03 +0000169FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_cases))
Gian Marco05288a22017-11-21 10:57:50 +0000170{
171 // Validate output
172 validate(CLAccessor(_target), _reference);
173}
174
Gian Marco58c57942017-11-28 09:10:03 +0000175FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), quantize_down_int32_to_uint8_scale_cases))
Gian Marco05288a22017-11-21 10:57:50 +0000176{
177 // Validate output
178 validate(CLAccessor(_target), _reference);
179}
180
181TEST_SUITE(BoundedReLu)
Gian Marco58c57942017-11-28 09:10:03 +0000182FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_relu_cases))
Gian Marco05288a22017-11-21 10:57:50 +0000183{
184 // Validate output
185 validate(CLAccessor(_target), _reference);
186}
187
Gian Marco58c57942017-11-28 09:10:03 +0000188FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
189 quantize_down_int32_to_uint8_scale_relu_cases))
Gian Marco05288a22017-11-21 10:57:50 +0000190{
191 // Validate output
192 validate(CLAccessor(_target), _reference);
193}
194TEST_SUITE_END() // BoundedReLu
Gian Marco05288a22017-11-21 10:57:50 +0000195TEST_SUITE_END() // QuantizeDownInt32ToUint8Scale
Gian Marco58c57942017-11-28 09:10:03 +0000196
197TEST_SUITE(QuantizeDownInt32ToUint8ScaleByFixedPoint)
198
199const auto quantize_down_int32_to_uint8_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
200 2)
201 * 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 });
202
203const 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,
204 2)
205 * 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 });
206
207using CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture =
208 GEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointValidationFixture<CLTensor, CLAccessor, CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint>;
209
Michalis Spyrou80943252019-01-10 17:19:50 +0000210DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
Gian Marco58c57942017-11-28 09:10:03 +0000211 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases),
212 shape, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max, add_bias)
213{
214 TensorShape shape_bias(shape[0]);
215
216 // Create tensors
217 CLTensor in = create_tensor<CLTensor>(shape, DataType::S32);
218 CLTensor bias = create_tensor<CLTensor>(shape_bias, DataType::S32);
219 CLTensor out = create_tensor<CLTensor>(shape, DataType::QASYMM8);
220
221 ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS);
222 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
223 ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS);
224
225 // Create and configure function
226 CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint output_stage;
227 output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max);
228
229 // Validate valid region input and output
230 const ValidRegion valid_region = shape_to_valid_region(shape);
231 validate(in.info()->valid_region(), valid_region);
232 validate(out.info()->valid_region(), valid_region);
233
234 // Validate valid region bias
235 if(add_bias)
236 {
237 const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias);
238 validate(bias.info()->valid_region(), valid_region_bias);
239 }
240
241 // Validate padding
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100242 const PaddingSize padding = PaddingCalculator(shape.x(), 4).required_padding();
Gian Marco58c57942017-11-28 09:10:03 +0000243 validate(in.info()->padding(), padding);
244 validate(out.info()->padding(), padding);
245
246 if(add_bias)
247 {
248 validate(bias.info()->padding(), padding);
249 }
250}
251
252FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
253 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases))
254{
255 // Validate output
256 validate(CLAccessor(_target), _reference);
257}
258
259FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
260 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases))
261{
262 // Validate output
263 validate(CLAccessor(_target), _reference);
264}
265
266TEST_SUITE(BoundedReLu)
267FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
268 quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases))
269{
270 // Validate output
271 validate(CLAccessor(_target), _reference);
272}
273
274FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
275 quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases))
276{
277 // Validate output
278 validate(CLAccessor(_target), _reference);
279}
280TEST_SUITE_END() // BoundedReLu
281TEST_SUITE_END() // QuantizeDownInt32ToUint8ScaleByFixedPoint
282
Gian Marco05288a22017-11-21 10:57:50 +0000283TEST_SUITE_END() // OutputStage
284TEST_SUITE_END() // GEMMLowp
285TEST_SUITE_END() // CL
286} // namespace validation
287} // namespace test
288} // namespace arm_compute