Compute Library
 19.11
CLROIAlignLayerKernel Class Reference

Interface for the RoIAlign kernel. More...

#include <CLROIAlignLayerKernel.h>

Collaboration diagram for CLROIAlignLayerKernel:
[legend]

Public Member Functions

 CLROIAlignLayerKernel ()
 Constructor. More...
 
 CLROIAlignLayerKernel (const CLROIAlignLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLROIAlignLayerKerneloperator= (const CLROIAlignLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLROIAlignLayerKernel (CLROIAlignLayerKernel &&)=default
 Default Move Constructor. More...
 
CLROIAlignLayerKerneloperator= (CLROIAlignLayerKernel &&)=default
 Default move assignment operator. More...
 
 ~CLROIAlignLayerKernel ()=default
 Default destructor. More...
 
void configure (const ICLTensor *input, const ICLTensor *rois, ICLTensor *output, const ROIPoolingLayerInfo &pool_info)
 Set the input and output tensors. More...
 
void run (const Window &window, cl::CommandQueue &queue)
 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 *input, const ITensorInfo *rois, ITensorInfo *output, const ROIPoolingLayerInfo &pool_info)
 Static function to check if given info will lead to a valid configuration of CLROIAlignLayerKernel. 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 RoIAlign kernel.

Definition at line 36 of file CLROIAlignLayerKernel.h.

Constructor & Destructor Documentation

◆ CLROIAlignLayerKernel() [1/3]

Constructor.

Definition at line 100 of file CLROIAlignLayerKernel.cpp.

101  : _input(nullptr), _output(nullptr), _rois(nullptr), _pool_info(0, 0, 0.f)
102 {
103 }

◆ CLROIAlignLayerKernel() [2/3]

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

◆ CLROIAlignLayerKernel() [3/3]

Default Move Constructor.

◆ ~CLROIAlignLayerKernel()

~CLROIAlignLayerKernel ( )
default

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ICLTensor input,
const ICLTensor rois,
ICLTensor output,
const ROIPoolingLayerInfo pool_info 
)

Set the input and output tensors.

Parameters
[in]inputSource tensor. Data types supported: QASYMM8/F16/F32.
[in]roisROIs tensor, it is a 2D tensor of size [5, N] (where N is the number of ROIs) containing top left and bottom right corner as coordinate of an image and batch_id of ROI [ batch_id, x1, y1, x2, y2 ]. Data types supported: QASYMM16 with scale of 0.125 and 0 offset if input is QASYMM8, otherwise same as input
[out]outputDestination tensor. Data types supported: Same as input.
[in]pool_infoContains pooling operation information described in ROIPoolingLayerInfo.
Note
The x and y dimensions of output tensor must be the same as pool_info 's pooled width and pooled height.
The z dimensions of output tensor and input tensor must be the same.
The fourth dimension of output tensor must be the same as the number of elements in rois array.

Definition at line 105 of file CLROIAlignLayerKernel.cpp.

106 {
107  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output, rois);
108  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), rois->info(), output->info(), pool_info));
109 
110  // Configure kernel window
111  auto win_config = validate_and_configure_window(input->info(), rois->info(), output->info(), pool_info);
112  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
113 
114  _input = input;
115  _output = output;
116  _rois = rois;
117  _pool_info = pool_info;
118 
119  const DataType data_type = input->info()->data_type();
120  const bool is_qasymm = is_data_type_quantized_asymmetric(data_type);
121 
122  // Set build options
123  CLBuildOptions build_opts;
124  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type));
125  build_opts.add_option("-DDATA_SIZE=" + get_data_size_from_data_type(input->info()->data_type()));
126  build_opts.add_option("-DMAX_DIM_X=" + support::cpp11::to_string(_input->info()->dimension(get_data_layout_dimension_index(input->info()->data_layout(), DataLayoutDimension::WIDTH))));
127  build_opts.add_option("-DMAX_DIM_Y=" + support::cpp11::to_string(_input->info()->dimension(get_data_layout_dimension_index(input->info()->data_layout(), DataLayoutDimension::HEIGHT))));
128  build_opts.add_option("-DMAX_DIM_Z=" + support::cpp11::to_string(_input->info()->dimension(get_data_layout_dimension_index(input->info()->data_layout(), DataLayoutDimension::CHANNEL))));
129  build_opts.add_option("-DPOOLED_DIM_X=" + support::cpp11::to_string(pool_info.pooled_width()));
130  build_opts.add_option("-DPOOLED_DIM_Y=" + support::cpp11::to_string(pool_info.pooled_height()));
131  build_opts.add_option("-DSPATIAL_SCALE=" + float_to_string_with_full_precision(pool_info.spatial_scale()));
132  build_opts.add_option_if(input->info()->data_layout() == DataLayout::NHWC, "-DNHWC");
133  build_opts.add_option_if(pool_info.sampling_ratio() > 0, "-DSAMPLING_RATIO=" + support::cpp11::to_string(pool_info.sampling_ratio()));
134 
135  if(is_qasymm)
136  {
137  const UniformQuantizationInfo iq_info = input->info()->quantization_info().uniform();
138  const UniformQuantizationInfo roisq_info = rois->info()->quantization_info().uniform();
139  const UniformQuantizationInfo oq_info = output->info()->quantization_info().uniform();
140 
141  build_opts.add_option("-DOFFSET_IN=" + float_to_string_with_full_precision(iq_info.offset));
142  build_opts.add_option("-DSCALE_IN=" + float_to_string_with_full_precision(iq_info.scale));
143  build_opts.add_option("-DOFFSET_ROIS=" + float_to_string_with_full_precision(roisq_info.offset));
144  build_opts.add_option("-DSCALE_ROIS=" + float_to_string_with_full_precision(roisq_info.scale));
145  build_opts.add_option("-DOFFSET_OUT=" + float_to_string_with_full_precision(oq_info.offset));
146  build_opts.add_option("-DSCALE_OUT=" + float_to_string_with_full_precision(oq_info.scale));
147  }
148 
149  // Create kernel
150  const std::string kernel_name = (is_qasymm) ? "roi_align_layer_quantized" : "roi_align_layer";
151  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name, build_opts.options()));
152 
153  ICLKernel::configure_internal(win_config.second);
154 }
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
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:455
std::string get_data_size_from_data_type(const DataType &dt)
Get the size of a data type in number of bits.
Definition: CLHelpers.cpp:152
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
Definition: Utils.h:1099
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
Definition: CLHelpers.cpp:37
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
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
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
Definition: Utils.h:1044
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
Num samples, height, width, channels.
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:327
DataType
Available data types.
Definition: Types.h:74

