blob: d5866fad97405db0dc0bd17afda3c857cbcb18b2 [file] [log] [blame]
Isabella Gottardi1fab09f2017-07-13 15:55:57 +01001/*
2 * Copyright (c) 2017 ARM Limited.
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/Helpers.h"
25#include "arm_compute/core/Types.h"
26#include "arm_compute/runtime/CL/functions/CLScale.h"
27#include "arm_compute/runtime/Tensor.h"
28#include "arm_compute/runtime/TensorAllocator.h"
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010029#include "tests/CL/CLAccessor.h"
30#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010031#include "tests/datasets/BorderModeDataset.h"
32#include "tests/datasets/ShapeDatasets.h"
33#include "tests/framework/Asserts.h"
34#include "tests/framework/Macros.h"
35#include "tests/framework/datasets/Datasets.h"
36#include "tests/validation/Helpers.h"
37#include "tests/validation/Validation.h"
38#include "tests/validation/fixtures/ScaleFixture.h"
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010039
40namespace arm_compute
41{
42namespace test
43{
44namespace validation
45{
46namespace
47{
48/** Tolerance */
49constexpr AbsoluteTolerance<uint8_t> tolerance(1);
50} // namespace
51
52TEST_SUITE(CL)
53TEST_SUITE(Scale)
54
55DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", DataType::U8)),
56 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
57 datasets::BorderModes()),
58 shape, data_type, policy, border_mode)
59{
60 std::mt19937 generator(library->seed());
61 std::uniform_real_distribution<float> distribution_float(0.25, 2);
62 const float scale_x = distribution_float(generator);
63 const float scale_y = distribution_float(generator);
64 std::uniform_int_distribution<uint8_t> distribution_u8(0, 255);
65 uint8_t constant_border_value = distribution_u8(generator);
66
67 // Create tensors
68 CLTensor src = create_tensor<CLTensor>(shape, data_type);
69 TensorShape shape_scaled(shape);
70 shape_scaled.set(0, shape[0] * scale_x);
71 shape_scaled.set(1, shape[1] * scale_y);
72 CLTensor dst = create_tensor<CLTensor>(shape_scaled, data_type);
73
74 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
75 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
76
77 // Create and configure function
78 CLScale clscale;
79 clscale.configure(&src, &dst, policy, border_mode, constant_border_value);
80
81 // Validate valid region
82 const ValidRegion dst_valid_region = calculate_valid_region_scale(*(src.info()), shape_scaled, policy, BorderSize(1), (border_mode == BorderMode::UNDEFINED));
83
84 validate(dst.info()->valid_region(), dst_valid_region);
85
86 // Validate padding
87 PaddingCalculator calculator(shape_scaled.x(), 4);
88 calculator.set_border_mode(border_mode);
89
90 const PaddingSize read_padding(1);
91 const PaddingSize write_padding = calculator.required_padding(PaddingCalculator::Option::EXCLUDE_BORDER);
92 validate(src.info()->padding(), read_padding);
93 validate(dst.info()->padding(), write_padding);
94}
95
96template <typename T>
97using CLScaleFixture = ScaleValidationFixture<CLTensor, CLAccessor, CLScale, T>;
98
99FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
100 DataType::U8)),
101 framework::dataset::make("InterpolationPolicy",
102{ InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
103datasets::BorderModes()))
104{
105 //Create valid region
106 TensorInfo src_info(_shape, 1, _data_type);
107 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
108
109 // Validate output
110 validate(CLAccessor(_target), _reference, valid_region, tolerance);
111}
112FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
113 DataType::U8)),
114 framework::dataset::make("InterpolationPolicy",
115{ InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
116datasets::BorderModes()))
117{
118 //Create valid region
119 TensorInfo src_info(_shape, 1, _data_type);
120 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
121
122 // Validate output
123 validate(CLAccessor(_target), _reference, valid_region, tolerance);
124}
125TEST_SUITE_END()
126TEST_SUITE_END()
127} // namespace validation
128} // namespace test
129} // namespace arm_compute