blob: 831f0cdcdf1427de97b286b5969f9fb6c5b6b9b7 [file] [log] [blame]
Anthony Barbier871448e2017-03-24 14:54:29 +00001/*
Jenkins6a7771e2020-05-28 11:28:36 +01002 * Copyright (c) 2017-2020 ARM Limited.
Anthony Barbier871448e2017-03-24 14:54:29 +00003 *
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/runtime/CL/functions/CLLaplacianPyramid.h"
25
26#include "arm_compute/core/Error.h"
Anthony Barbier871448e2017-03-24 14:54:29 +000027#include "arm_compute/core/IPyramid.h"
28#include "arm_compute/core/TensorInfo.h"
29#include "arm_compute/core/Validate.h"
30#include "arm_compute/runtime/CL/CLTensor.h"
Anthony Barbier8140e1e2017-12-14 23:48:46 +000031#include "arm_compute/runtime/CL/functions/CLDepthConvertLayer.h"
Jenkins514be652019-02-28 12:25:18 +000032#include "arm_compute/runtime/CL/functions/CLElementwiseOperations.h"
Anthony Barbier871448e2017-03-24 14:54:29 +000033#include "arm_compute/runtime/CL/functions/CLGaussian5x5.h"
34#include "arm_compute/runtime/CL/functions/CLGaussianPyramid.h"
35
36using namespace arm_compute;
37
Kaizen8938bd32017-09-28 14:38:23 +010038CLLaplacianPyramid::CLLaplacianPyramid() // NOLINT
39 : _num_levels(0),
40 _gaussian_pyr_function(),
41 _convf(),
42 _subf(),
43 _depth_function(),
44 _gauss_pyr(),
45 _conv_pyr()
Anthony Barbier871448e2017-03-24 14:54:29 +000046{
47}
48
49void CLLaplacianPyramid::configure(ICLTensor *input, CLPyramid *pyramid, ICLTensor *output, BorderMode border_mode, uint8_t constant_border_value)
50{
Jenkins6a7771e2020-05-28 11:28:36 +010051 configure(CLKernelLibrary::get().get_compile_context(), input, pyramid, output, border_mode, constant_border_value);
52}
53
54void CLLaplacianPyramid::configure(const CLCompileContext &compile_context, ICLTensor *input, CLPyramid *pyramid, ICLTensor *output, BorderMode border_mode, uint8_t constant_border_value)
55{
Anthony Barbier871448e2017-03-24 14:54:29 +000056 ARM_COMPUTE_ERROR_ON(nullptr == pyramid);
57 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8);
58 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(output, 1, DataType::S16);
59 ARM_COMPUTE_ERROR_ON(0 == pyramid->info()->num_levels());
60 ARM_COMPUTE_ERROR_ON(input->info()->dimension(0) != pyramid->info()->width());
61 ARM_COMPUTE_ERROR_ON(input->info()->dimension(1) != pyramid->info()->height());
62 ARM_COMPUTE_ERROR_ON(output->info()->dimension(0) != pyramid->get_pyramid_level(pyramid->info()->num_levels() - 1)->info()->dimension(0));
63 ARM_COMPUTE_ERROR_ON(output->info()->dimension(1) != pyramid->get_pyramid_level(pyramid->info()->num_levels() - 1)->info()->dimension(1));
64
65 _num_levels = pyramid->info()->num_levels();
66
67 // Create and initialize the gaussian pyramid and the convoluted pyramid
68 PyramidInfo pyramid_info;
69 pyramid_info.init(_num_levels, 0.5f, pyramid->info()->tensor_shape(), arm_compute::Format::U8);
70
Anthony Barbiera4376382017-04-12 15:12:46 +010071 _gauss_pyr.init(pyramid_info);
72 _conv_pyr.init(pyramid_info);
Anthony Barbier871448e2017-03-24 14:54:29 +000073
74 // Create Gaussian Pyramid function
Jenkins6a7771e2020-05-28 11:28:36 +010075 _gaussian_pyr_function.configure(compile_context, input, &_gauss_pyr, border_mode, constant_border_value);
Anthony Barbier871448e2017-03-24 14:54:29 +000076
Jenkins4ba87db2019-05-23 17:11:51 +010077 _convf.resize(_num_levels);
78 _subf.resize(_num_levels);
Anthony Barbier871448e2017-03-24 14:54:29 +000079
80 for(unsigned int i = 0; i < _num_levels; ++i)
81 {
Jenkins6a7771e2020-05-28 11:28:36 +010082 _convf[i].configure(compile_context, _gauss_pyr.get_pyramid_level(i), _conv_pyr.get_pyramid_level(i), border_mode, constant_border_value);
83 _subf[i].configure(compile_context, _gauss_pyr.get_pyramid_level(i), _conv_pyr.get_pyramid_level(i), pyramid->get_pyramid_level(i), ConvertPolicy::WRAP);
Anthony Barbier871448e2017-03-24 14:54:29 +000084 }
85
Jenkins6a7771e2020-05-28 11:28:36 +010086 _depth_function.configure(compile_context, _conv_pyr.get_pyramid_level(_num_levels - 1), output, ConvertPolicy::WRAP, 0);
Anthony Barbiera4376382017-04-12 15:12:46 +010087
88 _gauss_pyr.allocate();
89 _conv_pyr.allocate();
Anthony Barbier871448e2017-03-24 14:54:29 +000090}
91
92void CLLaplacianPyramid::run()
93{
94 ARM_COMPUTE_ERROR_ON_MSG(0 == _num_levels, "Unconfigured function");
95
96 _gaussian_pyr_function.run(); // compute gaussian pyramid
97
98 for(unsigned int i = 0; i < _num_levels; ++i)
99 {
100 _convf[i].run(); // convolute gaussian pyramid
101 }
102
103 for(unsigned int i = 0; i < _num_levels; ++i)
104 {
105 _subf[i].run(); // compute laplacian image
106 }
107
108 _depth_function.run();
109}