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 | */ |
| 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" |
| 29 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 30 | #include "tests/datasets/LargeGEMMDataset.h" |
| 31 | #include "tests/datasets/SmallGEMMDataset.h" |
| 32 | #include "tests/framework/Asserts.h" |
| 33 | #include "tests/framework/Macros.h" |
| 34 | #include "tests/framework/datasets/Datasets.h" |
| 35 | #include "tests/validation/Validation.h" |
| 36 | #include "tests/validation/fixtures/GEMMFixture.h" |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
steniu01 | f81652d | 2017-09-11 15:29:12 +0100 | [diff] [blame] | 46 | RelativeTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for floating point data types */ |
| 47 | 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 */ |
| 48 | constexpr AbsoluteTolerance<float> tolerance_q(1.0f); /**< Tolerance value for comparing reference's output against implementation's output for fixed point data types */ |
| 49 | constexpr float tolerance_num = 0.02f; /**< Tolerance number */ |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 50 | |
| 51 | /** CNN data types */ |
| 52 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 53 | { |
| 54 | DataType::F16, |
| 55 | DataType::F32, |
| 56 | DataType::QS8, |
| 57 | DataType::QS16, |
| 58 | }); |
| 59 | } // namespace |
| 60 | |
| 61 | TEST_SUITE(CL) |
| 62 | TEST_SUITE(GEMM) |
| 63 | |
| 64 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallGEMMDataset(), datasets::LargeGEMMDataset()), CNNDataTypes), |
| 65 | shape_a, shape_b, shape_c, output_shape, alpha, beta, data_type) |
| 66 | { |
| 67 | // Set fixed point position data type allowed |
| 68 | const int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0; |
| 69 | |
| 70 | // Create tensors |
| 71 | CLTensor a = create_tensor<CLTensor>(shape_a, data_type, 1, fixed_point_position); |
| 72 | CLTensor b = create_tensor<CLTensor>(shape_b, data_type, 1, fixed_point_position); |
| 73 | CLTensor c = create_tensor<CLTensor>(shape_c, data_type, 1, fixed_point_position); |
| 74 | CLTensor dst = create_tensor<CLTensor>(output_shape, data_type, 1, fixed_point_position); |
| 75 | |
| 76 | ARM_COMPUTE_EXPECT(a.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 77 | ARM_COMPUTE_EXPECT(b.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 78 | ARM_COMPUTE_EXPECT(c.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 79 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 80 | |
| 81 | // Create and configure function |
| 82 | CLGEMM gemm; |
| 83 | gemm.configure(&a, &b, &c, &dst, alpha, beta); |
| 84 | |
| 85 | //TODO(COMPMID-415): Validate valid region |
| 86 | } |
| 87 | |
| 88 | template <typename T> |
| 89 | using CLGEMMFixture = GEMMValidationFixture<CLTensor, CLAccessor, CLGEMM, T>; |
| 90 | |
| 91 | TEST_SUITE(Float) |
| 92 | TEST_SUITE(FP16) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 93 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixture<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] | 94 | { |
| 95 | // Validate output |
steniu01 | f81652d | 2017-09-11 15:29:12 +0100 | [diff] [blame] | 96 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num); |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 97 | } |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 98 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMDataset(), framework::dataset::make("DataType", |
| 99 | DataType::F16))) |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 100 | { |
| 101 | // Validate output |
steniu01 | f81652d | 2017-09-11 15:29:12 +0100 | [diff] [blame] | 102 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num); |
Moritz Pflanzer | 4dfc235 | 2017-08-02 14:51:36 +0100 | [diff] [blame] | 103 | } |
| 104 | TEST_SUITE_END() |
| 105 | |
| 106 | TEST_SUITE(FP32) |
| 107 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallGEMMDataset(), framework::dataset::make("DataType", DataType::F32))) |
| 108 | { |
| 109 | // Validate output |
| 110 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 111 | } |
| 112 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeGEMMDataset(), framework::dataset::make("DataType", DataType::F32))) |
| 113 | { |
| 114 | // Validate output |
| 115 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 116 | } |
| 117 | TEST_SUITE_END() |
| 118 | TEST_SUITE_END() |
| 119 | |
| 120 | template <typename T> |
| 121 | using CLGEMMFixedPointFixture = GEMMValidationFixedPointFixture<CLTensor, CLAccessor, CLGEMM, T>; |
| 122 | |
| 123 | TEST_SUITE(Quantized) |
| 124 | TEST_SUITE(QS8) |
| 125 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(), |
| 126 | framework::dataset::make("DataType", |
| 127 | DataType::QS8)), |
| 128 | framework::dataset::make("FractionalBits", 1, 7))) |
| 129 | { |
| 130 | // Validate output |
| 131 | validate(CLAccessor(_target), _reference, tolerance_q); |
| 132 | } |
| 133 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(), |
| 134 | framework::dataset::make("DataType", |
| 135 | DataType::QS8)), |
| 136 | framework::dataset::make("FractionalBits", 1, 7))) |
| 137 | { |
| 138 | // Validate output |
| 139 | validate(CLAccessor(_target), _reference, tolerance_q); |
| 140 | } |
| 141 | TEST_SUITE_END() |
| 142 | |
| 143 | TEST_SUITE(QS16) |
| 144 | FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallGEMMDataset(), |
| 145 | framework::dataset::make("DataType", |
| 146 | DataType::QS16)), |
| 147 | framework::dataset::make("FractionalBits", 1, 14))) |
| 148 | { |
| 149 | // Validate output |
| 150 | validate(CLAccessor(_target), _reference, tolerance_q); |
| 151 | } |
| 152 | FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeGEMMDataset(), |
| 153 | framework::dataset::make("DataType", |
| 154 | DataType::QS16)), |
| 155 | framework::dataset::make("FractionalBits", 1, 14))) |
| 156 | { |
| 157 | // Validate output |
| 158 | validate(CLAccessor(_target), _reference, tolerance_q); |
| 159 | } |
| 160 | TEST_SUITE_END() |
| 161 | TEST_SUITE_END() |
| 162 | |
| 163 | TEST_SUITE_END() |
| 164 | TEST_SUITE_END() |
| 165 | } // namespace validation |
| 166 | } // namespace test |
| 167 | } // namespace arm_compute |