Compute Library
 19.08
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 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 *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 63 of file CLGenerateProposalsLayerKernel.cpp.

64  : _anchors(nullptr), _all_anchors(nullptr)
65 {
66 }

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

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: 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 68 of file CLGenerateProposalsLayerKernel.cpp.

69 {
70  ARM_COMPUTE_ERROR_ON_NULLPTR(anchors, all_anchors);
71  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(anchors->info(), all_anchors->info(), info));
72 
73  // Metadata
74  const size_t num_anchors = anchors->info()->dimension(1);
75  const DataType data_type = anchors->info()->data_type();
76  const float width = info.feat_width();
77  const float height = info.feat_height();
78 
79  // Initialize the output if empty
80  const TensorShape output_shape(info.values_per_roi(), width * height * num_anchors);
81  auto_init_if_empty(*all_anchors->info(), output_shape, 1, data_type);
82 
83  // Set instance variables
84  _anchors = anchors;
85  _all_anchors = all_anchors;
86 
87  // Set build options
88  CLBuildOptions build_opts;
89  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type));
90  build_opts.add_option("-DWIDTH=" + float_to_string_with_full_precision(width));
91  build_opts.add_option("-DHEIGHT=" + float_to_string_with_full_precision(height));
92  build_opts.add_option("-DSTRIDE=" + float_to_string_with_full_precision(1.f / info.spatial_scale()));
93  build_opts.add_option("-DNUM_ANCHORS=" + support::cpp11::to_string(num_anchors));
94  build_opts.add_option("-DNUM_ROI_FIELDS=" + support::cpp11::to_string(info.values_per_roi()));
95 
96  // Create kernel
97  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("generate_proposals_compute_all_anchors", build_opts.options()));
98 
99  // The tensor all_anchors can be interpreted as an array of structs (each structs has values_per_roi fields).
100  // This means we don't need to pad on the X dimension, as we know in advance how many fields
101  // compose the struct.
102  Window win = calculate_max_window(*all_anchors->info(), Steps(info.values_per_roi()));
103  ICLKernel::configure_internal(win);
104 }
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
DataType
Available data types.
Definition: Types.h:74

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(), arm_compute::test::validation::data_type, ITensorInfo::data_type(), ITensorInfo::dimension(), 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, CLBuildOptions::options(), arm_compute::test::validation::output_shape, and arm_compute::support::cpp11::to_string().

Referenced by CLGenerateProposalsLayer::configure().

◆ 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.

Implements ICLKernel.

Definition at line 112 of file CLGenerateProposalsLayerKernel.cpp.

113 {
116 
117  // Collapse everything on the first dimension
118  Window collapsed = window.collapse(ICLKernel::window(), Window::DimX);
119 
120  // Set arguments
121  unsigned int idx = 0;
122  add_1D_tensor_argument(idx, _anchors, collapsed);
123  add_1D_tensor_argument(idx, _all_anchors, collapsed);
124 
125  // Note that we don't need to loop over the slices, as we are launching exactly
126  // as many threads as all the anchors generated
127  enqueue(queue, *this, collapsed);
128 }
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
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:97
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
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

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(), 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: 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 106 of file CLGenerateProposalsLayerKernel.cpp.

107 {
108  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(anchors, all_anchors, info));
109  return Status{};
110 }
#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 CLComputeAllAnchors::validate(), and CLGenerateProposalsLayer::validate().


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