Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2020 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" |
Michalis Spyrou | d1794eb | 2018-06-15 16:15:26 +0100 | [diff] [blame] | 28 | #include "arm_compute/runtime/CL/functions/CLReductionOperation.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 29 | #include "arm_compute/runtime/IFunction.h" |
Michalis Spyrou | d1794eb | 2018-06-15 16:15:26 +0100 | [diff] [blame] | 30 | #include "arm_compute/runtime/IMemoryManager.h" |
Georgios Pinitas | 26014cf | 2019-09-09 19:00:57 +0100 | [diff] [blame] | 31 | #include "arm_compute/runtime/MemoryGroup.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 32 | |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 33 | #include <memory> |
| 34 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 35 | namespace arm_compute |
| 36 | { |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 37 | class CLCompileContext; |
| 38 | class ICLTensor; |
| 39 | class ITensorInfo; |
| 40 | class CLFillBorderKernel; |
| 41 | class CLMeanStdDevKernel; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 42 | /** Basic function to execute mean and standard deviation by calling @ref CLMeanStdDevKernel */ |
| 43 | class CLMeanStdDev : public IFunction |
| 44 | { |
| 45 | public: |
| 46 | /** Default Constructor. */ |
Michalis Spyrou | d1794eb | 2018-06-15 16:15:26 +0100 | [diff] [blame] | 47 | CLMeanStdDev(std::shared_ptr<IMemoryManager> memory_manager = nullptr); |
| 48 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 49 | CLMeanStdDev(const CLMeanStdDev &) = delete; |
| 50 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 51 | CLMeanStdDev &operator=(const CLMeanStdDev &) = delete; |
| 52 | /** Allow instances of this class to be moved */ |
| 53 | CLMeanStdDev(CLMeanStdDev &&) = default; |
| 54 | /** Allow instances of this class to be moved */ |
| 55 | CLMeanStdDev &operator=(CLMeanStdDev &&) = default; |
| 56 | /** Default destructor */ |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 57 | ~CLMeanStdDev(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 58 | /** Initialise the kernel's inputs and outputs. |
| 59 | * |
Michalis Spyrou | d1794eb | 2018-06-15 16:15:26 +0100 | [diff] [blame] | 60 | * @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] | 61 | * @param[out] mean Output average pixel value. |
Michalis Spyrou | d1794eb | 2018-06-15 16:15:26 +0100 | [diff] [blame] | 62 | * @param[out] stddev (Optional) Output standard deviation of pixel values. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 63 | */ |
Giorgio Arena | a261181 | 2017-07-21 10:08:48 +0100 | [diff] [blame] | 64 | void configure(ICLImage *input, float *mean, float *stddev = nullptr); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 65 | /** Initialise the kernel's inputs and outputs. |
| 66 | * |
| 67 | * @param[in] compile_context The compile context to be used. |
| 68 | * @param[in, out] input Input image. Data types supported: U8/F16/F32. (Written to only for border filling) |
| 69 | * @param[out] mean Output average pixel value. |
| 70 | * @param[out] stddev (Optional) Output standard deviation of pixel values. |
| 71 | */ |
| 72 | void configure(const CLCompileContext &compile_context, ICLImage *input, float *mean, float *stddev = nullptr); |
Michalis Spyrou | d1794eb | 2018-06-15 16:15:26 +0100 | [diff] [blame] | 73 | /** Static function to check if given info will lead to a valid configuration of @ref CLMeanStdDev |
| 74 | * |
| 75 | * @param[in] input Input image. Data types supported: U8/F16/F32. |
| 76 | * @param[in] mean Output average pixel value. |
| 77 | * @param[in] stddev (Optional) Output standard deviation of pixel values. |
| 78 | * |
| 79 | * @return a status |
| 80 | */ |
| 81 | static Status validate(ITensorInfo *input, float *mean, float *stddev = nullptr); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 82 | |
| 83 | // Inherited methods overridden: |
| 84 | void run() override; |
| 85 | |
| 86 | private: |
Michalis Spyrou | d1794eb | 2018-06-15 16:15:26 +0100 | [diff] [blame] | 87 | template <typename T> |
| 88 | void run_float(); |
| 89 | void run_int(); |
| 90 | |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 91 | MemoryGroup _memory_group; /**< Function's memory group */ |
| 92 | DataType _data_type; /**< Input data type. */ |
| 93 | unsigned int _num_pixels; /**< Number of image's pixels. */ |
| 94 | bool _run_stddev; /**< Flag for knowing if we should run stddev reduction function. */ |
| 95 | CLReductionOperation _reduction_operation_mean; /**< Reduction operation function for computing mean value. */ |
| 96 | CLReductionOperation _reduction_operation_stddev; /**< Reduction operation function for computing standard deviation. */ |
| 97 | CLTensor _reduction_output_mean; /**< Reduction operation output tensor for mean value. */ |
| 98 | CLTensor _reduction_output_stddev; /**< Reduction operation output tensor for standard deviation value. */ |
| 99 | float *_mean; /**< Pointer that holds the mean value. */ |
| 100 | float *_stddev; /**< Pointer that holds the standard deviation value. */ |
| 101 | std::unique_ptr<CLMeanStdDevKernel> _mean_stddev_kernel; /**< Kernel that standard deviation calculation. */ |
| 102 | std::unique_ptr<CLFillBorderKernel> _fill_border_kernel; /**< Kernel that fills the border with zeroes. */ |
| 103 | cl::Buffer _global_sum; /**< Variable that holds the global sum among calls in order to ease reduction */ |
| 104 | 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] | 105 | }; |
| 106 | } |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 107 | #endif /*ARM_COMPUTE_CLMEANSTDDEV_H */ |