Compute Library
 19.08
CLMinMaxLocation Class Reference

Basic function to execute min and max location. More...

#include <CLMinMaxLocation.h>

Collaboration diagram for CLMinMaxLocation:
[legend]

Public Member Functions

 CLMinMaxLocation ()
 Constructor. More...
 
 CLMinMaxLocation (const CLMinMaxLocation &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLMinMaxLocationoperator= (const CLMinMaxLocation &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLMinMaxLocation (CLMinMaxLocation &&)=default
 Allow instances of this class to be moved. More...
 
CLMinMaxLocationoperator= (CLMinMaxLocation &&)=default
 Allow instances of this class to be moved. More...
 
void configure (const ICLImage *input, void *min, void *max, CLCoordinates2DArray *min_loc=nullptr, CLCoordinates2DArray *max_loc=nullptr, uint32_t *min_count=nullptr, uint32_t *max_count=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...
 

Detailed Description

Basic function to execute min and max location.

This function calls the following OpenCL kernels:

  1. CLMinMaxKernel
  2. CLMinMaxLocationKernel

Definition at line 41 of file CLMinMaxLocation.h.

Constructor & Destructor Documentation

◆ CLMinMaxLocation() [1/3]

Constructor.

Definition at line 30 of file CLMinMaxLocation.cpp.

31  : _min_max_kernel(),
32  _min_max_loc_kernel(),
33  _min_max_vals(),
34  _min_max_count_vals(),
35  _min(nullptr),
36  _max(nullptr),
37  _min_count(nullptr),
38  _max_count(nullptr),
39  _min_loc(nullptr),
40  _max_loc(nullptr)
41 {
42 }

◆ CLMinMaxLocation() [2/3]

CLMinMaxLocation ( const CLMinMaxLocation )
delete

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

◆ CLMinMaxLocation() [3/3]

Allow instances of this class to be moved.

Member Function Documentation

◆ configure()

void configure ( const ICLImage input,
void *  min,
void *  max,
CLCoordinates2DArray min_loc = nullptr,
CLCoordinates2DArray max_loc = nullptr,
uint32_t *  min_count = nullptr,
uint32_t *  max_count = nullptr 
)

Initialise the kernel's inputs and outputs.

Note
When locations of min and max occurrences are requested, the reported number of locations is limited to the given array size.
Parameters
[in]inputInput image. Data types supported: U8/S16/F32.
[out]minMinimum value of image. Data types supported: S32 if input type is U8/S16, F32 if input type is F32.
[out]maxMaximum value of image. Data types supported: S32 if input type is U8/S16, F32 if input type is F32.
[out]min_loc(Optional) Array of Coordinates2D used to store minimum value locations.
[out]max_loc(Optional) Array of Coordinates2D used to store maximum value locations.
[out]min_count(Optional) Number of minimum value encounters.
[out]max_count(Optional) Number of maximum value encounters.

Definition at line 44 of file CLMinMaxLocation.cpp.

45 {
46  ARM_COMPUTE_ERROR_ON(nullptr == min);
47  ARM_COMPUTE_ERROR_ON(nullptr == max);
48 
49  _min_max_vals = cl::Buffer(CLScheduler::get().context(), CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE, 2 * sizeof(int32_t));
50  _min_max_count_vals = cl::Buffer(CLScheduler::get().context(), CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE, 2 * sizeof(uint32_t));
51  _min = min;
52  _max = max;
53  _min_count = min_count;
54  _max_count = max_count;
55  _min_loc = min_loc;
56  _max_loc = max_loc;
57 
58  _min_max_kernel.configure(input, &_min_max_vals);
59  _min_max_loc_kernel.configure(input, &_min_max_vals, &_min_max_count_vals, _min_loc, _max_loc);
60 }
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:41
#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
void configure(const ICLImage *input, cl::Buffer *min_max)
Initialise the kernel's input and output.
void configure(const ICLImage *input, cl::Buffer *min_max, cl::Buffer *min_max_count, ICLCoordinates2DArray *min_loc=nullptr, ICLCoordinates2DArray *max_loc=nullptr)
Initialise the kernel's input and outputs.

References ARM_COMPUTE_ERROR_ON, CLMinMaxKernel::configure(), CLMinMaxLocationKernel::configure(), and CLScheduler::get().

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

◆ operator=() [1/2]

CLMinMaxLocation& operator= ( const CLMinMaxLocation )
delete

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

◆ operator=() [2/2]

CLMinMaxLocation& operator= ( CLMinMaxLocation &&  )
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 62 of file CLMinMaxLocation.cpp.

63 {
64  cl::CommandQueue q = CLScheduler::get().queue();
65 
66  CLScheduler::get().enqueue(_min_max_kernel, false);
67  CLScheduler::get().enqueue(_min_max_loc_kernel, false);
68 
69  // Update min and max
70  q.enqueueReadBuffer(_min_max_vals, CL_FALSE, 0 * sizeof(int32_t), sizeof(int32_t), static_cast<int32_t *>(_min));
71  q.enqueueReadBuffer(_min_max_vals, CL_FALSE, 1 * sizeof(int32_t), sizeof(int32_t), static_cast<int32_t *>(_max));
72 
73  // Update min and max count
74  if(_min_count != nullptr)
75  {
76  q.enqueueReadBuffer(_min_max_count_vals, CL_FALSE, 0 * sizeof(uint32_t), sizeof(uint32_t), _min_count);
77  }
78  if(_max_count != nullptr)
79  {
80  q.enqueueReadBuffer(_min_max_count_vals, CL_FALSE, 1 * sizeof(uint32_t), sizeof(uint32_t), _max_count);
81  }
82 
83  // Update min/max point arrays (Makes the kernel blocking)
84  if(_min_loc != nullptr)
85  {
86  unsigned int min_count = 0;
87  q.enqueueReadBuffer(_min_max_count_vals, CL_TRUE, 0 * sizeof(uint32_t), sizeof(uint32_t), &min_count);
88  size_t min_corner_size = std::min(static_cast<size_t>(min_count), _min_loc->max_num_values());
89  _min_loc->resize(min_corner_size);
90  }
91  if(_max_loc != nullptr)
92  {
93  unsigned int max_count = 0;
94  q.enqueueReadBuffer(_min_max_count_vals, CL_TRUE, 1 * sizeof(uint32_t), sizeof(uint32_t), &max_count);
95  size_t max_corner_size = std::min(static_cast<size_t>(max_count), _max_loc->max_num_values());
96  _max_loc->resize(max_corner_size);
97  }
98 }
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:41
void resize(size_t num)
Resizes the array to contain "num" elements.
Definition: IArray.h:128
void enqueue(ICLKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.
Definition: CLScheduler.cpp:95
cl::CommandQueue & queue()
Accessor for the associated CL command queue.
Definition: CLScheduler.h:102
size_t max_num_values() const
Maximum number of values which can be stored in this array.
Definition: IArray.h:58

References CLScheduler::enqueue(), CLScheduler::get(), IArray< T >::max_num_values(), CLScheduler::queue(), and IArray< T >::resize().


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