blob: f9b417fd2b645bc022f979c1ff39bf7f727bba4a [file] [log] [blame]
Michalis Spyrouceb889e2018-09-17 18:24:41 +01001/*
Michalis Spyrou80943252019-01-10 17:19:50 +00002 * Copyright (c) 2018-2019 ARM Limited.
Michalis Spyrouceb889e2018-09-17 18:24:41 +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/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
27#include "arm_compute/runtime/CL/functions/CLUpsampleLayer.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/UpsampleLayerFixture.h"
36
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
45constexpr AbsoluteTolerance<float> tolerance(0.001f);
46} // namespace
47
48TEST_SUITE(CL)
49TEST_SUITE(UpsampleLayer)
50
Michalis Spyrouceb889e2018-09-17 18:24:41 +010051// *INDENT-OFF*
52// clang-format off
53DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
54 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(10U, 10U, 2U), 1, DataType::F32), // Mismatching data type
55 TensorInfo(TensorShape(10U, 10U, 2U), 1, DataType::F32), // Invalid output shape
56 TensorInfo(TensorShape(10U, 10U, 2U), 1, DataType::F32), // Invalid stride
57 TensorInfo(TensorShape(10U, 10U, 2U), 1, DataType::F32), // Invalid policy
58 TensorInfo(TensorShape(10U, 10U, 2U), 1, DataType::F32),
59 }),
60 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(20U, 20U, 2U), 1, DataType::F16),
61 TensorInfo(TensorShape(20U, 10U, 2U), 1, DataType::F32),
62 TensorInfo(TensorShape(20U, 20U, 2U), 1, DataType::F32),
63 TensorInfo(TensorShape(20U, 20U, 2U), 1, DataType::F32),
64 TensorInfo(TensorShape(20U, 20U, 2U), 1, DataType::F32),
65 })),
66 framework::dataset::make("PadInfo", { Size2D(2, 2),
67 Size2D(2, 2),
68 Size2D(1, 1),
69 Size2D(2, 2),
70 Size2D(2, 2),
71 })),
72 framework::dataset::make("UpsamplingPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR,
73 InterpolationPolicy::NEAREST_NEIGHBOR,
74 InterpolationPolicy::NEAREST_NEIGHBOR,
75 InterpolationPolicy::BILINEAR,
76 InterpolationPolicy::NEAREST_NEIGHBOR,
77 })),
78 framework::dataset::make("Expected", { false, false, false, false, true })),
79 input_info, output_info, pad_info, upsampling_policy, expected)
80{
81 bool is_valid = bool(CLUpsampleLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), pad_info, upsampling_policy));
82 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
83}
84// clang-format on
85// *INDENT-ON*
86
87template <typename T>
88using CLUpsampleLayerFixture = UpsampleLayerFixture<CLTensor, CLAccessor, CLUpsampleLayer, T>;
89
90TEST_SUITE(Float)
91TEST_SUITE(FP32)
92FIXTURE_DATA_TEST_CASE(RunSmall, CLUpsampleLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
93 framework::dataset::make("DataType", DataType::F32)),
94 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
95 framework::dataset::make("PadInfo", { Size2D(2, 2) })),
96 framework::dataset::make("UpsamplingPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR })))
97{
98 // Validate output
99 validate(CLAccessor(_target), _reference, tolerance);
100}
101TEST_SUITE_END() // FP32
102
103TEST_SUITE(FP16)
104
105FIXTURE_DATA_TEST_CASE(RunSmall, CLUpsampleLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
106 framework::dataset::make("DataType",
107 DataType::F16)),
108 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
109 framework::dataset::make("PadInfo", { Size2D(2, 2) })),
110 framework::dataset::make("UpsamplingPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR })))
111{
112 // Validate output
113 validate(CLAccessor(_target), _reference, tolerance);
114}
115
116TEST_SUITE_END() // FP16
117TEST_SUITE_END() // Float
118
119TEST_SUITE_END() // UpsampleLayer
120TEST_SUITE_END() // CL
121} // namespace validation
122} // namespace test
123} // namespace arm_compute