Compute Library
 21.05
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...
 
bool is_window_configured () const
 Function to check if the embedded window of this kernel has been configured. 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 68 of file CLGenerateProposalsLayerKernel.cpp.

69  : _anchors(nullptr), _all_anchors(nullptr)
70 {
71 }

◆ 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 73 of file CLGenerateProposalsLayerKernel.cpp.

74 {
75  configure(CLKernelLibrary::get().get_compile_context(), anchors, all_anchors, info);
76 }
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)

References CLKernelLibrary::get(), and arm_compute::test::validation::info.

◆ 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 78 of file CLGenerateProposalsLayerKernel.cpp.

79 {
80  ARM_COMPUTE_ERROR_ON_NULLPTR(anchors, all_anchors);
81  auto padding_info = get_padding_info({ anchors, all_anchors });
82  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(anchors->info(), all_anchors->info(), info));
83 
84  // Metadata
85  const size_t num_anchors = anchors->info()->dimension(1);
86  const DataType data_type = anchors->info()->data_type();
87  const float width = info.feat_width();
88  const float height = info.feat_height();
89 
90  // Initialize the output if empty
91  const TensorShape output_shape(info.values_per_roi(), width * height * num_anchors);
92  auto_init_if_empty(*all_anchors->info(), TensorInfo(output_shape, 1, data_type, anchors->info()->quantization_info()));
93 
94  // Set instance variables
95  _anchors = anchors;
96  _all_anchors = all_anchors;
97 
98  const bool is_quantized = is_data_type_quantized(anchors->info()->data_type());
99 
100  // Set build options
101  CLBuildOptions build_opts;
102  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type));
103  build_opts.add_option("-DWIDTH=" + float_to_string_with_full_precision(width));
104  build_opts.add_option("-DHEIGHT=" + float_to_string_with_full_precision(height));
105  build_opts.add_option("-DSTRIDE=" + float_to_string_with_full_precision(1.f / info.spatial_scale()));
106  build_opts.add_option("-DNUM_ANCHORS=" + support::cpp11::to_string(num_anchors));
107  build_opts.add_option("-DNUM_ROI_FIELDS=" + support::cpp11::to_string(info.values_per_roi()));
108 
109  if(is_quantized)
110  {
111  const UniformQuantizationInfo qinfo = anchors->info()->quantization_info().uniform();
112  build_opts.add_option("-DSCALE=" + float_to_string_with_full_precision(qinfo.scale));
113  build_opts.add_option("-DOFFSET=" + float_to_string_with_full_precision(qinfo.offset));
114  }
115 
116  // Create kernel
117  const std::string kernel_name = (is_quantized) ? "generate_proposals_compute_all_anchors_quantized" : "generate_proposals_compute_all_anchors";
118  _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
119 
120  // The tensor all_anchors can be interpreted as an array of structs (each structs has values_per_roi fields).
121  // This means we don't need to pad on the X dimension, as we know in advance how many fields
122  // compose the struct.
123  Window win = calculate_max_window(*all_anchors->info(), Steps(info.values_per_roi()));
124  ICLKernel::configure_internal(win);
126 }
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Definition: Utils.h:967
const std::vector< int32_t > & offset() const
Offset vector accessor.
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
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:489
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:1061
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...
const std::vector< float > & scale() const
Scale vector accessor.
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:504
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
const QuantizationInfo qinfo
Definition: Im2Col.cpp:155
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:157
DataType
Available data types.
Definition: Types.h:77

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(), 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, QuantizationInfo::offset(), arm_compute::test::validation::output_shape, arm_compute::test::validation::qinfo, ITensorInfo::quantization_info(), QuantizationInfo::scale(), arm_compute::support::cpp11::to_string(), QuantizationInfo::uniform(), and arm_compute::validate_arguments().

◆ 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 134 of file CLGenerateProposalsLayerKernel.cpp.

135 {
138 
139  // Collapse everything on the first dimension
140  Window collapsed = window.collapse(ICLKernel::window(), Window::DimX);
141 
142  // Set arguments
143  unsigned int idx = 0;
144  add_1D_tensor_argument(idx, _anchors, collapsed);
145  add_1D_tensor_argument(idx, _all_anchors, collapsed);
146 
147  // Note that we don't need to loop over the slices, as we are launching exactly
148  // as many threads as all the anchors generated
149  enqueue(queue, *this, collapsed, lws_hint());
150 }
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:32
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:915
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:124
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201

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().

◆ 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 128 of file CLGenerateProposalsLayerKernel.cpp.

129 {
130  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(anchors, all_anchors, info));
131  return Status{};
132 }
#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)

References ARM_COMPUTE_RETURN_ON_ERROR, arm_compute::test::validation::info, and arm_compute::validate_arguments().

Referenced by CLGenerateProposalsLayer::validate().


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