blob: 5d8733098274396ae698ac551d35ec3fab2ee0e0 [file] [log] [blame]
Pablo Tello299025a2017-09-29 11:30:12 +01001/*
Sheri Zhangac6499a2021-02-10 15:32:38 +00002 * Copyright (c) 2017-2021 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"
Gian Marcoe75a02b2017-11-08 12:24:09 +000025#include "arm_compute/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCore.h"
26#include "arm_compute/runtime/NEON/functions/NEGEMMLowpOutputStage.h"
Pablo Tello299025a2017-09-29 11:30:12 +010027#include "arm_compute/runtime/Tensor.h"
28#include "arm_compute/runtime/TensorAllocator.h"
29#include "tests/NEON/Accessor.h"
Gian Marco Iodiceab182122017-10-09 15:05:40 +010030#include "tests/NEON/Helper.h"
Gian Marcoe75a02b2017-11-08 12:24:09 +000031#include "tests/PaddingCalculator.h"
George Wort2d7e6832019-02-22 16:37:41 +000032#include "tests/datasets/GEMMLowpFusedOffsetOutputDataset.h"
Gian Marcofa4cacd2017-10-18 17:05:02 +010033#include "tests/datasets/LargeGEMMLowpDataset.h"
Gian Marcoe75a02b2017-11-08 12:24:09 +000034#include "tests/datasets/ShapeDatasets.h"
Gian Marcofa4cacd2017-10-18 17:05:02 +010035#include "tests/datasets/SmallGEMMLowpDataset.h"
Pablo Tello299025a2017-09-29 11:30:12 +010036#include "tests/framework/Asserts.h"
37#include "tests/framework/Macros.h"
38#include "tests/framework/datasets/Datasets.h"
39#include "tests/validation/Validation.h"
40#include "tests/validation/fixtures/GEMMLowpFixture.h"
41
42namespace arm_compute
43{
44namespace test
45{
46namespace validation
47{
Pablo Tello299025a2017-09-29 11:30:12 +010048TEST_SUITE(NEON)
49TEST_SUITE(GEMMLowp)
Gian Marcoe75a02b2017-11-08 12:24:09 +000050TEST_SUITE(MatrixMultiplyCore)
51using NEGEMMLowpMatrixMultiplyCoreFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<Tensor, Accessor, NEGEMMLowpMatrixMultiplyCore>;
Gian Marcofa4cacd2017-10-18 17:05:02 +010052
morgolock4adaddb2020-09-29 14:24:32 +010053DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallGEMMLowpDataset(), datasets::LargeGEMMLowpDataset()),
54 shape_a, shape_b, shape_c, a_offset, b_offset)
55{
56 // Create tensors
57 Tensor a = create_tensor<Tensor>(shape_a, DataType::QASYMM8);
58 Tensor b = create_tensor<Tensor>(shape_b, DataType::QASYMM8);
59 Tensor c = create_tensor<Tensor>(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 NEGEMMLowpMatrixMultiplyCore gemmlowp_mm;
70 gemmlowp_mm.configure(&a, &b, nullptr, &c);
71
72 // Validate padding is zero
73 validate(a.info()->padding(), PaddingSize());
74 validate(b.info()->padding(), PaddingSize());
75 validate(c.info()->padding(), PaddingSize());
76}
77
Georgios Pinitasa3b1b462017-11-16 19:24:39 +000078// *INDENT-OFF*
79// clang-format off
80DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
81 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 +010082 TensorInfo(TensorShape(21U, 13U), 1, DataType::S32), // Mismatching data type
Georgios Pinitasa3b1b462017-11-16 19:24:39 +000083 TensorInfo(TensorShape(20U, 13U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), // Invalid dimensions
84 TensorInfo(TensorShape(21U, 13U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)), // Invalid dimensions
85 TensorInfo(TensorShape(16U, 32U), 1, DataType::QASYMM8, QuantizationInfo(1.f/255, 10)),
86 }),
87 framework::dataset::make("InputBInfo",{ TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
88 TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
89 TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
90 TensorInfo(TensorShape(33U, 21U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
91 TensorInfo(TensorShape(64U, 16U), 1, DataType::QASYMM8, QuantizationInfo(1.f/256, 10)),
92 })),
93 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(33U, 13U), 1, DataType::S32),
94 TensorInfo(TensorShape(33U, 13U), 1, DataType::S32),
95 TensorInfo(TensorShape(33U, 13U), 1, DataType::S32),
96 TensorInfo(TensorShape(8U, 11U), 1, DataType::S32),
97 TensorInfo(TensorShape(64U, 32U), 1, DataType::S32),
98 })),
morgolock4adaddb2020-09-29 14:24:32 +010099 framework::dataset::make("Expected", { true, false, false, false, true })),
Georgios Pinitasa3b1b462017-11-16 19:24:39 +0000100 a_info, b_info, output_info, expected)
101{
102 // Lock tensors
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000103 Status status = NEGEMMLowpMatrixMultiplyCore::validate(&a_info.clone()->set_is_resizable(false),
104 &b_info.clone()->set_is_resizable(false),
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100105 nullptr,
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000106 &output_info.clone()->set_is_resizable(false));
107 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
Georgios Pinitasa3b1b462017-11-16 19:24:39 +0000108}
109// clang-format on
110// *INDENT-ON*
111
Gian Marcoe75a02b2017-11-08 12:24:09 +0000112FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::ALL, datasets::SmallGEMMLowpDataset())
Pablo Tello299025a2017-09-29 11:30:12 +0100113{
114 // Validate output
Gian Marcofa4cacd2017-10-18 17:05:02 +0100115 validate(Accessor(_target), _reference);
116}
117
Gian Marcoe75a02b2017-11-08 12:24:09 +0000118FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpDataset())
Gian Marcofa4cacd2017-10-18 17:05:02 +0100119{
120 // Validate output
121 validate(Accessor(_target), _reference);
Pablo Tello299025a2017-09-29 11:30:12 +0100122}
Pablo Tello299025a2017-09-29 11:30:12 +0100123
George Wort2d7e6832019-02-22 16:37:41 +0000124using NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture = GEMMLowpMatrixMultiplyCoreFusedOffsetOutputValidationFixture<Tensor, Accessor, NEGEMMLowpMatrixMultiplyCore>;
125TEST_SUITE(FusedOffsetOutput)
Manuel Bottini959c26d2019-12-02 16:22:35 +0000126FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture, framework::DatasetMode::ALL, combine(datasets::SmallGEMMLowpFusedOffsetOutputUint8Dataset(),
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000127 framework::dataset::make("DataType", { DataType::QASYMM8 })))
George Wort2d7e6832019-02-22 16:37:41 +0000128{
129 // Validate output
130 validate(Accessor(_target), _reference);
131}
132
Manuel Bottini959c26d2019-12-02 16:22:35 +0000133FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpMatrixMultiplyCoreFusedOffsetOutputFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMLowpFusedOffsetOutputUint8Dataset(),
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000134 framework::dataset::make("DataType", { DataType::QASYMM8 })))
George Wort2d7e6832019-02-22 16:37:41 +0000135{
136 // Validate output
137 validate(Accessor(_target), _reference);
138}
139TEST_SUITE_END() // FusedOffsetOutput
Gian Marcoe75a02b2017-11-08 12:24:09 +0000140TEST_SUITE_END() // MatrixMultiplyCore
Gian Marcoe75a02b2017-11-08 12:24:09 +0000141TEST_SUITE_END() // GEMMLowp
Manuel Bottiniae58bdf2021-06-17 17:18:45 +0100142TEST_SUITE_END() // NEON
Pablo Tello299025a2017-09-29 11:30:12 +0100143} // namespace validation
144} // namespace test
145} // namespace arm_compute