blob: 55688cf1605af5e78eea9712ae7bb3e1eb61d3b5 [file] [log] [blame]
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +00001/*
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +01002 * Copyright (c) 2018-2020 ARM Limited.
Gian Marco Iodice3b0a2652018-12-07 11:18: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/CLGEMMReshapeRHSMatrixKernel.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/GEMMReshapeRHSMatrixFixture.h"
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45namespace
46{
47// *INDENT-OFF*
48// clang-format off
49/** Data types */
50const auto data_types = framework::dataset::make("DataType", { DataType::QASYMM8, DataType::F16, DataType::F32 });
51
52/** Batch size values to test */
53const auto b_values = framework::dataset::make("batchsize", 1, 3);
54
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +010055/** N0 values to test */
56const auto n0_values_nt_s32 = framework::dataset::make("N0", { 1, 2, 3 });
57const auto n0_values_nt_s16 = framework::dataset::make("N0", { 4, 8 });
58const auto n0_values_nt_s8 = framework::dataset::make("N0", { 16 });
59const auto n0_values_t_s32 = framework::dataset::make("N0", { 4, 8 });
60const auto n0_values_t_s16 = framework::dataset::make("N0", { 16 });
61const auto n0_values_t_s8 = framework::dataset::make("N0", { 2, 3 });
Gian Marco Iodice89124342018-12-19 14:17:22 +000062
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +010063/** K0 values to test */
64const auto k0_values_nt_s32 = framework::dataset::make("K0", { 1, 2 });
65const auto k0_values_nt_s16 = framework::dataset::make("K0", { 16 });
66const auto k0_values_nt_s8 = framework::dataset::make("K0", { 3,4 });
67const auto k0_values_t_s32 = framework::dataset::make("K0", { 2, 3 });
68const auto k0_values_t_s16 = framework::dataset::make("K0", { 4, 8 });
69const auto k0_values_t_s8 = framework::dataset::make("K0", { 16 });
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000070
71/** H0 values to test */
72const auto h0_values = framework::dataset::make("H0", 1, 4);
73
74/** Interleave values to test */
75const auto i_values = framework::dataset::make("interleave", { true, false });
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +000076} // namespace
77
78using namespace arm_compute::misc::shape_calculator;
79
80// Initialize the output tensor with zero and fill the border with zero
81using CLGEMMReshapeRHSMatrix = CLSynthetizeFunctionInitOutputWithZeroAndWithZeroConstantBorder<CLGEMMReshapeRHSMatrixKernel, 16>;
82
83template <typename T>
84using CLGEMMReshapeRHSMatrixFixture = GEMMReshapeRHSMatrixValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeRHSMatrix, T>;
85
86TEST_SUITE(CL)
87TEST_SUITE(GEMMReshapeRHSMatrix)
88
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +010089// *INDENT-OFF*
90// clang-format off
91DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
92 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32),
93 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Mismatching data types
94 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Wrong n0 value
95 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Wrong k0 value
96 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Wrong h0 value
97 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // n0 > 16
98 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // k0 > 16
99 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // k0 == 1 && transpose
100 }),
101 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(64U, 2U, 2U), 1, DataType::F32),
102 TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F16),
103 TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
104 TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
105 TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
106 TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
107 TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
108 TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32),
109 })),
110 framework::dataset::make("N0",{ 4, 0, 4, 4, 4, 17, 4, 4 })),
111 framework::dataset::make("K0",{ 4, 4, 0, 4, 4, 4, 17, 1 })),
112 framework::dataset::make("H0",{ 4, 4, 4, 0, 4, 4, 4, 4 })),
113 framework::dataset::make("Expected", { false, false, false, false, false, false, false})),
114 input_info, output_info, n0, k0, h0, expected)
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000115{
116 GEMMRHSMatrixInfo rhs_info;
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100117 rhs_info.n0 = n0;
118 rhs_info.k0 = k0;
119 rhs_info.h0 = h0;
120 rhs_info.transpose = true;
121 rhs_info.interleave = true;
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000122
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100123 bool has_error = bool(CLGEMMReshapeRHSMatrixKernel::validate(&input_info.clone()->set_is_resizable(false), (output_info.total_size() == 0) ? nullptr : &output_info.clone()->set_is_resizable(false), rhs_info));
124 ARM_COMPUTE_EXPECT(has_error == expected, framework::LogLevel::ERRORS);
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000125}
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100126// clang-format on
127// *INDENT-ON*
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000128
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100129// Run S32 tests only for transpose = false
130FIXTURE_DATA_TEST_CASE(S32_NT, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::ALL,
131 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
132 b_values),
133 framework::dataset::make("DataType", DataType::S32)),
134 n0_values_nt_s32),
135 k0_values_nt_s32),
136 h0_values),
137 i_values),
138 framework::dataset::make("transpose", false)))
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000139{
140 // Validate output
141 validate(CLAccessor(_target), _reference);
142}
143
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100144// Run S32 tests only for transpose = true
145FIXTURE_DATA_TEST_CASE(S32_T, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::ALL,
146 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
147 b_values),
148 framework::dataset::make("DataType", DataType::S32)),
149 n0_values_t_s32),
150 k0_values_t_s32),
151 h0_values),
152 i_values),
153 framework::dataset::make("transpose", true)))
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000154{
155 // Validate output
156 validate(CLAccessor(_target), _reference);
157}
158
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100159// Run S16 tests only for transpose = false
160FIXTURE_DATA_TEST_CASE(S16_NT, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::ALL,
161 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
162 b_values),
163 framework::dataset::make("DataType", DataType::S16)),
164 n0_values_nt_s16),
165 k0_values_nt_s16),
166 h0_values),
167 i_values),
168 framework::dataset::make("transpose", false)))
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000169{
170 // Validate output
171 validate(CLAccessor(_target), _reference);
172}
173
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100174// Run S16 tests only for transpose = true
175FIXTURE_DATA_TEST_CASE(S16_T, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::ALL,
176 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
177 b_values),
178 framework::dataset::make("DataType", DataType::S16)),
179 n0_values_t_s16),
180 k0_values_t_s16),
181 h0_values),
182 i_values),
183 framework::dataset::make("transpose", true)))
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000184{
185 // Validate output
186 validate(CLAccessor(_target), _reference);
187}
188
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100189// Run S8 tests only for transpose = false
190FIXTURE_DATA_TEST_CASE(S8_NT, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::ALL,
191 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
192 b_values),
193 framework::dataset::make("DataType", DataType::S8)),
194 n0_values_nt_s8),
195 k0_values_nt_s8),
196 h0_values),
197 i_values),
198 framework::dataset::make("transpose", false)))
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000199{
200 // Validate output
201 validate(CLAccessor(_target), _reference);
202}
203
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100204// Run S8 tests only for transpose = true
205FIXTURE_DATA_TEST_CASE(S8_T, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::ALL,
206 combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(),
207 b_values),
208 framework::dataset::make("DataType", DataType::S8)),
209 n0_values_t_s8),
210 k0_values_t_s8),
211 h0_values),
212 i_values),
213 framework::dataset::make("transpose", true)))
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000214{
215 // Validate output
216 validate(CLAccessor(_target), _reference);
217}
218
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +0000219TEST_SUITE_END() // GEMMReshapeRHSMatrix
220TEST_SUITE_END() // CL
221} // namespace validation
222} // namespace test
Michalis Spyrou5c2df4e2020-04-27 18:10:58 +0100223} // namespace arm_compute