Compute Library
 21.02
CLPriorBoxLayerKernel Class Reference

Interface for the PriorBox layer kernel. More...

#include <CLPriorBoxLayerKernel.h>

Collaboration diagram for CLPriorBoxLayerKernel:
[legend]

Public Member Functions

 CLPriorBoxLayerKernel ()
 Constructor. More...
 
 CLPriorBoxLayerKernel (const CLPriorBoxLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLPriorBoxLayerKerneloperator= (const CLPriorBoxLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLPriorBoxLayerKernel (CLPriorBoxLayerKernel &&)=default
 Default Move Constructor. More...
 
CLPriorBoxLayerKerneloperator= (CLPriorBoxLayerKernel &&)=default
 Default move assignment operator. More...
 
 ~CLPriorBoxLayerKernel ()=default
 Default destructor. More...
 
void configure (const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output, const PriorBoxLayerInfo &info, cl::Buffer *min, cl::Buffer *max, cl::Buffer *aspect_ratios)
 Set the input and output tensors. More...
 
void configure (const CLCompileContext &compile_context, const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output, const PriorBoxLayerInfo &info, cl::Buffer *min, cl::Buffer *max, cl::Buffer *aspect_ratios)
 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 *input1, const ITensorInfo *input2, const ITensorInfo *output, const PriorBoxLayerInfo &info)
 Static function to check if given info will lead to a valid configuration of CLPriorBoxLayerKernel. 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 PriorBox layer kernel.

Definition at line 34 of file CLPriorBoxLayerKernel.h.

Constructor & Destructor Documentation

◆ CLPriorBoxLayerKernel() [1/3]

Constructor.

Definition at line 99 of file CLPriorBoxLayerKernel.cpp.

100  : _input1(nullptr), _input2(nullptr), _output(nullptr), _info(), _num_priors(), _min(), _max(), _aspect_ratios()
101 {
102 }

◆ CLPriorBoxLayerKernel() [2/3]

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

◆ CLPriorBoxLayerKernel() [3/3]

Default Move Constructor.

◆ ~CLPriorBoxLayerKernel()

~CLPriorBoxLayerKernel ( )
default

Default destructor.

Member Function Documentation

◆ configure() [1/2]

void configure ( const ICLTensor input1,
const ICLTensor input2,
ICLTensor output,
const PriorBoxLayerInfo info,
cl::Buffer *  min,
cl::Buffer *  max,
cl::Buffer *  aspect_ratios 
)

Set the input and output tensors.

Parameters
[in]input1First source tensor. Data types supported: F32. Data layouts supported: NCHW/NHWC.
[in]input2Second source tensor. Data types and layouts supported: same as input1
[out]outputDestination tensor. Output dimensions are [W * H * num_priors * 4, 2]. Data types and layouts supported: same as input1
[in]infoPrior box layer info.
[in]minMinimum prior box values
[in]maxMaximum prior box values
[in]aspect_ratiosAspect ratio values

Definition at line 104 of file CLPriorBoxLayerKernel.cpp.

References CLKernelLibrary::get().

105 {
106  configure(CLKernelLibrary::get().get_compile_context(), input1, input2, output, info, min, max, aspect_ratios);
107 }
void configure(const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output, const PriorBoxLayerInfo &info, cl::Buffer *min, cl::Buffer *max, cl::Buffer *aspect_ratios)
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 input1,
const ICLTensor input2,
ICLTensor output,
const PriorBoxLayerInfo info,
cl::Buffer *  min,
cl::Buffer *  max,
cl::Buffer *  aspect_ratios 
)

Set the input and output tensors.

Parameters
[in]compile_contextThe compile context to be used.
[in]input1First source tensor. Data types supported: F32. Data layouts supported: NCHW/NHWC.
[in]input2Second source tensor. Data types and layouts supported: same as input1
[out]outputDestination tensor. Output dimensions are [W * H * num_priors * 4, 2]. Data types and layouts supported: same as input1
[in]infoPrior box layer info.
[in]minMinimum prior box values
[in]maxMaximum prior box values
[in]aspect_ratiosAspect ratio values

Definition at line 109 of file CLPriorBoxLayerKernel.cpp.

