Giuseppe Rossini | d7647d4 | 2018-07-17 18:13:13 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2018 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/CLScheduler.h" |
| 25 | #include "arm_compute/runtime/CL/functions/CLPadLayer.h" |
| 26 | #include "tests/CL/CLAccessor.h" |
| 27 | #include "tests/Globals.h" |
| 28 | #include "tests/datasets/ShapeDatasets.h" |
| 29 | #include "tests/framework/Macros.h" |
| 30 | #include "tests/framework/datasets/Datasets.h" |
| 31 | #include "tests/validation/Validation.h" |
| 32 | #include "tests/validation/fixtures/PadLayerFixture.h" |
| 33 | #include "utils/TypePrinter.h" |
| 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | namespace test |
| 38 | { |
| 39 | namespace validation |
| 40 | { |
| 41 | namespace |
| 42 | { |
| 43 | const auto PaddingSizesDataset = framework::dataset::make("PaddingSize", { PaddingList{ { 0, 0 } }, |
| 44 | PaddingList{ { 1, 1 } }, |
| 45 | PaddingList{ { 1, 1 }, { 2, 2 } }, |
| 46 | PaddingList{ { 1, 1 }, { 1, 1 }, { 1, 1 }, { 1, 1 } }, |
| 47 | PaddingList{ { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 2 } }, |
| 48 | PaddingList{ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 1, 1 } } |
| 49 | }); |
| 50 | } // namespace |
| 51 | |
| 52 | TEST_SUITE(CL) |
| 53 | TEST_SUITE(Padding) |
| 54 | |
| 55 | // *INDENT-OFF* |
| 56 | // clang-format off |
| 57 | |
| 58 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 59 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data type input/output |
| 60 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching shapes |
| 61 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), |
| 62 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), |
| 63 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), |
| 64 | TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32) |
| 65 | }), |
| 66 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F16), |
| 67 | TensorInfo(TensorShape(28U, 11U, 2U), 1, DataType::F32), |
| 68 | TensorInfo(TensorShape(29U, 17U, 2U), 1, DataType::F32), |
| 69 | TensorInfo(TensorShape(29U, 15U, 4U, 3U), 1, DataType::F32), |
| 70 | TensorInfo(TensorShape(27U, 14U, 3U, 4U), 1, DataType::F32), |
| 71 | TensorInfo(TensorShape(32U, 13U, 2U, 3U), 1, DataType::F32) |
| 72 | })), |
| 73 | framework::dataset::make("PaddingSize", { PaddingList{{0, 0}}, |
| 74 | PaddingList{{1, 1}}, |
| 75 | PaddingList{{1, 1}, {2, 2}}, |
| 76 | PaddingList{{1,1}, {1,1}, {1,1}, {1,1}}, |
| 77 | PaddingList{{0,0}, {1,0}, {0,1}, {1,2}}, |
| 78 | PaddingList{{0,0}, {0,0}, {0,0}, {1,1}} |
| 79 | })), |
| 80 | framework::dataset::make("Expected", { false, false, true, true, true, true })), |
| 81 | input_info, output_info, padding, expected) |
| 82 | { |
| 83 | ARM_COMPUTE_EXPECT(bool(CLPadLayer::validate(&input_info.clone()->set_is_resizable(true), &output_info.clone()->set_is_resizable(true), padding)) == expected, framework::LogLevel::ERRORS); |
| 84 | } |
| 85 | |
| 86 | // clang-format on |
| 87 | // *INDENT-ON* |
| 88 | |
| 89 | template <typename T> |
| 90 | using CLPaddingFixture = PaddingFixture<CLTensor, CLAccessor, CLPadLayer, T>; |
| 91 | |
| 92 | TEST_SUITE(Float) |
| 93 | |
| 94 | TEST_SUITE(FP32) |
| 95 | |
| 96 | FIXTURE_DATA_TEST_CASE(RunPadding, CLPaddingFixture<float>, framework::DatasetMode::ALL, |
| 97 | combine( |
| 98 | combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::F32 })), |
| 99 | PaddingSizesDataset)) |
| 100 | { |
| 101 | // Validate output |
| 102 | validate(CLAccessor(_target), _reference); |
| 103 | } |
| 104 | |
| 105 | TEST_SUITE_END() // FP32 |
| 106 | |
| 107 | TEST_SUITE(FP16) |
| 108 | FIXTURE_DATA_TEST_CASE(RunPadding, CLPaddingFixture<half>, framework::DatasetMode::ALL, |
| 109 | combine( |
| 110 | combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::F16 })), |
| 111 | PaddingSizesDataset)) |
| 112 | { |
| 113 | // Validate output |
| 114 | validate(CLAccessor(_target), _reference); |
| 115 | } |
| 116 | TEST_SUITE_END() // FP16 |
| 117 | |
| 118 | TEST_SUITE_END() // Float |
| 119 | |
| 120 | TEST_SUITE(S8) |
| 121 | FIXTURE_DATA_TEST_CASE(RunPadding, CLPaddingFixture<int8_t>, framework::DatasetMode::ALL, |
| 122 | combine( |
| 123 | combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::S8 })), |
| 124 | PaddingSizesDataset)) |
| 125 | { |
| 126 | // Validate output |
| 127 | validate(CLAccessor(_target), _reference); |
| 128 | } |
| 129 | TEST_SUITE_END() // S8 |
| 130 | |
| 131 | TEST_SUITE_END() // Padding |
| 132 | TEST_SUITE_END() // CL |
| 133 | } // namespace validation |
| 134 | } // namespace test |
| 135 | } // namespace arm_compute |