Compute Library
 21.02
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...
 
 ~CLMinMaxLocation ()
 Default destructor. 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 configure (const CLCompileContext &compile_context, 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
Deprecated:
This function is deprecated and is intended to be removed in 21.05 release

Definition at line 48 of file CLMinMaxLocation.h.

Constructor & Destructor Documentation

◆ CLMinMaxLocation() [1/3]

Constructor.

Definition at line 30 of file CLMinMaxLocation.cpp.

References CLMinMaxLocation::~CLMinMaxLocation().

31  : _min_max_kernel(std::make_unique<CLMinMaxKernel>()),
32  _min_max_loc_kernel(std::make_unique<CLMinMaxLocationKernel>()),
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.

◆ ~CLMinMaxLocation()

~CLMinMaxLocation ( )
default

Default destructor.

Referenced by CLMinMaxLocation::CLMinMaxLocation().

Member Function Documentation

◆ configure() [1/2]

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 46 of file CLMinMaxLocation.cpp.

References CLKernelLibrary::get().

47 {
48  configure(CLKernelLibrary::get().get_compile_context(), input, min, max, min_loc, max_loc, min_count, max_count);
49 }
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&#39;s inputs and outputs.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
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]compile_contextThe compile context to be used.
[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 51 of file CLMinMaxLocation.cpp.

References ARM_COMPUTE_ERROR_ON, and CLScheduler::get().

54 {
55  ARM_COMPUTE_ERROR_ON(nullptr == min);
56  ARM_COMPUTE_ERROR_ON(nullptr == max);
57 
58  _min_max_vals = cl::Buffer(CLScheduler::get().context(), CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE, 2 * sizeof(int32_t));
59  _min_max_count_vals = cl::Buffer(CLScheduler::get().context(), CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE, 2 * sizeof(uint32_t));
60  _min = min;
61  _max = max;
62  _min_count = min_count;
63  _max_count = max_count;
64  _min_loc = min_loc;
65  _max_loc = max_loc;
66 
67  _min_max_kernel->configure(compile_context, input, &_min_max_vals);
68  _min_max_loc_kernel->configure(compile_context, input, &_min_max_vals, &_min_max_count_vals, _min_loc, _max_loc);
69 }
static CLScheduler & get()
Access the scheduler singleton.
#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

◆ 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 71 of file CLMinMaxLocation.cpp.

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

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

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