Pablo Tello | 299025a | 2017-09-29 11:30:12 +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 | */ |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 24 | #include "arm_compute/core/NEON/kernels/NEGEMMInterleaveBlockedKernel.h" |
Pablo Tello | 181e651 | 2017-11-15 13:28:27 +0000 | [diff] [blame] | 25 | #include "arm_compute/core/NEON/kernels/arm64/NEGEMMLowpAArch64Kernel.h" |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/Types.h" |
Pablo Tello | 181e651 | 2017-11-15 13:28:27 +0000 | [diff] [blame] | 27 | #include "arm_compute/runtime/NEON/functions/NEGEMMLowpAssemblyMatrixMultiplyCore.h" |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 28 | #include "arm_compute/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCore.h" |
| 29 | #include "arm_compute/runtime/NEON/functions/NEGEMMLowpOutputStage.h" |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 30 | #include "arm_compute/runtime/Tensor.h" |
| 31 | #include "arm_compute/runtime/TensorAllocator.h" |
| 32 | #include "tests/NEON/Accessor.h" |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 33 | #include "tests/NEON/Helper.h" |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 34 | #include "tests/PaddingCalculator.h" |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 35 | #include "tests/datasets/LargeGEMMLowpDataset.h" |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 36 | #include "tests/datasets/ShapeDatasets.h" |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 37 | #include "tests/datasets/SmallGEMMLowpDataset.h" |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 38 | #include "tests/framework/Asserts.h" |
| 39 | #include "tests/framework/Macros.h" |
| 40 | #include "tests/framework/datasets/Datasets.h" |
| 41 | #include "tests/validation/Validation.h" |
Pablo Tello | bf2fb95 | 2017-09-29 16:43:25 +0100 | [diff] [blame] | 42 | #include "tests/validation/fixtures/GEMMInterleaveBlockedFixture.h" |
Pablo Tello | 181e651 | 2017-11-15 13:28:27 +0000 | [diff] [blame] | 43 | #include "tests/validation/fixtures/GEMMLowpAssemblyFixture.h" |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 44 | #include "tests/validation/fixtures/GEMMLowpFixture.h" |
| 45 | |
| 46 | namespace arm_compute |
| 47 | { |
| 48 | namespace test |
| 49 | { |
| 50 | namespace validation |
| 51 | { |
| 52 | namespace |
| 53 | { |
Pablo Tello | 181e651 | 2017-11-15 13:28:27 +0000 | [diff] [blame] | 54 | const auto data_int_blk = framework::dataset::make("M", 8, 12) * framework::dataset::make("N", 8, 12) * framework::dataset::make("by", 8, 13) * framework::dataset::make("block", 4, 9); |
| 55 | const auto data_int_blk_tr = framework::dataset::make("M", 8, 17) * framework::dataset::make("N", 8, 14) * framework::dataset::make("by", 12) * framework::dataset::make("block", 4); |
| 56 | const auto data_matrix_multiply = framework::dataset::make("M", 12, 20) * framework::dataset::make("N", 12, 20) * framework::dataset::make("K", 16); |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 57 | } // namespace |
| 58 | |
| 59 | TEST_SUITE(NEON) |
Pablo Tello | 181e651 | 2017-11-15 13:28:27 +0000 | [diff] [blame] | 60 | TEST_SUITE(ASSEMBLY_MATRIX_MULTIPLY) |
| 61 | using NEGEMMAssemblyFixture = GEMMLowpAssemblyFixture<Tensor, Accessor, NEGEMMLowpAssemblyMatrixMultiplyCore>; |
| 62 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMAssemblyFixture, framework::DatasetMode::PRECOMMIT, data_matrix_multiply) |
| 63 | { |
| 64 | // Validate output |
| 65 | validate(Accessor(_target), _reference); |
| 66 | } |
| 67 | TEST_SUITE_END() |
| 68 | |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 69 | TEST_SUITE(GEMMLowp) |
| 70 | |
Pablo Tello | bf2fb95 | 2017-09-29 16:43:25 +0100 | [diff] [blame] | 71 | TEST_SUITE(INTERLEAVE_BLOCKED) |
| 72 | |
| 73 | using NEInterleaveBlocked = NESynthetizeFunction<NEGEMMInterleaveBlockedKernel>; |
| 74 | using NEGEMMInterleaveBlockedFixture = GEMMInterleaveBlockedValidationFixture<Tensor, Accessor, NEInterleaveBlocked>; |
| 75 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleaveBlockedFixture, framework::DatasetMode::PRECOMMIT, data_int_blk) |
| 76 | { |
| 77 | // Validate output |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 78 | validate(Accessor(_target), _reference); |
Pablo Tello | bf2fb95 | 2017-09-29 16:43:25 +0100 | [diff] [blame] | 79 | } |
| 80 | TEST_SUITE_END() |
| 81 | |
| 82 | TEST_SUITE(INTERLEAVE_BLOCKED_TRANSPOSED) |
| 83 | using NEInterleaveBlockedTransposed = NESynthetizeFunction<NEGEMMInterleaveBlockedKernel>; |
| 84 | using NEGEMMInterleaveBlockedTransposedFixture = GEMMInterleaveBlockedValidationFixture<Tensor, Accessor, NEInterleaveBlockedTransposed, true>; |
| 85 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMInterleaveBlockedTransposedFixture, framework::DatasetMode::PRECOMMIT, data_int_blk_tr) |
| 86 | { |
| 87 | // Validate output |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 88 | validate(Accessor(_target), _reference); |
Pablo Tello | bf2fb95 | 2017-09-29 16:43:25 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | TEST_SUITE_END() |
| 92 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 93 | TEST_SUITE(MatrixMultiplyCore) |
| 94 | using NEGEMMLowpMatrixMultiplyCoreFixture = GEMMLowpMatrixMultiplyCoreValidationFixture<Tensor, Accessor, NEGEMMLowpMatrixMultiplyCore>; |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 95 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 96 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallGEMMLowpDataset(), datasets::LargeGEMMLowpDataset()), |
| 97 | shape_a, shape_b, shape_c, a_offset, b_offset) |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 98 | { |
| 99 | // Create tensors |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 100 | Tensor a = create_tensor<Tensor>(shape_a, DataType::QASYMM8); |
| 101 | Tensor b = create_tensor<Tensor>(shape_b, DataType::QASYMM8); |
| 102 | Tensor c = create_tensor<Tensor>(shape_c, DataType::S32); |
| 103 | |
| 104 | a.info()->set_quantization_info(QuantizationInfo(1.0f / 255, a_offset)); |
| 105 | b.info()->set_quantization_info(QuantizationInfo(1.0f / 255, b_offset)); |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 106 | |
| 107 | ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 108 | ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 109 | ARM_COMPUTE_EXPECT(c.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 110 | |
| 111 | // Create and configure function |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 112 | NEGEMMLowpMatrixMultiplyCore gemmlowp_mm; |
| 113 | gemmlowp_mm.configure(&a, &b, &c); |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 114 | } |
| 115 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 116 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::ALL, datasets::SmallGEMMLowpDataset()) |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 117 | { |
| 118 | // Validate output |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 119 | validate(Accessor(_target), _reference); |
| 120 | } |
| 121 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 122 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpMatrixMultiplyCoreFixture, framework::DatasetMode::NIGHTLY, datasets::LargeGEMMLowpDataset()) |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 123 | { |
| 124 | // Validate output |
| 125 | validate(Accessor(_target), _reference); |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 126 | } |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 127 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 128 | TEST_SUITE_END() // MatrixMultiplyCore |
| 129 | |
| 130 | TEST_SUITE(OutputStage) |
| 131 | |
| 132 | TEST_SUITE(QuantizeDownInt32ToUint8Scale) |
| 133 | |
| 134 | using NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture = GEMMLowpQuantizeDownInt32ToUint8ScaleValidationFixture<Tensor, Accessor, NEGEMMLowpQuantizeDownInt32ToUint8Scale>; |
| 135 | |
| 136 | const auto quantize_down_int32_to_uint8_scale_cases = framework::dataset::make("result_offset", -4, 4) * framework::dataset::make("result_mult_int", 1, 3) * framework::dataset::make("result_shift", 2, |
| 137 | 4); |
| 138 | |
| 139 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), quantize_down_int32_to_uint8_scale_cases), |
| 140 | shape, result_offset, result_mult_int, result_shift) |
| 141 | { |
| 142 | // Create tensors |
| 143 | Tensor in = create_tensor<Tensor>(shape, DataType::S32); |
| 144 | Tensor out = create_tensor<Tensor>(shape, DataType::QASYMM8); |
| 145 | |
| 146 | ARM_COMPUTE_EXPECT(in.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 147 | ARM_COMPUTE_EXPECT(out.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 148 | |
| 149 | // Create and configure function |
| 150 | NEGEMMLowpQuantizeDownInt32ToUint8Scale output_stage; |
| 151 | output_stage.configure(&in, &out, result_offset, result_mult_int, result_shift); |
| 152 | |
| 153 | // Validate valid region |
| 154 | const ValidRegion valid_region = shape_to_valid_region(shape); |
| 155 | validate(in.info()->valid_region(), valid_region); |
| 156 | validate(out.info()->valid_region(), valid_region); |
| 157 | |
| 158 | // Validate padding |
| 159 | const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding(); |
| 160 | validate(in.info()->padding(), padding); |
| 161 | validate(out.info()->padding(), padding); |
| 162 | } |
| 163 | |
| 164 | FIXTURE_DATA_TEST_CASE(RunSmall, NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), quantize_down_int32_to_uint8_scale_cases)) |
Pablo Tello | bf2fb95 | 2017-09-29 16:43:25 +0100 | [diff] [blame] | 165 | { |
| 166 | // Validate output |
Gian Marco | fa4cacd | 2017-10-18 17:05:02 +0100 | [diff] [blame] | 167 | validate(Accessor(_target), _reference); |
Pablo Tello | bf2fb95 | 2017-09-29 16:43:25 +0100 | [diff] [blame] | 168 | } |
Pablo Tello | 6ff12a0 | 2017-11-02 16:09:35 +0000 | [diff] [blame] | 169 | |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 170 | FIXTURE_DATA_TEST_CASE(RunLarge, NEGEMMLowpQuantizeDownInt32ToUint8ScaleFixture, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), quantize_down_int32_to_uint8_scale_cases)) |
| 171 | { |
| 172 | // Validate output |
| 173 | validate(Accessor(_target), _reference); |
| 174 | } |
| 175 | |
| 176 | TEST_SUITE_END() // QuantizeDownInt32ToUint8Scale |
| 177 | |
| 178 | TEST_SUITE_END() // OutputStage |
| 179 | |
| 180 | TEST_SUITE_END() // GEMMLowp |
| 181 | TEST_SUITE_END() // NEON |
Pablo Tello | 299025a | 2017-09-29 11:30:12 +0100 | [diff] [blame] | 182 | } // namespace validation |
| 183 | } // namespace test |
| 184 | } // namespace arm_compute |