1 /*
2 * Copyright (c) 2018-2020 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
38 namespace arm_compute
39 {
40 namespace test
41 {
42 namespace validation
43 {
44 namespace
45 {
46 /* Absolute tolerance value for comparing reference's output against implementation's output for DataType::S16
47 * Tolerance is needed for calculation uncertainties introduced from the layers
48 */
49 AbsoluteTolerance<int16_t> tolerance_int16(1);
50 const auto small_laplacian_pyramid_levels = framework::dataset::make("NumLevels", 2, 3);
51 const auto large_laplacian_pyramid_levels = framework::dataset::make("NumLevels", 2, 5);
52
53 const auto formats = combine(framework::dataset::make("FormatIn", Format::U8), framework::dataset::make("FormatOut", Format::S16));
54
55 template <typename T>
validate_laplacian_pyramid(const CLPyramid & target,const std::vector<SimpleTensor<T>> & reference,BorderMode border_mode)56 inline void validate_laplacian_pyramid(const CLPyramid &target, const std::vector<SimpleTensor<T>> &reference, BorderMode border_mode)
57 {
58 CLTensor *level_image = target.get_pyramid_level(0);
59 ValidRegion valid_region = shape_to_valid_region(reference[0].shape(), border_mode == BorderMode::UNDEFINED, BorderSize(2));
60
61 // Validate lowest level
62 validate(CLAccessor(*level_image), reference[0], valid_region);
63
64 // Validate remaining levels
65 for(size_t lev = 1; lev < target.info()->num_levels(); lev++)
66 {
67 level_image = target.get_pyramid_level(lev);
68 CLTensor *prev_level_image = target.get_pyramid_level(lev - 1);
69
70 valid_region = shape_to_valid_region_laplacian_pyramid(prev_level_image->info()->tensor_shape(),
71 prev_level_image->info()->valid_region(),
72 border_mode == BorderMode::UNDEFINED);
73
74 // Validate level
75 validate(CLAccessor(*level_image), reference[lev], valid_region, tolerance_int16);
76 }
77 }
78 } // namespace
79
80 TEST_SUITE(CL)
81 TEST_SUITE(LaplacianPyramid)
82
83 // *INDENT-OFF*
84 // clang-format off
85
86 using CLLaplacianPyramidFixture = LaplacianPyramidValidationFixture<CLTensor, CLAccessor, CLLaplacianPyramid, uint8_t, int16_t, CLPyramid>;
87
FIXTURE_DATA_TEST_CASE(RunSmall,CLLaplacianPyramidFixture,framework::DatasetMode::PRECOMMIT,combine (combine (combine (datasets::Medium2DShapes (),datasets::BorderModes ()),small_laplacian_pyramid_levels),formats))88 FIXTURE_DATA_TEST_CASE(RunSmall, CLLaplacianPyramidFixture, framework::DatasetMode::PRECOMMIT,
89 combine(combine(combine(
90 datasets::Medium2DShapes(),
91 datasets::BorderModes()),
92 small_laplacian_pyramid_levels),
93 formats))
94 {
95 validate_laplacian_pyramid(_target, _reference, _border_mode);
96 }
97
FIXTURE_DATA_TEST_CASE(RunLarge,CLLaplacianPyramidFixture,framework::DatasetMode::NIGHTLY,combine (combine (combine (datasets::Large2DShapes (),datasets::BorderModes ()),large_laplacian_pyramid_levels),formats))98 FIXTURE_DATA_TEST_CASE(RunLarge, CLLaplacianPyramidFixture, framework::DatasetMode::NIGHTLY,
99 combine(combine(combine(
100 datasets::Large2DShapes(),
101 datasets::BorderModes()),
102 large_laplacian_pyramid_levels),
103 formats))
104 {
105 validate_laplacian_pyramid(_target, _reference, _border_mode);
106 }
107 // clang-format on
108 // *INDENT-ON*
109
110 TEST_SUITE_END()
111 TEST_SUITE_END()
112 } // namespace validation
113 } // namespace test
114 } // namespace arm_compute
115