Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 | */ |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame^] | 24 | #include "arm_compute/core/NEON/kernels/NEGEMMInterleave4x4Kernel.h" |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 25 | #include "arm_compute/core/Types.h" |
| 26 | #include "arm_compute/runtime/NEON/functions/NEGEMM.h" |
| 27 | #include "arm_compute/runtime/Tensor.h" |
| 28 | #include "arm_compute/runtime/TensorAllocator.h" |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 29 | #include "tests/NEON/Accessor.h" |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame^] | 30 | #include "tests/NEON/Helper.h" |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 31 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 32 | #include "tests/datasets/LargeGEMMDataset.h" |
| 33 | #include "tests/datasets/SmallGEMMDataset.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" |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame^] | 39 | #include "tests/validation/fixtures/GEMMInterleave4x4Fixture.h" |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 40 | |
| 41 | namespace arm_compute |
| 42 | { |
| 43 | namespace test |
| 44 | { |
| 45 | namespace validation |
| 46 | { |
| 47 | namespace |
| 48 | { |
| 49 | constexpr AbsoluteTolerance<float> tolerance_f(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for floating point data types */ |
| 50 | constexpr AbsoluteTolerance<float> tolerance_q(1.0f); /**< Tolerance value for comparing reference's output against implementation's output for fixed point data types */ |
| 51 | |
| 52 | /** CNN data types */ |
| 53 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 54 | { |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 55 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 56 | DataType::F16, |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 57 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 58 | DataType::F32, |
| 59 | DataType::QS8, |
| 60 | DataType::QS16, |
| 61 | }); |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame^] | 62 | |
| 63 | const auto data_interleave = framework::dataset::make("M", 8, 12) * framework::dataset::make("N", 8, 12); |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 64 | } // namespace |
| 65 | |
| 66 | TEST_SUITE(NEON) |
| 67 | TEST_SUITE(GEMM) |
| 68 | |
Pablo Tello | 2fdc409 | 2017-11-23 15:50:08 +0000 | [diff] [blame^] | 69 | TEST_SUITE(INTERLEAVE_4X4) |
| 70 | using NEGEMMInterleave4x4 = NESynthetizeFunctionWithZeroConstantBorder<NEGEMMInterleave4x4Kernel, 4>; |
| 71 | |
| 72 | TEST_SUITE(FP32) |
| 73 | using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixture<Tensor, Accessor, NEGEMMInterleave4x4, float>; |
| 74 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * framework::dataset::make("DataType", DataType::F32)) |
| 75 | { |
| 76 | // Validate output |
| 77 | validate(Accessor(_target), _reference); |
| 78 | } |
| 79 | TEST_SUITE_END() // FP32 |
| 80 | |
| 81 | TEST_SUITE(Quantized) |
| 82 | TEST_SUITE(QS8) |
| 83 | using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixedPointFixture<Tensor, Accessor, NEGEMMInterleave4x4, int8_t>; |
| 84 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * |
| 85 | framework::dataset::make("DataType", DataType::QS8) |
| 86 | * framework::dataset::make("FractionalBits", 1, 7)) |
| 87 | { |
| 88 | // Validate output |
| 89 | validate(Accessor(_target), _reference); |
| 90 | } |
| 91 | TEST_SUITE_END() |
| 92 | |
| 93 | TEST_SUITE(QS16) |
| 94 | using NEGEMMInterleave4x4Fixture = GEMMInterleave4x4ValidationFixedPointFixture<Tensor, Accessor, NEGEMMInterleave4x4, int16_t>; |
| 95 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleave4x4Fixture, framework::DatasetMode::PRECOMMIT, data_interleave * |
| 96 | framework::dataset::make("DataType", DataType::QS16) |
| 97 | * framework::dataset::make("FractionalBits", 1, 14)) |
| 98 | { |
| 99 | // Validate output |
| 100 | validate(Accessor(_target), _reference); |
| 101 | } |
| 102 | TEST_SUITE_END() |
| 103 | |
| 104 | TEST_SUITE_END() |
| 105 | |
| 106 | TEST_SUITE_END() // INTERLEAVE_4X4 |
| 107 | |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 108 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallGEMMDataset(), datasets::LargeGEMMDataset()), CNNDataTypes), |
| 109 | shape_a, shape_b, shape_c, output_shape, alpha, beta, data_type) |
| 110 | { |
| 111 | // Set fixed point position data type allowed |
| 112 | const int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0; |
| 113 | |
| 114 | // Create tensors |
| 115 | Tensor a = create_tensor<Tensor>(shape_a, data_type, 1, fixed_point_position); |
| 116 | Tensor b = create_tensor<Tensor>(shape_b, data_type, 1, fixed_point_position); |
| 117 | Tensor c = create_tensor<Tensor>(shape_c, data_type, 1, fixed_point_position); |
| 118 | Tensor dst = create_tensor<Tensor>(output_shape, data_type, 1, fixed_point_position); |
| 119 | |
| 120 | ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 121 | ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 122 | ARM_COMPUTE_EXPECT(c.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 123 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 124 | |
| 125 | // Create and configure function |
| 126 | NEGEMM gemm; |
| 127 | gemm.configure(&a, &b, &c, &dst, alpha, beta); |
| 128 | |
| 129 | //TODO(COMPMID-415): Validate valid region |
| 130 | } |
| 131 | |
| 132 | template <typename T> |
| 133 | using NEGEMMFixture = GEMMValidationFixture<Tensor, Accessor, NEGEMM, T>; |
| 134 | |
| 135 | TEST_SUITE(Float) |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 136 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 137 | TEST_SUITE(FP16) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 138 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<half>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallGEMMDataset(), framework::dataset::make("DataType", DataType::F16))) |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 139 | { |
| 140 | // Validate output |
| 141 | validate(Accessor(_target), _reference, tolerance_f); |
| 142 | } |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 143 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMDataset(), framework::dataset::make("DataType", |
| 144 | DataType::F16))) |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 145 | { |
| 146 | // Validate output |
| 147 | validate(Accessor(_target), _reference, tolerance_f); |
| 148 | } |
| 149 | TEST_SUITE_END() |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 150 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 151 | |
| 152 | TEST_SUITE(FP32) |
| 153 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallGEMMDataset(), framework::dataset::make("DataType", DataType::F32))) |
| 154 | { |
| 155 | // Validate output |
| 156 | validate(Accessor(_target), _reference, tolerance_f); |
| 157 | } |
| 158 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMDataset(), framework::dataset::make("DataType", DataType::F32))) |
| 159 | { |
| 160 | // Validate output |
| 161 | validate(Accessor(_target), _reference, tolerance_f); |
| 162 | } |
| 163 | TEST_SUITE_END() |
| 164 | TEST_SUITE_END() |
| 165 | |
| 166 | template <typename T> |
| 167 | using NEGEMMFixedPointFixture = GEMMValidationFixedPointFixture<Tensor, Accessor, NEGEMM, T>; |
| 168 | |
| 169 | TEST_SUITE(Quantized) |
| 170 | TEST_SUITE(QS8) |
| 171 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(), |
| 172 | framework::dataset::make("DataType", |
| 173 | DataType::QS8)), |
| 174 | framework::dataset::make("FractionalBits", 1, 7))) |
| 175 | { |
| 176 | // Validate output |
| 177 | validate(Accessor(_target), _reference, tolerance_q); |
| 178 | } |
| 179 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(), |
| 180 | framework::dataset::make("DataType", |
| 181 | DataType::QS8)), |
| 182 | framework::dataset::make("FractionalBits", 1, 7))) |
| 183 | { |
| 184 | // Validate output |
| 185 | validate(Accessor(_target), _reference, tolerance_q); |
| 186 | } |
| 187 | TEST_SUITE_END() |
| 188 | |
| 189 | TEST_SUITE(QS16) |
| 190 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(), |
| 191 | framework::dataset::make("DataType", |
| 192 | DataType::QS16)), |
| 193 | framework::dataset::make("FractionalBits", 1, 14))) |
| 194 | { |
| 195 | // Validate output |
| 196 | validate(Accessor(_target), _reference, tolerance_q); |
| 197 | } |
| 198 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(), |
| 199 | framework::dataset::make("DataType", |
| 200 | DataType::QS16)), |
| 201 | framework::dataset::make("FractionalBits", 1, 14))) |
| 202 | { |
| 203 | // Validate output |
| 204 | validate(Accessor(_target), _reference, tolerance_q); |
| 205 | } |
| 206 | TEST_SUITE_END() |
| 207 | TEST_SUITE_END() |
| 208 | |
| 209 | TEST_SUITE_END() |
| 210 | TEST_SUITE_END() |
| 211 | } // namespace validation |
| 212 | } // namespace test |
| 213 | } // namespace arm_compute |