Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 1 | /* |
Gian Marco Iodice | feaea10 | 2020-09-03 13:20:34 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2017-2020 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 | */ |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 24 | #include "arm_compute/core/NEON/kernels/NEGEMMInterleave4x4Kernel.h" |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 25 | #include "arm_compute/core/NEON/kernels/NEGEMMTranspose1xWKernel.h" |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/Types.h" |
| 27 | #include "arm_compute/runtime/NEON/functions/NEGEMM.h" |
| 28 | #include "arm_compute/runtime/Tensor.h" |
| 29 | #include "arm_compute/runtime/TensorAllocator.h" |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 30 | #include "tests/NEON/Accessor.h" |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 31 | #include "tests/NEON/Helper.h" |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 32 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 33 | #include "tests/datasets/LargeGEMMDataset.h" |
| 34 | #include "tests/datasets/SmallGEMMDataset.h" |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 35 | #include "tests/datasets/TinyGEMMDataset.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 36 | #include "tests/framework/Asserts.h" |
| 37 | #include "tests/framework/Macros.h" |
| 38 | #include "tests/framework/datasets/Datasets.h" |
| 39 | #include "tests/validation/Validation.h" |
| 40 | #include "tests/validation/fixtures/GEMMFixture.h" |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 41 | #include "tests/validation/fixtures/GEMMInterleave4x4Fixture.h" |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 42 | #include "tests/validation/fixtures/GEMMTranspose1xWFixture.h" |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 43 | |
| 44 | namespace arm_compute |
| 45 | { |
| 46 | namespace test |
| 47 | { |
| 48 | namespace validation |
| 49 | { |
| 50 | namespace |
| 51 | { |
Gian Marco Iodice | fbf3ecc | 2018-08-23 17:26:21 +0100 | [diff] [blame] | 52 | constexpr AbsoluteTolerance<float> tolerance_f(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for FP32 data types */ |
| 53 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 54 | 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 */ |
| 55 | const AbsoluteTolerance<float> abs_tolerance_f16(0.2f); /**< Absolute tolerance value for comparing reference's output against implementation's output for FP16 data types */ |
| 56 | constexpr float tolerance_num = 0.07f; /**< Tolerance number for FP16 data types */ |
| 57 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 58 | /** CNN data types */ |
| 59 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 60 | { |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 61 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 62 | DataType::F16, |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 63 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 64 | DataType::F32, |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 65 | }); |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 66 | |
| 67 | const auto data_interleave = framework::dataset::make("M", 8, 12) * framework::dataset::make("N", 8, 12); |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 68 | const auto data_transpose = framework::dataset::make("M", 8, 14) * framework::dataset::make("N", 7, 14); |
| 69 | |
Gian Marco Iodice | feaea10 | 2020-09-03 13:20:34 +0100 | [diff] [blame^] | 70 | /** Zero padding test */ |
| 71 | bool validate_zero_padding(unsigned int m_value, unsigned int k_value) |
| 72 | { |
| 73 | const unsigned int M = m_value; |
| 74 | const unsigned int K = k_value; |
| 75 | |
| 76 | const TensorShape lhs_shape(K, M); |
| 77 | const TensorShape lhs_shape_reshaped(K * 4, std::ceil(M / 4.0f)); |
| 78 | |
| 79 | // Create tensors |
| 80 | Tensor lhs = create_tensor<Tensor>(lhs_shape, DataType::U32); |
| 81 | Tensor dst = create_tensor<Tensor>(lhs_shape_reshaped, DataType::U32); |
| 82 | |
| 83 | ARM_COMPUTE_EXPECT(lhs.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 84 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 85 | |
| 86 | // Validate zero-padding |
| 87 | NEGEMMInterleave4x4Kernel lhs_reshape; |
| 88 | |
| 89 | lhs_reshape.configure(&lhs, &dst); |
| 90 | |
| 91 | return lhs.info()->padding().empty(); |
| 92 | } |
| 93 | |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 94 | } // namespace |
| 95 | |
| 96 | TEST_SUITE(NEON) |
| 97 | TEST_SUITE(GEMM) |
| 98 | |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 99 | TEST_SUITE(TRANSPOSE_1XW) |
| 100 | using NEGEMMTranspose1xW = NESynthetizeFunctionWithZeroConstantBorder<NEGEMMTranspose1xWKernel, 4>; |
| 101 | using NEGEMMTranspose1xWFixture = GEMMTranspose1xWValidationFixture<Tensor, Accessor, NEGEMMTranspose1xW, float>; |
| 102 | TEST_SUITE(FP32) |
| 103 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMTranspose1xWFixture, framework::DatasetMode::PRECOMMIT, data_transpose * framework::dataset::make("DataType", DataType::F32)) |
| 104 | { |
| 105 | // Validate output |
| 106 | validate(Accessor(_target), _reference); |
| 107 | } |
| 108 | TEST_SUITE_END() // FP32 |
| 109 | |
Pablo Tello | 088cc7f | 2017-12-07 15:20:55 +0000 | [diff] [blame] | 110 | TEST_SUITE_END() // TRANSPOSE_1XW |
| 111 | |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 112 | TEST_SUITE(INTERLEAVE_4X4) |
| 113 | using NEGEMMInterleave4x4 = NESynthetizeFunctionWithZeroConstantBorder<NEGEMMInterleave4x4Kernel, 4>; |
| 114 | |
Gian Marco Iodice | feaea10 | 2020-09-03 13:20:34 +0100 | [diff] [blame^] | 115 | DATA_TEST_CASE(ValidateZeroPadding, framework::DatasetMode::ALL, zip( |
| 116 | framework::dataset::make("M", { 1, 23, 63, 101 }), |
| 117 | framework::dataset::make("K", { 1, 47, 29, 27 })), |
| 118 | m_value, k_value) |
| 119 | { |
| 120 | bool status = validate_zero_padding(m_value, k_value); |
| 121 | ARM_COMPUTE_EXPECT(status, framework::LogLevel::ERRORS); |
| 122 | } |
| 123 | |
| 124 | TEST_SUITE(U32) |
| 125 | using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, NEGEMMInterleave4x4, uint32_t>; |
| 126 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * framework::dataset::make("DataType", DataType::U32)) |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 127 | { |
| 128 | // Validate output |
| 129 | validate(Accessor(_target), _reference); |
| 130 | } |
Gian Marco Iodice | feaea10 | 2020-09-03 13:20:34 +0100 | [diff] [blame^] | 131 | TEST_SUITE_END() // U32 |
| 132 | |
| 133 | TEST_SUITE(U16) |
| 134 | using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, NEGEMMInterleave4x4, uint16_t>; |
| 135 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * framework::dataset::make("DataType", DataType::U16)) |
| 136 | { |
| 137 | // Validate output |
| 138 | validate(Accessor(_target), _reference); |
| 139 | } |
| 140 | TEST_SUITE_END() // U16 |
| 141 | |
| 142 | TEST_SUITE(U8) |
| 143 | using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, NEGEMMInterleave4x4, uint8_t>; |
| 144 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * framework::dataset::make("DataType", DataType::QASYMM8)) |
| 145 | { |
| 146 | // Validate output |
| 147 | validate(Accessor(_target), _reference); |
| 148 | } |
| 149 | TEST_SUITE_END() // U8 |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 150 | |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame] | 151 | TEST_SUITE_END() // INTERLEAVE_4X4 |
| 152 | |
Michalis Spyrou | 5c9f0c4 | 2019-01-16 14:48:48 +0000 | [diff] [blame] | 153 | //TODO(COMPMID-415): Validate valid region |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 154 | |
| 155 | template <typename T> |
| 156 | using NEGEMMFixture = GEMMValidationFixture<Tensor, Accessor, NEGEMM, T>; |
| 157 | |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 158 | template <typename T> |
| 159 | using NEGEMMFixtureDisabledC = GEMMValidationFixture<Tensor, Accessor, NEGEMM, T, true>; |
| 160 | |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 161 | TEST_SUITE(Float) |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 162 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 163 | TEST_SUITE(FP16) |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 164 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(), |
| 165 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 166 | framework::dataset::make("DataType", DataType::F16))) |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 167 | { |
| 168 | // Validate output |
Gian Marco Iodice | fbf3ecc | 2018-08-23 17:26:21 +0100 | [diff] [blame] | 169 | validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16); |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 170 | } |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 171 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(), |
| 172 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 173 | |
| 174 | framework::dataset::make("DataType", DataType::F16))) |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 175 | { |
| 176 | // Validate output |
Gian Marco Iodice | fbf3ecc | 2018-08-23 17:26:21 +0100 | [diff] [blame] | 177 | validate(Accessor(_target), _reference, rel_tolerance_f16, tolerance_num, abs_tolerance_f16); |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 178 | } |
| 179 | TEST_SUITE_END() |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 180 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 181 | |
| 182 | TEST_SUITE(FP32) |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 183 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(), |
| 184 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 185 | |
| 186 | framework::dataset::make("DataType", DataType::F32))) |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 187 | { |
| 188 | // Validate output |
| 189 | validate(Accessor(_target), _reference, tolerance_f); |
| 190 | } |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 191 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(), |
| 192 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 193 | |
| 194 | framework::dataset::make("DataType", DataType::F32))) |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 195 | { |
| 196 | // Validate output |
| 197 | validate(Accessor(_target), _reference, tolerance_f); |
| 198 | } |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 199 | TEST_SUITE(DisabledC) |
| 200 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixtureDisabledC<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(), |
| 201 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 202 | |
| 203 | framework::dataset::make("DataType", DataType::F32))) |
| 204 | { |
| 205 | // Validate output |
| 206 | validate(Accessor(_target), _reference, tolerance_f); |
| 207 | } |
| 208 | TEST_SUITE_END() |
| 209 | |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 210 | TEST_SUITE_END() |
| 211 | TEST_SUITE_END() |
| 212 | |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 213 | TEST_SUITE_END() |
| 214 | TEST_SUITE_END() |
| 215 | } // namespace validation |
| 216 | } // namespace test |
| 217 | } // namespace arm_compute |