Sanghoon Lee | fc35b51 | 2017-10-18 12:09:04 +0100 | [diff] [blame] | 1 | /* |
Frederick Liardet | 36dff9f | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2021 Arm Limited. |
Sanghoon Lee | fc35b51 | 2017-10-18 12:09:04 +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 | #include "arm_compute/core/Types.h" |
| 25 | #include "arm_compute/runtime/CL/functions/CLRemap.h" |
| 26 | #include "arm_compute/runtime/Tensor.h" |
| 27 | #include "arm_compute/runtime/TensorAllocator.h" |
| 28 | #include "tests/CL/CLAccessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
| 30 | #include "tests/datasets/BorderModeDataset.h" |
| 31 | #include "tests/datasets/ShapeDatasets.h" |
| 32 | #include "tests/framework/Asserts.h" |
| 33 | #include "tests/framework/Macros.h" |
| 34 | #include "tests/framework/datasets/Datasets.h" |
| 35 | #include "tests/validation/Validation.h" |
| 36 | #include "tests/validation/fixtures/RemapFixture.h" |
| 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
| 46 | constexpr AbsoluteTolerance<uint8_t> tolerance_value(1); |
Sanghoon Lee | fc35b51 | 2017-10-18 12:09:04 +0100 | [diff] [blame] | 47 | } // namespace |
| 48 | |
| 49 | TEST_SUITE(CL) |
| 50 | TEST_SUITE(Remap) |
Freddie Liardet | ef5aac6 | 2021-06-10 16:45:58 +0100 | [diff] [blame] | 51 | |
| 52 | // *INDENT-OFF* |
| 53 | // clang-format off |
| 54 | |
| 55 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip( |
| 56 | framework::dataset::make("input", { TensorInfo(TensorShape(10U, 10U), 1, DataType::U8, DataLayout::NCHW), |
| 57 | TensorInfo(TensorShape(10U, 10U), 1, DataType::U8, DataLayout::NHWC), |
| 58 | TensorInfo(TensorShape(10U, 10U), 1, DataType::F16, DataLayout::NCHW), |
| 59 | TensorInfo(TensorShape(10U, 10U), 1, DataType::F16, DataLayout::NHWC) |
| 60 | }), |
| 61 | framework::dataset::make("map_x", { TensorInfo(TensorShape(10U, 10U), 1, DataType::F32, DataLayout::NCHW), |
| 62 | TensorInfo(TensorShape(10U, 10U), 1, DataType::F32, DataLayout::NHWC), |
| 63 | TensorInfo(TensorShape(10U, 10U), 1, DataType::F32, DataLayout::NCHW), |
| 64 | TensorInfo(TensorShape(10U, 10U), 1, DataType::F32, DataLayout::NHWC) |
| 65 | |
| 66 | })), |
| 67 | framework::dataset::make("map_y", { TensorInfo(TensorShape(10U, 10U), 1, DataType::F32, DataLayout::NCHW), |
| 68 | TensorInfo(TensorShape(10U, 10U), 1, DataType::F32, DataLayout::NHWC), |
| 69 | TensorInfo(TensorShape(10U, 10U), 1, DataType::F32, DataLayout::NCHW), |
| 70 | TensorInfo(TensorShape(10U, 10U), 1, DataType::F32, DataLayout::NHWC) |
| 71 | })), |
| 72 | framework::dataset::make("output", { TensorInfo(TensorShape(10U, 10U), 1, DataType::U8, DataLayout::NCHW), |
| 73 | TensorInfo(TensorShape(10U, 10U), 1, DataType::U8, DataLayout::NHWC), |
| 74 | TensorInfo(TensorShape(10U, 10U), 1, DataType::F16, DataLayout::NCHW), |
| 75 | TensorInfo(TensorShape(10U, 10U), 1, DataType::F16, DataLayout::NHWC) |
| 76 | })), |
| 77 | framework::dataset::make("policy",{ InterpolationPolicy::NEAREST_NEIGHBOR, |
| 78 | InterpolationPolicy::NEAREST_NEIGHBOR, |
| 79 | InterpolationPolicy::NEAREST_NEIGHBOR, |
| 80 | InterpolationPolicy::NEAREST_NEIGHBOR |
| 81 | })), |
| 82 | framework::dataset::make("border_mode",{ BorderMode::CONSTANT, |
| 83 | BorderMode::CONSTANT, |
| 84 | BorderMode::CONSTANT, |
| 85 | BorderMode::CONSTANT |
| 86 | })), |
| 87 | framework::dataset::make("Expected", { true, // NCHW, U8 |
| 88 | true, // NHWC, U8 |
| 89 | false, // NCHW, F16 |
| 90 | true // NHWC, F16 |
| 91 | })), |
| 92 | input, map_x, map_y, output, policy, border_mode, expected) |
| 93 | { |
| 94 | ARM_COMPUTE_EXPECT(bool(CLRemap::validate(&input, &map_x, &map_y, &output, policy, border_mode, PixelValue{})) == expected, framework::LogLevel::ERRORS); |
| 95 | } |
| 96 | // clang-format on |
| 97 | // *INDENT-ON* |
Sanghoon Lee | fc35b51 | 2017-10-18 12:09:04 +0100 | [diff] [blame] | 98 | template <typename T> |
| 99 | using CLRemapFixture = RemapValidationFixture<CLTensor, CLAccessor, CLRemap, T>; |
Frederick Liardet | 36dff9f | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 100 | template <typename T> |
| 101 | using CLRemapLayoutFixture = RemapValidationMixedLayoutFixture<CLTensor, CLAccessor, CLRemap, T>; |
Sanghoon Lee | fc35b51 | 2017-10-18 12:09:04 +0100 | [diff] [blame] | 102 | |
Freddie Liardet | ef5aac6 | 2021-06-10 16:45:58 +0100 | [diff] [blame] | 103 | TEST_SUITE(U8) |
| 104 | FIXTURE_DATA_TEST_CASE(RunSmall, CLRemapLayoutFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(), |
| 105 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
| 106 | framework::dataset::make("DataType", DataType::U8)), |
| 107 | framework::dataset::make("BorderModes", { BorderMode::UNDEFINED, BorderMode::CONSTANT })), |
| 108 | framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC }))) |
Sanghoon Lee | fc35b51 | 2017-10-18 12:09:04 +0100 | [diff] [blame] | 109 | { |
| 110 | // Validate output |
Frederick Liardet | 36dff9f | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 111 | validate(CLAccessor(_target), _reference, _valid_mask, tolerance_value); |
Sanghoon Lee | fc35b51 | 2017-10-18 12:09:04 +0100 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | FIXTURE_DATA_TEST_CASE(RunLarge, CLRemapFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
Frederick Liardet | 36dff9f | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 115 | framework::dataset::make("DataType", DataType::U8)), |
Sanghoon Lee | fc35b51 | 2017-10-18 12:09:04 +0100 | [diff] [blame] | 116 | framework::dataset::make("BorderModes", { BorderMode::UNDEFINED, BorderMode::CONSTANT }))) |
| 117 | { |
| 118 | // Validate output |
Frederick Liardet | 36dff9f | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 119 | validate(CLAccessor(_target), _reference, _valid_mask, tolerance_value); |
Sanghoon Lee | fc35b51 | 2017-10-18 12:09:04 +0100 | [diff] [blame] | 120 | } |
Freddie Liardet | ef5aac6 | 2021-06-10 16:45:58 +0100 | [diff] [blame] | 121 | TEST_SUITE_END() // U8 |
Sanghoon Lee | fc35b51 | 2017-10-18 12:09:04 +0100 | [diff] [blame] | 122 | |
Freddie Liardet | ef5aac6 | 2021-06-10 16:45:58 +0100 | [diff] [blame] | 123 | TEST_SUITE(F16) |
| 124 | FIXTURE_DATA_TEST_CASE(RunSmall, CLRemapLayoutFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(), |
| 125 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
| 126 | framework::dataset::make("DataType", DataType::F16)), |
| 127 | framework::dataset::make("BorderModes", { BorderMode::UNDEFINED, BorderMode::CONSTANT })), |
| 128 | framework::dataset::make("DataLayout", DataLayout::NHWC))) |
| 129 | { |
| 130 | // Validate output |
| 131 | validate(CLAccessor(_target), _reference, _valid_mask, tolerance_value); |
| 132 | } |
| 133 | TEST_SUITE_END() // F16 |
Sanghoon Lee | fc35b51 | 2017-10-18 12:09:04 +0100 | [diff] [blame] | 134 | TEST_SUITE_END() |
| 135 | TEST_SUITE_END() |
| 136 | } // namespace validation |
| 137 | } // namespace test |
| 138 | } // namespace arm_compute |