Compute Library
 19.08
CLBoundingBoxTransformKernel Class Reference

Interface for the bounding box kernel. More...

#include <CLBoundingBoxTransformKernel.h>

Collaboration diagram for CLBoundingBoxTransformKernel:
[legend]

Public Member Functions

 CLBoundingBoxTransformKernel ()
 Default constructor. More...
 
 CLBoundingBoxTransformKernel (const CLBoundingBoxTransformKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLBoundingBoxTransformKerneloperator= (const CLBoundingBoxTransformKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLBoundingBoxTransformKernel (CLBoundingBoxTransformKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLBoundingBoxTransformKerneloperator= (CLBoundingBoxTransformKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~CLBoundingBoxTransformKernel ()=default
 Default destructor. More...
 
void configure (const ICLTensor *boxes, ICLTensor *pred_boxes, const ICLTensor *deltas, const BoundingBoxTransformInfo &info)
 Set the input and output tensors. 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...
 

Static Public Member Functions

static Status validate (const ITensorInfo *boxes, const ITensorInfo *pred_boxes, const ITensorInfo *deltas, const BoundingBoxTransformInfo &info)
 Static function to check if given info will lead to a valid configuration of CLBoundingBoxTransform. More...
 
- 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 bounding box kernel.

Definition at line 34 of file CLBoundingBoxTransformKernel.h.

Constructor & Destructor Documentation

◆ CLBoundingBoxTransformKernel() [1/3]

Default constructor.

Definition at line 65 of file CLBoundingBoxTransformKernel.cpp.

66  : _boxes(nullptr), _pred_boxes(nullptr), _deltas(nullptr)
67 {
68 }

◆ CLBoundingBoxTransformKernel() [2/3]

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

◆ CLBoundingBoxTransformKernel() [3/3]

Allow instances of this class to be moved.

◆ ~CLBoundingBoxTransformKernel()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ICLTensor boxes,
ICLTensor pred_boxes,
const ICLTensor deltas,
const BoundingBoxTransformInfo info 
)

Set the input and output tensors.

Parameters
[in]boxesSource tensor. Bounding box proposals in pixel coordinates. Size(M, 4), format [x1, y1, x2, y2]. Data types supported: F16/F32.
[out]pred_boxesDestination tensor. Pixel coordinates of the transformed bounding boxes. Size (M, 4*K), format [x1, y1, x2, y2]. Data types supported: Same as input
[in]deltasBounding box translations and scales. Size (M, 4*K), format [dx, dy, dw, dh], K is the number of classes. Data types supported: Same as input
[in]infoContains BoundingBox operation information described in BoundingBoxTransformInfo.
Note
Only single image prediction is supported. Height and Width (and scale) of the image will be contained in the BoundingBoxTransformInfo struct.

Definition at line 70 of file CLBoundingBoxTransformKernel.cpp.

71 {
72  ARM_COMPUTE_ERROR_ON_NULLPTR(boxes, pred_boxes, deltas);
73  auto_init_if_empty(*pred_boxes->info(), *deltas->info());
74 
75  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(boxes->info(), pred_boxes->info(), deltas->info(), info));
76 
77  // Set instance variables
78  _boxes = boxes;
79  _pred_boxes = pred_boxes;
80  _deltas = deltas;
81 
82  // Get image height and widht (rescaled)
83  const int img_h = floor(info.img_height() / info.scale() + 0.5f);
84  const int img_w = floor(info.img_width() / info.scale() + 0.5f);
85 
86  // Set build options
87  CLBuildOptions build_opts;
88  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(deltas->info()->data_type()));
89  build_opts.add_option("-DWEIGHT_X=" + float_to_string_with_full_precision(info.weights()[0]));
90  build_opts.add_option("-DWEIGHT_Y=" + float_to_string_with_full_precision(info.weights()[1]));
91  build_opts.add_option("-DWEIGHT_W=" + float_to_string_with_full_precision(info.weights()[2]));
92  build_opts.add_option("-DWEIGHT_H=" + float_to_string_with_full_precision(info.weights()[3]));
93  build_opts.add_option("-DBBOX_XFORM_CLIP=" + float_to_string_with_full_precision(info.bbox_xform_clip()));
94  build_opts.add_option("-DIMG_WIDTH=" + support::cpp11::to_string(img_w));
95  build_opts.add_option("-DIMG_HEIGHT=" + support::cpp11::to_string(img_h));
96  build_opts.add_option("-DBOX_FIELDS=" + support::cpp11::to_string(4));
97  build_opts.add_option("-DSCALE_BEFORE=" + float_to_string_with_full_precision(info.scale()));
98  build_opts.add_option_if(info.apply_scale(), "-DSCALE_AFTER=" + float_to_string_with_full_precision(info.scale()));
99  build_opts.add_option_if(info.correct_transform_coords(), "-DOFFSET=1");
100 
101  // Create kernel
102  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("bounding_box_transform", build_opts.options()));
103 
104  // Since the number of columns is a multiple of 4 by definition, we don't need to pad the tensor
105  const unsigned int num_elems_processed_per_iteration = 4;
106  Window win = calculate_max_window(*deltas->info(), Steps(num_elems_processed_per_iteration));
107  ICLKernel::configure_internal(win);
108 }
std::string to_string(T &&value)
Convert integer and float values to string.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
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
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
Definition: Helpers.inl:201
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
Definition: Utils.h:1066
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
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
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References CLBuildOptions::add_option(), ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), arm_compute::calculate_max_window(), arm_compute::create_kernel(), ITensorInfo::data_type(), arm_compute::float_to_string_with_full_precision(), CLKernelLibrary::get(), arm_compute::get_cl_type_from_data_type(), ITensor::info(), arm_compute::test::validation::info, and arm_compute::support::cpp11::to_string().