References CLBuildOptions::add_option(), CLBuildOptions::add_option_if(), ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, PriorBoxLayerInfo::aspect_ratios(), PriorBoxLayerInfo::clip(), arm_compute::create_kernel(), arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), ITensorInfo::data_type(), ITensorInfo::dimension(), arm_compute::get_cl_type_from_data_type(), arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, PriorBoxLayerInfo::img_size(), ITensor::info(), arm_compute::test::validation::info, PriorBoxLayerInfo::max_sizes(), PriorBoxLayerInfo::min_sizes(), ICLKernel::num_arguments_per_2D_tensor(), PriorBoxLayerInfo::offset(), CLBuildOptions::options(), PriorBoxLayerInfo::steps(), arm_compute::support::cpp11::to_string(), arm_compute::validate_arguments(), PriorBoxLayerInfo::variances(), arm_compute::WIDTH, Coordinates2D::x, and Coordinates2D::y.

111 {
112  ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
113 
114  _input1 = input1;
115  _input2 = input2;
116  _output = output;
117  _info = info;
118  _min = min;
119  _max = max;
120  _aspect_ratios = aspect_ratios;
121 
122  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input1->info(), input2->info(), output->info(), info));
123 
124  // Calculate number of aspect ratios
125  _num_priors = info.aspect_ratios().size() * info.min_sizes().size() + info.max_sizes().size();
126 
127  const DataLayout data_layout = input1->info()->data_layout();
128 
129  const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
130  const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
131 
132  const int layer_width = input1->info()->dimension(width_idx);
133  const int layer_height = input1->info()->dimension(height_idx);
134 
135  int img_width = info.img_size().x;
136  int img_height = info.img_size().y;
137  if(img_width == 0 || img_height == 0)
138  {
139  img_width = input2->info()->dimension(width_idx);
140  img_height = input2->info()->dimension(height_idx);
141  }
142 
143  float step_x = info.steps()[0];
144  float step_y = info.steps()[0];
145  if(step_x == 0.f || step_y == 0.f)
146  {
147  step_x = static_cast<float>(img_width) / layer_width;
148  step_y = static_cast<float>(img_height) / layer_height;
149  }
150 
151  // Set build options
152  CLBuildOptions build_opts;
153  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input1->info()->data_type()));
154  build_opts.add_option("-DWIDTH=" + support::cpp11::to_string(img_width));
155  build_opts.add_option("-DHEIGHT=" + support::cpp11::to_string(img_height));
156  build_opts.add_option("-DLAYER_WIDTH=" + support::cpp11::to_string(layer_width));
157  build_opts.add_option("-DLAYER_HEIGHT=" + support::cpp11::to_string(layer_height));
158  build_opts.add_option("-DSTEP_X=" + support::cpp11::to_string(step_x));
159  build_opts.add_option("-DSTEP_Y=" + support::cpp11::to_string(step_y));
160  build_opts.add_option("-DNUM_PRIORS=" + support::cpp11::to_string(_num_priors));
161  build_opts.add_option("-DOFFSET=" + support::cpp11::to_string(info.offset()));
162  build_opts.add_option_if(info.clip(), "-DIN_PLACE");
163 
164  if(info.variances().size() > 1)
165  {
166  for(unsigned int i = 0; i < info.variances().size(); ++i)
167  {
168  build_opts.add_option("-DVARIANCE_" + support::cpp11::to_string(i) + "=" + support::cpp11::to_string(info.variances().at(i)));
169  }
170  }
171  else
172  {
173  for(unsigned int i = 0; i < 4; ++i)
174  {
175  build_opts.add_option("-DVARIANCE_" + support::cpp11::to_string(i) + "=" + support::cpp11::to_string(info.variances().at(0)));
176  }
177  }
178 
179  unsigned int idx = num_arguments_per_2D_tensor();
180  _kernel = create_kernel(compile_context, "prior_box_layer_nchw", build_opts.options());
181 
182  _kernel.setArg(idx++, *_min);
183  _kernel.setArg(idx++, *_max);
184  _kernel.setArg(idx++, *_aspect_ratios);
185  _kernel.setArg<unsigned int>(idx++, info.min_sizes().size());
186  _kernel.setArg<unsigned int>(idx++, info.max_sizes().size());
187  _kernel.setArg<unsigned int>(idx++, info.aspect_ratios().size());
188 
189  // Configure kernel window
190  auto win_config = validate_and_configure_window(input1->info(), input2->info(), output->info(), info, _num_priors);
191 
192  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
193  ICLKernel::configure_internal(win_config.second);
194 }
std::string to_string(T &&value)
Convert integer and float values to string.
const DataLayout data_layout
Definition: Im2Col.cpp:151
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
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 get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
Definition: CLHelpers.cpp:37
static constexpr unsigned int num_arguments_per_2D_tensor()
Returns the number of arguments enqueued per 2D tensor object.
Definition: ICLKernel.h:206
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)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
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:193
DataLayout
[DataLayout enum definition]
Definition: Types.h:120

