blob: 960dceef05354ee4e12927ea55144983aa865924 [file] [log] [blame]
John Richardson2d008a42018-03-22 13:48:41 +00001/*
2 * Copyright (c) 2018 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/Types.h"
25#include "arm_compute/runtime/CL/CLPyramid.h"
26#include "arm_compute/runtime/CL/CLTensor.h"
27#include "arm_compute/runtime/CL/CLTensorAllocator.h"
28#include "arm_compute/runtime/CL/functions/CLLaplacianPyramid.h"
29#include "tests/CL/CLAccessor.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/LaplacianPyramidFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46const auto small_laplacian_pyramid_levels = framework::dataset::make("NumLevels", 2, 3);
47const auto large_laplacian_pyramid_levels = framework::dataset::make("NumLevels", 2, 5);
48
49const auto formats = combine(framework::dataset::make("FormatIn", Format::U8), framework::dataset::make("FormatOut", Format::S16));
50
51template <typename T>
52inline void validate_laplacian_pyramid(const CLPyramid &target, const std::vector<SimpleTensor<T>> &reference, BorderMode border_mode)
53{
54 CLTensor *level_image = target.get_pyramid_level(0);
55 ValidRegion valid_region = shape_to_valid_region(reference[0].shape(), border_mode == BorderMode::UNDEFINED, BorderSize(2));
56
57 // Validate lowest level
58 validate(CLAccessor(*level_image), reference[0], valid_region);
59
60 // Validate remaining levels
61 for(size_t lev = 1; lev < target.info()->num_levels(); lev++)
62 {
63 level_image = target.get_pyramid_level(lev);
64 CLTensor *prev_level_image = target.get_pyramid_level(lev - 1);
65
66 valid_region = shape_to_valid_region_laplacian_pyramid(prev_level_image->info()->tensor_shape(),
67 prev_level_image->info()->valid_region(),
68 border_mode == BorderMode::UNDEFINED);
69
70 // Validate level
71 validate(CLAccessor(*level_image), reference[lev], valid_region);
72 }
73}
74} // namespace
75
76TEST_SUITE(CL)
77TEST_SUITE(LaplacianPyramid)
78
79// *INDENT-OFF*
80// clang-format off
81DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(
82 concat(datasets::Medium2DShapes(), datasets::Large2DShapes()),
83 datasets::BorderModes()),
84 large_laplacian_pyramid_levels),
85 shape, border_mode, num_levels)
86{
87 // Create pyramid info
88 PyramidInfo pyramid_info(num_levels, SCALE_PYRAMID_HALF, shape, Format::S16);
89 CLPyramid dst_pyramid{};
90 dst_pyramid.init(pyramid_info);
91
92 // Create Tensors
93 CLTensor src = create_tensor<CLTensor>(shape, Format::U8);
94
95 // The first two dimensions of the output tensor must match the first two
96 // dimensions of the tensor in the last level of the pyramid
97 TensorShape dst_shape(shape);
98 dst_shape.set(0, dst_pyramid.get_pyramid_level(num_levels - 1)->info()->dimension(0));
99 dst_shape.set(1, dst_pyramid.get_pyramid_level(num_levels - 1)->info()->dimension(1));
100 CLTensor dst = create_tensor<CLTensor>(dst_shape, Format::S16);
101
102 // Create and configure function
103 CLLaplacianPyramid laplacian_pyramid;
104 laplacian_pyramid.configure(&src, &dst_pyramid, &dst, border_mode, 0);
105
106 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
107 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
108
109 for(size_t level = 0; level < pyramid_info.num_levels(); ++level)
110 {
111 ARM_COMPUTE_EXPECT(dst_pyramid.get_pyramid_level(level)->info()->is_resizable(), framework::LogLevel::ERRORS);
112 }
113}
114
115using CLLaplacianPyramidFixture = LaplacianPyramidValidationFixture<CLTensor, CLAccessor, CLLaplacianPyramid, uint8_t, int16_t, CLPyramid>;
116
117FIXTURE_DATA_TEST_CASE(RunSmall, CLLaplacianPyramidFixture, framework::DatasetMode::PRECOMMIT,
118 combine(combine(combine(
119 datasets::Medium2DShapes(),
120 datasets::BorderModes()),
121 small_laplacian_pyramid_levels),
122 formats))
123{
124 validate_laplacian_pyramid(_target, _reference, _border_mode);
125}
126
127FIXTURE_DATA_TEST_CASE(RunLarge, CLLaplacianPyramidFixture, framework::DatasetMode::NIGHTLY,
128 combine(combine(combine(
129 datasets::Large2DShapes(),
130 datasets::BorderModes()),
131 large_laplacian_pyramid_levels),
132 formats))
133{
134 validate_laplacian_pyramid(_target, _reference, _border_mode);
135}
136// clang-format on
137// *INDENT-ON*
138
139TEST_SUITE_END()
140TEST_SUITE_END()
141} // namespace validation
142} // namespace test
143} // namespace arm_compute