Michalis Spyrou | 5237e01 | 2018-01-17 09:40:27 +0000 | [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/core/Types.h" |
| 25 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 26 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
| 27 | #include "arm_compute/runtime/CL/functions/CLPermute.h" |
| 28 | #include "tests/CL/CLAccessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
| 30 | #include "tests/datasets/ShapeDatasets.h" |
| 31 | #include "tests/framework/Asserts.h" |
| 32 | #include "tests/framework/Macros.h" |
| 33 | #include "tests/framework/datasets/Datasets.h" |
| 34 | #include "tests/validation/Validation.h" |
| 35 | #include "tests/validation/fixtures/PermuteFixture.h" |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | namespace |
| 44 | { |
| 45 | const auto PermuteParametersSmall = combine(datasets::Small4DShapes(), |
| 46 | framework::dataset::make("PermutationVector", { PermutationVector(2U, 0U, 1U), PermutationVector(1U, 2U, 0U), PermutationVector(3U, 2U, 0U, 1U) })); |
| 47 | const auto PermuteParametersLarge = combine(datasets::Large4DShapes(), |
| 48 | framework::dataset::make("PermutationVector", { PermutationVector(2U, 0U, 1U), PermutationVector(1U, 2U, 0U), PermutationVector(3U, 2U, 0U, 1U) })); |
| 49 | } // namespace |
| 50 | TEST_SUITE(CL) |
| 51 | TEST_SUITE(Permute) |
| 52 | |
Isabella Gottardi | aad9f2c | 2018-02-21 11:51:23 +0000 | [diff] [blame] | 53 | // *INDENT-OFF* |
| 54 | // clang-format off |
| 55 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
Anthony Barbier | a8a4d9e | 2018-05-14 14:43:29 +0100 | [diff] [blame] | 56 | framework::dataset::make("InputInfo",{ |
Isabella Gottardi | aad9f2c | 2018-02-21 11:51:23 +0000 | [diff] [blame] | 57 | TensorInfo(TensorShape(7U, 7U, 5U, 3U), 1, DataType::U16), // permutation not supported |
| 58 | TensorInfo(TensorShape(7U, 7U, 5U, 3U), 1, DataType::U16), // permutation not supported |
| 59 | TensorInfo(TensorShape(7U, 7U, 5U, 3U), 1, DataType::U16), // permutation not supported |
| 60 | TensorInfo(TensorShape(1U, 7U), 1, DataType::U8), // invalid input size |
| 61 | TensorInfo(TensorShape(7U, 7U, 5U, 3U), 1, DataType::U16), // valid |
| 62 | TensorInfo(TensorShape(27U, 13U, 37U, 2U), 1, DataType::F32), // valid |
| 63 | TensorInfo(TensorShape(27U, 13U, 37U, 2U), 1, DataType::F32), // valid |
| 64 | TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::QASYMM8), // permutation not supported |
| 65 | TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::F32), // permutation not supported |
| 66 | TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::F32), // permutation not supported |
| 67 | TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::U16), // permutation not supported |
| 68 | }), |
Anthony Barbier | a8a4d9e | 2018-05-14 14:43:29 +0100 | [diff] [blame] | 69 | framework::dataset::make("OutputInfo", { |
| 70 | TensorInfo(TensorShape(5U, 7U, 7U, 3U), 1, DataType::U16), |
| 71 | TensorInfo(TensorShape(5U, 5U, 7U, 3U), 1, DataType::U16), |
Isabella Gottardi | aad9f2c | 2018-02-21 11:51:23 +0000 | [diff] [blame] | 72 | TensorInfo(TensorShape(7U, 7U, 7U, 3U), 1, DataType::U16), |
| 73 | TensorInfo(TensorShape(5U, 7U), 1, DataType::U8), |
Anthony Barbier | a8a4d9e | 2018-05-14 14:43:29 +0100 | [diff] [blame] | 74 | TensorInfo(TensorShape(5U, 7U, 7U, 3U), 1, DataType::U16), |
| 75 | TensorInfo(TensorShape(13U, 37U, 27U, 2U), 1, DataType::F32), |
| 76 | TensorInfo(TensorShape(2U, 37U, 27U, 13U), 1, DataType::F32), |
Isabella Gottardi | aad9f2c | 2018-02-21 11:51:23 +0000 | [diff] [blame] | 77 | TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::QASYMM8), |
| 78 | TensorInfo(TensorShape(128U, 64U, 21U, 2U), 1, DataType::F32), |
Anthony Barbier | a8a4d9e | 2018-05-14 14:43:29 +0100 | [diff] [blame] | 79 | TensorInfo(TensorShape(21U, 64U, 2U, 128U), 1, DataType::F32), |
| 80 | TensorInfo(TensorShape(2U, 21U, 64U, 128U), 1, DataType::U16), |
Isabella Gottardi | aad9f2c | 2018-02-21 11:51:23 +0000 | [diff] [blame] | 81 | })), |
Anthony Barbier | a8a4d9e | 2018-05-14 14:43:29 +0100 | [diff] [blame] | 82 | framework::dataset::make("PermutationVector", { |
Isabella Gottardi | aad9f2c | 2018-02-21 11:51:23 +0000 | [diff] [blame] | 83 | PermutationVector(2U, 1U, 0U), |
| 84 | PermutationVector(2U, 2U, 1U), |
| 85 | PermutationVector(1U, 1U, 1U), |
| 86 | PermutationVector(2U, 0U, 1U), |
Anthony Barbier | a8a4d9e | 2018-05-14 14:43:29 +0100 | [diff] [blame] | 87 | PermutationVector(2U, 0U, 1U), |
| 88 | PermutationVector(1U, 2U, 0U), |
| 89 | PermutationVector(3U, 2U, 0U, 1U), |
Isabella Gottardi | aad9f2c | 2018-02-21 11:51:23 +0000 | [diff] [blame] | 90 | PermutationVector(2U, 3U, 1U, 0U), |
| 91 | PermutationVector(1U, 1U, 1U, 1U), |
| 92 | PermutationVector(2U, 1U, 3U, 0U), |
| 93 | PermutationVector(3U, 2U, 1U, 0U), |
| 94 | })), |
| 95 | framework::dataset::make("Expected", { false, false, false, false, true, true, true, false, false, false, false })), |
| 96 | input_info, output_info, perm_vect, expected) |
| 97 | { |
| 98 | ARM_COMPUTE_EXPECT(bool(CLPermute::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), perm_vect)) == expected, framework::LogLevel::ERRORS); |
| 99 | } |
| 100 | // clang-format on |
| 101 | // *INDENT-ON* |
| 102 | |
Michalis Spyrou | 5237e01 | 2018-01-17 09:40:27 +0000 | [diff] [blame] | 103 | DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::Small4DShapes(), framework::dataset::make("DataType", { DataType::S8, DataType::U8, DataType::S16, DataType::U16, DataType::U32, DataType::S32, DataType::F16, DataType::F32 })), |
| 104 | shape, data_type) |
| 105 | { |
| 106 | // Define permutation vector |
| 107 | const PermutationVector perm(2U, 0U, 1U); |
| 108 | |
| 109 | // Permute shapes |
| 110 | TensorShape output_shape = shape; |
| 111 | permute(output_shape, perm); |
| 112 | |
| 113 | // Create tensors |
| 114 | CLTensor ref_src = create_tensor<CLTensor>(shape, data_type); |
| 115 | CLTensor dst = create_tensor<CLTensor>(output_shape, data_type); |
| 116 | |
| 117 | // Create and Configure function |
| 118 | CLPermute perm_func; |
| 119 | perm_func.configure(&ref_src, &dst, perm); |
| 120 | |
| 121 | // Validate valid region |
| 122 | const ValidRegion valid_region = shape_to_valid_region(output_shape); |
| 123 | validate(dst.info()->valid_region(), valid_region); |
| 124 | } |
| 125 | |
| 126 | template <typename T> |
| 127 | using CLPermuteFixture = PermuteValidationFixture<CLTensor, CLAccessor, CLPermute, T>; |
| 128 | |
| 129 | TEST_SUITE(U8) |
| 130 | FIXTURE_DATA_TEST_CASE(RunSmall, CLPermuteFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(PermuteParametersSmall, framework::dataset::make("DataType", DataType::U8))) |
| 131 | { |
| 132 | // Validate output |
| 133 | validate(CLAccessor(_target), _reference); |
| 134 | } |
| 135 | FIXTURE_DATA_TEST_CASE(RunLarge, CLPermuteFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(PermuteParametersLarge, framework::dataset::make("DataType", DataType::U8))) |
| 136 | { |
| 137 | // Validate output |
| 138 | validate(CLAccessor(_target), _reference); |
| 139 | } |
| 140 | TEST_SUITE_END() |
| 141 | |
| 142 | TEST_SUITE(U16) |
| 143 | FIXTURE_DATA_TEST_CASE(RunSmall, CLPermuteFixture<uint16_t>, framework::DatasetMode::PRECOMMIT, combine(PermuteParametersSmall, framework::dataset::make("DataType", DataType::U16))) |
| 144 | { |
| 145 | // Validate output |
| 146 | validate(CLAccessor(_target), _reference); |
| 147 | } |
| 148 | FIXTURE_DATA_TEST_CASE(RunLarge, CLPermuteFixture<uint16_t>, framework::DatasetMode::NIGHTLY, combine(PermuteParametersLarge, framework::dataset::make("DataType", DataType::U16))) |
| 149 | { |
| 150 | // Validate output |
| 151 | validate(CLAccessor(_target), _reference); |
| 152 | } |
| 153 | TEST_SUITE_END() |
| 154 | |
| 155 | TEST_SUITE(U32) |
| 156 | FIXTURE_DATA_TEST_CASE(RunSmall, CLPermuteFixture<uint32_t>, framework::DatasetMode::PRECOMMIT, combine(PermuteParametersSmall, framework::dataset::make("DataType", DataType::U32))) |
| 157 | { |
| 158 | // Validate output |
| 159 | validate(CLAccessor(_target), _reference); |
| 160 | } |
| 161 | FIXTURE_DATA_TEST_CASE(RunLarge, CLPermuteFixture<uint32_t>, framework::DatasetMode::NIGHTLY, combine(PermuteParametersLarge, framework::dataset::make("DataType", DataType::U32))) |
| 162 | { |
| 163 | // Validate output |
| 164 | validate(CLAccessor(_target), _reference); |
| 165 | } |
| 166 | TEST_SUITE_END() |
| 167 | |
| 168 | TEST_SUITE_END() |
| 169 | TEST_SUITE_END() |
| 170 | } // namespace validation |
| 171 | } // namespace test |
| 172 | } // namespace arm_compute |