Gian Marco Iodice | adc5395 | 2019-02-15 11:10:31 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2019 ARM Limited. |
| 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/CLGEMMMatrixMultiplyReshapedOnlyRHSKernel.h" |
| 25 | #include "arm_compute/core/CL/kernels/CLGEMMReshapeRHSMatrixKernel.h" |
| 26 | #include "arm_compute/core/Types.h" |
| 27 | #include "arm_compute/core/utils/misc/ShapeCalculator.h" |
| 28 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 29 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
| 30 | #include "tests/CL/CLAccessor.h" |
| 31 | #include "tests/CL/Helper.h" |
| 32 | #include "tests/PaddingCalculator.h" |
| 33 | #include "tests/datasets/ShapeDatasets.h" |
| 34 | #include "tests/framework/Asserts.h" |
| 35 | #include "tests/framework/Macros.h" |
| 36 | #include "tests/framework/datasets/Datasets.h" |
| 37 | #include "tests/validation/Validation.h" |
| 38 | #include "tests/validation/fixtures/GEMMFixture.h" |
| 39 | |
| 40 | namespace arm_compute |
| 41 | { |
| 42 | namespace test |
| 43 | { |
| 44 | namespace validation |
| 45 | { |
| 46 | using namespace arm_compute::misc::shape_calculator; |
| 47 | |
| 48 | // Create function for CLGEMMReshapeRHSMatrixKernel |
| 49 | using CLGEMMReshapeRHSMatrix = CLSynthetizeFunction<CLGEMMReshapeRHSMatrixKernel>; |
| 50 | |
| 51 | // Create function for CLGEMMMatrixMultiplyReshapedOnlyRHSKernel |
| 52 | using CLGEMMMatrixMultiplyReshapedOnlyRHS = CLSynthetizeFunction<CLGEMMMatrixMultiplyReshapedOnlyRHSKernel>; |
| 53 | |
| 54 | // Fixture for CLGEMMMatrixMultiplyReshapedOnlyRHS |
| 55 | template <typename T> |
| 56 | using CLGEMMMatrixMultiplyReshapedOnlyRHSFixture = GEMMMatrixMultiplyReshapedOnlyRHSValidationFixture<CLTensor, CLAccessor, T, CLGEMMReshapeRHSMatrix, CLGEMMMatrixMultiplyReshapedOnlyRHS>; |
| 57 | |
| 58 | // Fixture for CLGEMMMatrixMultiplyReshapedOnlyRHS3D |
| 59 | template <typename T> |
| 60 | using CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture = GEMMMatrixMultiplyReshapedOnlyRHS3DValidationFixture<CLTensor, CLAccessor, T, CLGEMMReshapeRHSMatrix, CLGEMMMatrixMultiplyReshapedOnlyRHS>; |
| 61 | |
| 62 | namespace |
| 63 | { |
| 64 | // *INDENT-OFF* |
| 65 | // clang-format off |
| 66 | RelativeTolerance<float> rel_tolerance_f32(0.001f); |
| 67 | constexpr float abs_tolerance_f32(0.0001f); |
| 68 | |
| 69 | RelativeTolerance<half> rel_tolerance_f16(half(0.2)); |
| 70 | constexpr float tolerance_num_f16 = 0.02f; |
| 71 | |
| 72 | /** Alpha values to test - Precommit */ |
| 73 | const auto a_values = framework::dataset::make("alpha", {1.0f, -0.75f} ); |
| 74 | |
| 75 | /** M values to test */ |
| 76 | const auto m_values = framework::dataset::make("M", 37); |
| 77 | |
| 78 | /** M_W values to test */ |
| 79 | const auto m_w_values = framework::dataset::make("M_W", 5); |
| 80 | |
| 81 | /** M_H values to test */ |
| 82 | const auto m_h_values = framework::dataset::make("M_H", 7); |
| 83 | |
| 84 | /** N values to test */ |
| 85 | const auto n_values = framework::dataset::make("N", 51); |
| 86 | |
| 87 | /** K values to test */ |
| 88 | const auto k_values = framework::dataset::make("K", 23); |
| 89 | |
| 90 | /** Batch size values to test */ |
| 91 | const auto b_values = framework::dataset::make("batch_size", 1, 3); |
| 92 | |
| 93 | /** M0 values to test - Precommit */ |
| 94 | const auto m0_values_precommit = framework::dataset::make("M0", {4, 6}); |
| 95 | |
| 96 | /** N0 values to test - Precommit */ |
| 97 | const auto n0_values_precommit = framework::dataset::make("N0", { 2, 4 }); |
| 98 | |
| 99 | /** K0 values to test - Precommit */ |
| 100 | const auto k0_values_precommit = framework::dataset::make("K0", { 4 }); |
| 101 | |
| 102 | /** H0 values to test - Precommit */ |
| 103 | const auto h0_values_precommit = framework::dataset::make("H0", 1, 3); |
| 104 | |
| 105 | /** M0 values to test - Nightly */ |
| 106 | const auto m0_values_nightly = framework::dataset::make("M0", 2, 8); |
| 107 | |
| 108 | /** N0 values to test - Nightly */ |
| 109 | const auto n0_values_nightly = framework::dataset::make("N0", { 2, 3, 4, 8 }); |
| 110 | |
| 111 | /** K0 values to test - Nightly */ |
| 112 | const auto k0_values_nightly = framework::dataset::make("K0", { 2, 3, 4, 8 }); |
| 113 | |
| 114 | /** H0 values to test - Nightly */ |
| 115 | const auto h0_values_nightly = framework::dataset::make("H0", 1, 4); |
| 116 | |
| 117 | /** Interleave values to test with RHS matrix */ |
| 118 | const auto i_values_rhs = framework::dataset::make("interleave_rhs", { true, false }); |
| 119 | |
| 120 | /** Transpose values to test with RHS matrix */ |
| 121 | const auto t_values_rhs = framework::dataset::make("transpose_rhs", { true }); |
| 122 | |
| 123 | /** Configuration test */ |
| 124 | void validate_configuration(unsigned int m_value, unsigned int n_value, unsigned int k_value, unsigned int b_value, unsigned int m0_value, unsigned int n0_value, unsigned int k0_value, unsigned int h0_value, bool i_value_rhs, DataType data_type) |
| 125 | { |
| 126 | const unsigned int M = m_value; |
| 127 | const unsigned int N = n_value; |
| 128 | const unsigned int K = k_value; |
| 129 | |
| 130 | GEMMLHSMatrixInfo lhs_info; |
| 131 | lhs_info.m0 = m0_value; |
| 132 | lhs_info.k0 = k0_value; |
| 133 | |
| 134 | GEMMRHSMatrixInfo rhs_info; |
| 135 | rhs_info.n0 = n0_value; |
| 136 | rhs_info.k0 = k0_value; |
| 137 | rhs_info.h0 = h0_value; |
| 138 | rhs_info.interleave = i_value_rhs; |
| 139 | rhs_info.transpose = true; |
| 140 | |
| 141 | GEMMReshapeInfo gemm_info(M, N, K); |
| 142 | |
| 143 | const TensorShape lhs_shape(K, M, b_value); |
| 144 | const TensorShape rhs_shape(N, K, b_value); |
| 145 | const TensorShape rhs_shape_reshaped = compute_rhs_reshaped_shape(TensorInfo(rhs_shape, 1, data_type), |
| 146 | rhs_info); |
| 147 | |
| 148 | const TensorShape dst_shape = compute_mm_shape(TensorInfo(lhs_shape, 1, data_type), |
| 149 | TensorInfo(rhs_shape_reshaped, 1, data_type), |
| 150 | gemm_info); |
| 151 | |
| 152 | // Create tensors |
| 153 | CLTensor lhs = create_tensor<CLTensor>(lhs_shape, data_type); |
| 154 | CLTensor rhs_reshaped = create_tensor<CLTensor>(rhs_shape_reshaped, data_type); |
| 155 | CLTensor dst = create_tensor<CLTensor>(dst_shape, data_type); |
| 156 | |
| 157 | ARM_COMPUTE_EXPECT(lhs.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 158 | ARM_COMPUTE_EXPECT(rhs_reshaped.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 159 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 160 | |
| 161 | // Create and configure function |
| 162 | CLGEMMMatrixMultiplyReshapedOnlyRHS gemm; |
| 163 | gemm.configure(&lhs, &rhs_reshaped, &dst, 1.0f, lhs_info, rhs_info, gemm_info); |
| 164 | } |
| 165 | } // namespace |
| 166 | |
| 167 | TEST_SUITE(CL) |
| 168 | TEST_SUITE(GEMMMatrixMultiplyReshapedOnlyRHS) |
| 169 | TEST_SUITE(Float) |
| 170 | TEST_SUITE(FP32) |
| 171 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine( |
| 172 | m_values, |
| 173 | n_values), |
| 174 | k_values), |
| 175 | framework::dataset::make("batch_size", 1)), |
| 176 | m0_values_precommit), |
| 177 | n0_values_precommit), |
| 178 | k0_values_precommit), |
| 179 | h0_values_precommit), |
| 180 | i_values_rhs), |
| 181 | m_value, n_value, k_value, b_value, m0_value, n0_value, k0_value, h0_value, i_value_rhs) |
| 182 | { |
| 183 | validate_configuration(m_value, n_value, k_value, b_value, m0_value, n0_value, k0_value, h0_value, i_value_rhs, DataType::F32); |
| 184 | } |
| 185 | |
| 186 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<float>, framework::DatasetMode::ALL, |
| 187 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 188 | m_values, |
| 189 | n_values), |
| 190 | k_values), |
| 191 | b_values), |
| 192 | m0_values_precommit), |
| 193 | n0_values_precommit), |
| 194 | k0_values_precommit), |
| 195 | h0_values_precommit), |
| 196 | i_values_rhs), |
| 197 | t_values_rhs), |
| 198 | framework::dataset::make("DataType", DataType::F32)), |
| 199 | a_values)) |
| 200 | { |
| 201 | // Validate output |
| 202 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 203 | } |
| 204 | |
| 205 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<float>, framework::DatasetMode::NIGHTLY, |
| 206 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 207 | m_values, |
| 208 | n_values), |
| 209 | k_values), |
| 210 | b_values), |
| 211 | m0_values_nightly), |
| 212 | n0_values_nightly), |
| 213 | k0_values_nightly), |
| 214 | h0_values_nightly), |
| 215 | i_values_rhs), |
| 216 | t_values_rhs), |
| 217 | framework::dataset::make("DataType", DataType::F32)), |
| 218 | a_values)) |
| 219 | { |
| 220 | // Validate output |
| 221 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 222 | } |
| 223 | |
| 224 | FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<float>, framework::DatasetMode::ALL, |
| 225 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 226 | m_w_values, |
| 227 | m_h_values), |
| 228 | n_values), |
| 229 | k_values), |
| 230 | b_values), |
| 231 | m0_values_precommit), |
| 232 | n0_values_precommit), |
| 233 | k0_values_precommit), |
| 234 | h0_values_precommit), |
| 235 | i_values_rhs), |
| 236 | t_values_rhs), |
| 237 | framework::dataset::make("DataType", DataType::F32)), |
| 238 | a_values)) |
| 239 | { |
| 240 | // Validate output |
| 241 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 242 | } |
| 243 | |
| 244 | FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<float>, framework::DatasetMode::NIGHTLY, |
| 245 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 246 | m_w_values, |
| 247 | m_h_values), |
| 248 | n_values), |
| 249 | k_values), |
| 250 | b_values), |
| 251 | m0_values_nightly), |
| 252 | n0_values_nightly), |
| 253 | k0_values_nightly), |
| 254 | h0_values_nightly), |
| 255 | i_values_rhs), |
| 256 | t_values_rhs), |
| 257 | framework::dataset::make("DataType", DataType::F32)), |
| 258 | a_values)) |
| 259 | { |
| 260 | // Validate output |
| 261 | validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32); |
| 262 | } |
| 263 | TEST_SUITE_END() // FP32 |
| 264 | |
| 265 | TEST_SUITE(FP16) |
| 266 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<half>, framework::DatasetMode::ALL, |
| 267 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 268 | m_values, |
| 269 | n_values), |
| 270 | k_values), |
| 271 | b_values), |
| 272 | m0_values_precommit), |
| 273 | n0_values_precommit), |
| 274 | k0_values_precommit), |
| 275 | h0_values_precommit), |
| 276 | i_values_rhs), |
| 277 | t_values_rhs), |
| 278 | framework::dataset::make("DataType", DataType::F16)), |
| 279 | a_values)) |
| 280 | { |
| 281 | // Validate output |
| 282 | validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16); |
| 283 | } |
| 284 | |
| 285 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMMatrixMultiplyReshapedOnlyRHSFixture<half>, framework::DatasetMode::NIGHTLY, |
| 286 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 287 | m_values, |
| 288 | n_values), |
| 289 | k_values), |
| 290 | b_values), |
| 291 | m0_values_nightly), |
| 292 | n0_values_nightly), |
| 293 | k0_values_nightly), |
| 294 | h0_values_nightly), |
| 295 | i_values_rhs), |
| 296 | t_values_rhs), |
| 297 | framework::dataset::make("DataType", DataType::F16)), |
| 298 | a_values)) |
| 299 | { |
| 300 | // Validate output |
| 301 | validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16); |
| 302 | } |
| 303 | |
| 304 | FIXTURE_DATA_TEST_CASE(RunSmall3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<half>, framework::DatasetMode::ALL, |
| 305 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 306 | m_w_values, |
| 307 | m_h_values), |
| 308 | n_values), |
| 309 | k_values), |
| 310 | b_values), |
| 311 | m0_values_precommit), |
| 312 | n0_values_precommit), |
| 313 | k0_values_precommit), |
| 314 | h0_values_precommit), |
| 315 | i_values_rhs), |
| 316 | t_values_rhs), |
| 317 | framework::dataset::make("DataType", DataType::F16)), |
| 318 | a_values)) |
| 319 | { |
| 320 | // Validate output |
| 321 | validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16); |
| 322 | } |
| 323 | |
| 324 | FIXTURE_DATA_TEST_CASE(RunLarge3D, CLGEMMMatrixMultiplyReshapedOnlyRHS3DFixture<half>, framework::DatasetMode::NIGHTLY, |
| 325 | combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(combine( |
| 326 | m_w_values, |
| 327 | m_h_values), |
| 328 | n_values), |
| 329 | k_values), |
| 330 | b_values), |
| 331 | m0_values_nightly), |
| 332 | n0_values_nightly), |
| 333 | k0_values_nightly), |
| 334 | h0_values_nightly), |
| 335 | i_values_rhs), |
| 336 | t_values_rhs), |
| 337 | framework::dataset::make("DataType", DataType::F16)), |
| 338 | a_values)) |
| 339 | { |
| 340 | // Validate output |
| 341 | validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16); |
| 342 | } |
| 343 | TEST_SUITE_END() // FP16 |
| 344 | TEST_SUITE_END() // Float |
| 345 | TEST_SUITE_END() // GEMMMatrixMulipltyReshapedOnlyRHS |
| 346 | TEST_SUITE_END() // CL |
| 347 | } // namespace validation |
| 348 | } // namespace test |
| 349 | } // namespace arm_compute |