◆ operator=() [1/2]

CLPriorBoxLayerKernel& operator= ( const CLPriorBoxLayerKernel )
delete

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

◆ operator=() [2/2]

CLPriorBoxLayerKernel& operator= ( CLPriorBoxLayerKernel &&  )
default

Default move assignment operator.

◆ 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 207 of file CLPriorBoxLayerKernel.cpp.

References ICLKernel::add_2D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, PriorBoxLayerInfo::aspect_ratios(), ITensorInfo::dimension(), Window::DimY, arm_compute::enqueue(), Window::first_slice_window_2D(), ITensor::info(), ICLKernel::lws_hint(), PriorBoxLayerInfo::max_sizes(), PriorBoxLayerInfo::min_sizes(), Window::set(), arm_compute::test::validation::reference::slice(), and IKernel::window().

208 {
211 
212  queue.enqueueWriteBuffer(*_min, CL_TRUE, 0, _info.min_sizes().size() * sizeof(float), _info.min_sizes().data());
213  queue.enqueueWriteBuffer(*_aspect_ratios, CL_TRUE, 0, _info.aspect_ratios().size() * sizeof(float), _info.aspect_ratios().data());
214  if(!_info.max_sizes().empty())
215  {
216  queue.enqueueWriteBuffer(*_max, CL_TRUE, 0, _info.max_sizes().size() * sizeof(float), _info.max_sizes().data());
217  }
218 
220  slice.set(Window::DimY, Window::Dimension(0, _output->info()->dimension(1), 2));
221 
222  unsigned int idx = 0;
223  add_2D_tensor_argument(idx, _output, slice);
224  enqueue(queue, *this, slice, lws_hint());
225 }
Window first_slice_window_2D() const
First 2D slice of the window.
Definition: Window.h:283
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
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:276
std::vector< float > aspect_ratios() const
Get aspect ratios.
Definition: Types.h:944
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:49
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
void add_2D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 2D tensor&#39;s parameters to the object&#39;s kernel&#39;s arguments starting from the index idx...
Definition: ICLKernel.h:148
std::vector< float > max_sizes() const
Get max sizes.
Definition: Types.h:939
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
std::vector< float > min_sizes() const
Get min sizes.
Definition: Types.h:904

◆ validate()

Status validate ( const ITensorInfo input1,
const ITensorInfo input2,
const ITensorInfo output,
const PriorBoxLayerInfo info 
)
static

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

Parameters
[in]input1First source tensor info. Data types supported: F32. Data layouts supported: NCHW/NHWC.
[in]input2Second source tensor info. Data types and layouts supported: same as input1
[in]outputDestination tensor info. Output dimensions are [W * H * num_priors * 4, 2]. Data type supported: same as input1
[in]infoPrior box layer info.
Returns
a status

Definition at line 196 of file CLPriorBoxLayerKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, PriorBoxLayerInfo::aspect_ratios(), ICloneable< T >::clone(), arm_compute::test::validation::info, PriorBoxLayerInfo::max_sizes(), PriorBoxLayerInfo::min_sizes(), and arm_compute::validate_arguments().

Referenced by CLPriorBoxLayer::validate().

197 {
198  ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
199  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input1, input2, output, info));
200  const int num_priors = info.aspect_ratios().size() * info.min_sizes().size() + info.max_sizes().size();
201  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input1->clone().get(), input2->clone().get(), output->clone().get(), info, num_priors)
202  .first);
203 
204  return Status{};
205 }
#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)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

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