Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 1 | /* |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +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 | */ |
| 24 | #include "arm_compute/core/Types.h" |
| 25 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 26 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
| 27 | #include "arm_compute/runtime/CL/functions/CLGEMM.h" |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 28 | #include "tests/CL/CLAccessor.h" |
Pablo Tello | 1d1c026 | 2017-12-08 16:02:38 +0000 | [diff] [blame] | 29 | #include "tests/CL/Helper.h" |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 30 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 31 | #include "tests/datasets/LargeGEMMDataset.h" |
| 32 | #include "tests/datasets/SmallGEMMDataset.h" |
Anthony Barbier | 1c0d0ff | 2018-01-31 13:05:09 +0000 | [diff] [blame] | 33 | #include "tests/datasets/TinyGEMMDataset.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 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" |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 39 | |
| 40 | namespace arm_compute |
| 41 | { |
| 42 | namespace test |
| 43 | { |
| 44 | namespace validation |
| 45 | { |
| 46 | namespace |
| 47 | { |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 48 | RelativeTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for floating point data types */ |
| 49 | constexpr float abs_tolerance_f32( |
| 50 | 0.0001f); /**< Absolute tolerance value for comparing reference's output against implementation's output for floating point data types in case using relative tolerance fails because of small values */ |
steniu01 | f81652d | 2017-09-11 15:29:12 +0100 | [diff] [blame] | 51 | RelativeTolerance<half_float::half> tolerance_f16(half(0.2)); /**< Tolerance value for comparing reference's output against implementation's output for floating point data types */ |
SiCong Li | 6bc4e96 | 2020-12-03 12:52:28 +0000 | [diff] [blame] | 52 | constexpr float tolerance_num = 0.02f; /**< Tolerance number */ |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 53 | |
| 54 | /** CNN data types */ |
| 55 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 56 | { |
| 57 | DataType::F16, |
| 58 | DataType::F32, |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 59 | }); |
| 60 | } // namespace |
| 61 | |
| 62 | TEST_SUITE(CL) |
| 63 | TEST_SUITE(GEMM) |
| 64 | |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 65 | template <typename T> |
| 66 | using CLGEMMFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T>; |
| 67 | |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 68 | template <typename T> |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 69 | using CLGEMMOutput3DFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T, false, false, true>; |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 70 | |
| 71 | template <typename T> |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 72 | using CLGEMMInputOutput3DFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T, false, true, true>; |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 73 | |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 74 | TEST_SUITE(Float) |
| 75 | TEST_SUITE(FP16) |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 76 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(), |
| 77 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 78 | framework::dataset::make("DataType", DataType::F16))) |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 79 | { |
| 80 | // Validate output |
steniu01 | f81652d | 2017-09-11 15:29:12 +0100 | [diff] [blame] | 81 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num); |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 82 | } |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 83 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(), |
| 84 | framework::dataset::make("ReshapeWeights", { true })), |
| 85 | framework::dataset::make("DataType", DataType::F16))) |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 86 | { |
| 87 | // Validate output |
steniu01 | f81652d | 2017-09-11 15:29:12 +0100 | [diff] [blame] | 88 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num); |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 89 | } |
| 90 | TEST_SUITE_END() |
| 91 | |
| 92 | TEST_SUITE(FP32) |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 93 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(), |
| 94 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 95 | framework::dataset::make("DataType", DataType::F32))) |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 96 | { |
| 97 | // Validate output |
| 98 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 99 | } |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 100 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(), |
| 101 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 102 | framework::dataset::make("DataType", DataType::F32))) |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 103 | { |
| 104 | // Validate output |
Michele Di Giorgio | ff6c260 | 2018-02-26 15:22:16 +0000 | [diff] [blame] | 105 | validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32); |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 106 | } |
| 107 | TEST_SUITE_END() |
| 108 | TEST_SUITE_END() |
| 109 | |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 110 | TEST_SUITE(INPUT_OUTPUT_3D) |
Isabella Gottardi | 8e74f44 | 2018-03-01 16:42:00 +0000 | [diff] [blame] | 111 | TEST_SUITE(Float) |
| 112 | TEST_SUITE(FP32) |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 113 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMInputOutput3DFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMInputOutput3DDataset(), |
| 114 | framework::dataset::make("ReshapeWeights", { true, false })), |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 115 | framework::dataset::make("DataType", DataType::F32))) |
Isabella Gottardi | 8e74f44 | 2018-03-01 16:42:00 +0000 | [diff] [blame] | 116 | { |
| 117 | // Validate output |
| 118 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 119 | } |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 120 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMInputOutput3DFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMInputOutput3DDataset(), |
| 121 | framework::dataset::make("ReshapeWeights", { true, false })), |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 122 | framework::dataset::make("DataType", DataType::F32))) |
Isabella Gottardi | 8e74f44 | 2018-03-01 16:42:00 +0000 | [diff] [blame] | 123 | { |
| 124 | // Validate output |
| 125 | validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32); |
| 126 | } |
| 127 | TEST_SUITE_END() // FP32 |
| 128 | |
| 129 | TEST_SUITE(FP16) |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 130 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMInputOutput3DFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMInputOutput3DDataset(), |
| 131 | framework::dataset::make("ReshapeWeights", { true, false })), |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 132 | framework::dataset::make("DataType", DataType::F16))) |
Isabella Gottardi | 8e74f44 | 2018-03-01 16:42:00 +0000 | [diff] [blame] | 133 | { |
| 134 | // Validate output |
| 135 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num); |
| 136 | } |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 137 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMInputOutput3DFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMInputOutput3DDataset(), |
| 138 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 139 | framework::dataset::make("DataType", DataType::F16))) |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 140 | { |
| 141 | // Validate output |
| 142 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num); |
| 143 | } |
| 144 | TEST_SUITE_END() // FP16 |
| 145 | |
| 146 | TEST_SUITE_END() // Float |
| 147 | TEST_SUITE_END() // INPUT_OUTPUT_3D |
| 148 | |
| 149 | TEST_SUITE(OUTPUT_3D) |
| 150 | TEST_SUITE(Float) |
| 151 | TEST_SUITE(FP32) |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 152 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMOutput3DFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMOutput3DDataset(), |
| 153 | framework::dataset::make("ReshapeWeights", { true, false })), |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 154 | framework::dataset::make("DataType", DataType::F32))) |
| 155 | { |
| 156 | // Validate output |
| 157 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 158 | } |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 159 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMOutput3DFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMOutput3DDataset(), |
| 160 | framework::dataset::make("ReshapeWeights", { true, false })), |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 161 | framework::dataset::make("DataType", DataType::F32))) |
| 162 | { |
| 163 | // Validate output |
| 164 | validate(CLAccessor(_target), _reference, tolerance_f32, 0.f, abs_tolerance_f32); |
| 165 | } |
| 166 | TEST_SUITE_END() // FP32 |
| 167 | |
| 168 | TEST_SUITE(FP16) |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 169 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMOutput3DFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMOutput3DDataset(), |
| 170 | framework::dataset::make("ReshapeWeights", { true, false })), |
Gian Marco Iodice | 68a3f56 | 2018-07-26 11:44:03 +0100 | [diff] [blame] | 171 | framework::dataset::make("DataType", DataType::F16))) |
| 172 | { |
| 173 | // Validate output |
| 174 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num); |
| 175 | } |
Pablo Tello | 0e37b5c | 2018-10-30 11:18:37 +0000 | [diff] [blame] | 176 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMOutput3DFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMOutput3DDataset(), |
| 177 | framework::dataset::make("ReshapeWeights", { true, false })), |
| 178 | framework::dataset::make("DataType", DataType::F16))) |
Isabella Gottardi | 8e74f44 | 2018-03-01 16:42:00 +0000 | [diff] [blame] | 179 | { |
| 180 | // Validate output |
| 181 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num); |
| 182 | } |
| 183 | TEST_SUITE_END() // FP16 |
| 184 | |
| 185 | TEST_SUITE_END() // Float |
| 186 | TEST_SUITE_END() // OUTPUT_3D |
| 187 | |
| 188 | TEST_SUITE_END() // GEMM |
| 189 | TEST_SUITE_END() // CL |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 190 | } // namespace validation |
| 191 | } // namespace test |
| 192 | } // namespace arm_compute |