Compute Library
 21.02
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 destructor. More...
 
void configure (ICLImage *input, float *mean, float *stddev=nullptr)
 Initialise the kernel's inputs and outputs. More...
 
void configure (const CLCompileContext &compile_context, 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 43 of file CLMeanStdDev.h.

Constructor & Destructor Documentation

◆ CLMeanStdDev() [1/3]

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

Default Constructor.

Definition at line 34 of file CLMeanStdDev.cpp.

References CLMeanStdDev::~CLMeanStdDev().

35  : _memory_group(std::move(memory_manager)),
36  _data_type(),
37  _num_pixels(),
38  _run_stddev(),
39  _reduction_operation_mean(),
40  _reduction_operation_stddev(),
41  _reduction_output_mean(),
42  _reduction_output_stddev(),
43  _mean(nullptr),
44  _stddev(nullptr),
45  _mean_stddev_kernel(std::make_unique<CLMeanStdDevKernel>()),
46  _fill_border_kernel(std::make_unique<CLFillBorderKernel>()),
47  _global_sum(),
48  _global_sum_squared()
49 {
50 }

◆ 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.

Referenced by CLMeanStdDev::CLMeanStdDev().

Member Function Documentation

◆ configure() [1/2]

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 72 of file CLMeanStdDev.cpp.

References CLKernelLibrary::get().

73 {
74  configure(CLKernelLibrary::get().get_compile_context(), input, mean, stddev);
75 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void configure(ICLImage *input, float *mean, float *stddev=nullptr)
Initialise the kernel&#39;s inputs and outputs.

◆ configure() [2/2]

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

Initialise the kernel's inputs and outputs.

Parameters
[in]compile_contextThe compile context to be used.
[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 77 of file CLMeanStdDev.cpp.

References CLTensorAllocator::allocate(), CLTensor::allocator(), ICLTensor::buffer(), CLReductionOperation::configure(), arm_compute::CONSTANT, ITensorInfo::data_type(), ITensorInfo::dimension(), TensorInfo::dimension(), CLScheduler::enqueue(), CLScheduler::get(), ITensor::info(), CLTensor::info(), arm_compute::is_data_type_float(), MemoryGroup::manage(), CLTensor::map(), TensorInfo::offset_element_in_bytes(), CLReductionOperation::run(), arm_compute::SUM, arm_compute::SUM_SQUARE, and CLTensor::unmap().

78 {
79  // In the case of F16/F32 we call reduction operation for calculating CLMeanStdDev
80  _data_type = input->info()->data_type();
81 
82  if(is_data_type_float(_data_type))
83  {
84  _num_pixels = input->info()->dimension(0) * input->info()->dimension(1);
85 
86  _memory_group.manage(&_reduction_output_mean);
87  _reduction_operation_mean.configure(compile_context, input, &_reduction_output_mean, 0, ReductionOperation::SUM);
88  _reduction_output_mean.allocator()->allocate();
89  _mean = mean;
90 
91  if(stddev != nullptr)
92  {
93  _memory_group.manage(&_reduction_output_stddev);
94  _reduction_operation_stddev.configure(compile_context, input, &_reduction_output_stddev, 0, ReductionOperation::SUM_SQUARE);
95  _reduction_output_stddev.allocator()->allocate();
96  _stddev = stddev;
97  _run_stddev = true;
98  }
99  }
100  else
101  {
102  _global_sum = cl::Buffer(CLScheduler::get().context(), CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE, sizeof(cl_ulong));
103 
104  if(stddev != nullptr)
105  {
106  _global_sum_squared = cl::Buffer(CLScheduler::get().context(), CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE, sizeof(cl_ulong));
107  }
108 
109  _mean_stddev_kernel->configure(compile_context, input, mean, &_global_sum, stddev, &_global_sum_squared);
110  _fill_border_kernel->configure(compile_context, input, _mean_stddev_kernel->border_size(), BorderMode::CONSTANT, PixelValue(static_cast<uint8_t>(0)));
111  }
112 }
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.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
CLTensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
Definition: CLTensor.cpp:61
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
void allocate() override
Allocate size specified by TensorInfo of OpenCL memory.
void configure(ICLTensor *input, ICLTensor *output, unsigned int axis, ReductionOperation op, bool keep_dims=true)
Set the input and output tensors.
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
Definition: Utils.h:1148

◆ 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 161 of file CLMeanStdDev.cpp.

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

162 {
163  switch(_data_type)
164  {
165  case DataType::F16:
166  run_float<half>();
167  break;
168  case DataType::F32:
169  run_float<float>();
170  break;
171  case DataType::U8:
172  run_int();
173  break;
174  default:
175  ARM_COMPUTE_ERROR_ON("Not supported");
176  }
177 }
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:466
1 channel, 1 F16 per channel

◆ 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 54 of file CLMeanStdDev.cpp.

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().

Referenced by arm_compute::test::validation::DATA_TEST_CASE().

55 {
57  if(is_data_type_float(input->data_type()))
58  {
59  ARM_COMPUTE_UNUSED(mean);
60  ARM_COMPUTE_UNUSED(stddev);
61 
63  TensorInfo output_shape_info = TensorInfo(output_shape, 1, DataType::U8);
64  return CLReductionOperation::validate(input, &output_shape_info, 0, ReductionOperation::SUM);
65  }
66  else
67  {
68  return CLMeanStdDevKernel::validate(input, mean, nullptr, stddev, nullptr);
69  }
70 }
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.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
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.
#define ARM_COMPUTE_RETURN_ERROR_ON_TENSOR_NOT_2D(t)
Definition: Validate.h:858
static Status validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op, bool keep_dims=true)
Static function to check if given info will lead to a valid configuration of CLReductionOperation.
Store the tensor&#39;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:1148

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