Compute Library
 21.02
CLComputeAllAnchorsKernel Class Reference

Interface for Compute All Anchors kernel. More...

#include <CLGenerateProposalsLayerKernel.h>

Collaboration diagram for CLComputeAllAnchorsKernel:
[legend]

Public Member Functions

 CLComputeAllAnchorsKernel ()
 Default constructor. More...
 
 CLComputeAllAnchorsKernel (const CLComputeAllAnchorsKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLComputeAllAnchorsKerneloperator= (const CLComputeAllAnchorsKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLComputeAllAnchorsKernel (CLComputeAllAnchorsKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLComputeAllAnchorsKerneloperator= (CLComputeAllAnchorsKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~CLComputeAllAnchorsKernel ()=default
 Default destructor. More...
 
void configure (const ICLTensor *anchors, ICLTensor *all_anchors, const ComputeAnchorsInfo &info)
 Set the input and output tensors. More...
 
void configure (const CLCompileContext &compile_context, const ICLTensor *anchors, ICLTensor *all_anchors, const ComputeAnchorsInfo &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...
 
virtual void run_op (ITensorPack &tensors, const Window &window, cl::CommandQueue &queue)
 Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue. 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...
 
void set_wbsm_hint (const cl_int &wbsm_hint)
 Set the workgroup batch size modifier hint. More...
 
cl_int wbsm_hint () const
 Return the workgroup batch size modifier 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<unsigned int dimension_size>
void add_tensor_argument (unsigned &idx, const ICLTensor *tensor, const Window &window)
 
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...
 
- 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 *anchors, const ITensorInfo *all_anchors, const ComputeAnchorsInfo &info)
 Static function to check if given info will lead to a valid configuration of CLComputeAllAnchorsKernel. 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 Compute All Anchors kernel.

Definition at line 33 of file CLGenerateProposalsLayerKernel.h.

Constructor & Destructor Documentation

◆ CLComputeAllAnchorsKernel() [1/3]

Default constructor.

Definition at line 70 of file CLGenerateProposalsLayerKernel.cpp.

71  : _anchors(nullptr), _all_anchors(nullptr)
72 {
73 }

◆ CLComputeAllAnchorsKernel() [2/3]

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

◆ CLComputeAllAnchorsKernel() [3/3]

Allow instances of this class to be moved.

◆ ~CLComputeAllAnchorsKernel()

Default destructor.

Member Function Documentation

◆ configure() [1/2]

void configure ( const ICLTensor anchors,
ICLTensor all_anchors,
const ComputeAnchorsInfo info 
)

Set the input and output tensors.

Parameters
[in]anchorsSource tensor. Original set of anchors of size (4, A), where A is the number of anchors. Data types supported: QSYMM16/F16/F32
[out]all_anchorsDestination tensor. Destination anchors of size (4, H*W*A) where H and W are the height and width of the feature map and A is the number of anchors. Data types supported: Same as input
[in]infoContains Compute Anchors operation information described in ComputeAnchorsInfo

Definition at line 75 of file CLGenerateProposalsLayerKernel.cpp.

References CLKernelLibrary::get().

76 {
77  configure(CLKernelLibrary::get().get_compile_context(), anchors, all_anchors, info);
78 }
void configure(const ICLTensor *anchors, ICLTensor *all_anchors, const ComputeAnchorsInfo &info)
Set the input and output tensors.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
const ICLTensor anchors,
ICLTensor all_anchors,
const ComputeAnchorsInfo info 
)

Set the input and output tensors.

Parameters
[in]compile_contextThe compile context to be used.
[in]anchorsSource tensor. Original set of anchors of size (4, A), where A is the number of anchors. Data types supported: QSYMM16/F16/F32
[out]all_anchorsDestination tensor. Destination anchors of size (4, H*W*A) where H and W are the height and width of the feature map and A is the number of anchors. Data types supported: Same as input
[in]infoContains Compute Anchors operation information described in ComputeAnchorsInfo

Definition at line 80 of file CLGenerateProposalsLayerKernel.cpp.

References CLBuildOptions::add_option(), ARM_COMPUTE_ERROR_ON, 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(), arm_compute::test::validation::data_type, ITensorInfo::data_type(), ITensorInfo::dimension(), ComputeAnchorsInfo::feat_height(), ComputeAnchorsInfo::feat_width(), arm_compute::float_to_string_with_full_precision(), arm_compute::get_cl_type_from_data_type(), arm_compute::get_padding_info(), arm_compute::has_padding_changed(), ITensor::info(), arm_compute::test::validation::info, arm_compute::is_data_type_quantized(), kernel_name, UniformQuantizationInfo::offset, arm_compute::test::validation::output_shape, arm_compute::test::validation::qinfo, ITensorInfo::quantization_info(), UniformQuantizationInfo::scale, ComputeAnchorsInfo::spatial_scale(), arm_compute::support::cpp11::to_string(), QuantizationInfo::uniform(), arm_compute::validate_arguments(), and ComputeAnchorsInfo::values_per_roi().

81 {
82  ARM_COMPUTE_ERROR_ON_NULLPTR(anchors, all_anchors);
83  auto padding_info = get_padding_info({ anchors, all_anchors });
84  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(anchors->info(), all_anchors->info(), info));
85 
86  // Metadata
87  const size_t num_anchors = anchors->info()->dimension(1);
88  const DataType data_type = anchors->info()->data_type();
89  const float width = info.feat_width();
90  const float height = info.feat_height();
91 
92  // Initialize the output if empty
93  const TensorShape output_shape(info.values_per_roi(), width * height * num_anchors);
94  auto_init_if_empty(*all_anchors->info(), TensorInfo(output_shape, 1, data_type, anchors->info()->quantization_info()));
95 
96  // Set instance variables
97  _anchors = anchors;
98  _all_anchors = all_anchors;
99 
100  const bool is_quantized = is_data_type_quantized(anchors->info()->data_type());
101 
102  // Set build options
103  CLBuildOptions build_opts;
104  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type));
105  build_opts.add_option("-DWIDTH=" + float_to_string_with_full_precision(width));
106  build_opts.add_option("-DHEIGHT=" + float_to_string_with_full_precision(height));
107  build_opts.add_option("-DSTRIDE=" + float_to_string_with_full_precision(1.f / info.spatial_scale()));
108  build_opts.add_option("-DNUM_ANCHORS=" + support::cpp11::to_string(num_anchors));
109  build_opts.add_option("-DNUM_ROI_FIELDS=" + support::cpp11::to_string(info.values_per_roi()));
110 
111  if(is_quantized)
112  {
113  const UniformQuantizationInfo qinfo = anchors->info()->quantization_info().uniform();
114  build_opts.add_option("-DSCALE=" + float_to_string_with_full_precision(qinfo.scale));
115  build_opts.add_option("-DOFFSET=" + float_to_string_with_full_precision(qinfo.offset));
116  }
117 
118  // Create kernel
119  const std::string kernel_name = (is_quantized) ? "generate_proposals_compute_all_anchors_quantized" : "generate_proposals_compute_all_anchors";
120  _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
121 
122  // The tensor all_anchors can be interpreted as an array of structs (each structs has values_per_roi fields).
123  // This means we don't need to pad on the X dimension, as we know in advance how many fields
124  // compose the struct.
125  Window win = calculate_max_window(*all_anchors->info(), Steps(info.values_per_roi()));
126  ICLKernel::configure_internal(win);
128 }
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Definition: Utils.h:1168
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
std::string to_string(T &&value)
Convert integer and float values to string.
#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
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
const DataType data_type
Definition: Im2Col.cpp:150
cl::Kernel create_kernel(const CLCompileContext &ctx, const std::string &kernel_name, const std::set< std::string > &build_opts=std::set< std::string >())
Creates an opencl kernel using a compile context.
Definition: CLHelpers.cpp:403
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
Definition: Utils.h:1262
std::string kernel_name
UniformQuantizationInfo uniform() const
Return per layer quantization info.
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
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...
bool has_padding_changed(const std::unordered_map< const ITensorInfo *, PaddingSize > &padding_map)
Check if the previously stored padding info has changed after configuring a kernel.
Definition: Utils.cpp:528
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
const QuantizationInfo qinfo
Definition: Im2Col.cpp:155
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo *> infos)
Stores padding information before configuring a kernel.
Definition: Utils.cpp:513
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
DataType
Available data types.
Definition: Types.h:77

