Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 1 | /* |
Gian Marco Iodice | 1e6c915 | 2019-08-20 11:27:20 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [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, |
Gian Marco Iodice | 1e6c915 | 2019-08-20 11:27:20 +0100 | [diff] [blame] | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 22 | * SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | #include "arm_compute/core/Types.h" |
| 26 | #include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h" |
| 27 | #include "arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h" |
| 28 | #include "arm_compute/runtime/GLES_COMPUTE/functions/GCConvolutionLayer.h" |
| 29 | #include "tests/GLES_COMPUTE/GCAccessor.h" |
| 30 | #include "tests/PaddingCalculator.h" |
| 31 | #include "tests/datasets/LargeConvolutionLayerDataset.h" |
| 32 | #include "tests/datasets/SmallConvolutionLayerDataset.h" |
| 33 | #include "tests/framework/Asserts.h" |
| 34 | #include "tests/framework/Macros.h" |
| 35 | #include "tests/framework/datasets/Datasets.h" |
| 36 | #include "tests/validation/Validation.h" |
| 37 | #include "tests/validation/fixtures/ConvolutionLayerFixture.h" |
| 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
| 45 | namespace |
| 46 | { |
| 47 | RelativeTolerance<half_float::half> tolerance_f16(half_float::half(0.2)); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F16 */ |
Michele Di Giorgio | fc1d1e2 | 2018-04-10 14:24:35 +0100 | [diff] [blame] | 48 | RelativeTolerance<float> tolerance_f32(0.00001f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */ |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 49 | constexpr float tolerance_num = 0.07f; /**< Tolerance number */ |
| 50 | |
| 51 | /** CNN data types */ |
| 52 | const auto CNNDataTypes = framework::dataset::make("DataType", |
| 53 | { |
| 54 | DataType::F16, |
Michele Di Giorgio | fc1d1e2 | 2018-04-10 14:24:35 +0100 | [diff] [blame] | 55 | DataType::F32, |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 56 | }); |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 57 | const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo", |
| 58 | { |
| 59 | ActivationLayerInfo(), |
| 60 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU), |
| 61 | ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.5f) |
| 62 | }); |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 63 | } // namespace |
| 64 | |
| 65 | TEST_SUITE(GC) |
| 66 | TEST_SUITE(ConvolutionLayer) |
| 67 | |
Gian Marco Iodice | 1e6c915 | 2019-08-20 11:27:20 +0100 | [diff] [blame] | 68 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(datasets::SmallConvolutionLayerReducedDataset(), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 69 | CNNDataTypes), |
| 70 | ActivationFunctionsDataset), |
| 71 | input_shape, weights_shape, bias_shape, output_shape, info, dilation, data_type, act_info) |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 72 | { |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 73 | auto bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type; |
| 74 | |
| 75 | // Create tensors |
Vidhya Sudhan Loganathan | 014333d | 2018-07-02 09:13:49 +0100 | [diff] [blame] | 76 | GCTensor src = create_tensor<GCTensor>(input_shape, data_type, 1, QuantizationInfo(2.f / 255.f, 127)); |
| 77 | GCTensor weights = create_tensor<GCTensor>(weights_shape, data_type, 1, QuantizationInfo(2.f / 255.f, 127)); |
| 78 | GCTensor bias = create_tensor<GCTensor>(bias_shape, bias_data_type, 1, QuantizationInfo(2.f / 255.f, 127)); |
| 79 | GCTensor dst = create_tensor<GCTensor>(output_shape, data_type, 1, QuantizationInfo(2.f / 255.f, 127)); |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 80 | |
| 81 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 82 | ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 83 | ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 84 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 85 | |
| 86 | const QuantizationInfo src_quantization_info = src.info()->quantization_info(); |
| 87 | const QuantizationInfo weights_quantization_info = weights.info()->quantization_info(); |
| 88 | |
| 89 | // Create and configure function |
| 90 | GCConvolutionLayer conv; |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 91 | conv.configure(&src, &weights, &bias, &dst, info, WeightsInfo(), dilation, act_info); |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 92 | |
| 93 | // Validate valid region |
| 94 | const ValidRegion src_valid_region = shape_to_valid_region(input_shape); |
| 95 | const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape); |
| 96 | const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape); |
| 97 | const ValidRegion dst_valid_region = shape_to_valid_region(output_shape); |
| 98 | |
| 99 | validate(src.info()->valid_region(), src_valid_region); |
| 100 | validate(weights.info()->valid_region(), weights_valid_region); |
| 101 | validate(bias.info()->valid_region(), bias_valid_region); |
| 102 | validate(dst.info()->valid_region(), dst_valid_region); |
| 103 | |
| 104 | // Validate QuantizationInfo |
| 105 | ARM_COMPUTE_EXPECT(src.info()->quantization_info() == src_quantization_info, framework::LogLevel::ERRORS); |
| 106 | ARM_COMPUTE_EXPECT(weights.info()->quantization_info() == weights_quantization_info, framework::LogLevel::ERRORS); |
| 107 | |
| 108 | //Validate padding |
| 109 | //TODO(COMPMID-415) Need to validate padding? |
| 110 | } |
| 111 | |
| 112 | template <typename T> |
| 113 | using GCConvolutionLayerFixture = ConvolutionValidationFixture<GCTensor, GCAccessor, GCConvolutionLayer, T>; |
| 114 | |
| 115 | TEST_SUITE(Float) |
| 116 | TEST_SUITE(FP16) |
Gian Marco Iodice | 3139f03 | 2018-11-05 14:26:32 +0000 | [diff] [blame] | 117 | FIXTURE_DATA_TEST_CASE(RunSmall, GCConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallConvolutionLayerReducedDataset(), |
Michele Di Giorgio | 164b65d | 2018-04-13 14:28:08 +0100 | [diff] [blame] | 118 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 119 | framework::dataset::make("DataType", |
| 120 | DataType::F16)), |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 121 | framework::dataset::make("DataLayout", |
| 122 | DataLayout::NCHW)), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 123 | ActivationFunctionsDataset)) |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 124 | { |
| 125 | // Validate output |
| 126 | validate(GCAccessor(_target), _reference, tolerance_f16, tolerance_num); |
| 127 | } |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 128 | FIXTURE_DATA_TEST_CASE(RunLarge, GCConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeConvolutionLayerDataset(), |
Michele Di Giorgio | 164b65d | 2018-04-13 14:28:08 +0100 | [diff] [blame] | 129 | framework::dataset::make("ReshapeWeights", { true })), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 130 | framework::dataset::make("DataType", |
| 131 | DataType::F16)), |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 132 | framework::dataset::make("DataLayout", |
| 133 | DataLayout::NCHW)), |
Isabella Gottardi | 3f217ec | 2018-02-12 14:59:19 +0000 | [diff] [blame] | 134 | ActivationFunctionsDataset)) |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 135 | { |
| 136 | // Validate output |
| 137 | validate(GCAccessor(_target), _reference, tolerance_f16, tolerance_num); |
| 138 | } |
| 139 | TEST_SUITE_END() |
Michele Di Giorgio | fc1d1e2 | 2018-04-10 14:24:35 +0100 | [diff] [blame] | 140 | |
| 141 | TEST_SUITE(FP32) |
Gian Marco Iodice | 3139f03 | 2018-11-05 14:26:32 +0000 | [diff] [blame] | 142 | FIXTURE_DATA_TEST_CASE(RunSmall, GCConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallConvolutionLayerReducedDataset(), |
Michele Di Giorgio | 164b65d | 2018-04-13 14:28:08 +0100 | [diff] [blame] | 143 | framework::dataset::make("ReshapeWeights", { true })), |
Michele Di Giorgio | fc1d1e2 | 2018-04-10 14:24:35 +0100 | [diff] [blame] | 144 | framework::dataset::make("DataType", DataType::F32)), |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 145 | framework::dataset::make("DataLayout", |
| 146 | DataLayout::NCHW)), |
Michele Di Giorgio | fc1d1e2 | 2018-04-10 14:24:35 +0100 | [diff] [blame] | 147 | ActivationFunctionsDataset)) |
| 148 | { |
| 149 | // Validate output |
| 150 | validate(GCAccessor(_target), _reference, tolerance_f32, tolerance_num); |
| 151 | } |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 152 | FIXTURE_DATA_TEST_CASE(RunLarge, GCConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeConvolutionLayerDataset(), |
Michele Di Giorgio | 164b65d | 2018-04-13 14:28:08 +0100 | [diff] [blame] | 153 | framework::dataset::make("ReshapeWeights", { true })), |
Michele Di Giorgio | fc1d1e2 | 2018-04-10 14:24:35 +0100 | [diff] [blame] | 154 | framework::dataset::make("DataType", DataType::F32)), |
Michalis Spyrou | e250389 | 2018-04-23 15:17:31 +0100 | [diff] [blame] | 155 | framework::dataset::make("DataLayout", |
| 156 | DataLayout::NCHW)), |
Michele Di Giorgio | fc1d1e2 | 2018-04-10 14:24:35 +0100 | [diff] [blame] | 157 | ActivationFunctionsDataset)) |
| 158 | { |
| 159 | // Validate output |
| 160 | validate(GCAccessor(_target), _reference, tolerance_f32, tolerance_num); |
| 161 | } |
| 162 | TEST_SUITE_END() |
Anthony Barbier | 51b074a | 2018-02-20 12:09:07 +0000 | [diff] [blame] | 163 | TEST_SUITE_END() |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 164 | |
| 165 | TEST_SUITE_END() |
| 166 | TEST_SUITE_END() |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 167 | } // namespace validation |
| 168 | } // namespace test |
| 169 | } // namespace arm_compute |