blob: d9439f63f1e5aad5f0a77f6b2501c77aa4fdcfad [file] [log] [blame]
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +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/CL/kernels/CLGEMMReshapeLHSMatrixKernel.h"
25#include "arm_compute/core/Types.h"
26#include "arm_compute/core/utils/misc/ShapeCalculator.h"
27#include "arm_compute/runtime/CL/CLTensor.h"
28#include "arm_compute/runtime/CL/CLTensorAllocator.h"
29#include "tests/CL/CLAccessor.h"
30#include "tests/CL/Helper.h"
31#include "tests/PaddingCalculator.h"
32#include "tests/datasets/ShapeDatasets.h"
33#include "tests/framework/Asserts.h"
34#include "tests/framework/Macros.h"
35#include "tests/framework/datasets/Datasets.h"
36#include "tests/validation/Validation.h"
37#include "tests/validation/fixtures/GEMMReshapeLHSMatrixFixture.h"
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +000045using namespace arm_compute::misc::shape_calculator;
46
47// Initialize the output tensor with zero and fill the border with zero
48using CLGEMMReshapeLHSMatrix = CLSynthetizeFunctionInitOutputWithZeroAndWithZeroConstantBorder<CLGEMMReshapeLHSMatrixKernel, 16>;
49
50template <typename T>
51using CLGEMMReshapeLHSMatrixFixture = GEMMReshapeLHSMatrixValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeLHSMatrix, T, false>;
52
53// Fixture to use when the input has to be reinterpreted as 3D
54template <typename T>
55using CLGEMMReshapeLHSMatrix3DFixture = GEMMReshapeLHSMatrixValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeLHSMatrix, T, true>;
56
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +000057// *INDENT-OFF*
58// clang-format off
59/** Data types */
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +000060
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +000061namespace
62{
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +000063/** Batch size values to test */
64const auto b_values = framework::dataset::make("batchsize", 1, 3);
65
Michalis Spyrou8bb8de32020-04-29 13:22:15 +010066/** M0 values to test */
67const auto m0_values_s32 = framework::dataset::make("M0", { 2, 3 });
68const auto m0_values_s16 = framework::dataset::make("M0", { 4, 5 });
69const auto m0_values_s8 = framework::dataset::make("M0", { 6, 7, 8 });
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +000070
Michalis Spyrou8bb8de32020-04-29 13:22:15 +010071/** K0 values to test */
72const auto k0_values_s32 = framework::dataset::make("K0", { 2, 3 });
73const auto k0_values_s16 = framework::dataset::make("K0", { 4, 8 });
74const auto k0_values_s8 = framework::dataset::make("K0", { 16 });
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +000075
76/** V0 values to test */
77const auto v0_values = framework::dataset::make("V0", 1, 4);
78
79/** Interleave values to test */
80const auto i_values = framework::dataset::make("interleave", { true, false });
81
82/** Transpose values to test */
83const auto t_values = framework::dataset::make("transpose", { true, false });
Gian Marco Iodice73cdaac2020-08-10 21:44:14 +010084
85/** Zero padding test */
86bool validate_zero_padding(unsigned int m_value, unsigned int k_value, unsigned int b_value, unsigned int m0_value, unsigned int k0_value, unsigned int v0_value,
87 bool i_value_lhs, bool t_value_lhs, bool input_as_3d, DataType dt)
88{
89 const unsigned int M = m_value;
90 const unsigned int K = k_value;
91 const unsigned int B = b_value;
92
93 GEMMLHSMatrixInfo lhs_info;
94 lhs_info.m0 = m0_value;
95 lhs_info.k0 = k0_value;
96 lhs_info.v0 = v0_value;
97 lhs_info.interleave = i_value_lhs;
98 lhs_info.transpose = t_value_lhs;
99
100 const TensorShape lhs_shape(K, M, B);
101 const TensorShape lhs_shape_reshaped = compute_lhs_reshaped_shape(TensorInfo(lhs_shape, 1, dt), lhs_info, input_as_3d);
102
103 // Create tensors
104 CLTensor lhs = create_tensor<CLTensor>(lhs_shape, dt);
105 CLTensor dst = create_tensor<CLTensor>(lhs_shape_reshaped, dt);
106
107 ARM_COMPUTE_EXPECT(lhs.info()->is_resizable(), framework::LogLevel::ERRORS);
108 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
109
110 // Validate zero-padding
111 CLGEMMReshapeLHSMatrixKernel lhs_reshape;
112
113 lhs_reshape.configure(&lhs, &dst, lhs_info, input_as_3d);
114
115 return lhs.info()->padding().empty();
116}
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000117} // namespace
118
119TEST_SUITE(CL)
120TEST_SUITE(GEMMReshapeLHSMatrix)
Gian Marco Iodice73cdaac2020-08-10 21:44:14 +0100121
122/** Validate zero padding tests for the LHS input tensor
123 *
124 * A series of validation tests to test the zero padding requirement
125 *
126 * Checks performed in order:
127 * - Case where M and K are smaller than M0 and K0
128 * - Generic test case with batch size = 1
129 * - Generic test case with batch size = 4
130 * - Generic test case with input_as_3d_value = true
131 */
132DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
133framework::dataset::make("M", { 1, 23, 63, 101 }),
134framework::dataset::make("K", { 1, 47, 29, 27 })),
135framework::dataset::make("B", { 1, 1, 4, 7 })),
136framework::dataset::make("M0", { 4, 2, 4, 8 })),
137framework::dataset::make("K0", { 2, 2, 4, 8 })),
138framework::dataset::make("input_as_3d", { false, false, false, true })),
139m_value, k_value, b_value, m0_value, k0_value, input_as_3d_value)
140{
141 constexpr DataType dt = DataType::F32;
142
143 bool status = validate_zero_padding(m_value, k_value, b_value, m0_value, k0_value, 2, false, false, input_as_3d_value, dt);
144 ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS);
145}
146
Michalis Spyrou8bb8de32020-04-29 13:22:15 +0100147FIXTURE_DATA_TEST_CASE(S32, CLGEMMReshapeLHSMatrixFixture<int>, framework::DatasetMode::ALL,
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000148 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
149 b_values),
150 framework::dataset::make("DataType", DataType::S32)),
Michalis Spyrou8bb8de32020-04-29 13:22:15 +0100151 m0_values_s32),
152 k0_values_s32),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000153 v0_values),
154 i_values),
155 t_values))
156{
157 // Validate output
158 validate(CLAccessor(_target), _reference);
159}
Michalis Spyrou8bb8de32020-04-29 13:22:15 +0100160FIXTURE_DATA_TEST_CASE(S16, CLGEMMReshapeLHSMatrixFixture<short>, framework::DatasetMode::ALL,
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000161 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
162 b_values),
163 framework::dataset::make("DataType", DataType::S16)),
Michalis Spyrou8bb8de32020-04-29 13:22:15 +0100164 m0_values_s16),
165 k0_values_s16),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000166 v0_values),
167 i_values),
168 t_values))
169{
170 // Validate output
171 validate(CLAccessor(_target), _reference);
172}
Michalis Spyrou8bb8de32020-04-29 13:22:15 +0100173FIXTURE_DATA_TEST_CASE(S8, CLGEMMReshapeLHSMatrixFixture<char>, framework::DatasetMode::ALL,
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000174 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
175 b_values),
176 framework::dataset::make("DataType", DataType::S8)),
Michalis Spyrou8bb8de32020-04-29 13:22:15 +0100177 m0_values_s8),
178 k0_values_s8),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000179 v0_values),
180 i_values),
181 t_values))
182{
183 // Validate output
184 validate(CLAccessor(_target), _reference);
185}
186
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000187TEST_SUITE(ReinterpretInputAs3D)
Michalis Spyrou8bb8de32020-04-29 13:22:15 +0100188FIXTURE_DATA_TEST_CASE(S32, CLGEMMReshapeLHSMatrix3DFixture<int>, framework::DatasetMode::ALL,
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000189 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(),
190 b_values),
191 framework::dataset::make("DataType", DataType::S32)),
Michalis Spyrou8bb8de32020-04-29 13:22:15 +0100192 m0_values_s32),
193 k0_values_s32),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000194 v0_values),
195 i_values),
196 t_values))
197{
198 // Validate output
199 validate(CLAccessor(_target), _reference);
200}
201
Michalis Spyrou8bb8de32020-04-29 13:22:15 +0100202FIXTURE_DATA_TEST_CASE(S16, CLGEMMReshapeLHSMatrix3DFixture<short>, framework::DatasetMode::ALL,
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000203 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(),
204 b_values),
205 framework::dataset::make("DataType", DataType::S16)),
Michalis Spyrou8bb8de32020-04-29 13:22:15 +0100206 m0_values_s16),
207 k0_values_s16),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000208 v0_values),
209 i_values),
210 t_values))
211{
212 // Validate output
213 validate(CLAccessor(_target), _reference);
214}
215
Michalis Spyrou8bb8de32020-04-29 13:22:15 +0100216FIXTURE_DATA_TEST_CASE(S8, CLGEMMReshapeLHSMatrix3DFixture<char>, framework::DatasetMode::ALL,
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000217 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(),
218 b_values),
219 framework::dataset::make("DataType", DataType::S8)),
Michalis Spyrou8bb8de32020-04-29 13:22:15 +0100220 m0_values_s8),
221 k0_values_s8),
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000222 v0_values),
223 i_values),
224 t_values))
225{
226 // Validate output
227 validate(CLAccessor(_target), _reference);
228}
Gian Marco Iodice08ddd7b2018-12-19 10:01:18 +0000229TEST_SUITE_END() // ReinterpretInputAs3D
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +0000230TEST_SUITE_END() // GEMMReshapeLHSMatrix
231TEST_SUITE_END() // CL
232} // namespace validation
233} // namespace test
Gian Marco Iodice73cdaac2020-08-10 21:44:14 +0100234} // namespace arm_compute