Compute Library
 19.08
CLMinMaxLocationKernel Class Reference

Interface for the kernel to find min max locations of an image. More...

#include <CLMinMaxLocationKernel.h>

Collaboration diagram for CLMinMaxLocationKernel:
[legend]

Public Member Functions

 CLMinMaxLocationKernel ()
 Constructor. More...
 
 CLMinMaxLocationKernel (const CLMinMaxLocationKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLMinMaxLocationKerneloperator= (const CLMinMaxLocationKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLMinMaxLocationKernel (CLMinMaxLocationKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLMinMaxLocationKerneloperator= (CLMinMaxLocationKernel &&)=default
 Allow instances of this class to be moved. More...
 
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. More...
 
void run (const Window &window, cl::CommandQueue &queue) override
 Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue. More...
 
- Public Member Functions inherited from ICLKernel
 ICLKernel ()
 Constructor. More...
 
cl::Kernel & kernel ()
 Returns a reference to the OpenCL kernel of this object. More...
 
template<typename T >
void add_1D_array_argument (unsigned int &idx, const ICLArray< T > *array, const Strides &strides, unsigned int num_dimensions, const Window &window)
 Add the passed 1D array's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_1D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_1D_tensor_argument_if (bool cond, unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx if the condition is true. More...
 
void add_2D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_2D_tensor_argument_if (bool cond, unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx if the condition is true. More...
 
void add_3D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_4D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 4D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
template<typename T >
void add_argument (unsigned int &idx, T value)
 Add the passed parameters to the object's kernel's arguments starting from the index idx. More...
 
void set_lws_hint (const cl::NDRange &lws_hint)
 Set the Local-Workgroup-Size hint. More...
 
cl::NDRange lws_hint () const
 Return the Local-Workgroup-Size hint. More...
 
const std::string & config_id () const
 Get the configuration ID. More...
 
void set_target (GPUTarget target)
 Set the targeted GPU architecture. More...
 
void set_target (cl::Device &device)
 Set the targeted GPU architecture according to the CL device. More...
 
GPUTarget get_target () const
 Get the targeted GPU architecture. More...
 
size_t get_max_workgroup_size ()
 Get the maximum workgroup size for the device the CLKernelLibrary uses. More...
 
template<typename T , unsigned int dimension_size>
void add_array_argument (unsigned &idx, const ICLArray< T > *array, const Strides &strides, unsigned int num_dimensions, const Window &window)
 Add the passed array's parameters to the object's kernel's arguments starting from the index idx. More...
 
template<unsigned int dimension_size>
void add_tensor_argument (unsigned &idx, const ICLTensor *tensor, const Window &window)
 
- Public Member Functions inherited from IKernel
 IKernel ()
 Constructor. More...
 
virtual ~IKernel ()=default
 Destructor. More...
 
virtual bool is_parallelisable () const
 Indicates whether or not the kernel is parallelisable. More...
 
virtual BorderSize border_size () const
 The size of the border for that kernel. More...
 
const Windowwindow () const
 The maximum window the kernel can be executed on. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from ICLKernel
static constexpr unsigned int num_arguments_per_1D_array ()
 Returns the number of arguments enqueued per 1D array object. More...
 
static constexpr unsigned int num_arguments_per_1D_tensor ()
 Returns the number of arguments enqueued per 1D tensor object. More...
 
static constexpr unsigned int num_arguments_per_2D_tensor ()
 Returns the number of arguments enqueued per 2D tensor object. More...
 
static constexpr unsigned int num_arguments_per_3D_tensor ()
 Returns the number of arguments enqueued per 3D tensor object. More...
 
static constexpr unsigned int num_arguments_per_4D_tensor ()
 Returns the number of arguments enqueued per 4D tensor object. More...
 
static cl::NDRange gws_from_window (const Window &window)
 Get the global work size given an execution window. More...
 

Detailed Description

Interface for the kernel to find min max locations of an image.

Definition at line 70 of file CLMinMaxLocationKernel.h.

Constructor & Destructor Documentation

◆ CLMinMaxLocationKernel() [1/3]

Constructor.

Definition at line 164 of file CLMinMaxLocationKernel.cpp.

165  : _input(nullptr), _min_max_count(nullptr)
166 {
167 }

◆ CLMinMaxLocationKernel() [2/3]

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

◆ CLMinMaxLocationKernel() [3/3]

Allow instances of this class to be moved.

Member Function Documentation

◆ configure()

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.

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]min_maxBuffer of 2 elements to store the min value at position 0 and the max value at position 1. Data type supported: S32 if input type is U8/S16, F32 if input type is F32.
[out]min_max_countBuffer of 2 elements to store the min value occurrences at position 0 and the max value occurrences at position 1. Data type supported: S32
[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.

Definition at line 169 of file CLMinMaxLocationKernel.cpp.

170 {
173  ARM_COMPUTE_ERROR_ON(min_max == nullptr);
174  ARM_COMPUTE_ERROR_ON(min_max_count == nullptr && min_loc == nullptr && max_loc == nullptr);
175 
176  _input = input;
177  _min_max_count = min_max_count;
178 
179  // Set kernel build options
180  std::set<std::string> build_opts;
181  build_opts.emplace("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type()));
182  build_opts.emplace((min_max_count != nullptr) ? "-DCOUNT_MIN_MAX" : "");
183  build_opts.emplace((min_loc != nullptr) ? "-DLOCATE_MIN" : "");
184  build_opts.emplace((max_loc != nullptr) ? "-DLOCATE_MAX" : "");
185  if(input->info()->data_type() == DataType::F32)
186  {
187  build_opts.emplace("-DIS_DATA_TYPE_FLOAT");
188  }
189 
190  // Create kernel
191  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("minmaxloc", build_opts));
192 
193  // Set static arguments
194  unsigned int idx = num_arguments_per_2D_tensor(); //Skip the input and output parameters
195  _kernel.setArg(idx++, *min_max);
196  _kernel.setArg(idx++, *min_max_count);
197  if(min_loc != nullptr)
198  {
199  _kernel.setArg(idx++, min_loc->cl_buffer());
200  _kernel.setArg<cl_uint>(idx++, min_loc->max_num_values());
201  }
202  if(max_loc != nullptr)
203  {
204  _kernel.setArg(idx++, max_loc->cl_buffer());
205  _kernel.setArg<cl_uint>(idx++, max_loc->max_num_values());
206  }
207 
208  // Configure kernel window
209  constexpr unsigned int num_elems_processed_per_iteration = 1;
210  Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration));
211  update_window_and_padding(win, AccessWindowHorizontal(input->info(), 0, num_elems_processed_per_iteration));
212  ICLKernel::configure_internal(win);
213 }
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
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps=Steps(), bool skip_border=false, BorderSize border_size=BorderSize())
Calculate the maximum window for a given tensor shape and border setting.
Definition: Helpers.cpp:28
#define ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(t)
Definition: Validate.h:855
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: Helpers.h:402
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
Definition: CLHelpers.cpp:35
static constexpr unsigned int num_arguments_per_2D_tensor()
Returns the number of arguments enqueued per 2D tensor object.
Definition: ICLKernel.h:192
std::unique_ptr< Kernel > create_kernel()
Helper function to create and return a unique_ptr pointed to a CL/GLES kernel object.
Definition: Helpers.h:86
1 channel, 1 S16 per channel
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:789

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D, arm_compute::calculate_max_window(), ICLArray< T >::cl_buffer(), arm_compute::create_kernel(), ITensorInfo::data_type(), arm_compute::F32, CLKernelLibrary::get(), arm_compute::get_cl_type_from_data_type(), ITensor::info(), IArray< T >::max_num_values(), ICLKernel::num_arguments_per_2D_tensor(), arm_compute::S16, arm_compute::U8, and arm_compute::update_window_and_padding().

Referenced by CLMinMaxLocation::configure().

◆ operator=() [1/2]

CLMinMaxLocationKernel& operator= ( const CLMinMaxLocationKernel )
delete

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

◆ operator=() [2/2]

CLMinMaxLocationKernel& operator= ( CLMinMaxLocationKernel &&  )
default

Allow instances of this class to be moved.

◆ run()

void run ( const Window window,
cl::CommandQueue &  queue 
)
overridevirtual

Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.

Note
The queue is not flushed by this method, and therefore the kernel will not have been executed by the time this method returns.
Parameters
[in]windowRegion on which to execute the kernel. (Must be a valid region of the window returned by window()).
[in,out]queueCommand queue on which to enqueue the kernel.

Implements ICLKernel.

Definition at line 215 of file CLMinMaxLocationKernel.cpp.

216 {
219 
220  static const unsigned int zero_count = 0;
221  queue.enqueueWriteBuffer(*_min_max_count, CL_FALSE, 0 * sizeof(zero_count), sizeof(zero_count), &zero_count);
222  queue.enqueueWriteBuffer(*_min_max_count, CL_FALSE, 1 * sizeof(zero_count), sizeof(zero_count), &zero_count);
223 
225  do
226  {
227  unsigned int idx = 0;
228  add_2D_tensor_argument(idx, _input, slice);
229  enqueue(queue, *this, slice);
230  }
232 }
Window first_slice_window_2D() const
First 2D slice of the window.
Definition: Window.h:267
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
void enqueue(cl::CommandQueue &queue, ICLKernel &kernel, const Window &window, const cl::NDRange &lws_hint=CLKernelLibrary::get().default_ndrange(), bool use_dummy_work_items=false)
Add the kernel to the command queue with the given window.
Definition: ICLKernel.cpp:39
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
Definition: Window.h:307
void add_2D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx.
Definition: ICLKernel.h:134
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

References ICLKernel::add_2D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, arm_compute::enqueue(), Window::first_slice_window_2D(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_2D(), and IKernel::window().


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