Gian Marco Iodice | 761c8d0 | 2019-06-10 14:46:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 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/runtime/CL/functions/CLFuseBatchNormalization.h" |
| 25 | #include "tests/CL/CLAccessor.h" |
| 26 | #include "tests/Globals.h" |
| 27 | #include "tests/datasets/ShapeDatasets.h" |
| 28 | #include "tests/framework/Macros.h" |
| 29 | #include "tests/framework/datasets/Datasets.h" |
| 30 | #include "tests/validation/Validation.h" |
| 31 | #include "tests/validation/fixtures/FuseBatchNormalizationFixture.h" |
| 32 | |
| 33 | namespace arm_compute |
| 34 | { |
| 35 | namespace test |
| 36 | { |
| 37 | namespace validation |
| 38 | { |
| 39 | namespace |
| 40 | { |
| 41 | AbsoluteTolerance<float> absolute_tolerance_f32(0.001f); |
| 42 | AbsoluteTolerance<float> absolute_tolerance_f16(0.2f); |
| 43 | } // namespace |
| 44 | |
| 45 | template <typename T> |
| 46 | using CLFuseBatchNormalizationConvFixture = FuseBatchNormalizationFixture<CLTensor, CLAccessor, CLFuseBatchNormalization, 4, T>; |
| 47 | |
| 48 | // *INDENT-OFF* |
| 49 | // clang-format off |
| 50 | |
| 51 | /** Shapes to test - Precommit */ |
| 52 | const auto shape_conv_values_precommit = concat(datasets::Small4DShapes(), datasets::Small3DShapes()); |
| 53 | |
| 54 | /** Shapes to test - Nightly */ |
| 55 | const auto shape_conv_values_nightly = concat(datasets::Large4DShapes(), datasets::Large3DShapes()); |
| 56 | |
| 57 | /** Data layout to test */ |
| 58 | const auto data_layout_values = framework::dataset::make("DataLayout", { DataLayout::NHWC, DataLayout::NCHW }); |
| 59 | |
| 60 | /** In-place flags to test */ |
| 61 | const auto in_place_values = framework::dataset::make("InPlace", { true, false }); |
| 62 | |
| 63 | /** With bias flags to test */ |
| 64 | const auto with_bias_values = framework::dataset::make("WithBias", { true, false }); |
| 65 | |
| 66 | /** With gamma flags to test */ |
| 67 | const auto with_gamma_values = framework::dataset::make("WithGamma", { true, false }); |
| 68 | |
| 69 | /** With beta flags to test */ |
| 70 | const auto with_beta_values = framework::dataset::make("WithBeta", { true, false }); |
| 71 | |
| 72 | TEST_SUITE(CL) |
| 73 | TEST_SUITE(FuseBatchNormalization) |
| 74 | TEST_SUITE(Convolution) |
| 75 | TEST_SUITE(Float) |
| 76 | TEST_SUITE(FP32) |
| 77 | FIXTURE_DATA_TEST_CASE(RunSmall, CLFuseBatchNormalizationConvFixture<float>, framework::DatasetMode::PRECOMMIT, |
| 78 | combine(combine(combine(combine(combine(combine( |
| 79 | shape_conv_values_precommit, |
| 80 | framework::dataset::make("DataType", { DataType::F32 })), |
| 81 | data_layout_values), |
| 82 | in_place_values), |
| 83 | with_bias_values), |
| 84 | with_gamma_values), |
| 85 | with_beta_values)) |
| 86 | { |
| 87 | // Validate outputs |
| 88 | validate(CLAccessor(_target_w), _reference_w, absolute_tolerance_f32); |
| 89 | validate(CLAccessor(_target_b), _reference_b, absolute_tolerance_f32); |
| 90 | } |
| 91 | |
| 92 | FIXTURE_DATA_TEST_CASE(RunLarge, CLFuseBatchNormalizationConvFixture<float>, framework::DatasetMode::NIGHTLY, |
| 93 | combine(combine(combine(combine(combine(combine( |
| 94 | shape_conv_values_nightly, |
| 95 | framework::dataset::make("DataType", { DataType::F32 })), |
| 96 | data_layout_values), |
| 97 | in_place_values), |
| 98 | with_bias_values), |
| 99 | with_gamma_values), |
| 100 | with_beta_values)) |
| 101 | { |
| 102 | // Validate outputs |
| 103 | validate(CLAccessor(_target_w), _reference_w, absolute_tolerance_f32); |
| 104 | validate(CLAccessor(_target_b), _reference_b, absolute_tolerance_f32); |
| 105 | } |
| 106 | |
| 107 | TEST_SUITE_END() // FP32 |
| 108 | |
| 109 | TEST_SUITE(FP16) |
| 110 | FIXTURE_DATA_TEST_CASE(RunSmall, CLFuseBatchNormalizationConvFixture<half>, framework::DatasetMode::PRECOMMIT, |
| 111 | combine(combine(combine(combine(combine(combine( |
| 112 | shape_conv_values_precommit, |
| 113 | framework::dataset::make("DataType", { DataType::F16 })), |
| 114 | data_layout_values), |
| 115 | in_place_values), |
| 116 | with_bias_values), |
| 117 | with_gamma_values), |
| 118 | with_beta_values)) |
| 119 | { |
| 120 | // Validate outputs |
| 121 | validate(CLAccessor(_target_w), _reference_w, absolute_tolerance_f16); |
| 122 | validate(CLAccessor(_target_b), _reference_b, absolute_tolerance_f16); |
| 123 | } |
| 124 | |
| 125 | FIXTURE_DATA_TEST_CASE(RunLarge, CLFuseBatchNormalizationConvFixture<half>, framework::DatasetMode::NIGHTLY, |
| 126 | combine(combine(combine(combine(combine(combine( |
| 127 | shape_conv_values_nightly, |
| 128 | framework::dataset::make("DataType", { DataType::F16 })), |
| 129 | data_layout_values), |
| 130 | in_place_values), |
| 131 | with_bias_values), |
| 132 | with_gamma_values), |
| 133 | with_beta_values)) |
| 134 | { |
| 135 | // Validate outputs |
| 136 | validate(CLAccessor(_target_w), _reference_w, absolute_tolerance_f16); |
| 137 | validate(CLAccessor(_target_b), _reference_b, absolute_tolerance_f16); |
| 138 | } |
| 139 | |
| 140 | TEST_SUITE_END() // FP16 |
| 141 | TEST_SUITE_END() // Float |
| 142 | TEST_SUITE_END() // Convolution |
| 143 | TEST_SUITE_END() // FuseBatchNormalization |
| 144 | TEST_SUITE_END() // CL |
| 145 | } // namespace validation |
| 146 | } // namespace test |
| 147 | } // namespace arm_compute |