◆ operator=() [1/2]

CLComputeAllAnchorsKernel& operator= ( const CLComputeAllAnchorsKernel )
delete

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.

Reimplemented from ICLKernel.

Definition at line 136 of file CLGenerateProposalsLayerKernel.cpp.

References ICLKernel::add_1D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, Window::collapse(), Window::DimX, arm_compute::enqueue(), ICLKernel::lws_hint(), and IKernel::window().

137 {
140 
141  // Collapse everything on the first dimension
142  Window collapsed = window.collapse(ICLKernel::window(), Window::DimX);
143 
144  // Set arguments
145  unsigned int idx = 0;
146  add_1D_tensor_argument(idx, _anchors, collapsed);
147  add_1D_tensor_argument(idx, _all_anchors, collapsed);
148 
149  // Note that we don't need to loop over the slices, as we are launching exactly
150  // as many threads as all the anchors generated
151  enqueue(queue, *this, collapsed, lws_hint());
152 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
void enqueue(IGCKernel &kernel, const Window &window, const gles::NDRange &lws=gles::NDRange(1U, 1U, 1U))
Add the kernel to the command queue with the given window.
Definition: IGCKernel.cpp:41
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:276
Window collapse(const Window &full_window, size_t first, size_t last=Coordinates::num_max_dimensions) const
Collapse the dimensions between first and last.
Definition: Window.inl:111
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
void add_1D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 1D tensor&#39;s parameters to the object&#39;s kernel&#39;s arguments starting from the index idx...
Definition: ICLKernel.h:124
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

◆ validate()

Status validate ( const ITensorInfo anchors,
const ITensorInfo all_anchors,
const ComputeAnchorsInfo info 
)
static

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

Parameters
[in]anchorsSource tensor info. Original set of anchors of size (4, A), where A is the number of anchors. Data types supported: QSYMM16/F16/F32
[in]all_anchorsDestination tensor info. Destination anchors of size (4, H*W*A) where H and W are the height and width of the feature map and A is the number of anchors. Data types supported: Same as input
[in]infoContains Compute Anchors operation information described in ComputeAnchorsInfo
Returns
a Status

Definition at line 130 of file CLGenerateProposalsLayerKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, and arm_compute::validate_arguments().

Referenced by CLGenerateProposalsLayer::validate().

131 {
132  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(anchors, all_anchors, info));
133  return Status{};
134 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)

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