Mohammed Suhail Munshi | a18d85c | 2023-01-03 10:16:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023 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 | */ |
Adnan AlSinan | 2e6d659 | 2023-08-21 13:54:27 +0100 | [diff] [blame] | 24 | #ifdef ACL_INTERNAL_TEST_CKW_IN_DF |
Mohammed Suhail Munshi | a18d85c | 2023-01-03 10:16:16 +0000 | [diff] [blame] | 25 | #include "arm_compute/dynamic_fusion/sketch/gpu/operators/GpuPool2d.h" |
| 26 | |
| 27 | #include "tests/CL/CLAccessor.h" |
| 28 | #include "tests/datasets/ShapeDatasets.h" |
| 29 | #include "tests/datasets/dynamic_fusion/PoolingLayerDataset.h" |
| 30 | #include "tests/framework/Fixture.h" |
| 31 | #include "tests/framework/Macros.h" |
| 32 | #include "tests/framework/datasets/Datasets.h" |
| 33 | #include "tests/validation/Validation.h" |
| 34 | #include "tests/validation/fixtures/dynamic_fusion/gpu/cl/Pool2dFixture.h" |
| 35 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | namespace test |
| 39 | { |
| 40 | namespace validation |
| 41 | { |
| 42 | TEST_SUITE(CL) |
| 43 | TEST_SUITE(DYNAMIC_FUSION) |
| 44 | TEST_SUITE(POOL2D) |
| 45 | |
| 46 | constexpr AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for 32-bit floating-point type */ |
| 47 | constexpr AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit floating-point type */ |
| 48 | |
| 49 | const auto PoolingLayerDatasetFP = combine(combine(combine(combine(framework::dataset::make("PoolingType", { PoolingType::MAX, PoolingType::AVG }), framework::dataset::make("PoolingSize", { Size2D(2, 2), Size2D(3, 3) })), |
| 50 | framework::dataset::make("Pad", { Padding2D() })), |
| 51 | framework::dataset::make("Stride", { Size2D(1, 1), Size2D(2, 1), Size2D(5, 7) })), |
| 52 | framework::dataset::make("ExcludePadding", { true })); |
| 53 | |
| 54 | const auto pool_fp_mixed_precision_dataset = framework::dataset::make("FpMixedPrecision", { true, false }); |
| 55 | |
| 56 | template <typename T> |
| 57 | using DynamicFusionGpuPool2dFixture = DynamicFusionGpuPool2dValidationFixture<CLTensor, CLAccessor, GpuPool2d, T>; |
| 58 | |
| 59 | template <typename T> |
| 60 | using DFSpecialGpuPool2dFixture = DynamicFusionGpuPool2dSpecialValidationFixture<CLTensor, CLAccessor, GpuPool2d, T>; |
| 61 | |
| 62 | template <typename T> |
| 63 | using DFPoolMixedPrecisionFixture = DynamicFusionGpuPool2dMixedPrecisionValidationFixture<CLTensor, CLAccessor, GpuPool2d, T>; |
| 64 | // *INDENT-OFF* |
| 65 | // clang-format off |
| 66 | |
Jakub Sujak | e57eea3 | 2023-09-04 16:53:37 +0100 | [diff] [blame] | 67 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip( |
| 68 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(2U, 27U, 13U), 1, DataType::QASYMM8, DataLayout::NHWC), // Invalid parameters, unsupported pooling |
Mohammed Suhail Munshi | a18d85c | 2023-01-03 10:16:16 +0000 | [diff] [blame] | 69 | TensorInfo(TensorShape(5U, 15U, 13U), 1, DataType::F32, DataLayout::NHWC), // Valid Non-rectangular Global Pooling |
Mohammed Suhail Munshi | a18d85c | 2023-01-03 10:16:16 +0000 | [diff] [blame] | 70 | TensorInfo(TensorShape(5U, 13U, 13U), 1, DataType::QASYMM8, DataLayout::NHWC), // Invalid - Quantized not supported. |
| 71 | TensorInfo(TensorShape(5U, 13U, 13U), 1, DataType::F32, DataLayout::NHWC), // Valid global pooling |
| 72 | TensorInfo(TensorShape(13U, 13U, 5U), 1, DataType::F32, DataLayout::NCHW), // Unsupported data layout |
| 73 | }), |
Mohammed Suhail Munshi | a18d85c | 2023-01-03 10:16:16 +0000 | [diff] [blame] | 74 | framework::dataset::make("Pool2dAttributes", { |
Mohammed Suhail Munshi | a18d85c | 2023-01-03 10:16:16 +0000 | [diff] [blame] | 75 | Pool2dAttributes().pool_type(PoolingType::L2).pool_size(Size2D(3,3)).pad(Padding2D(0,0,0,0)).stride(Size2D(1,1)), |
| 76 | Pool2dAttributes().pool_type(PoolingType::AVG).pool_size(Size2D(15U, 13U)), |
Mohammed Suhail Munshi | a18d85c | 2023-01-03 10:16:16 +0000 | [diff] [blame] | 77 | Pool2dAttributes().pool_type(PoolingType::AVG).pool_size(Size2D(2,2)).pad(Padding2D()).stride(Size2D(1,1)), |
| 78 | Pool2dAttributes().pool_type(PoolingType::AVG).pool_size(Size2D(13U,13U)), |
| 79 | Pool2dAttributes().pool_type(PoolingType::AVG).pool_size(Size2D(13U,13U)), |
| 80 | })), |
Jakub Sujak | e57eea3 | 2023-09-04 16:53:37 +0100 | [diff] [blame] | 81 | framework::dataset::make("Expected", { false, true, false, true, false })), |
| 82 | input_info, pool2d_attr, expected) |
Mohammed Suhail Munshi | a18d85c | 2023-01-03 10:16:16 +0000 | [diff] [blame] | 83 | { |
| 84 | // Create a new workload sketch |
| 85 | auto cl_compile_ctx = CLKernelLibrary::get().get_compile_context(); |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame] | 86 | auto context = GpuWorkloadContext{ &cl_compile_ctx }; |
| 87 | GpuWorkloadSketch sketch{ &context }; |
Mohammed Suhail Munshi | a18d85c | 2023-01-03 10:16:16 +0000 | [diff] [blame] | 88 | |
| 89 | // Declare GpuPool2d settings |
| 90 | const GpuPool2dSettings &settings = GpuPool2dSettings().mixed_precision(false); |
| 91 | |
| 92 | // Validate Pool2d Configuration |
Viet-Hoa Do | 3fcf3dc | 2023-05-17 15:17:48 +0100 | [diff] [blame] | 93 | auto src_info = context.create_tensor_info(input_info); |
Adnan AlSinan | 2e6d659 | 2023-08-21 13:54:27 +0100 | [diff] [blame] | 94 | bool res = bool(GpuPool2d::validate_op(sketch, &src_info, pool2d_attr, settings)); |
Mohammed Suhail Munshi | a18d85c | 2023-01-03 10:16:16 +0000 | [diff] [blame] | 95 | ARM_COMPUTE_EXPECT(res == expected, framework::LogLevel::ERRORS); |
| 96 | } |
| 97 | |
| 98 | // clang-format on |
| 99 | // *INDENT-ON* |
| 100 | |
| 101 | TEST_SUITE(Float) |
| 102 | TEST_SUITE(FP32) |
| 103 | FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuPool2dFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallNoneUnitShapes(), PoolingLayerDatasetFP), |
| 104 | framework::dataset::make("DataType", DataType::F32))) |
| 105 | { |
| 106 | // Validate output |
| 107 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 108 | } |
| 109 | FIXTURE_DATA_TEST_CASE(RunLarge, DynamicFusionGpuPool2dFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), PoolingLayerDatasetFP), |
| 110 | framework::dataset::make("DataType", DataType::F32))) |
| 111 | { |
| 112 | // Validate output |
| 113 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 114 | } |
| 115 | FIXTURE_DATA_TEST_CASE(RunSpecial, DFSpecialGpuPool2dFixture<float>, framework::DatasetMode::ALL, combine(datasets::PoolingLayerDatasetSpecialDynamicFusion(), |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame] | 116 | framework::dataset::make("DataType", DataType::F32))) |
Mohammed Suhail Munshi | a18d85c | 2023-01-03 10:16:16 +0000 | [diff] [blame] | 117 | { |
| 118 | // Validate output |
| 119 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 120 | } |
| 121 | |
| 122 | TEST_SUITE(GlobalPooling) |
| 123 | FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuPool2dFixture<float>, framework::DatasetMode::ALL, |
| 124 | combine(combine(combine(combine(combine(combine( |
| 125 | framework::dataset::make("InputShape", { TensorShape(27U, 13U, 2U), |
| 126 | TensorShape(27U, 13U, 2U, 4U) |
| 127 | }), |
| 128 | framework::dataset::make("PoolingType", { PoolingType::AVG, PoolingType::MAX })), |
| 129 | framework::dataset::make("PoolingSize", { Size2D(27, 13) })), |
| 130 | framework::dataset::make("Pad", { Padding2D() })), |
| 131 | framework::dataset::make("Stride", { Size2D(1, 1) })), |
| 132 | framework::dataset::make("ExcludePadding", true)), |
| 133 | framework::dataset::make("DataType", DataType::F32))) |
| 134 | { |
| 135 | // Validate output |
| 136 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 137 | } |
| 138 | |
| 139 | FIXTURE_DATA_TEST_CASE(RunLarge, DynamicFusionGpuPool2dFixture<float>, framework::DatasetMode::NIGHTLY, |
| 140 | combine(combine(combine(combine(combine(combine( |
| 141 | framework::dataset::make("InputShape", { TensorShape(79U, 37U, 11U), |
| 142 | TensorShape(79U, 37U, 11U, 4U) |
| 143 | }), |
| 144 | framework::dataset::make("PoolingType", { PoolingType::AVG, PoolingType::MAX })), |
| 145 | framework::dataset::make("PoolingSize", { Size2D(79, 37) })), |
| 146 | framework::dataset::make("Pad", { Padding2D() })), |
| 147 | framework::dataset::make("Stride", { Size2D(1, 1) })), |
| 148 | framework::dataset::make("ExcludePadding", true)), |
| 149 | framework::dataset::make("DataType", DataType::F32))) |
| 150 | { |
| 151 | // Validate output |
| 152 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 153 | } |
| 154 | TEST_SUITE_END() // GlobalPooling |
| 155 | TEST_SUITE_END() // FP32 |
| 156 | |
| 157 | TEST_SUITE(FP16) |
| 158 | FIXTURE_DATA_TEST_CASE(RunSmall, DFPoolMixedPrecisionFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallNoneUnitShapes(), PoolingLayerDatasetFP), |
| 159 | framework::dataset::make("DataType", DataType::F16)), |
| 160 | pool_fp_mixed_precision_dataset)) |
| 161 | { |
| 162 | // Validate output |
| 163 | validate(CLAccessor(_target), _reference, tolerance_f16); |
| 164 | } |
| 165 | FIXTURE_DATA_TEST_CASE(RunLarge, DFPoolMixedPrecisionFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), PoolingLayerDatasetFP), |
| 166 | framework::dataset::make("DataType", DataType::F16)), |
| 167 | pool_fp_mixed_precision_dataset)) |
| 168 | { |
| 169 | // Validate output |
| 170 | validate(CLAccessor(_target), _reference, tolerance_f16); |
| 171 | } |
| 172 | |
| 173 | TEST_SUITE(GlobalPooling) |
| 174 | FIXTURE_DATA_TEST_CASE(RunSmall, DynamicFusionGpuPool2dFixture<half>, framework::DatasetMode::ALL, |
| 175 | combine(combine(combine(combine(combine(combine( |
| 176 | framework::dataset::make("InputShape", { TensorShape(27U, 13U, 2U), |
| 177 | TensorShape(27U, 13U, 2U, 4U) |
| 178 | }), |
| 179 | framework::dataset::make("PoolingType", { PoolingType::AVG, PoolingType::MAX })), |
| 180 | framework::dataset::make("PoolingSize", { Size2D(27, 13) })), |
| 181 | framework::dataset::make("Pad", { Padding2D() })), |
| 182 | framework::dataset::make("Stride", { Size2D(1, 1) })), |
| 183 | framework::dataset::make("ExcludePadding", true)), |
| 184 | framework::dataset::make("DataType", DataType::F16))) |
| 185 | { |
| 186 | // Validate output |
| 187 | validate(CLAccessor(_target), _reference, tolerance_f16); |
| 188 | } |
| 189 | |
| 190 | FIXTURE_DATA_TEST_CASE(RunLarge, DynamicFusionGpuPool2dFixture<half>, framework::DatasetMode::NIGHTLY, |
| 191 | combine(combine(combine(combine(combine(combine( |
| 192 | framework::dataset::make("InputShape", { TensorShape(79U, 37U, 11U), |
| 193 | TensorShape(79U, 37U, 11U, 4U) |
| 194 | }), |
| 195 | framework::dataset::make("PoolingType", { PoolingType::AVG, PoolingType::MAX })), |
| 196 | framework::dataset::make("PoolingSize", { Size2D(79, 37) })), |
| 197 | framework::dataset::make("Pad", { Padding2D() })), |
| 198 | framework::dataset::make("Stride", { Size2D(1, 1) })), |
| 199 | framework::dataset::make("ExcludePadding", true)), |
| 200 | framework::dataset::make("DataType", DataType::F16))) |
| 201 | { |
| 202 | // Validate output |
| 203 | validate(CLAccessor(_target), _reference, tolerance_f16); |
| 204 | } |
| 205 | TEST_SUITE_END() // GlobalPooling |
| 206 | TEST_SUITE_END() // FP16 |
| 207 | TEST_SUITE_END() // FLOAT |
| 208 | |
| 209 | TEST_SUITE_END() // POOL2D |
| 210 | TEST_SUITE_END() // DYNAMIC_FUSION |
| 211 | TEST_SUITE_END() // CL |
| 212 | } |
| 213 | } |
| 214 | } |
SiCong Li | 23882a9 | 2023-06-28 09:49:45 +0100 | [diff] [blame] | 215 | #endif // ACL_INTERNAL_TEST_CKW_IN_DF |