Compute Library
 19.08
CLMeanStdDev Class Reference

Basic function to execute mean and standard deviation by calling CLMeanStdDevKernel. More...

#include <CLMeanStdDev.h>

Collaboration diagram for CLMeanStdDev:
[legend]

Public Member Functions

 CLMeanStdDev (std::shared_ptr< IMemoryManager > memory_manager=nullptr)
 Default Constructor. More...
 
 CLMeanStdDev (const CLMeanStdDev &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLMeanStdDevoperator= (const CLMeanStdDev &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLMeanStdDev (CLMeanStdDev &&)=default
 Allow instances of this class to be moved. More...
 
CLMeanStdDevoperator= (CLMeanStdDev &&)=default
 Allow instances of this class to be moved. More...
 
 ~CLMeanStdDev ()=default
 Default destructor. More...
 
void configure (ICLImage *input, float *mean, float *stddev=nullptr)
 Initialise the kernel's inputs and outputs. More...
 
void run () override
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from IFunction
virtual ~IFunction ()=default
 Destructor. More...
 
virtual void prepare ()
 Prepare the function for executing. More...
 

Static Public Member Functions

static Status validate (ITensorInfo *input, float *mean, float *stddev=nullptr)
 Static function to check if given info will lead to a valid configuration of CLMeanStdDev. More...
 

Detailed Description

Basic function to execute mean and standard deviation by calling CLMeanStdDevKernel.

Definition at line 38 of file CLMeanStdDev.h.

Constructor & Destructor Documentation

◆ CLMeanStdDev() [1/3]

CLMeanStdDev ( std::shared_ptr< IMemoryManager memory_manager = nullptr)

Default Constructor.

Definition at line 31 of file CLMeanStdDev.cpp.

32  : _memory_group(std::move(memory_manager)),
33  _data_type(),
34  _num_pixels(),
35  _run_stddev(),
36  _reduction_operation_mean(),
37  _reduction_operation_stddev(),
38  _reduction_output_mean(),
39  _reduction_output_stddev(),
40  _mean(nullptr),
41  _stddev(nullptr),
42  _mean_stddev_kernel(),
43  _fill_border_kernel(),
44  _global_sum(),
45  _global_sum_squared()
46 {
47 }

◆ CLMeanStdDev() [2/3]

CLMeanStdDev ( const CLMeanStdDev )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ CLMeanStdDev() [3/3]

CLMeanStdDev ( CLMeanStdDev &&  )
default

Allow instances of this class to be moved.

◆ ~CLMeanStdDev()

~CLMeanStdDev ( )
default

Default destructor.

Member Function Documentation

◆ configure()

void configure ( ICLImage input,
float *  mean,
float *  stddev = nullptr 
)

Initialise the kernel's inputs and outputs.

Parameters
[in,out]inputInput image. Data types supported: U8/F16/F32. (Written to only for border filling)
[out]meanOutput average pixel value.
[out]stddev(Optional) Output standard deviation of pixel values.

Definition at line 67 of file CLMeanStdDev.cpp.

68 {
69  // In the case of F16/F32 we call reduction operation for calculating CLMeanStdDev
70  _data_type = input->info()->data_type();
71 
72  if(is_data_type_float(_data_type))
73  {
74  _num_pixels = input->info()->dimension(0) * input->info()->dimension(1);
75 
76  _memory_group.manage(&_reduction_output_mean);
77  _reduction_operation_mean.configure(input, &_reduction_output_mean, 0, ReductionOperation::SUM);
78  _reduction_output_mean.allocator()->allocate();
79  _mean = mean;
80 
81  if(stddev != nullptr)
82  {
83  _memory_group.manage(&_reduction_output_stddev);
84  _reduction_operation_stddev.configure(input, &_reduction_output_stddev, 0, ReductionOperation::SUM_SQUARE);
85  _reduction_output_stddev.allocator()->allocate();
86  _stddev = stddev;
87  _run_stddev = true;
88  }
89  }
90  else
91  {
92  _global_sum = cl::Buffer(CLScheduler::get().context(), CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE, sizeof(cl_ulong));
93 
94  if(stddev != nullptr)
95  {
96  _global_sum_squared = cl::Buffer(CLScheduler::get().context(), CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE, sizeof(cl_ulong));
97  }
98 
99  _mean_stddev_kernel.configure(input, mean, &_global_sum, stddev, &_global_sum_squared);
100  _fill_border_kernel.configure(input, _mean_stddev_kernel.border_size(), BorderMode::CONSTANT, PixelValue(static_cast<uint8_t>(0)));
101  }
102 }
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:41
void configure(ICLTensor *input, ICLTensor *output, unsigned int axis, ReductionOperation op)
Set the input and output tensors.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
void configure(const ICLImage *input, float *mean, cl::Buffer *global_sum, float *stddev=nullptr, cl::Buffer *global_sum_squared=nullptr)
Initialise the kernel's input and outputs.
CLTensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: CLTensor.cpp:55
void configure(ICLTensor *tensor, BorderSize border_size, BorderMode border_mode, const PixelValue &constant_border_value=PixelValue())
Initialise the kernel's input, output and border mode.
void manage(TensorType *obj)
Sets a object to be managed by the given memory group.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
void allocate() override
Allocate size specified by TensorInfo of OpenCL memory.
BorderSize border_size() const override
The size of the border for that kernel.
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
Definition: Utils.h:990

References CLTensorAllocator::allocate(), CLTensor::allocator(), CLMeanStdDevKernel::border_size(), CLFillBorderKernel::configure(), CLReductionOperation::configure(), CLMeanStdDevKernel::configure(), arm_compute::CONSTANT, ITensorInfo::data_type(), ITensorInfo::dimension(), CLScheduler::get(), ITensor::info(), arm_compute::is_data_type_float(), MemoryGroupBase< TensorType >::manage(), arm_compute::SUM, and arm_compute::SUM_SQUARE.

◆ operator=() [1/2]

CLMeanStdDev& operator= ( const CLMeanStdDev )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ operator=() [2/2]

CLMeanStdDev& operator= ( CLMeanStdDev &&  )
default

Allow instances of this class to be moved.

◆ run()

void run ( )
overridevirtual

Run the kernels contained in the function.

For NEON kernels:

  • Multi-threading is used for the kernels which are parallelisable.
  • By default std::thread::hardware_concurrency() threads are used.
Note
CPPScheduler::set_num_threads() can be used to manually set the number of threads

For OpenCL kernels:

  • All the kernels are enqueued on the queue associated with CLScheduler.
  • The queue is then flushed.
Note
The function will not block until the kernels are executed. It is the user's responsibility to wait.
Will call prepare() on first run if hasn't been done

Implements IFunction.

Definition at line 151 of file CLMeanStdDev.cpp.

152 {
153  switch(_data_type)
154  {
155  case DataType::F16:
156  run_float<half>();
157  break;
158  case DataType::F32:
159  run_float<float>();
160  break;
161  case DataType::U8:
162  run_int();
163  break;
164  default:
165  ARM_COMPUTE_ERROR_ON("Not supported");
166  }
167 }
1 channel, 1 U8 per channel
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
1 channel, 1 F16 per channel

References ARM_COMPUTE_ERROR_ON, arm_compute::F16, arm_compute::F32, and arm_compute::U8.

◆ validate()

Status validate ( ITensorInfo input,
float *  mean,
float *  stddev = nullptr 
)
static

Static function to check if given info will lead to a valid configuration of CLMeanStdDev.

Parameters
[in]inputInput image. Data types supported: U8/F16/F32.
[in]meanOutput average pixel value.
[in]stddev(Optional) Output standard deviation of pixel values.
Returns
a status

Definition at line 49 of file CLMeanStdDev.cpp.

50 {
52  if(is_data_type_float(input->data_type()))
53  {
54  ARM_COMPUTE_UNUSED(mean);
55  ARM_COMPUTE_UNUSED(stddev);
56 
58  TensorInfo output_shape_info = TensorInfo(output_shape, 1, DataType::U8);
59  return CLReductionOperation::validate(input, &output_shape_info, 0, ReductionOperation::SUM);
60  }
61  else
62  {
63  return CLMeanStdDevKernel::validate(input, mean, nullptr, stddev, nullptr);
64  }
65 }
Shape of a tensor.
Definition: TensorShape.h:39
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
1 channel, 1 U8 per channel
virtual DataType data_type() const =0
Data type used for each element of the tensor.
static Status validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op)
Static function to check if given info will lead to a valid configuration of CLReductionOperation.
#define ARM_COMPUTE_RETURN_ERROR_ON_TENSOR_NOT_2D(t)
Definition: Validate.h:857
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
static Status validate(const ITensorInfo *input, float *mean, cl::Buffer *global_sum, float *stddev=nullptr, cl::Buffer *global_sum_squared=nullptr)
Static function to check if given info will lead to a valid configuration of CLMeanStdDevKernel.
Store the tensor's metadata.
Definition: TensorInfo.h:45
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
Definition: Utils.h:990

References ARM_COMPUTE_RETURN_ERROR_ON_TENSOR_NOT_2D, ARM_COMPUTE_UNUSED, ITensorInfo::data_type(), ITensorInfo::dimension(), arm_compute::is_data_type_float(), arm_compute::test::validation::output_shape, arm_compute::SUM, arm_compute::U8, CLMeanStdDevKernel::validate(), and CLReductionOperation::validate().


The documentation for this class was generated from the following files: