Ramy Elgammal | 73f19af | 2022-10-23 11:44:49 +0100 | [diff] [blame] | 1 | /* |
SiCong Li | 5a63d1e | 2023-01-06 16:28:57 +0000 | [diff] [blame] | 2 | * Copyright (c) 2022-2023 Arm Limited. |
Ramy Elgammal | 73f19af | 2022-10-23 11:44:49 +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 | |
Ramy Elgammal | 73f19af | 2022-10-23 11:44:49 +0100 | [diff] [blame] | 25 | #include "tests/AssetsLibrary.h" |
| 26 | #include "tests/CL/CLAccessor.h" |
Ramy Elgammal | 73f19af | 2022-10-23 11:44:49 +0100 | [diff] [blame] | 27 | #include "tests/framework/Fixture.h" |
| 28 | #include "tests/framework/Macros.h" |
| 29 | #include "tests/framework/datasets/Datasets.h" |
| 30 | #include "tests/validation/Validation.h" |
| 31 | #include "tests/validation/reference/ConvolutionLayer.h" |
| 32 | |
| 33 | #include "tests/datasets/SmallConvolutionLayerDataset.h" |
| 34 | #include "tests/validation/fixtures/dynamic_fusion/gpu/cl/DirectConv2dFixture.h" |
| 35 | |
Ramy Elgammal | 73f19af | 2022-10-23 11:44:49 +0100 | [diff] [blame] | 36 | namespace arm_compute |
| 37 | { |
| 38 | namespace test |
| 39 | { |
| 40 | namespace validation |
| 41 | { |
SiCong Li | 5a63d1e | 2023-01-06 16:28:57 +0000 | [diff] [blame] | 42 | namespace |
| 43 | { |
SiCong Li | 54eafd8 | 2023-01-26 17:36:08 +0000 | [diff] [blame] | 44 | /** Tolerances from tests/validation/CL/DirectConvolutionLayer.cpp |
| 45 | */ |
SiCong Li | 5a63d1e | 2023-01-06 16:28:57 +0000 | [diff] [blame] | 46 | RelativeTolerance<float> tolerance_f32(0.05f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */ |
| 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 */ |
| 48 | constexpr float abs_tolerance_f32(0.0001f); /**< Absolute tolerance for FP32 tests*/ |
SiCong Li | 54eafd8 | 2023-01-26 17:36:08 +0000 | [diff] [blame] | 49 | constexpr float tolerance_num = 0.07f; /**< Tolerance number */ |
SiCong Li | 5a63d1e | 2023-01-06 16:28:57 +0000 | [diff] [blame] | 50 | } // namespace |
| 51 | |
Ramy Elgammal | 73f19af | 2022-10-23 11:44:49 +0100 | [diff] [blame] | 52 | TEST_SUITE(CL) |
| 53 | TEST_SUITE(DYNAMIC_FUSION) |
SiCong Li | 54eafd8 | 2023-01-26 17:36:08 +0000 | [diff] [blame] | 54 | /** Synced with tests/validation/CL/ConvolutionLayer.cpp |
| 55 | * |
| 56 | * Difference | Why the difference |
| 57 | * f32 tolerance here is smaller | To use the same tolerance as that of DirectConv2d; lowering tolerance is safe |
| 58 | * No quantized tests | Not supported yet |
| 59 | * No grouped CNN tests | Not supported yet |
| 60 | * No mixed layout tests | Not needed; only NHWC is supported |
Jakub Sujak | 0d27b2e | 2023-08-24 14:01:20 +0100 | [diff] [blame] | 61 | * No activation | Not needed in fusion |
SiCong Li | 54eafd8 | 2023-01-26 17:36:08 +0000 | [diff] [blame] | 62 | * No ValidateConvolutionMethod | Only a single method (direct conv2d) is supported |
| 63 | * No ReshapeWeights = true tests | Not applicable yet. This parameter only concerns gemm-based conv2d |
| 64 | * No RunSmallWithPadding tests | Padding is removed |
| 65 | * |
| 66 | */ |
Ramy Elgammal | 404462a | 2022-11-08 02:14:46 +0000 | [diff] [blame] | 67 | TEST_SUITE(CONV2D) |
Ramy Elgammal | 73f19af | 2022-10-23 11:44:49 +0100 | [diff] [blame] | 68 | |
Ramy Elgammal | 73f19af | 2022-10-23 11:44:49 +0100 | [diff] [blame] | 69 | template <typename T> |
| 70 | using DynamicFusionGpuConv2dFixture = DynamicFusionGpuConv2dValidationFixture<CLTensor, CLAccessor, GpuConv2d, T>; |
| 71 | TEST_SUITE(FP32) |
| 72 | FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuConv2dFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
Jakub Sujak | 0d27b2e | 2023-08-24 14:01:20 +0100 | [diff] [blame] | 73 | framework::dataset::make("DataType", DataType::F32)), framework::dataset::make("DataLayout", { DataLayout::NHWC })), framework::dataset::make("QuantizationInfo", QuantizationInfo()))) |
Ramy Elgammal | 73f19af | 2022-10-23 11:44:49 +0100 | [diff] [blame] | 74 | { |
| 75 | // Validate output |
| 76 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 77 | } |
| 78 | TEST_SUITE_END() // FP32 |
| 79 | |
Ramy Elgammal | 73f19af | 2022-10-23 11:44:49 +0100 | [diff] [blame] | 80 | TEST_SUITE(FP16) |
| 81 | FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuConv2dFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallConvolutionLayerDataset(), |
Jakub Sujak | 0d27b2e | 2023-08-24 14:01:20 +0100 | [diff] [blame] | 82 | framework::dataset::make("DataType", DataType::F16)), framework::dataset::make("DataLayout", { DataLayout::NHWC })), framework::dataset::make("QuantizationInfo", QuantizationInfo()))) |
Ramy Elgammal | 73f19af | 2022-10-23 11:44:49 +0100 | [diff] [blame] | 83 | { |
| 84 | // Validate output |
| 85 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num); |
| 86 | } |
| 87 | TEST_SUITE_END() // FP16 |
Ramy Elgammal | 73f19af | 2022-10-23 11:44:49 +0100 | [diff] [blame] | 88 | |
SiCong Li | 5a63d1e | 2023-01-06 16:28:57 +0000 | [diff] [blame] | 89 | // Tests for specific conv2d methods |
SiCong Li | 54eafd8 | 2023-01-26 17:36:08 +0000 | [diff] [blame] | 90 | /** Synced with tests/validation/CL/DirectConvolutionLayer.cpp |
| 91 | * |
| 92 | * Difference | Why the difference |
| 93 | * No quantized tests | Not supported yet |
| 94 | * No Invalid output size test | Not applicable. Output is removed from the interface |
| 95 | * No mixed layout/NCHW tests | Not needed; only NHWC is supported |
| 96 | * No activation tests | Not needed in fusion |
| 97 | */ |
SiCong Li | 5a63d1e | 2023-01-06 16:28:57 +0000 | [diff] [blame] | 98 | TEST_SUITE(DIRECT_CONV2D) |
| 99 | |
| 100 | // *INDENT-OFF* |
| 101 | // clang-format off |
| 102 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( |
| 103 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Invalid: Mismatching data type input/weights |
| 104 | TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Invalid: Mismatching input feature maps |
| 105 | TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Invalid weights dimensions |
| 106 | TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Unsupported biases size |
| 107 | TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Unsupported biases dimensions |
| 108 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, DataLayout::NCHW), // Unsupported data layout: NCHW |
| 109 | TensorInfo(TensorShape(2U, 32U, 16U), 1, DataType::QASYMM8, DataLayout::NHWC), // Unsupported data type: quantized |
| 110 | TensorInfo(TensorShape(2U, 32U, 16U), 1, DataType::F32, DataLayout::NHWC), |
| 111 | TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Arbitrary weight sizes for NHWC are supported |
| 112 | TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Non-rectangular weights dimensions for NHWC are supported |
| 113 | TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::F32, DataLayout::NHWC), // Strides > 2 for any kernel sizes for NHWC are supported |
| 114 | }), |
| 115 | framework::dataset::make("WeightsInfo",{ TensorInfo(TensorShape(2U, 3U, 3U, 4U), 1, DataType::F16, DataLayout::NHWC), |
| 116 | TensorInfo(TensorShape(3U, 3U, 3U, 4U), 1, DataType::F32, DataLayout::NHWC), |
| 117 | TensorInfo(TensorShape(2U, 3U, 3U, 4U, 3U), 1, DataType::F32, DataLayout::NHWC), |
| 118 | TensorInfo(TensorShape(2U, 3U, 3U, 4U), 1, DataType::F32, DataLayout::NHWC), |
| 119 | TensorInfo(TensorShape(2U, 3U, 3U, 4U), 1, DataType::F32, DataLayout::NHWC), |
| 120 | TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, DataLayout::NCHW), |
| 121 | TensorInfo(TensorShape(2U, 1U, 1U, 4U), 1, DataType::QASYMM8, DataLayout::NHWC), |
| 122 | TensorInfo(TensorShape(2U, 1U, 1U, 4U), 1, DataType::F32, DataLayout::NHWC), |
| 123 | TensorInfo(TensorShape(2U, 13U, 13U, 4U), 1, DataType::F32, DataLayout::NHWC), |
| 124 | TensorInfo(TensorShape(2U, 5U, 3U, 4U), 1, DataType::F32, DataLayout::NHWC), |
| 125 | TensorInfo(TensorShape(2U, 3U, 3U, 4U), 1, DataType::F32, DataLayout::NHWC), |
| 126 | })), |
| 127 | framework::dataset::make("BiasesInfo",{ TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC), |
| 128 | TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC), |
| 129 | TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC), |
| 130 | TensorInfo(TensorShape(3U), 1, DataType::F32, DataLayout::NHWC), |
| 131 | TensorInfo(TensorShape(4U, 2U), 1, DataType::F32, DataLayout::NHWC), |
| 132 | TensorInfo(TensorShape(25U), 1, DataType::F32, DataLayout::NCHW), |
| 133 | TensorInfo(TensorShape(4U), 1, DataType::QASYMM8, DataLayout::NHWC), |
| 134 | TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC), |
| 135 | TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC), |
| 136 | TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC), |
| 137 | TensorInfo(TensorShape(4U), 1, DataType::F32, DataLayout::NHWC), |
| 138 | })), |
| 139 | framework::dataset::make("Conv2dAttributes", { |
| 140 | Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}), |
| 141 | Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}), |
| 142 | Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}), |
| 143 | Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}), |
| 144 | Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}), |
| 145 | Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}), |
| 146 | Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}), |
| 147 | Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}), |
| 148 | Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}), |
| 149 | Conv2dAttributes().stride({1, 1}).pad({0, 0, 0, 0}), |
| 150 | Conv2dAttributes().stride({3, 3}).pad({0, 0, 0, 0}), |
| 151 | })), |
| 152 | framework::dataset::make("Expected", { false, false, false, false, false, false, false, true, true, true, true })), |
| 153 | input_info, weights_info, biases_info, conv2d_attrs, expected) |
| 154 | { |
| 155 | auto cl_compile_ctx = CLKernelLibrary::get().get_compile_context(); |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame] | 156 | auto context = GpuWorkloadContext{ &cl_compile_ctx }; |
| 157 | GpuWorkloadSketch sketch{ &context }; |
SiCong Li | 5a63d1e | 2023-01-06 16:28:57 +0000 | [diff] [blame] | 158 | |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame] | 159 | const TensorInfo sketch_input_info = context.create_tensor_info(input_info); |
| 160 | const TensorInfo sketch_weights_info = context.create_tensor_info(weights_info); |
| 161 | const TensorInfo sketch_biases_info = context.create_tensor_info(biases_info); |
SiCong Li | 5a63d1e | 2023-01-06 16:28:57 +0000 | [diff] [blame] | 162 | bool is_valid = bool(GpuConv2d::validate_op(sketch, &sketch_input_info, &sketch_weights_info, &sketch_biases_info, conv2d_attrs)); |
| 163 | ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS); |
| 164 | } |
| 165 | template <typename T> |
| 166 | using DynamicFusionGpuDirectConv2dFixture = DynamicFusionDirectConv2dValidationFixture<CLTensor, CLAccessor, GpuConv2d, T>; |
| 167 | |
| 168 | TEST_SUITE(FP16) |
| 169 | FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuDirectConv2dFixture<half>, framework::DatasetMode::PRECOMMIT, |
| 170 | combine(combine(combine(zip(zip(zip(zip(zip( |
| 171 | framework::dataset::make("InputShape", { TensorShape(27U, 13U, 23U), |
| 172 | TensorShape(19U, 5U, 16U, 4U), |
| 173 | TensorShape(13U, 5U, 17U, 2U), |
| 174 | TensorShape(32U, 37U, 13U) } ), |
| 175 | framework::dataset::make("StrideX", { 1, 3, 1, 1 })), |
| 176 | framework::dataset::make("StrideY", { 1, 3, 2, 1 })), |
| 177 | framework::dataset::make("PadX", { 1, 3, 0, 4 })), |
| 178 | framework::dataset::make("PadY", { 1, 3, 0, 4 })), |
| 179 | framework::dataset::make("KernelSize", { 3, 8, 1, 9 })), |
| 180 | framework::dataset::make("NumKernels", { 17, 3, 1, 19 })), |
| 181 | framework::dataset::make("DataType", DataType::F16)), |
| 182 | framework::dataset::make("DataLayout", DataLayout::NHWC))) |
| 183 | { |
| 184 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num); |
| 185 | } |
| 186 | |
| 187 | FIXTURE_DATA_TEST_CASE(RunLarge, DynamicFusionGpuDirectConv2dFixture<half>, framework::DatasetMode::NIGHTLY, |
| 188 | combine(combine(combine(zip(zip(zip(zip(zip( |
| 189 | framework::dataset::make("InputShape", { TensorShape(800U, 800U, 3U) } ), |
| 190 | framework::dataset::make("StrideX", { 1 })), |
| 191 | framework::dataset::make("StrideY", { 1 })), |
| 192 | framework::dataset::make("PadX", { 1 })), |
| 193 | framework::dataset::make("PadY", { 1 })), |
| 194 | framework::dataset::make("KernelSize", { 9 })), |
| 195 | framework::dataset::make("NumKernels", { 3 })), |
| 196 | framework::dataset::make("DataType", DataType::F16)), |
| 197 | framework::dataset::make("DataLayout", DataLayout::NHWC))) |
| 198 | { |
| 199 | validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num); |
| 200 | } |
| 201 | |
| 202 | TEST_SUITE_END() // FP16 |
| 203 | |
| 204 | TEST_SUITE(FP32) |
| 205 | FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuDirectConv2dFixture<float>, framework::DatasetMode::PRECOMMIT, |
| 206 | combine(combine(combine(zip(zip(zip(zip(zip( |
| 207 | framework::dataset::make("InputShape", { TensorShape(27U, 13U, 23U), |
| 208 | TensorShape(19U, 5U, 16U, 4U), |
| 209 | TensorShape(13U, 5U, 17U, 2U), |
| 210 | TensorShape(32U, 37U, 13U) } ), |
| 211 | framework::dataset::make("StrideX", { 1, 3, 1, 1 })), |
| 212 | framework::dataset::make("StrideY", { 1, 3, 2, 1 })), |
| 213 | framework::dataset::make("PadX", { 1, 3, 0, 4 })), |
| 214 | framework::dataset::make("PadY", { 1, 3, 0, 4 })), |
| 215 | framework::dataset::make("KernelSize", { 3, 8, 1, 9 })), |
| 216 | framework::dataset::make("NumKernels", { 17, 3, 1, 19 })), |
| 217 | framework::dataset::make("DataType", DataType::F32)), |
| 218 | framework::dataset::make("DataLayout", DataLayout::NHWC))) |
| 219 | { |
| 220 | validate(CLAccessor(_target), _reference, tolerance_f32, 0.0, abs_tolerance_f32); |
| 221 | } |
| 222 | |
| 223 | FIXTURE_DATA_TEST_CASE(RunLarge, DynamicFusionGpuDirectConv2dFixture<float>, framework::DatasetMode::NIGHTLY, |
| 224 | combine(combine(combine(zip(zip(zip(zip(zip( |
| 225 | framework::dataset::make("InputShape", { TensorShape(800U, 800U, 3U) } ), |
| 226 | framework::dataset::make("StrideX", { 1 })), |
| 227 | framework::dataset::make("StrideY", { 1 })), |
| 228 | framework::dataset::make("PadX", { 1 })), |
| 229 | framework::dataset::make("PadY", { 1 })), |
| 230 | framework::dataset::make("KernelSize", { 9 })), |
| 231 | framework::dataset::make("NumKernels", { 3 })), |
| 232 | framework::dataset::make("DataType", DataType::F32)), |
| 233 | framework::dataset::make("DataLayout", DataLayout::NHWC))) |
| 234 | { |
| 235 | validate(CLAccessor(_target), _reference, tolerance_f32, 0.0, abs_tolerance_f32); |
| 236 | } |
| 237 | // clang-format on |
| 238 | // *INDENT-ON* |
| 239 | |
| 240 | TEST_SUITE_END() // FP32 |
| 241 | TEST_SUITE_END() // DIRECT_CONV2D |
Ramy Elgammal | 404462a | 2022-11-08 02:14:46 +0000 | [diff] [blame] | 242 | TEST_SUITE_END() // CONV2D |
Ramy Elgammal | 73f19af | 2022-10-23 11:44:49 +0100 | [diff] [blame] | 243 | TEST_SUITE_END() // DYNAMIC_FUSION |
| 244 | TEST_SUITE_END() // CL |
| 245 | } // namespace validation |
| 246 | } // namespace test |
| 247 | } // namespace arm_compute |