Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 1 | /* |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2024 Arm Limited. |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [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/Types.h" |
Matthew Bentham | 314d3e2 | 2023-06-23 10:53:52 +0000 | [diff] [blame] | 25 | #include "arm_compute/core/utils/StringUtils.h" |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 26 | #include "arm_compute/runtime/NEON/functions/NEGEMM.h" |
| 27 | #include "arm_compute/runtime/Tensor.h" |
| 28 | #include "arm_compute/runtime/TensorAllocator.h" |
Michele Di Giorgio | 4dfc553 | 2021-06-30 12:05:34 +0100 | [diff] [blame] | 29 | #include "src/core/helpers/MemoryHelpers.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 30 | #include "src/cpu/kernels/CpuGemmInterleave4x4Kernel.h" |
| 31 | #include "src/cpu/kernels/CpuGemmMatrixMultiplyKernel.h" |
| 32 | #include "src/cpu/kernels/CpuGemmTranspose1xWKernel.h" |
| 33 | #include "src/cpu/operators/CpuGemm.h" |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 34 | #include "tests/NEON/Accessor.h" |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 35 | #include "tests/NEON/Helper.h" |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 36 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 37 | #include "tests/datasets/LargeGEMMDataset.h" |
| 38 | #include "tests/datasets/SmallGEMMDataset.h" |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 39 | #include "tests/datasets/TinyGEMMDataset.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 40 | #include "tests/framework/Asserts.h" |
| 41 | #include "tests/framework/Macros.h" |
| 42 | #include "tests/framework/datasets/Datasets.h" |
| 43 | #include "tests/validation/Validation.h" |
| 44 | #include "tests/validation/fixtures/GEMMFixture.h" |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 45 | #include "tests/validation/fixtures/GEMMInterleave4x4Fixture.h" |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 46 | #include "tests/validation/fixtures/GEMMTranspose1xWFixture.h" |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 47 | |
| 48 | namespace arm_compute |
| 49 | { |
| 50 | namespace test |
| 51 | { |
| 52 | namespace validation |
| 53 | { |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 54 | using framework::dataset::make; |
| 55 | |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 56 | namespace |
| 57 | { |
Gian Marco Iodice | fbf3ecc | 2018-08-23 17:26:21 +0100 | [diff] [blame] | 58 | constexpr AbsoluteTolerance<float> tolerance_f(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for FP32 data types */ |
| 59 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 60 | RelativeTolerance<half_float::half> rel_tolerance_f16(half(0.2)); /**< Relative tolerance value for comparing reference's output against implementation's output for FP16 data types */ |
| 61 | const AbsoluteTolerance<float> abs_tolerance_f16(0.2f); /**< Absolute tolerance value for comparing reference's output against implementation's output for FP16 data types */ |
| 62 | constexpr float tolerance_num = 0.07f; /**< Tolerance number for FP16 data types */ |
| 63 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 64 | /** CNN data types */ |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 65 | const auto CNNDataTypes = make("DataType", |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 66 | { |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 67 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 68 | DataType::F16, |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 69 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 70 | DataType::F32, |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 71 | }); |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 72 | |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 73 | const auto data_interleave = make("M", 8, 12) * make("N", 8, 12); |
| 74 | const auto data_transpose = make("M", 8, 14) * make("N", 7, 14); |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 75 | |
Gian Marco Iodice | feaea10 | 2020-09-03 13:20:34 +0100 | [diff] [blame] | 76 | /** Zero padding test */ |
Gian Marco Iodice | b3182b1 | 2020-09-04 08:44:52 +0100 | [diff] [blame] | 77 | template <typename FunctionType> |
| 78 | bool validate_zero_padding(unsigned int dim0_value, unsigned int dim1_value) |
Gian Marco Iodice | feaea10 | 2020-09-03 13:20:34 +0100 | [diff] [blame] | 79 | { |
Gian Marco Iodice | b3182b1 | 2020-09-04 08:44:52 +0100 | [diff] [blame] | 80 | const TensorShape in_shape(dim0_value, dim1_value); |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 81 | TensorInfo in(in_shape, 1, DataType::U32); |
| 82 | TensorInfo dst; |
| 83 | |
| 84 | ARM_COMPUTE_EXPECT(in.is_resizable(), framework::LogLevel::ERRORS); |
| 85 | |
| 86 | // Validate zero-padding |
| 87 | FunctionType func; |
| 88 | |
| 89 | func.configure(&in, &dst); |
| 90 | |
| 91 | return in.padding().empty(); |
| 92 | } |
| 93 | |
Michele Di Giorgio | cf9e29e | 2020-10-08 11:54:42 +0100 | [diff] [blame] | 94 | /* Zero padding test for GEMM kernels */ |
| 95 | bool validate_gemm_zero_padding(const TensorShape shape0, const TensorShape shape1) |
| 96 | { |
| 97 | // Create tensors |
Michele Di Giorgio | 53832b2 | 2021-06-21 14:45:44 +0100 | [diff] [blame] | 98 | TensorInfo in0(shape0, 1, DataType::F32); |
| 99 | TensorInfo in1(shape1, 1, DataType::F32); |
| 100 | TensorInfo dst; |
Michele Di Giorgio | cf9e29e | 2020-10-08 11:54:42 +0100 | [diff] [blame] | 101 | |
| 102 | // Validate zero-padding |
Michele Di Giorgio | 53832b2 | 2021-06-21 14:45:44 +0100 | [diff] [blame] | 103 | cpu::kernels::CpuGemmMatrixMultiplyKernel gemm; |
Michele Di Giorgio | cf9e29e | 2020-10-08 11:54:42 +0100 | [diff] [blame] | 104 | gemm.configure(&in0, &in1, &dst, 1.0, false); |
| 105 | |
Michele Di Giorgio | 53832b2 | 2021-06-21 14:45:44 +0100 | [diff] [blame] | 106 | return in0.padding().empty() && in1.padding().empty() && dst.padding().empty(); |
Michele Di Giorgio | cf9e29e | 2020-10-08 11:54:42 +0100 | [diff] [blame] | 107 | } |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 108 | } // namespace |
| 109 | |
| 110 | TEST_SUITE(NEON) |
| 111 | TEST_SUITE(GEMM) |
| 112 | |
Michele Di Giorgio | 4dfc553 | 2021-06-30 12:05:34 +0100 | [diff] [blame] | 113 | /** Test case for memory injection in @ref cpu::CpuGemm. |
| 114 | * |
| 115 | * Configure the operator once and inject memory at run-time in multiple executions. |
| 116 | * |
| 117 | * Checks performed in order: |
| 118 | * - Both runs compute the same output |
| 119 | */ |
| 120 | TEST_CASE(MemoryInjection, framework::DatasetMode::ALL) |
| 121 | { |
| 122 | auto gemm = std::make_unique<cpu::CpuGemm>(); |
| 123 | const auto lhs_info = TensorInfo(TensorShape(3U, 3U), 1, DataType::F32); |
| 124 | const auto rhs_info = TensorInfo(TensorShape(4U, 3U), 1, DataType::F32); |
| 125 | const auto c_info = TensorInfo(TensorShape(4U, 3U), 1, DataType::F32); |
| 126 | auto dst_info = TensorInfo(TensorShape(4U, 3U), 1, DataType::F32); |
| 127 | const auto gemm_info = GEMMInfo{}; |
| 128 | gemm->configure(&lhs_info, &rhs_info, &c_info, &dst_info, 1.f, 1.f, gemm_info); |
| 129 | |
| 130 | // telhs are newly created every call of this lambda function |
| 131 | auto lhs = create_tensor<Tensor>(lhs_info); |
| 132 | auto rhs = create_tensor<Tensor>(rhs_info); |
| 133 | auto c = create_tensor<Tensor>(c_info); |
| 134 | lhs.allocator()->allocate(); |
| 135 | rhs.allocator()->allocate(); |
| 136 | c.allocator()->allocate(); |
| 137 | |
| 138 | ITensorPack run_pack{ { TensorType::ACL_SRC_0, &lhs }, { TensorType::ACL_SRC_1, &rhs }, { TensorType::ACL_SRC_2, &c } }; |
| 139 | ITensorPack prep_pack{ { TensorType::ACL_SRC_1, &rhs }, { TensorType::ACL_SRC_2, &c } }; |
| 140 | |
| 141 | auto mg = MemoryGroup{}; |
| 142 | auto ws = manage_workspace<Tensor>(gemm->workspace(), mg, run_pack, prep_pack); |
| 143 | |
| 144 | auto run_conv = [&]() -> Tensor |
| 145 | { |
| 146 | auto dst = create_tensor<Tensor>(dst_info); |
| 147 | dst.allocator()->allocate(); |
| 148 | run_pack.add_tensor(TensorType::ACL_DST, &dst); |
| 149 | |
| 150 | library->fill_tensor_value(Accessor(lhs), 1.f); |
| 151 | library->fill_tensor_value(Accessor(rhs), 2.f); |
| 152 | library->fill_tensor_value(Accessor(c), 3.f); |
| 153 | // This operator is configured once and captured by this lambda. |
| 154 | gemm->prepare(prep_pack); |
| 155 | gemm->run(run_pack); |
| 156 | return dst; |
| 157 | }; |
| 158 | auto result_0 = run_conv(); |
| 159 | auto result_1 = run_conv(); |
| 160 | for(size_t i = 0; i < result_0.info()->tensor_shape().total_size(); ++i) |
| 161 | { |
| 162 | ARM_COMPUTE_EXPECT(((float *)result_0.buffer())[i] == ((float *)result_1.buffer())[i], framework::LogLevel::ERRORS); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /** Test case for memory injection in @ref NEGEMM. |
| 167 | * |
| 168 | * Make sure @ref NEGEMM still works through injecting the memory at configure time using the old API. |
| 169 | * |
| 170 | * Checks performed in order: |
| 171 | * - Both runs compute the same output |
| 172 | */ |
| 173 | TEST_CASE(MultipleExecutionWithConfigure, framework::DatasetMode::ALL) |
| 174 | { |
| 175 | auto gemm = std::make_unique<NEGEMM>(); |
| 176 | const auto lhs_info = TensorInfo(TensorShape(3U, 3U), 1, DataType::F32); |
| 177 | const auto rhs_info = TensorInfo(TensorShape(4U, 3U), 1, DataType::F32); |
| 178 | const auto c_info = TensorInfo(TensorShape(4U, 3U), 1, DataType::F32); |
| 179 | auto dst_info = TensorInfo(TensorShape(4U, 3U), 1, DataType::F32); |
| 180 | const auto gemm_info = GEMMInfo{}; |
| 181 | auto run_conv = [&]() |
| 182 | { |
| 183 | auto lhs = create_tensor<Tensor>(lhs_info); |
| 184 | auto rhs = create_tensor<Tensor>(rhs_info); |
| 185 | auto c = create_tensor<Tensor>(c_info); |
| 186 | auto dst = create_tensor<Tensor>(dst_info); |
| 187 | gemm->configure(&lhs, &rhs, &c, &dst, 1.f, 1.f, gemm_info); |
| 188 | lhs.allocator()->allocate(); |
| 189 | rhs.allocator()->allocate(); |
| 190 | c.allocator()->allocate(); |
| 191 | dst.allocator()->allocate(); |
| 192 | library->fill_tensor_value(Accessor(lhs), 1.f); |
| 193 | library->fill_tensor_value(Accessor(rhs), 2.f); |
| 194 | library->fill_tensor_value(Accessor(c), 3.f); |
| 195 | gemm->run(); |
| 196 | return dst; |
| 197 | }; |
| 198 | auto result_0 = run_conv(); |
| 199 | auto result_1 = run_conv(); |
| 200 | for(size_t i = 0; i < result_0.info()->tensor_shape().total_size(); ++i) |
| 201 | { |
| 202 | ARM_COMPUTE_EXPECT(((float *)result_0.buffer())[i] == ((float *)result_1.buffer())[i], framework::LogLevel::ERRORS); |
| 203 | } |
| 204 | } |
| 205 | |
SiCong Li | 13bab71 | 2023-01-13 15:29:39 +0000 | [diff] [blame] | 206 | // *INDENT-OFF* |
| 207 | // clang-format off |
| 208 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 209 | make("LhsInfo", { TensorInfo(TensorShape(27U, 13U), 1, DataType::S32), // Unsupported data type |
SiCong Li | 13bab71 | 2023-01-13 15:29:39 +0000 | [diff] [blame] | 210 | TensorInfo(TensorShape(27U, 13U), 1, DataType::F32), |
| 211 | }), |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 212 | make("RhsInfo",{ TensorInfo(TensorShape(8U, 27U), 1, DataType::S32), |
SiCong Li | 13bab71 | 2023-01-13 15:29:39 +0000 | [diff] [blame] | 213 | TensorInfo(TensorShape(8U, 27U), 1, DataType::F32), |
| 214 | })), |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 215 | make("OutputInfo",{ TensorInfo(TensorShape(8U, 13U), 1, DataType::S32), |
SiCong Li | 13bab71 | 2023-01-13 15:29:39 +0000 | [diff] [blame] | 216 | TensorInfo(TensorShape(8U, 13U), 1, DataType::F32), |
| 217 | })), |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 218 | make("Expected", { false, true })), |
SiCong Li | 13bab71 | 2023-01-13 15:29:39 +0000 | [diff] [blame] | 219 | lhs_info, rhs_info, output_info, expected) |
| 220 | { |
| 221 | constexpr float alpha = 1.0; |
| 222 | constexpr float beta = 0.0; |
| 223 | const auto gemm_info = GEMMInfo(); |
| 224 | bool is_valid = bool(NEGEMM::validate(&lhs_info.clone()->set_is_resizable(true), &rhs_info.clone()->set_is_resizable(true), nullptr, &output_info.clone()->set_is_resizable(true), alpha, beta, gemm_info)); |
| 225 | ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS); |
| 226 | } |
| 227 | // clang-format on |
| 228 | // *INDENT-ON* |
Dana Zlotnik | 256ac62 | 2022-02-02 15:06:11 +0200 | [diff] [blame] | 229 | TEST_SUITE(KERNEL_SELECTION) |
| 230 | DATA_TEST_CASE(KernelSelection_mul_and_add, framework::DatasetMode::ALL, |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 231 | combine(make("CpuExt", std::string("NEON")), |
| 232 | make("DataType", { DataType::F32, |
Dana Zlotnik | 256ac62 | 2022-02-02 15:06:11 +0200 | [diff] [blame] | 233 | DataType::F16 |
| 234 | })), |
| 235 | cpu_ext, data_type) |
| 236 | { |
| 237 | using namespace cpu::kernels; |
| 238 | |
| 239 | cpuinfo::CpuIsaInfo cpu_isa{}; |
| 240 | cpu_isa.neon = (cpu_ext == "NEON"); |
| 241 | cpu_isa.fp16 = (data_type == DataType::F16); |
| 242 | |
| 243 | const auto *selected_impl_mul = CpuGemmMatrixMultiplyKernel::get_implementation(DataTypeISASelectorData{ data_type, cpu_isa }, cpu::KernelSelectionType::Preferred); |
| 244 | |
| 245 | ARM_COMPUTE_ERROR_ON_NULLPTR(selected_impl_mul); |
| 246 | |
| 247 | std::string expected = lower_string(cpu_ext) + "_" + cpu_impl_dt(data_type) + "_gemm_matrix_mul"; |
| 248 | std::string actual = selected_impl_mul->name; |
| 249 | |
| 250 | ARM_COMPUTE_EXPECT_EQUAL(expected, actual, framework::LogLevel::ERRORS); |
| 251 | |
| 252 | const auto *selected_impl_add = CpuGemmMatrixAdditionKernel::get_implementation(DataTypeISASelectorData{ data_type, cpu_isa }, cpu::KernelSelectionType::Preferred); |
| 253 | |
| 254 | ARM_COMPUTE_ERROR_ON_NULLPTR(selected_impl_add); |
| 255 | |
| 256 | expected = lower_string(cpu_ext) + "_" + cpu_impl_dt(data_type) + "_gemm_matrix_add"; |
| 257 | actual = selected_impl_add->name; |
| 258 | |
| 259 | ARM_COMPUTE_EXPECT_EQUAL(expected, actual, framework::LogLevel::ERRORS); |
| 260 | } |
| 261 | TEST_SUITE_END() // KERNEL_SELECTION |
| 262 | |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 263 | TEST_SUITE(TRANSPOSE_1XW) |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 264 | using CpuGemmTranspose1xW = NESynthetizeFunctionWithZeroConstantKernelBorder<cpu::kernels::CpuGemmTranspose1xWKernel>; |
Gian Marco Iodice | b3182b1 | 2020-09-04 08:44:52 +0100 | [diff] [blame] | 265 | DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip( |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 266 | make("N", { 1, 23, 63, 101 }), |
| 267 | make("K", { 1, 47, 29, 27 })), |
Gian Marco Iodice | b3182b1 | 2020-09-04 08:44:52 +0100 | [diff] [blame] | 268 | n_value, k_value) |
| 269 | { |
Michele Di Giorgio | 4dfc553 | 2021-06-30 12:05:34 +0100 | [diff] [blame] | 270 | bool status = validate_zero_padding<CpuGemmTranspose1xW>(n_value, k_value); |
Gian Marco Iodice | b3182b1 | 2020-09-04 08:44:52 +0100 | [diff] [blame] | 271 | ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS); |
| 272 | } |
| 273 | |
| 274 | TEST_SUITE(U32) |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 275 | using CpuGemmTranspose1xWFixture = GEMMTranspose1xWValidationFixture<Tensor, Accessor, CpuGemmTranspose1xW, uint32_t>; |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 276 | FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * make("DataType", DataType::U32)) |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 277 | { |
| 278 | // Validate output |
| 279 | validate(Accessor(_target), _reference); |
| 280 | } |
Gian Marco Iodice | b3182b1 | 2020-09-04 08:44:52 +0100 | [diff] [blame] | 281 | TEST_SUITE_END() // U32 |
| 282 | |
| 283 | TEST_SUITE(U16) |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 284 | using CpuGemmTranspose1xWFixture = GEMMTranspose1xWValidationFixture<Tensor, Accessor, CpuGemmTranspose1xW, uint16_t>; |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 285 | FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * make("DataType", DataType::U16)) |
Gian Marco Iodice | b3182b1 | 2020-09-04 08:44:52 +0100 | [diff] [blame] | 286 | { |
| 287 | // Validate output |
| 288 | validate(Accessor(_target), _reference); |
| 289 | } |
| 290 | TEST_SUITE_END() // U16 |
| 291 | |
| 292 | TEST_SUITE(U8) |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 293 | using CpuGemmTranspose1xWFixture = GEMMTranspose1xWValidationFixture<Tensor, Accessor, CpuGemmTranspose1xW, uint8_t>; |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 294 | FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * make("DataType", DataType::U8)) |
Gian Marco Iodice | b3182b1 | 2020-09-04 08:44:52 +0100 | [diff] [blame] | 295 | { |
| 296 | // Validate output |
| 297 | validate(Accessor(_target), _reference); |
| 298 | } |
| 299 | TEST_SUITE_END() // U8 |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 300 | |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 301 | TEST_SUITE_END() // TRANSPOSE_1XW |
| 302 | |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 303 | TEST_SUITE(INTERLEAVE_4X4) |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 304 | using CpuGemmInterleave4x4 = NESynthetizeFunctionWithZeroConstantKernelBorder<cpu::kernels::CpuGemmInterleave4x4Kernel>; |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 305 | |
Gian Marco Iodice | feaea10 | 2020-09-03 13:20:34 +0100 | [diff] [blame] | 306 | DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip( |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 307 | make("M", { 1, 23, 63, 101 }), |
| 308 | make("K", { 1, 47, 29, 27 })), |
Gian Marco Iodice | feaea10 | 2020-09-03 13:20:34 +0100 | [diff] [blame] | 309 | m_value, k_value) |
| 310 | { |
Michele Di Giorgio | 4dfc553 | 2021-06-30 12:05:34 +0100 | [diff] [blame] | 311 | bool status = validate_zero_padding<cpu::kernels::CpuGemmInterleave4x4Kernel>(m_value, k_value); |
Gian Marco Iodice | feaea10 | 2020-09-03 13:20:34 +0100 | [diff] [blame] | 312 | ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS); |
| 313 | } |
| 314 | |
| 315 | TEST_SUITE(U32) |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 316 | using CpuGemmInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, CpuGemmInterleave4x4, uint32_t>; |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 317 | FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * make("DataType", DataType::U32)) |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 318 | { |
| 319 | // Validate output |
| 320 | validate(Accessor(_target), _reference); |
| 321 | } |
Gian Marco Iodice | feaea10 | 2020-09-03 13:20:34 +0100 | [diff] [blame] | 322 | TEST_SUITE_END() // U32 |
| 323 | |
| 324 | TEST_SUITE(U16) |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 325 | using CpuGemmInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, CpuGemmInterleave4x4, uint16_t>; |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 326 | FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * make("DataType", DataType::U16)) |
Gian Marco Iodice | feaea10 | 2020-09-03 13:20:34 +0100 | [diff] [blame] | 327 | { |
| 328 | // Validate output |
| 329 | validate(Accessor(_target), _reference); |
| 330 | } |
| 331 | TEST_SUITE_END() // U16 |
| 332 | |
| 333 | TEST_SUITE(U8) |
Michele Di Giorgio | 93b75e0 | 2021-06-21 12:00:43 +0100 | [diff] [blame] | 334 | using CpuGemmInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, CpuGemmInterleave4x4, uint8_t>; |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 335 | FIXTURE_DATA_TEST_CASE(RunSmall, CpuGemmInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * make("DataType", DataType::QASYMM8)) |
Gian Marco Iodice | feaea10 | 2020-09-03 13:20:34 +0100 | [diff] [blame] | 336 | { |
| 337 | // Validate output |
| 338 | validate(Accessor(_target), _reference); |
| 339 | } |
| 340 | TEST_SUITE_END() // U8 |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 341 | |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 342 | TEST_SUITE_END() // INTERLEAVE_4X4 |
| 343 | |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 344 | template <typename T> |
| 345 | using NEGEMMFixture = GEMMValidationFixture<Tensor, Accessor, NEGEMM, T>; |
| 346 | |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 347 | template <typename T> |
Adnan AlSinan | 26c9d1a | 2022-09-07 13:54:53 +0100 | [diff] [blame] | 348 | using NEBatchedMatMulFixture = GEMMValidationFixture<Tensor, Accessor, NEGEMM, T, true, false, false, false, false, true>; |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 349 | |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 350 | template <typename T> |
| 351 | using NEGEMMAccumulateFixture = GEMMAccumulateValidationFixture<Tensor, Accessor, NEGEMM, T>; |
| 352 | |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 353 | TEST_SUITE(Float) |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 354 | DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip(make("In0", { TensorShape(21U, 13U), |
Michele Di Giorgio | cf9e29e | 2020-10-08 11:54:42 +0100 | [diff] [blame] | 355 | TensorShape(31U, 1U), |
| 356 | TensorShape(31U, 1U), |
| 357 | TensorShape(8U, 2U), |
| 358 | TensorShape(38U, 12U), |
| 359 | TensorShape(32U, 1U) |
| 360 | }), |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 361 | make("In1", { TensorShape(33U, 21U), |
Michele Di Giorgio | cf9e29e | 2020-10-08 11:54:42 +0100 | [diff] [blame] | 362 | TensorShape(23U, 31U), |
| 363 | TensorShape(23U, 31U), |
| 364 | TensorShape(16U, 8U), |
| 365 | TensorShape(21U, 38U), |
| 366 | TensorShape(17U, 32U) |
| 367 | })), |
| 368 | shape0, shape1) |
| 369 | { |
| 370 | bool status = validate_gemm_zero_padding(shape0, shape1); |
| 371 | ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS); |
| 372 | } |
| 373 | |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 374 | DATA_TEST_CASE(ValidateAccumulate, framework::DatasetMode::ALL, combine( |
| 375 | zip(make("In0",{ TensorShape(21U, 13U) }), |
| 376 | make("In1", { TensorShape(33U, 21U) }), |
| 377 | make("Dst", { TensorShape(33U, 13U) })), |
| 378 | zip( |
| 379 | make("alpha", { 1.0, 100.0, 1.0, 1.0 }), |
| 380 | make("beta", { 0.0, 0.0, 1.0, 1.0 }), |
| 381 | make("is_c_null", { false, false, false, true }), |
| 382 | make("Expected", { true, false, false, true }))), |
| 383 | shape_a, shape_b, shape_dst, alpha, beta, is_c_null, expected) |
| 384 | { |
| 385 | /* Accumulation test for GEMM kernels */ |
| 386 | // Create tensors |
| 387 | TensorInfo in_a(shape_a, 1, DataType::F32); |
| 388 | TensorInfo in_b(shape_b, 1, DataType::F32); |
| 389 | TensorInfo in_c(shape_dst, 1, DataType::F32); |
| 390 | TensorInfo dst(shape_dst, 1, DataType::F32); |
| 391 | |
| 392 | GEMMInfo gemm_info = GEMMInfo(); |
| 393 | gemm_info.set_accumulate(true); |
| 394 | |
| 395 | // Validate accumulation |
| 396 | cpu::CpuGemm gemm; |
| 397 | Status status = gemm.validate(&in_a, &in_b, (is_c_null ? nullptr : &in_c), &dst, alpha, beta, gemm_info); |
| 398 | ARM_COMPUTE_EXPECT((expected == bool(status)), framework::LogLevel::ERRORS); |
| 399 | } |
| 400 | |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 401 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 402 | TEST_SUITE(FP16) |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 403 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(), |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 404 | make("ReshapeWeights", { true, false })), |
| 405 | make("DataType", DataType::F16))) |
| 406 | { |
| 407 | // Validate output |
| 408 | validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16); |
| 409 | } |
| 410 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(), |
| 411 | make("ReshapeWeights", { true, false })), |
| 412 | make("DataType", DataType::F16))) |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 413 | { |
| 414 | // Validate output |
Gian Marco Iodice | fbf3ecc | 2018-08-23 17:26:21 +0100 | [diff] [blame] | 415 | validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16); |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 416 | } |
Adnan AlSinan | 304dfdb | 2022-09-21 13:20:45 +0100 | [diff] [blame] | 417 | |
| 418 | TEST_SUITE(BATCHED_MATMUL) |
Adnan AlSinan | 304dfdb | 2022-09-21 13:20:45 +0100 | [diff] [blame] | 419 | FIXTURE_DATA_TEST_CASE(RunSmall, NEBatchedMatMulFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallBatchedMatMulDataset(), |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 420 | make("ReshapeWeights", { false })), |
| 421 | make("DataType", DataType::F16))) |
Adnan AlSinan | 304dfdb | 2022-09-21 13:20:45 +0100 | [diff] [blame] | 422 | { |
| 423 | // Validate output |
| 424 | validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16); |
| 425 | } |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 426 | TEST_SUITE_END() // BATCHED_MATMUL |
Adnan AlSinan | 304dfdb | 2022-09-21 13:20:45 +0100 | [diff] [blame] | 427 | |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 428 | TEST_SUITE_END() // FP16 |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 429 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 430 | |
| 431 | TEST_SUITE(FP32) |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 432 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(), |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 433 | make("ReshapeWeights", { true, false })), |
| 434 | make("DataType", DataType::F32))) |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 435 | { |
| 436 | // Validate output |
| 437 | validate(Accessor(_target), _reference, tolerance_f); |
| 438 | } |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 439 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(), |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 440 | make("ReshapeWeights", { true, false })), |
| 441 | make("DataType", DataType::F32))) |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 442 | { |
| 443 | // Validate output |
| 444 | validate(Accessor(_target), _reference, tolerance_f); |
| 445 | } |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 446 | |
Adnan AlSinan | 26c9d1a | 2022-09-07 13:54:53 +0100 | [diff] [blame] | 447 | TEST_SUITE(BATCHED_MATMUL) |
Adnan AlSinan | 26c9d1a | 2022-09-07 13:54:53 +0100 | [diff] [blame] | 448 | FIXTURE_DATA_TEST_CASE(RunSmall, NEBatchedMatMulFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallBatchedMatMulDataset(), |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 449 | make("ReshapeWeights", { false })), |
| 450 | make("DataType", DataType::F32))) |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 451 | { |
| 452 | // Validate output |
| 453 | validate(Accessor(_target), _reference, tolerance_f); |
| 454 | } |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 455 | TEST_SUITE_END() // BATCHED_MATMUL |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 456 | |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 457 | TEST_SUITE(ACCUMULATE) |
| 458 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMAccumulateFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallAccumulateGEMMDataset(), |
| 459 | make("ReshapeWeights", { false }), |
| 460 | make("DataType", DataType::F32))) |
| 461 | { |
| 462 | // Validate output |
| 463 | validate(Accessor(_target), _reference, tolerance_f); |
| 464 | } |
| 465 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMAccumulateFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeAccumulateGEMMDataset(), |
| 466 | make("ReshapeWeights", { false }), |
| 467 | make("DataType", DataType::F32))) |
| 468 | { |
| 469 | // Validate output |
| 470 | validate(Accessor(_target), _reference, tolerance_f); |
| 471 | } |
| 472 | TEST_SUITE_END() // ACCUMULATE |
Gian Marco Iodice | 37a4611 | 2021-08-04 15:22:28 +0100 | [diff] [blame] | 473 | |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 474 | TEST_SUITE_END() // FP32 |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 475 | |
Radu Salavat | f1f1f87 | 2024-02-27 18:32:26 +0000 | [diff] [blame] | 476 | TEST_SUITE_END() // Float |
| 477 | TEST_SUITE_END() // GEMM |
| 478 | TEST_SUITE_END() // NEON |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 479 | } // namespace validation |
| 480 | } // namespace test |
| 481 | } // namespace arm_compute |