blob: 5148a31936ceada0e0eb47e07ed695381b84b07b [file] [log] [blame]
Gian Marco05288a22017-11-21 10:57:50 +00001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
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)
50using CLGEMMLowpMatrixMultiplyCoreFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<CLTensor, CLAccessor, CLGEMMLowpMatrixMultiplyCore>;
51
52DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallGEMMLowpDataset(), datasets::LargeGEMMLowpDataset()),
53 shape_a, shape_b, shape_c, a_offset, b_offset)
54{
55 // Create tensors
56 CLTensor a = create_tensor<CLTensor>(shape_a, DataType::QASYMM8);
57 CLTensor b = create_tensor<CLTensor>(shape_b, DataType::QASYMM8);
58 CLTensor c = create_tensor<CLTensor>(shape_c, DataType::S32);
59
60 a.info()->set_quantization_info(QuantizationInfo(1.0f / 255, a_offset));
61 b.info()->set_quantization_info(QuantizationInfo(1.0f / 255, b_offset));
62
63 ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS);
64 ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS);
65 ARM_COMPUTE_EXPECT(c.info()->is_resizable(), framework::LogLevel::ERRORS);
66
67 // Create and configure function
68 CLGEMMLowpMatrixMultiplyCore gemmlowp_mm;
69 gemmlowp_mm.configure(&a, &b, &c);
70}
71
72FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::ALL, datasets::SmallGEMMLowpDataset())
73{
74 // Validate output
75 validate(CLAccessor(_target), _reference);
76}
77
78FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpDataset())
79{
80 // Validate output
81 validate(CLAccessor(_target), _reference);
82}
83
84TEST_SUITE_END() // MatrixMultiplyCore
85
86TEST_SUITE(OutputStage)
87TEST_SUITE(QuantizeDownInt32ToUint8Scale)
88
89const 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,
90 3)
91 * framework::dataset::make("min", 0) * framework::dataset::make("max", 0) * framework::dataset::make("addBias", { false, true });
92
93const auto quantize_down_int32_to_uint8_scale_relu_cases = framework::dataset::make("result_offset", -2, 1) * framework::dataset::make("result_mult_int", 1,
94 2)
95 * 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 });
96
97using CLGEMMLowpQuantizeDownInt32ToUint8ScaleFixture = GEMMLowpQuantizeDownInt32ToUint8ScaleValidationFixture<CLTensor, CLAccessor, CLGEMMLowpQuantizeDownInt32ToUint8Scale>;
98
99DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), quantize_down_int32_to_uint8_scale_cases),
100 shape, result_offset, result_mult_int, result_shift, min, max, add_bias)
101{
102 TensorShape shape_bias(shape[0]);
103
104 // Create tensors
105 CLTensor in = create_tensor<CLTensor>(shape, DataType::S32);
106 CLTensor bias = create_tensor<CLTensor>(shape_bias, DataType::S32);
107 CLTensor out = create_tensor<CLTensor>(shape, DataType::QASYMM8);
108
109 ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS);
110 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
111 ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS);
112
113 // Create and configure function
114 CLGEMMLowpQuantizeDownInt32ToUint8Scale output_stage;
115 output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_offset, result_mult_int, result_shift, min, max);
116
117 // Validate valid region input and output
118 const ValidRegion valid_region = shape_to_valid_region(shape);
119 validate(in.info()->valid_region(), valid_region);
120 validate(out.info()->valid_region(), valid_region);
121
122 // Validate valid region bias
123 if(add_bias)
124 {
125 const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias);
126 validate(bias.info()->valid_region(), valid_region_bias);
127 }
128
129 // Validate padding
130 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
131 validate(in.info()->padding(), padding);
132 validate(out.info()->padding(), padding);
133
134 if(add_bias)
135 {
136 validate(bias.info()->padding(), padding);
137 }
138}
139
Gian Marco58c57942017-11-28 09:10:03 +0000140FIXTURE_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 +0000141{
142 // Validate output
143 validate(CLAccessor(_target), _reference);
144}
145
Gian Marco58c57942017-11-28 09:10:03 +0000146FIXTURE_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 +0000147{
148 // Validate output
149 validate(CLAccessor(_target), _reference);
150}
151
152TEST_SUITE(BoundedReLu)
Gian Marco58c57942017-11-28 09:10:03 +0000153FIXTURE_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 +0000154{
155 // Validate output
156 validate(CLAccessor(_target), _reference);
157}
158
Gian Marco58c57942017-11-28 09:10:03 +0000159FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
160 quantize_down_int32_to_uint8_scale_relu_cases))
Gian Marco05288a22017-11-21 10:57:50 +0000161{
162 // Validate output
163 validate(CLAccessor(_target), _reference);
164}
165TEST_SUITE_END() // BoundedReLu
Gian Marco05288a22017-11-21 10:57:50 +0000166TEST_SUITE_END() // QuantizeDownInt32ToUint8Scale
Gian Marco58c57942017-11-28 09:10:03 +0000167
168TEST_SUITE(QuantizeDownInt32ToUint8ScaleByFixedPoint)
169
170const auto quantize_down_int32_to_uint8_scale_by_fixedpoint_cases = framework::dataset::make("result_fixedpoint_multiplier", 254601600, 254601602) * framework::dataset::make("result_shift", 1,
171 2)
172 * 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 });
173
174const 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,
175 2)
176 * 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 });
177
178using CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture =
179 GEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointValidationFixture<CLTensor, CLAccessor, CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint>;
180
181DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()),
182 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases),
183 shape, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max, add_bias)
184{
185 TensorShape shape_bias(shape[0]);
186
187 // Create tensors
188 CLTensor in = create_tensor<CLTensor>(shape, DataType::S32);
189 CLTensor bias = create_tensor<CLTensor>(shape_bias, DataType::S32);
190 CLTensor out = create_tensor<CLTensor>(shape, DataType::QASYMM8);
191
192 ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS);
193 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
194 ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS);
195
196 // Create and configure function
197 CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPoint output_stage;
198 output_stage.configure(&in, add_bias ? &bias : nullptr, &out, result_fixedpoint_multiplier, result_shift, result_offset_after_shift, min, max);
199
200 // Validate valid region input and output
201 const ValidRegion valid_region = shape_to_valid_region(shape);
202 validate(in.info()->valid_region(), valid_region);
203 validate(out.info()->valid_region(), valid_region);
204
205 // Validate valid region bias
206 if(add_bias)
207 {
208 const ValidRegion valid_region_bias = shape_to_valid_region(shape_bias);
209 validate(bias.info()->valid_region(), valid_region_bias);
210 }
211
212 // Validate padding
213 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
214 validate(in.info()->padding(), padding);
215 validate(out.info()->padding(), padding);
216
217 if(add_bias)
218 {
219 validate(bias.info()->padding(), padding);
220 }
221}
222
223FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
224 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases))
225{
226 // Validate output
227 validate(CLAccessor(_target), _reference);
228}
229
230FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
231 quantize_down_int32_to_uint8_scale_by_fixedpoint_cases))
232{
233 // Validate output
234 validate(CLAccessor(_target), _reference);
235}
236
237TEST_SUITE(BoundedReLu)
238FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(),
239 quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases))
240{
241 // Validate output
242 validate(CLAccessor(_target), _reference);
243}
244
245FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(),
246 quantize_down_int32_to_uint8_scale_by_fixedpoint_relu_cases))
247{
248 // Validate output
249 validate(CLAccessor(_target), _reference);
250}
251TEST_SUITE_END() // BoundedReLu
252TEST_SUITE_END() // QuantizeDownInt32ToUint8ScaleByFixedPoint
253
Gian Marco05288a22017-11-21 10:57:50 +0000254TEST_SUITE_END() // OutputStage
255TEST_SUITE_END() // GEMMLowp
256TEST_SUITE_END() // CL
257} // namespace validation
258} // namespace test
259} // namespace arm_compute