blob: fea1ed194f8ab5c03d7c7c19b0994a01f3faefae [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Georgios Pinitas26014cf2019-09-09 19:00:57 +01002 * Copyright (c) 2016-2019 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_CLMEANSTDDEV_H
25#define ARM_COMPUTE_CLMEANSTDDEV_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/core/CL/OpenCL.h"
Giorgio Arenaa2611812017-07-21 10:08:48 +010028#include "arm_compute/core/CL/kernels/CLFillBorderKernel.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029#include "arm_compute/core/CL/kernels/CLMeanStdDevKernel.h"
Michalis Spyroud1794eb2018-06-15 16:15:26 +010030#include "arm_compute/runtime/CL/functions/CLReductionOperation.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031#include "arm_compute/runtime/IFunction.h"
Michalis Spyroud1794eb2018-06-15 16:15:26 +010032#include "arm_compute/runtime/IMemoryManager.h"
Georgios Pinitas26014cf2019-09-09 19:00:57 +010033#include "arm_compute/runtime/MemoryGroup.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034
35namespace arm_compute
36{
37/** Basic function to execute mean and standard deviation by calling @ref CLMeanStdDevKernel */
38class CLMeanStdDev : public IFunction
39{
40public:
41 /** Default Constructor. */
Michalis Spyroud1794eb2018-06-15 16:15:26 +010042 CLMeanStdDev(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
43 /** Prevent instances of this class from being copied (As this class contains pointers) */
44 CLMeanStdDev(const CLMeanStdDev &) = delete;
45 /** Prevent instances of this class from being copied (As this class contains pointers) */
46 CLMeanStdDev &operator=(const CLMeanStdDev &) = delete;
47 /** Allow instances of this class to be moved */
48 CLMeanStdDev(CLMeanStdDev &&) = default;
49 /** Allow instances of this class to be moved */
50 CLMeanStdDev &operator=(CLMeanStdDev &&) = default;
51 /** Default destructor */
52 ~CLMeanStdDev() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010053 /** Initialise the kernel's inputs and outputs.
54 *
Michalis Spyroud1794eb2018-06-15 16:15:26 +010055 * @param[in, out] input Input image. Data types supported: U8/F16/F32. (Written to only for border filling)
Giorgio Arenaa2611812017-07-21 10:08:48 +010056 * @param[out] mean Output average pixel value.
Michalis Spyroud1794eb2018-06-15 16:15:26 +010057 * @param[out] stddev (Optional) Output standard deviation of pixel values.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010058 */
Giorgio Arenaa2611812017-07-21 10:08:48 +010059 void configure(ICLImage *input, float *mean, float *stddev = nullptr);
Michalis Spyroud1794eb2018-06-15 16:15:26 +010060 /** Static function to check if given info will lead to a valid configuration of @ref CLMeanStdDev
61 *
62 * @param[in] input Input image. Data types supported: U8/F16/F32.
63 * @param[in] mean Output average pixel value.
64 * @param[in] stddev (Optional) Output standard deviation of pixel values.
65 *
66 * @return a status
67 */
68 static Status validate(ITensorInfo *input, float *mean, float *stddev = nullptr);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010069
70 // Inherited methods overridden:
71 void run() override;
72
73private:
Michalis Spyroud1794eb2018-06-15 16:15:26 +010074 template <typename T>
75 void run_float();
76 void run_int();
77
Georgios Pinitas26014cf2019-09-09 19:00:57 +010078 MemoryGroup _memory_group; /**< Function's memory group */
Michalis Spyroud1794eb2018-06-15 16:15:26 +010079 DataType _data_type; /**< Input data type. */
80 unsigned int _num_pixels; /**< Number of image's pixels. */
81 bool _run_stddev; /**< Flag for knowing if we should run stddev reduction function. */
82 CLReductionOperation _reduction_operation_mean; /**< Reduction operation function for computing mean value. */
83 CLReductionOperation _reduction_operation_stddev; /**< Reduction operation function for computing standard deviation. */
84 CLTensor _reduction_output_mean; /**< Reduction operation output tensor for mean value. */
85 CLTensor _reduction_output_stddev; /**< Reduction operation output tensor for standard deviation value. */
86 float *_mean; /**< Pointer that holds the mean value. */
87 float *_stddev; /**< Pointer that holds the standard deviation value. */
88 CLMeanStdDevKernel _mean_stddev_kernel; /**< Kernel that standard deviation calculation. */
89 CLFillBorderKernel _fill_border_kernel; /**< Kernel that fills the border with zeroes. */
90 cl::Buffer _global_sum; /**< Variable that holds the global sum among calls in order to ease reduction */
91 cl::Buffer _global_sum_squared; /**< Variable that holds the global sum of squared values among calls in order to ease reduction */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010092};
93}
Michalis Spyrouf4643372019-11-29 16:17:13 +000094#endif /*ARM_COMPUTE_CLMEANSTDDEV_H */