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

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

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

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

104 {
105  ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
106 
107  _input1 = input1;
108  _input2 = input2;
109  _output = output;
110  _info = info;
111  _min = min;
112  _max = max;
113  _aspect_ratios = aspect_ratios;
114 
115  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input1->info(), input2->info(), output->info(), info));
116 
117  // Calculate number of aspect ratios
118  _num_priors = info.aspect_ratios().size() * info.min_sizes().size() + info.max_sizes().size();
119 
120  const DataLayout data_layout = input1->info()->data_layout();
121 
124 
125  const int layer_width = input1->info()->dimension(width_idx);
126  const int layer_height = input1->info()->dimension(height_idx);
127 
128  int img_width = info.img_size().x;
129  int img_height = info.img_size().y;
130  if(img_width == 0 || img_height == 0)
131  {
132  img_width = input2->info()->dimension(width_idx);
133  img_height = input2->info()->dimension(height_idx);
134  }
135 
136  float step_x = info.steps()[0];
137  float step_y = info.steps()[0];
138  if(step_x == 0.f || step_y == 0.f)
139  {
140  step_x = static_cast<float>(img_width) / layer_width;
141  step_y = static_cast<float>(img_height) / layer_height;
142  }
143 
144  // Set build options
145  CLBuildOptions build_opts;
146  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input1->info()->data_type()));
147  build_opts.add_option("-DWIDTH=" + support::cpp11::to_string(img_width));
148  build_opts.add_option("-DHEIGHT=" + support::cpp11::to_string(img_height));
149  build_opts.add_option("-DLAYER_WIDTH=" + support::cpp11::to_string(layer_width));
150  build_opts.add_option("-DLAYER_HEIGHT=" + support::cpp11::to_string(layer_height));
151  build_opts.add_option("-DSTEP_X=" + support::cpp11::to_string(step_x));
152  build_opts.add_option("-DSTEP_Y=" + support::cpp11::to_string(step_y));
153  build_opts.add_option("-DNUM_PRIORS=" + support::cpp11::to_string(_num_priors));
154  build_opts.add_option("-DOFFSET=" + support::cpp11::to_string(info.offset()));
155  build_opts.add_option_if(info.clip(), "-DIN_PLACE");
156 
157  if(info.variances().size() > 1)
158  {
159  for(unsigned int i = 0; i < info.variances().size(); ++i)
160  {
161  build_opts.add_option("-DVARIANCE_" + support::cpp11::to_string(i) + "=" + support::cpp11::to_string(info.variances().at(i)));
162  }
163  }
164  else
165  {
166  for(unsigned int i = 0; i < 4; ++i)
167  {
168  build_opts.add_option("-DVARIANCE_" + support::cpp11::to_string(i) + "=" + support::cpp11::to_string(info.variances().at(0)));
169  }
170  }
171 
172  unsigned int idx = num_arguments_per_2D_tensor();
173  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("prior_box_layer_nchw", build_opts.options()));
174 
175  _kernel.setArg(idx++, *_min);
176  _kernel.setArg(idx++, *_max);
177  _kernel.setArg(idx++, *_aspect_ratios);
178  _kernel.setArg<unsigned int>(idx++, info.min_sizes().size());
179  _kernel.setArg<unsigned int>(idx++, info.max_sizes().size());
180  _kernel.setArg<unsigned int>(idx++, info.aspect_ratios().size());
181 
182  // Configure kernel window
183  auto win_config = validate_and_configure_window(input1->info(), input2->info(), output->info(), info, _num_priors);
184 
185  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
186  ICLKernel::configure_internal(win_config.second);
187 }
const DataLayout data_layout
Definition: Im2Col.cpp:146
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
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
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
static constexpr unsigned int num_arguments_per_2D_tensor()
Returns the number of arguments enqueued per 2D tensor object.
Definition: ICLKernel.h:192
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
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:326
DataLayout
[DataLayout enum definition]
Definition: Types.h:114

References CLBuildOptions::add_option(), CLBuildOptions::add_option_if(), ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::create_kernel(), arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), ITensorInfo::data_type(), ITensorInfo::dimension(), CLKernelLibrary::get(), arm_compute::get_cl_type_from_data_type(), arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, ITensor::info(), arm_compute::test::validation::info, ICLKernel::num_arguments_per_2D_tensor(), CLBuildOptions::options(), arm_compute::support::cpp11::to_string(), arm_compute::validate_and_configure_window(), and arm_compute::WIDTH.

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

Implements ICLKernel.

Definition at line 200 of file CLPriorBoxLayerKernel.cpp.

201 {
204 
205  queue.enqueueWriteBuffer(*_min, CL_TRUE, 0, _info.min_sizes().size() * sizeof(float), _info.min_sizes().data());
206  queue.enqueueWriteBuffer(*_aspect_ratios, CL_TRUE, 0, _info.aspect_ratios().size() * sizeof(float), _info.aspect_ratios().data());
207  if(!_info.max_sizes().empty())
208  {
209  queue.enqueueWriteBuffer(*_max, CL_TRUE, 0, _info.max_sizes().size() * sizeof(float), _info.max_sizes().data());
210  }
211 
213  slice.set(Window::DimY, Window::Dimension(0, _output->info()->dimension(1), 2));
214 
215  unsigned int idx = 0;
216  add_2D_tensor_argument(idx, _output, slice);
217  enqueue(queue, *this, slice);
218 }
Window first_slice_window_2D() const
First 2D slice of the window.
Definition: Window.h:267
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
std::vector< float > aspect_ratios() const
Get aspect ratios.
Definition: Types.h:930
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
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's parameters to the object's kernel's arguments starting from the index idx.
Definition: ICLKernel.h:134
std::vector< float > max_sizes() const
Get max sizes.
Definition: Types.h:925
#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
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
std::vector< float > min_sizes() const
Get min sizes.
Definition: Types.h:890

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(), PriorBoxLayerInfo::max_sizes(), PriorBoxLayerInfo::min_sizes(), arm_compute::test::validation::reference::slice(), and IKernel::window().

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

190 {
191  ARM_COMPUTE_ERROR_ON_NULLPTR(input1, input2, output);
192  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input1, input2, output, info));
193  const int num_priors = info.aspect_ratios().size() * info.min_sizes().size() + info.max_sizes().size();
194  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input1->clone().get(), input2->clone().get(), output->clone().get(), info, num_priors)
195  .first);
196 
197  return Status{};
198 }
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, ICloneable< T >::clone(), arm_compute::test::validation::info, and arm_compute::validate_and_configure_window().

Referenced by CLPriorBoxLayer::validate().


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