Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18: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 | 3b0a265 | 2018-12-07 11:18: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/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 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
| 45 | namespace |
| 46 | { |
| 47 | // *INDENT-OFF* |
| 48 | // clang-format off |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 49 | /** Batch size values to test */ |
| 50 | const auto b_values = framework::dataset::make("batchsize", 1, 3); |
| 51 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 52 | /** N0 values to test */ |
| 53 | const auto n0_values_nt_s32 = framework::dataset::make("N0", { 1, 2, 3 }); |
| 54 | const auto n0_values_nt_s16 = framework::dataset::make("N0", { 4, 8 }); |
| 55 | const auto n0_values_nt_s8 = framework::dataset::make("N0", { 16 }); |
| 56 | const auto n0_values_t_s32 = framework::dataset::make("N0", { 4, 8 }); |
| 57 | const auto n0_values_t_s16 = framework::dataset::make("N0", { 16 }); |
| 58 | const auto n0_values_t_s8 = framework::dataset::make("N0", { 2, 3 }); |
Gian Marco Iodice | 8912434 | 2018-12-19 14:17:22 +0000 | [diff] [blame] | 59 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 60 | /** K0 values to test */ |
| 61 | const auto k0_values_nt_s32 = framework::dataset::make("K0", { 1, 2 }); |
| 62 | const auto k0_values_nt_s16 = framework::dataset::make("K0", { 16 }); |
| 63 | const auto k0_values_nt_s8 = framework::dataset::make("K0", { 3,4 }); |
| 64 | const auto k0_values_t_s32 = framework::dataset::make("K0", { 2, 3 }); |
| 65 | const auto k0_values_t_s16 = framework::dataset::make("K0", { 4, 8 }); |
| 66 | const auto k0_values_t_s8 = framework::dataset::make("K0", { 16 }); |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 67 | |
| 68 | /** H0 values to test */ |
| 69 | const auto h0_values = framework::dataset::make("H0", 1, 4); |
| 70 | |
| 71 | /** Interleave values to test */ |
| 72 | const auto i_values = framework::dataset::make("interleave", { true, false }); |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 73 | } // namespace |
| 74 | |
| 75 | using namespace arm_compute::misc::shape_calculator; |
| 76 | |
| 77 | // Initialize the output tensor with zero and fill the border with zero |
| 78 | using CLGEMMReshapeRHSMatrix = CLSynthetizeFunctionInitOutputWithZeroAndWithZeroConstantBorder<CLGEMMReshapeRHSMatrixKernel, 16>; |
| 79 | |
| 80 | template <typename T> |
| 81 | using CLGEMMReshapeRHSMatrixFixture = GEMMReshapeRHSMatrixValidationFixture<CLTensor, CLAccessor, CLGEMMReshapeRHSMatrix, T>; |
| 82 | |
| 83 | TEST_SUITE(CL) |
| 84 | TEST_SUITE(GEMMReshapeRHSMatrix) |
| 85 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 86 | // *INDENT-OFF* |
| 87 | // clang-format off |
| 88 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip( |
| 89 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), |
| 90 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Mismatching data types |
| 91 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Wrong n0 value |
| 92 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Wrong k0 value |
| 93 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // Wrong h0 value |
| 94 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // n0 > 16 |
| 95 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // k0 > 16 |
| 96 | TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32), // k0 == 1 && transpose |
| 97 | }), |
| 98 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(64U, 2U, 2U), 1, DataType::F32), |
| 99 | TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F16), |
| 100 | TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32), |
| 101 | TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32), |
| 102 | TensorInfo(TensorShape(32U, 2U, 2U), 1, DataType::F32), |
| 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 | })), |
| 107 | framework::dataset::make("N0",{ 4, 0, 4, 4, 4, 17, 4, 4 })), |
| 108 | framework::dataset::make("K0",{ 4, 4, 0, 4, 4, 4, 17, 1 })), |
| 109 | framework::dataset::make("H0",{ 4, 4, 4, 0, 4, 4, 4, 4 })), |
| 110 | framework::dataset::make("Expected", { false, false, false, false, false, false, false})), |
| 111 | input_info, output_info, n0, k0, h0, expected) |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 112 | { |
| 113 | GEMMRHSMatrixInfo rhs_info; |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 114 | rhs_info.n0 = n0; |
| 115 | rhs_info.k0 = k0; |
| 116 | rhs_info.h0 = h0; |
| 117 | rhs_info.transpose = true; |
| 118 | rhs_info.interleave = true; |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 119 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 120 | 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)); |
| 121 | ARM_COMPUTE_EXPECT(has_error == expected, framework::LogLevel::ERRORS); |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 122 | } |
Gian Marco Iodice | a98dee2 | 2020-06-02 12:12:35 +0100 | [diff] [blame] | 123 | |
SiCong Li | 5bdde85 | 2020-08-26 13:55:15 +0100 | [diff] [blame^] | 124 | DATA_TEST_CASE(ValidatePadding, framework::DatasetMode::ALL, combine(combine(combine(combine( |
Gian Marco Iodice | a98dee2 | 2020-06-02 12:12:35 +0100 | [diff] [blame] | 125 | framework::dataset::make("InputShape", { TensorShape(32U, 16U, 1U), |
| 126 | TensorShape(32U, 16U, 2U) |
| 127 | }), |
| 128 | framework::dataset::make("N0",{ 4 })), |
Gian Marco Iodice | e3a849a | 2020-06-10 17:59:30 +0100 | [diff] [blame] | 129 | framework::dataset::make("K0",{ 4, 8, 16 })), |
Gian Marco Iodice | a98dee2 | 2020-06-02 12:12:35 +0100 | [diff] [blame] | 130 | framework::dataset::make("H0",{ 1, 2, 4 })), |
SiCong Li | 5bdde85 | 2020-08-26 13:55:15 +0100 | [diff] [blame^] | 131 | framework::dataset::make("DataType",{ DataType::F32, DataType::F16 })), |
| 132 | input_shape, n0, k0, h0, data_type) |
Gian Marco Iodice | a98dee2 | 2020-06-02 12:12:35 +0100 | [diff] [blame] | 133 | { |
| 134 | CLTensor input; |
| 135 | CLTensor output; |
| 136 | |
SiCong Li | 5bdde85 | 2020-08-26 13:55:15 +0100 | [diff] [blame^] | 137 | input.info()->init(input_shape, 1, data_type); |
Gian Marco Iodice | a98dee2 | 2020-06-02 12:12:35 +0100 | [diff] [blame] | 138 | |
| 139 | unsigned int padding = 0; |
| 140 | |
| 141 | GEMMRHSMatrixInfo rhs_info; |
| 142 | rhs_info.n0 = n0; |
| 143 | rhs_info.k0 = k0; |
| 144 | rhs_info.h0 = h0; |
| 145 | rhs_info.transpose = true; |
| 146 | rhs_info.interleave = true; |
| 147 | rhs_info.export_to_cl_image = image2d_from_buffer_supported(CLKernelLibrary::get().get_device()) && (get_cl_image_pitch_alignment(CLKernelLibrary::get().get_device()) != 0); |
| 148 | |
| 149 | if(rhs_info.export_to_cl_image) |
| 150 | { |
| 151 | TensorShape output_shape = compute_rhs_reshaped_shape(*input.info(), rhs_info); |
| 152 | constexpr unsigned int num_floats_per_pixel = 4; |
| 153 | |
| 154 | const unsigned int pixel_aligment = get_cl_image_pitch_alignment(CLKernelLibrary::get().get_device()); |
| 155 | const unsigned int row_pitch_alignment = pixel_aligment * num_floats_per_pixel; |
| 156 | const unsigned int round_up_width = ((output_shape[0] + row_pitch_alignment - 1) / row_pitch_alignment) * row_pitch_alignment; |
| 157 | |
| 158 | padding = round_up_width - output_shape[0]; |
| 159 | } |
| 160 | |
| 161 | CLGEMMReshapeRHSMatrixKernel kernel; |
| 162 | |
| 163 | kernel.configure(&input, &output, rhs_info); |
| 164 | |
| 165 | ARM_COMPUTE_EXPECT((output.info()->padding().right == padding), framework::LogLevel::ERRORS); |
| 166 | } |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 167 | // clang-format on |
| 168 | // *INDENT-ON* |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 169 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 170 | // Run S32 tests only for transpose = false |
| 171 | FIXTURE_DATA_TEST_CASE(S32_NT, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::ALL, |
| 172 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 173 | b_values), |
| 174 | framework::dataset::make("DataType", DataType::S32)), |
| 175 | n0_values_nt_s32), |
| 176 | k0_values_nt_s32), |
| 177 | h0_values), |
| 178 | i_values), |
| 179 | framework::dataset::make("transpose", false))) |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 180 | { |
| 181 | // Validate output |
| 182 | validate(CLAccessor(_target), _reference); |
| 183 | } |
| 184 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 185 | // Run S32 tests only for transpose = true |
| 186 | FIXTURE_DATA_TEST_CASE(S32_T, CLGEMMReshapeRHSMatrixFixture<int>, framework::DatasetMode::ALL, |
| 187 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 188 | b_values), |
| 189 | framework::dataset::make("DataType", DataType::S32)), |
| 190 | n0_values_t_s32), |
| 191 | k0_values_t_s32), |
| 192 | h0_values), |
| 193 | i_values), |
| 194 | framework::dataset::make("transpose", true))) |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 195 | { |
| 196 | // Validate output |
| 197 | validate(CLAccessor(_target), _reference); |
| 198 | } |
| 199 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 200 | // Run S16 tests only for transpose = false |
| 201 | FIXTURE_DATA_TEST_CASE(S16_NT, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::ALL, |
| 202 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 203 | b_values), |
| 204 | framework::dataset::make("DataType", DataType::S16)), |
| 205 | n0_values_nt_s16), |
| 206 | k0_values_nt_s16), |
| 207 | h0_values), |
| 208 | i_values), |
| 209 | framework::dataset::make("transpose", false))) |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 210 | { |
| 211 | // Validate output |
| 212 | validate(CLAccessor(_target), _reference); |
| 213 | } |
| 214 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 215 | // Run S16 tests only for transpose = true |
| 216 | FIXTURE_DATA_TEST_CASE(S16_T, CLGEMMReshapeRHSMatrixFixture<short>, framework::DatasetMode::ALL, |
| 217 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 218 | b_values), |
| 219 | framework::dataset::make("DataType", DataType::S16)), |
| 220 | n0_values_t_s16), |
| 221 | k0_values_t_s16), |
| 222 | h0_values), |
| 223 | i_values), |
| 224 | framework::dataset::make("transpose", true))) |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 225 | { |
| 226 | // Validate output |
| 227 | validate(CLAccessor(_target), _reference); |
| 228 | } |
| 229 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 230 | // Run S8 tests only for transpose = false |
| 231 | FIXTURE_DATA_TEST_CASE(S8_NT, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::ALL, |
| 232 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 233 | b_values), |
| 234 | framework::dataset::make("DataType", DataType::S8)), |
| 235 | n0_values_nt_s8), |
| 236 | k0_values_nt_s8), |
| 237 | h0_values), |
| 238 | i_values), |
| 239 | framework::dataset::make("transpose", false))) |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 240 | { |
| 241 | // Validate output |
| 242 | validate(CLAccessor(_target), _reference); |
| 243 | } |
| 244 | |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 245 | // Run S8 tests only for transpose = true |
| 246 | FIXTURE_DATA_TEST_CASE(S8_T, CLGEMMReshapeRHSMatrixFixture<char>, framework::DatasetMode::ALL, |
| 247 | combine(combine(combine(combine(combine(combine(combine(datasets::SmallGEMMReshape2DShapes(), |
| 248 | b_values), |
| 249 | framework::dataset::make("DataType", DataType::S8)), |
| 250 | n0_values_t_s8), |
| 251 | k0_values_t_s8), |
| 252 | h0_values), |
| 253 | i_values), |
| 254 | framework::dataset::make("transpose", true))) |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 255 | { |
| 256 | // Validate output |
| 257 | validate(CLAccessor(_target), _reference); |
| 258 | } |
| 259 | |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 260 | TEST_SUITE_END() // GEMMReshapeRHSMatrix |
| 261 | TEST_SUITE_END() // CL |
| 262 | } // namespace validation |
| 263 | } // namespace test |
Michalis Spyrou | 5c2df4e | 2020-04-27 18:10:58 +0100 | [diff] [blame] | 264 | } // namespace arm_compute |