blob: 7849d773942217a98f5d1a17d6b17e403cf5585b [file] [log] [blame]
Sanghoon Leefc35b512017-10-18 12:09:04 +01001/*
Frederick Liardet36dff9f2021-04-22 21:13:21 +01002 * Copyright (c) 2017-2021 Arm Limited.
Sanghoon Leefc35b512017-10-18 12:09:04 +01003 *
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
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46constexpr AbsoluteTolerance<uint8_t> tolerance_value(1);
Sanghoon Leefc35b512017-10-18 12:09:04 +010047} // namespace
48
49TEST_SUITE(CL)
50TEST_SUITE(Remap)
Freddie Liardetef5aac62021-06-10 16:45:58 +010051
52// *INDENT-OFF*
53// clang-format off
54
55DATA_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 Leefc35b512017-10-18 12:09:04 +010098template <typename T>
99using CLRemapFixture = RemapValidationFixture<CLTensor, CLAccessor, CLRemap, T>;
Frederick Liardet36dff9f2021-04-22 21:13:21 +0100100template <typename T>
101using CLRemapLayoutFixture = RemapValidationMixedLayoutFixture<CLTensor, CLAccessor, CLRemap, T>;
Sanghoon Leefc35b512017-10-18 12:09:04 +0100102
Freddie Liardetef5aac62021-06-10 16:45:58 +0100103TEST_SUITE(U8)
104FIXTURE_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 Leefc35b512017-10-18 12:09:04 +0100109{
110 // Validate output
Frederick Liardet36dff9f2021-04-22 21:13:21 +0100111 validate(CLAccessor(_target), _reference, _valid_mask, tolerance_value);
Sanghoon Leefc35b512017-10-18 12:09:04 +0100112}
113
114FIXTURE_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 Liardet36dff9f2021-04-22 21:13:21 +0100115 framework::dataset::make("DataType", DataType::U8)),
Sanghoon Leefc35b512017-10-18 12:09:04 +0100116 framework::dataset::make("BorderModes", { BorderMode::UNDEFINED, BorderMode::CONSTANT })))
117{
118 // Validate output
Frederick Liardet36dff9f2021-04-22 21:13:21 +0100119 validate(CLAccessor(_target), _reference, _valid_mask, tolerance_value);
Sanghoon Leefc35b512017-10-18 12:09:04 +0100120}
Freddie Liardetef5aac62021-06-10 16:45:58 +0100121TEST_SUITE_END() // U8
Sanghoon Leefc35b512017-10-18 12:09:04 +0100122
Freddie Liardetef5aac62021-06-10 16:45:58 +0100123TEST_SUITE(F16)
124FIXTURE_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}
133TEST_SUITE_END() // F16
Sanghoon Leefc35b512017-10-18 12:09:04 +0100134TEST_SUITE_END()
135TEST_SUITE_END()
136} // namespace validation
137} // namespace test
138} // namespace arm_compute