blob: 4bfa08f0607966602e44b1837b12adda383c3c4b [file] [log] [blame]
Frank Lei57a150a2017-12-19 10:14:57 +08001/*
Diego Lopez Recasff860cf2018-02-22 13:08:01 +00002 * Copyright (c) 2017-2018 ARM Limited.
Frank Lei57a150a2017-12-19 10:14:57 +08003 *
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/Helpers.h"
25#include "arm_compute/core/Types.h"
26#include "arm_compute/runtime/GLES_COMPUTE/functions/GCScale.h"
27#include "arm_compute/runtime/Tensor.h"
28#include "arm_compute/runtime/TensorAllocator.h"
29#include "tests/GLES_COMPUTE/GCAccessor.h"
30#include "tests/PaddingCalculator.h"
31#include "tests/datasets/BorderModeDataset.h"
32#include "tests/datasets/SamplingPolicyDataset.h"
33#include "tests/datasets/ShapeDatasets.h"
34#include "tests/framework/Asserts.h"
35#include "tests/framework/Macros.h"
36#include "tests/framework/datasets/Datasets.h"
37#include "tests/validation/Helpers.h"
38#include "tests/validation/Validation.h"
39#include "tests/validation/fixtures/ScaleFixture.h"
40
41namespace arm_compute
42{
43namespace test
44{
45namespace validation
46{
47namespace
48{
49/** CNN data types */
50const auto ScaleDataTypes = framework::dataset::make("DataType",
51{
52 DataType::F16,
53});
54
55/** Tolerance */
56RelativeTolerance<half> tolerance_f16(half(0.1));
57} // namespace
58
59TEST_SUITE(GC)
60TEST_SUITE(Scale)
61
62DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(concat(datasets::MediumShapes(), datasets::LargeShapes()), ScaleDataTypes),
63 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR })),
64 datasets::BorderModes()),
65 datasets::SamplingPolicies()),
66 shape, data_type, policy, border_mode, sampling_policy)
67{
68 std::mt19937 generator(library->seed());
69 std::uniform_real_distribution<float> distribution_float(0.25, 2);
70 const float scale_x = distribution_float(generator);
71 const float scale_y = distribution_float(generator);
72 std::uniform_int_distribution<uint8_t> distribution_u8(0, 255);
73 uint8_t constant_border_value = distribution_u8(generator);
74
75 // Create tensors
76 GCTensor src = create_tensor<GCTensor>(shape, data_type);
77 TensorShape shape_scaled(shape);
78 shape_scaled.set(0, shape[0] * scale_x);
79 shape_scaled.set(1, shape[1] * scale_y);
80 GCTensor dst = create_tensor<GCTensor>(shape_scaled, data_type);
81
82 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
83 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
84
85 // Create and configure function
86 GCScale gcscale;
87 gcscale.configure(&src, &dst, policy, border_mode, constant_border_value, sampling_policy);
88
89 // Get border size depending on border mode
90 const BorderSize border_size(border_mode == BorderMode::UNDEFINED ? 0 : 1);
91
92 // Validate valid region
Diego Lopez Recas00854292018-02-22 13:08:01 +000093 const ValidRegion dst_valid_region = calculate_valid_region_scale(*(src.info()), shape_scaled, policy, sampling_policy, (border_mode == BorderMode::UNDEFINED));
Frank Lei57a150a2017-12-19 10:14:57 +080094 validate(dst.info()->valid_region(), dst_valid_region);
95
96 // Validate padding
97 PaddingCalculator calculator(shape_scaled.x(), 4);
98 calculator.set_border_mode(border_mode);
99
100 //const PaddingSize read_padding(border_size);
101 const PaddingSize write_padding = calculator.required_padding(PaddingCalculator::Option::EXCLUDE_BORDER);
102 //validate(src.info()->padding(), read_padding);
103 validate(dst.info()->padding(), write_padding);
104}
105
106template <typename T>
107using GCScaleFixture = ScaleValidationFixture<GCTensor, GCAccessor, GCScale, T>;
108
109TEST_SUITE(Float)
110TEST_SUITE(FP16)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100111FIXTURE_DATA_TEST_CASE(RunSmall, GCScaleFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
112 DataType::F16)),
113 framework::dataset::make("DataLayout", { DataLayout::NCHW })),
Frank Lei57a150a2017-12-19 10:14:57 +0800114 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR })),
115 datasets::BorderModes()),
116 datasets::SamplingPolicies()))
117{
118 //Create valid region
119 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000120 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
Frank Lei57a150a2017-12-19 10:14:57 +0800121
122 // Validate output
123 validate(GCAccessor(_target), _reference, valid_region, tolerance_f16);
124}
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100125FIXTURE_DATA_TEST_CASE(RunLarge, GCScaleFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
Frank Lei57a150a2017-12-19 10:14:57 +0800126 DataType::F16)),
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100127 framework::dataset::make("DataLayout", { DataLayout::NCHW })),
Frank Lei57a150a2017-12-19 10:14:57 +0800128 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR })),
129 datasets::BorderModes()),
130 datasets::SamplingPolicies()))
131{
132 //Create valid region
133 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000134 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
Frank Lei57a150a2017-12-19 10:14:57 +0800135
136 // Validate output
137 validate(GCAccessor(_target), _reference, valid_region, tolerance_f16);
138}
139TEST_SUITE_END()
140TEST_SUITE_END()
141
142TEST_SUITE_END()
143TEST_SUITE_END()
144} // namespace validation
145} // namespace test
146} // namespace arm_compute