Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 Arm Limited. |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 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/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 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 45 | using namespace arm_compute::misc::shape_calculator; |
| 46 | |
| 47 | // Initialize the output tensor with zero and fill the border with zero |
| 48 | using CLGEMMReshapeLHSMatrix = CLSynthetizeFunctionInitOutputWithZeroAndWithZeroConstantBorder<CLGEMMReshapeLHSMatrixKernel, 16>; |
| 49 | |
| 50 | template <typename T> |
| 51 | using CLGEMMReshapeLHSMatrixFixture = GEMMReshapeLHSMatrixValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeLHSMatrix, T, false>; |
| 52 | |
| 53 | // Fixture to use when the input has to be reinterpreted as 3D |
| 54 | template <typename T> |
| 55 | using CLGEMMReshapeLHSMatrix3DFixture = GEMMReshapeLHSMatrixValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeLHSMatrix, T, true>; |
| 56 | |
Gian Marco Iodice | 08ddd7b | 2018-12-19 10:01:18 +0000 | [diff] [blame] | 57 | // *INDENT-OFF* |
| 58 | // clang-format off |
| 59 | /** Data types */ |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 60 | |
Gian Marco Iodice | 08ddd7b | 2018-12-19 10:01:18 +0000 | [diff] [blame] | 61 | namespace |
| 62 | { |
Gian Marco Iodice | 08ddd7b | 2018-12-19 10:01:18 +0000 | [diff] [blame] | 63 | /** Batch size values to test */ |
| 64 | const auto b_values = framework::dataset::make("batchsize", 1, 3); |
| 65 | |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 66 | /** M0 values to test */ |
| 67 | const auto m0_values_s32 = framework::dataset::make("M0", { 2, 3 }); |
| 68 | const auto m0_values_s16 = framework::dataset::make("M0", { 4, 5 }); |
| 69 | const auto m0_values_s8 = framework::dataset::make("M0", { 6, 7, 8 }); |
Gian Marco Iodice | 08ddd7b | 2018-12-19 10:01:18 +0000 | [diff] [blame] | 70 | |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 71 | /** K0 values to test */ |
| 72 | const auto k0_values_s32 = framework::dataset::make("K0", { 2, 3 }); |
| 73 | const auto k0_values_s16 = framework::dataset::make("K0", { 4, 8 }); |
| 74 | const auto k0_values_s8 = framework::dataset::make("K0", { 16 }); |
Gian Marco Iodice | 08ddd7b | 2018-12-19 10:01:18 +0000 | [diff] [blame] | 75 | |
| 76 | /** V0 values to test */ |
| 77 | const auto v0_values = framework::dataset::make("V0", 1, 4); |
| 78 | |
| 79 | /** Interleave values to test */ |
| 80 | const auto i_values = framework::dataset::make("interleave", { true, false }); |
| 81 | |
| 82 | /** Transpose values to test */ |
| 83 | const auto t_values = framework::dataset::make("transpose", { true, false }); |
Gian Marco Iodice | 73cdaac | 2020-08-10 21:44:14 +0100 | [diff] [blame] | 84 | |
| 85 | /** Zero padding test */ |
| 86 | bool 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 Iodice | 08ddd7b | 2018-12-19 10:01:18 +0000 | [diff] [blame] | 117 | } // namespace |
| 118 | |
| 119 | TEST_SUITE(CL) |
| 120 | TEST_SUITE(GEMMReshapeLHSMatrix) |
Gian Marco Iodice | 73cdaac | 2020-08-10 21:44:14 +0100 | [diff] [blame] | 121 | |
| 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 | */ |
| 132 | DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
| 133 | framework::dataset::make("M", { 1, 23, 63, 101 }), |
| 134 | framework::dataset::make("K", { 1, 47, 29, 27 })), |
| 135 | framework::dataset::make("B", { 1, 1, 4, 7 })), |
| 136 | framework::dataset::make("M0", { 4, 2, 4, 8 })), |
| 137 | framework::dataset::make("K0", { 2, 2, 4, 8 })), |
| 138 | framework::dataset::make("input_as_3d", { false, false, false, true })), |
| 139 | m_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 Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 147 | FIXTURE_DATA_TEST_CASE(S32, CLGEMMReshapeLHSMatrixFixture<int>, framework::DatasetMode::ALL, |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 148 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 149 | b_values), |
| 150 | framework::dataset::make("DataType", DataType::S32)), |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 151 | m0_values_s32), |
| 152 | k0_values_s32), |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 153 | v0_values), |
| 154 | i_values), |
| 155 | t_values)) |
| 156 | { |
| 157 | // Validate output |
| 158 | validate(CLAccessor(_target), _reference); |
| 159 | } |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 160 | FIXTURE_DATA_TEST_CASE(S16, CLGEMMReshapeLHSMatrixFixture<short>, framework::DatasetMode::ALL, |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 161 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 162 | b_values), |
| 163 | framework::dataset::make("DataType", DataType::S16)), |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 164 | m0_values_s16), |
| 165 | k0_values_s16), |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 166 | v0_values), |
| 167 | i_values), |
| 168 | t_values)) |
| 169 | { |
| 170 | // Validate output |
| 171 | validate(CLAccessor(_target), _reference); |
| 172 | } |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 173 | FIXTURE_DATA_TEST_CASE(S8, CLGEMMReshapeLHSMatrixFixture<char>, framework::DatasetMode::ALL, |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 174 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 175 | b_values), |
| 176 | framework::dataset::make("DataType", DataType::S8)), |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 177 | m0_values_s8), |
| 178 | k0_values_s8), |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 179 | v0_values), |
| 180 | i_values), |
| 181 | t_values)) |
| 182 | { |
| 183 | // Validate output |
| 184 | validate(CLAccessor(_target), _reference); |
| 185 | } |
| 186 | |
Gian Marco Iodice | 08ddd7b | 2018-12-19 10:01:18 +0000 | [diff] [blame] | 187 | TEST_SUITE(ReinterpretInputAs3D) |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 188 | FIXTURE_DATA_TEST_CASE(S32, CLGEMMReshapeLHSMatrix3DFixture<int>, framework::DatasetMode::ALL, |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 189 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(), |
| 190 | b_values), |
| 191 | framework::dataset::make("DataType", DataType::S32)), |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 192 | m0_values_s32), |
| 193 | k0_values_s32), |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 194 | v0_values), |
| 195 | i_values), |
| 196 | t_values)) |
| 197 | { |
| 198 | // Validate output |
| 199 | validate(CLAccessor(_target), _reference); |
| 200 | } |
| 201 | |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 202 | FIXTURE_DATA_TEST_CASE(S16, CLGEMMReshapeLHSMatrix3DFixture<short>, framework::DatasetMode::ALL, |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 203 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(), |
| 204 | b_values), |
| 205 | framework::dataset::make("DataType", DataType::S16)), |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 206 | m0_values_s16), |
| 207 | k0_values_s16), |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 208 | v0_values), |
| 209 | i_values), |
| 210 | t_values)) |
| 211 | { |
| 212 | // Validate output |
| 213 | validate(CLAccessor(_target), _reference); |
| 214 | } |
| 215 | |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 216 | FIXTURE_DATA_TEST_CASE(S8, CLGEMMReshapeLHSMatrix3DFixture<char>, framework::DatasetMode::ALL, |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 217 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape3DShapes(), |
| 218 | b_values), |
| 219 | framework::dataset::make("DataType", DataType::S8)), |
Michalis Spyrou | 8bb8de3 | 2020-04-29 13:22:15 +0100 | [diff] [blame] | 220 | m0_values_s8), |
| 221 | k0_values_s8), |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 222 | v0_values), |
| 223 | i_values), |
| 224 | t_values)) |
| 225 | { |
| 226 | // Validate output |
| 227 | validate(CLAccessor(_target), _reference); |
| 228 | } |
Gian Marco Iodice | 08ddd7b | 2018-12-19 10:01:18 +0000 | [diff] [blame] | 229 | TEST_SUITE_END() // ReinterpretInputAs3D |
Gian Marco Iodice | 5ba5e09 | 2018-12-06 17:13:09 +0000 | [diff] [blame] | 230 | TEST_SUITE_END() // GEMMReshapeLHSMatrix |
| 231 | TEST_SUITE_END() // CL |
| 232 | } // namespace validation |
| 233 | } // namespace test |
Gian Marco Iodice | 73cdaac | 2020-08-10 21:44:14 +0100 | [diff] [blame] | 234 | } // namespace arm_compute |