Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 Arm Limited. |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +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/GLES_COMPUTE/GCTensor.h" |
| 26 | #include "arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h" |
| 27 | #include "arm_compute/runtime/GLES_COMPUTE/functions/GCFullyConnectedLayer.h" |
| 28 | #include "tests/GLES_COMPUTE/GCAccessor.h" |
| 29 | #include "tests/GLES_COMPUTE/Helper.h" |
| 30 | #include "tests/PaddingCalculator.h" |
| 31 | #include "tests/datasets/FullyConnectedLayerDataset.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/FullyConnectedLayerFixture.h" |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
| 46 | /** Tolerance for float operations */ |
Michele Di Giorgio | b71d224 | 2019-11-25 14:22:31 +0000 | [diff] [blame] | 47 | constexpr RelativeTolerance<float> rel_tolerance_f32(0.05f); |
| 48 | constexpr AbsoluteTolerance<float> abs_tolerance_f32(0.0001f); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 49 | RelativeTolerance<half_float::half> tolerance_f16(half(0.2)); |
| 50 | constexpr float tolerance_num = 0.07f; /**< Tolerance number */ |
| 51 | |
| 52 | /** CNN data types */ |
| 53 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 54 | { |
| 55 | DataType::F16, |
| 56 | DataType::F32, |
| 57 | }); |
| 58 | |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 59 | const auto FullyConnectedParameters = combine(framework::dataset::make("TransposeWeights", { false, true }), framework::dataset::make("ReshapeWeights", { false, true })); |
| 60 | const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo", ActivationLayerInfo()); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 61 | } // namespace |
| 62 | |
| 63 | TEST_SUITE(GC) |
| 64 | TEST_SUITE(FullyConnectedLayer) |
| 65 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 66 | template <typename T> |
Giorgio Arena | a855af1 | 2018-07-16 17:20:38 +0100 | [diff] [blame] | 67 | using GCFullyConnectedLayerFixture = FullyConnectedLayerValidationFixture<GCTensor, GCAccessor, GCFullyConnectedLayer, T>; |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 68 | |
| 69 | TEST_SUITE(Float) |
| 70 | TEST_SUITE(FP16) |
Michalis Spyrou | cac09dc | 2020-11-24 00:16:49 +0000 | [diff] [blame] | 71 | FIXTURE_DATA_TEST_CASE(RunSmall, GCFullyConnectedLayerFixture<half_float::half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SmallFullyConnectedLayerDataset(), |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 72 | FullyConnectedParameters), |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 73 | framework::dataset::make("DataType", DataType::F16)), |
| 74 | ActivationFunctionsDataset)) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 75 | { |
| 76 | // Validate output |
| 77 | validate(GCAccessor(_target), _reference, tolerance_f16, tolerance_num); |
| 78 | } |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 79 | FIXTURE_DATA_TEST_CASE(RunLarge, GCFullyConnectedLayerFixture<half_float::half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeFullyConnectedLayerDataset(), |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 80 | FullyConnectedParameters), |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 81 | framework::dataset::make("DataType", DataType::F16)), |
| 82 | ActivationFunctionsDataset)) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 83 | { |
| 84 | // Validate output |
| 85 | validate(GCAccessor(_target), _reference, tolerance_f16, tolerance_num); |
| 86 | } |
| 87 | TEST_SUITE_END() |
| 88 | |
| 89 | TEST_SUITE(FP32) |
Michalis Spyrou | cac09dc | 2020-11-24 00:16:49 +0000 | [diff] [blame] | 90 | FIXTURE_DATA_TEST_CASE(RunSmall, GCFullyConnectedLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::SmallFullyConnectedLayerDataset(), FullyConnectedParameters), |
| 91 | framework::dataset::make("DataType", DataType::F32)), |
| 92 | ActivationFunctionsDataset)) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 93 | { |
| 94 | // Validate output |
Michele Di Giorgio | b71d224 | 2019-11-25 14:22:31 +0000 | [diff] [blame] | 95 | validate(GCAccessor(_target), _reference, rel_tolerance_f32); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 96 | } |
Giorgio Arena | 1856ff7 | 2020-02-07 13:46:45 +0000 | [diff] [blame] | 97 | FIXTURE_DATA_TEST_CASE(RunLarge, GCFullyConnectedLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeFullyConnectedLayerDataset(), FullyConnectedParameters), |
| 98 | framework::dataset::make("DataType", DataType::F32)), |
| 99 | ActivationFunctionsDataset)) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 100 | { |
| 101 | // Validate output |
Michele Di Giorgio | b71d224 | 2019-11-25 14:22:31 +0000 | [diff] [blame] | 102 | validate(GCAccessor(_target), _reference, rel_tolerance_f32, 0, abs_tolerance_f32); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 103 | } |
| 104 | TEST_SUITE_END() |
| 105 | TEST_SUITE_END() |
| 106 | |
| 107 | TEST_SUITE_END() |
| 108 | TEST_SUITE_END() |
| 109 | } // namespace validation |
| 110 | } // namespace test |
| 111 | } // namespace arm_compute |