Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 26014cf | 2019-09-09 19:00:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2019 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CLMEANSTDDEV_H |
| 25 | #define ARM_COMPUTE_CLMEANSTDDEV_H |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/CL/OpenCL.h" |
Giorgio Arena | a261181 | 2017-07-21 10:08:48 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/CL/kernels/CLFillBorderKernel.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 29 | #include "arm_compute/core/CL/kernels/CLMeanStdDevKernel.h" |
Michalis Spyrou | d1794eb | 2018-06-15 16:15:26 +0100 | [diff] [blame] | 30 | #include "arm_compute/runtime/CL/functions/CLReductionOperation.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 31 | #include "arm_compute/runtime/IFunction.h" |
Michalis Spyrou | d1794eb | 2018-06-15 16:15:26 +0100 | [diff] [blame] | 32 | #include "arm_compute/runtime/IMemoryManager.h" |
Georgios Pinitas | 26014cf | 2019-09-09 19:00:57 +0100 | [diff] [blame] | 33 | #include "arm_compute/runtime/MemoryGroup.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | /** Basic function to execute mean and standard deviation by calling @ref CLMeanStdDevKernel */ |
| 38 | class CLMeanStdDev : public IFunction |
| 39 | { |
| 40 | public: |
| 41 | /** Default Constructor. */ |
Michalis Spyrou | d1794eb | 2018-06-15 16:15:26 +0100 | [diff] [blame] | 42 | 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 53 | /** Initialise the kernel's inputs and outputs. |
| 54 | * |
Michalis Spyrou | d1794eb | 2018-06-15 16:15:26 +0100 | [diff] [blame] | 55 | * @param[in, out] input Input image. Data types supported: U8/F16/F32. (Written to only for border filling) |
Giorgio Arena | a261181 | 2017-07-21 10:08:48 +0100 | [diff] [blame] | 56 | * @param[out] mean Output average pixel value. |
Michalis Spyrou | d1794eb | 2018-06-15 16:15:26 +0100 | [diff] [blame] | 57 | * @param[out] stddev (Optional) Output standard deviation of pixel values. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 58 | */ |
Giorgio Arena | a261181 | 2017-07-21 10:08:48 +0100 | [diff] [blame] | 59 | void configure(ICLImage *input, float *mean, float *stddev = nullptr); |
Michalis Spyrou | d1794eb | 2018-06-15 16:15:26 +0100 | [diff] [blame] | 60 | /** 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 69 | |
| 70 | // Inherited methods overridden: |
| 71 | void run() override; |
| 72 | |
| 73 | private: |
Michalis Spyrou | d1794eb | 2018-06-15 16:15:26 +0100 | [diff] [blame] | 74 | template <typename T> |
| 75 | void run_float(); |
| 76 | void run_int(); |
| 77 | |
Georgios Pinitas | 26014cf | 2019-09-09 19:00:57 +0100 | [diff] [blame] | 78 | MemoryGroup _memory_group; /**< Function's memory group */ |
Michalis Spyrou | d1794eb | 2018-06-15 16:15:26 +0100 | [diff] [blame] | 79 | 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 92 | }; |
| 93 | } |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 94 | #endif /*ARM_COMPUTE_CLMEANSTDDEV_H */ |