References CLBuildOptions::add_option(), CLBuildOptions::add_option_if(), ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::CHANNEL, arm_compute::create_kernel(), arm_compute::test::validation::data_type, ITensorInfo::dimension(), arm_compute::float_to_string_with_full_precision(), CLKernelLibrary::get(), arm_compute::get_cl_type_from_data_type(), arm_compute::get_data_layout_dimension_index(), arm_compute::get_data_size_from_data_type(), arm_compute::HEIGHT, ITensor::info(), arm_compute::test::validation::input, arm_compute::is_data_type_quantized_asymmetric(), arm_compute::NHWC, UniformQuantizationInfo::offset, CLBuildOptions::options(), ROIPoolingLayerInfo::pooled_height(), ROIPoolingLayerInfo::pooled_width(), ITensorInfo::quantization_info(), ROIPoolingLayerInfo::sampling_ratio(), UniformQuantizationInfo::scale, ROIPoolingLayerInfo::spatial_scale(), arm_compute::support::cpp11::to_string(), QuantizationInfo::uniform(), and arm_compute::WIDTH.

◆ operator=() [1/2]

CLROIAlignLayerKernel& operator= ( const CLROIAlignLayerKernel )
delete

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

◆ operator=() [2/2]

CLROIAlignLayerKernel& operator= ( CLROIAlignLayerKernel &&  )
default

Default move assignment operator.

◆ run()

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

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 162 of file CLROIAlignLayerKernel.cpp.

163 {
166 
168  Window slice_rois = slice;
169  // Parallelize spatially and across the fourth dimension of the output tensor (also across ROITensor)
170  slice_rois.set_dimension_step(Window::DimX, _rois->info()->dimension(0));
172 
173  // Set arguments
174  unsigned int idx = 0;
175  add_3D_tensor_argument(idx, _input, slice);
176  add_2D_tensor_argument(idx, _rois, slice_rois);
177  add_3D_tensor_argument(idx, _output, slice);
178  add_argument<cl_uint>(idx, _input->info()->strides_in_bytes()[3]);
179  add_argument<cl_uint>(idx, _output->info()->strides_in_bytes()[3]);
180 
181  enqueue(queue, *this, slice, lws_hint());
182 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
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
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:247
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.
Definition: ICLKernel.h:158
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
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
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:327
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:289
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.

References ICLKernel::add_2D_tensor_argument(), ICLKernel::add_3D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, arm_compute::CHANNEL, ITensorInfo::data_layout(), ITensorInfo::dimension(), Window::DimX, arm_compute::enqueue(), Window::first_slice_window_3D(), arm_compute::get_data_layout_dimension_index(), ITensor::info(), ICLKernel::lws_hint(), Window::set_dimension_step(), arm_compute::test::validation::reference::slice(), ITensorInfo::strides_in_bytes(), and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo rois,
ITensorInfo output,
const ROIPoolingLayerInfo pool_info 
)
static

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

Parameters
[in]inputSource tensor info. Data types supported: QASYMM8/F16/F32.
[in]roisROIs tensor info. Data types supported: QASYMM16 with scale of 0.125 and 0 offset if input is QASYMM8, otherwise same as input
[in]outputDestination tensor info. Data types supported: Same as input.
[in]pool_infoContains pooling operation information described in ROIPoolingLayerInfo.
Note
The x and y dimensions of output tensor must be the same as pool_info 's pooled width and pooled height.
The z dimensions of output tensor and input tensor must be the same.
The fourth dimension of output tensor must be the same as the number of elements in rois array.
Returns
a Status

Definition at line 156 of file CLROIAlignLayerKernel.cpp.

157 {
158  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, rois, output, pool_info));
159  return Status{};
160 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204

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

Referenced by CLROIAlignLayer::validate().


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