Referenced by CLGenerateProposalsLayer::configure().

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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 116 of file CLBoundingBoxTransformKernel.cpp.

117 {
120 
122 
123  // Set arguments
124  unsigned int idx = 0;
125  add_1D_tensor_argument(idx, _boxes, slice);
126  add_2D_tensor_argument(idx, _pred_boxes, slice);
127  add_2D_tensor_argument(idx, _deltas, slice);
128 
129  // Note that we don't need to loop over the slices, as we are sure that we are dealing with all 2D tensors
130  enqueue(queue, *this, slice);
131 }
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
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
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.
Definition: ICLKernel.h:110
#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_1D_tensor_argument(), 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(), and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo boxes,
const ITensorInfo pred_boxes,
const ITensorInfo deltas,
const BoundingBoxTransformInfo info 
)
static

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

Parameters
[in]boxesSource tensor info. Bounding box proposals in pixel coordinates. Size(M, 4), format [x1, y1, x2, y2]. Data types supported: F16/F32.
[in]pred_boxesDestination tensor info. Pixel coordinates of the transformed bounding boxes. Size (M, 4*K), format [x1, y1, x2, y2]. Data types supported: Same as input
[in]deltasBounding box translations and scales. Size (M, 4*K), format [dx, dy, dw, dh], K is the number of classes. Data types supported: Same as input
[in]infoContains BoundingBox operation information described in BoundingBoxTransformInfo.
Note
Only single image prediction is supported. Height and Width (and scale) of the image will be contained in the BoundingBoxTransformInfo struct.
Returns
a Status

Definition at line 110 of file CLBoundingBoxTransformKernel.cpp.

111 {
112  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(boxes, pred_boxes, deltas, info));
113  return Status{};
114 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193

References ARM_COMPUTE_RETURN_ON_ERROR, and arm_compute::test::validation::info.

Referenced by CLBoundingBoxTransform::validate(), and CLGenerateProposalsLayer::validate().


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