blob: eff51a487c7d47fcfa76206c5e77c681d7b3c4fe [file] [log] [blame]
Michalis Spyrouceb889e2018-09-17 18:24:41 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 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
Manuel Bottini8481d832019-12-10 15:28:40 +000087TEST_SUITE(Float)
Michalis Spyrouceb889e2018-09-17 18:24:41 +010088template <typename T>
89using CLUpsampleLayerFixture = UpsampleLayerFixture<CLTensor, CLAccessor, CLUpsampleLayer, T>;
Michalis Spyrouceb889e2018-09-17 18:24:41 +010090TEST_SUITE(FP32)
91FIXTURE_DATA_TEST_CASE(RunSmall, CLUpsampleLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
92 framework::dataset::make("DataType", DataType::F32)),
93 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
94 framework::dataset::make("PadInfo", { Size2D(2, 2) })),
95 framework::dataset::make("UpsamplingPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR })))
96{
97 // Validate output
98 validate(CLAccessor(_target), _reference, tolerance);
99}
100TEST_SUITE_END() // FP32
101
102TEST_SUITE(FP16)
103
104FIXTURE_DATA_TEST_CASE(RunSmall, CLUpsampleLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
105 framework::dataset::make("DataType",
106 DataType::F16)),
107 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
108 framework::dataset::make("PadInfo", { Size2D(2, 2) })),
109 framework::dataset::make("UpsamplingPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR })))
110{
111 // Validate output
112 validate(CLAccessor(_target), _reference, tolerance);
113}
114
115TEST_SUITE_END() // FP16
116TEST_SUITE_END() // Float
117
Manuel Bottini8481d832019-12-10 15:28:40 +0000118TEST_SUITE(Quantized)
119template <typename T>
120using CLUpsampleLayerQuantizedFixture = UpsampleLayerQuantizedFixture<CLTensor, CLAccessor, CLUpsampleLayer, T>;
121TEST_SUITE(QASYMM8)
122FIXTURE_DATA_TEST_CASE(RunSmall, CLUpsampleLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(),
123 framework::dataset::make("DataType", DataType::QASYMM8)),
124 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
125 framework::dataset::make("PadInfo", { Size2D(2, 2) })),
126 framework::dataset::make("UpsamplingPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR })),
127 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 10) })))
128{
129 // Validate output
130 validate(CLAccessor(_target), _reference, tolerance);
131}
132TEST_SUITE_END() // QASYMM8
133TEST_SUITE(QASYMM8_SIGNED)
134FIXTURE_DATA_TEST_CASE(RunSmall, CLUpsampleLayerQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(),
135 framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
136 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
137 framework::dataset::make("PadInfo", { Size2D(2, 2) })),
138 framework::dataset::make("UpsamplingPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR })),
139 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 10) })))
140{
141 // Validate output
142 validate(CLAccessor(_target), _reference, tolerance);
143}
144TEST_SUITE_END() // QASYMM8_SIGNED
145TEST_SUITE_END() // Quantized
146
Michalis Spyrouceb889e2018-09-17 18:24:41 +0100147TEST_SUITE_END() // UpsampleLayer
148TEST_SUITE_END() // CL
149} // namespace validation
150} // namespace test
151} // namespace arm_compute