Compute Library
 21.05
ClCropKernel Class Reference

OpenCL kernel to perform a copy between two tensors. More...

#include <ClCropKernel.h>

Collaboration diagram for ClCropKernel:
[legend]

Public Member Functions

 ClCropKernel ()=default
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (ClCropKernel)
 
void configure (const ITensorInfo *src, ITensorInfo *dst, Coordinates2D start, Coordinates2D end, uint32_t batch_index, float extrapolation_value=0, Window *dst_window=nullptr)
 Configure kernel. More...
 
void configure (const CLCompileContext &compile_context, const ITensorInfo *src, ITensorInfo *dst, Coordinates2D start, Coordinates2D end, uint32_t batch_index, float extrapolation_value=0, Window *dst_window=nullptr)
 Configure kernel. More...
 
void run_op (ITensorPack &tensors, 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 (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 *src, const ITensorInfo *dst, Coordinates2D start, Coordinates2D end, uint32_t batch_index, float extrapolation_value=0, Window *dst_window=nullptr)
 Static function to check if given info will lead to a valid configuration of CLStridedSliceKernel. 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

OpenCL kernel to perform a copy between two tensors.

Definition at line 38 of file ClCropKernel.h.

Constructor & Destructor Documentation

◆ ClCropKernel()

ClCropKernel ( )
default

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( ClCropKernel  )

◆ configure() [1/2]

void configure ( const ITensorInfo src,
ITensorInfo dst,
Coordinates2D  start,
Coordinates2D  end,
uint32_t  batch_index,
float  extrapolation_value = 0,
Window dst_window = nullptr 
)

Configure kernel.

Note
Supported tensor rank: up to 4
Parameters
[in]srcSource tensor info. Data type supported: All. Data layouts supported: NHWC.
[out]dstDestination tensor info. Data type supported: F32
[in]startCoordinates of where to start cropping the image.
[in]endCoordinates of where to end cropping the image.
[in]batch_indexFourth dimension index of the 3D image to crop in src.
[in]extrapolation_valueValue to be used for values outside of the image. Default is 0.
[in]dst_windowOutput window to be used in case cropped image is being copied into a tensor. Default is nullptr.

Definition at line 44 of file ClCropKernel.cpp.

45 {
46  configure(CLKernelLibrary::get().get_compile_context(), src, dst, start, end, batch_index, extrapolation_value, dst_window);
47 }
void configure(const ITensorInfo *src, ITensorInfo *dst, Coordinates2D start, Coordinates2D end, uint32_t batch_index, float extrapolation_value=0, Window *dst_window=nullptr)
Configure kernel.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
SimpleTensor< float > src
Definition: DFT.cpp:155
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290

References arm_compute::test::validation::dst, arm_compute::mlgo::parser::end(), CLKernelLibrary::get(), and arm_compute::test::validation::src.

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
const ITensorInfo src,
ITensorInfo dst,
Coordinates2D  start,
Coordinates2D  end,
uint32_t  batch_index,
float  extrapolation_value = 0,
Window dst_window = nullptr 
)

Configure kernel.

Note
Supported tensor rank: up to 4
Parameters
[in]compile_contextThe compile context to be used.
[in]srcSource tensor info. Data type supported: All. Data layouts supported: NHWC.
[out]dstDestination tensor info. Data type supported: F32
[in]startCoordinates of where to start cropping the image.
[in]endCoordinates of where to end cropping the image.
[in]batch_indexFourth dimension index of the 3D image to crop in src.
[in]extrapolation_valueValue to be used for values outside of the image. Default is 0.
[in]dst_windowOutput window to be used in case cropped image is being copied into a tensor. Default is nullptr.

Definition at line 49 of file ClCropKernel.cpp.

51 {
53  ARM_COMPUTE_ERROR_THROW_ON(validate(src, dst, start, end, batch_index, extrapolation_value, dst_window));
54 
55  _start = start;
56  _batch_index = batch_index;
57  _extrapolation_value = extrapolation_value;
58 
59  const int vec_size_x = 4;
60  // Create and update the window (if needed)
61  Window win = calculate_max_window(*dst);
62 
63  if(dst_window != nullptr)
64  {
66  win = *dst_window;
67  }
68 
69  const int dst_width_x = win.num_iterations(0);
70  const bool multi_access_x = dst_width_x >= vec_size_x;
71  const bool remainder_x = dst_width_x % vec_size_x > 0;
72 
73  if(multi_access_x)
74  {
75  win.set(Window::DimX,
76  Window::Dimension(win.x().start(), ceil_to_multiple(win.x().end(), vec_size_x), vec_size_x));
77  }
78  ICLKernel::configure_internal(win);
79 
80  // Create kernel
81  CLBuildOptions build_opts;
82  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(src->data_type()));
83  build_opts.add_option_if(multi_access_x, "-DVEC_SIZE=" + support::cpp11::to_string(vec_size_x));
84  build_opts.add_option_if(multi_access_x && remainder_x, "-DLAST_ACCESSED_X=" + support::cpp11::to_string(std::max<int>(dst_width_x - vec_size_x, 0)));
85  build_opts.add_option_if(start.x > end.x, "-DWIDTH_FLIPPED=");
86  build_opts.add_option_if(start.y > end.y, "-DHEIGHT_FLIPPED=");
87  _kernel = create_kernel(compile_context, "crop_tensor", build_opts.options());
88 }
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_THROW_ON(status)
Definition: Error.h:455
SimpleTensor< float > src
Definition: DFT.cpp:155
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
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
auto ceil_to_multiple(S value, T divisor) -> decltype(((value+divisor - 1)/divisor) *divisor)
Computes the smallest number larger or equal to value that is a multiple of divisor.
Definition: Utils.h:71
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
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
int x
The x coordinate.
Definition: types.h:30
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
int y
The y coordinate.
Definition: types.h:31
static Status validate(const ITensorInfo *src, const ITensorInfo *dst, Coordinates2D start, Coordinates2D end, uint32_t batch_index, float extrapolation_value=0, Window *dst_window=nullptr)
Static function to check if given info will lead to a valid configuration of CLStridedSliceKernel.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201

References CLBuildOptions::add_option(), CLBuildOptions::add_option_if(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::calculate_max_window(), arm_compute::ceil_to_multiple(), arm_compute::create_kernel(), Window::DimX, arm_compute::test::validation::dst, Window::Dimension::end(), arm_compute::mlgo::parser::end(), arm_compute::get_cl_type_from_data_type(), Window::num_iterations(), CLBuildOptions::options(), Window::set(), arm_compute::test::validation::src, Window::Dimension::start(), arm_compute::support::cpp11::to_string(), ClCropKernel::validate(), Window::x(), Coordinates2D::x, and Coordinates2D::y.

◆ run_op()

void run_op ( ITensorPack tensors,
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]tensorsA vector containing the tensors to operato on.
[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 114 of file ClCropKernel.cpp.

115 {
118 
119  const auto src = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC));
120  auto dst = utils::cast::polymorphic_downcast<ICLTensor *>(tensors.get_tensor(TensorType::ACL_DST));
121 
122  Window in_slice = Window();
123  in_slice.use_tensor_dimensions(src->info()->tensor_shape());
124  in_slice.set(Window::DimX, Window::Dimension(in_slice.x().start(), ceil_to_multiple(in_slice.x().end(), window.x().step()), window.x().step()));
125  in_slice.set(3, Window::Dimension(_batch_index, _batch_index + 1, 1));
126 
127  unsigned int idx = 0;
128  add_3D_tensor_argument(idx, src, in_slice);
130  add_argument(idx, _start.x);
131  add_argument(idx, _start.y);
132  enqueue(queue, *this, window, lws_hint());
133 }
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
constexpr int step() const
Return the step of the dimension.
Definition: Window.h:104
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:276
void add_argument(unsigned int &idx, T value)
Add the passed parameters to the object's kernel's arguments starting from the index idx.
Definition: ICLKernel.h:255
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.
Definition: ICLKernel.h:172
SimpleTensor< float > src
Definition: DFT.cpp:155
int32_t x
X coordinates.
Definition: Types.h:418
int32_t y
Y coordinates.
Definition: Types.h:419
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
auto ceil_to_multiple(S value, T divisor) -> decltype(((value+divisor - 1)/divisor) *divisor)
Computes the smallest number larger or equal to value that is a multiple of divisor.
Definition: Utils.h:71
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
Definition: Window.h:145

References arm_compute::ACL_DST, arm_compute::ACL_SRC, ICLKernel::add_3D_tensor_argument(), ICLKernel::add_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, arm_compute::ceil_to_multiple(), Window::DimX, arm_compute::test::validation::dst, arm_compute::enqueue(), ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), ICLKernel::lws_hint(), arm_compute::test::validation::src, Window::Dimension::step(), IKernel::window(), Window::x(), Coordinates2D::x, and Coordinates2D::y.

◆ validate()

Status validate ( const ITensorInfo src,
const ITensorInfo dst,
Coordinates2D  start,
Coordinates2D  end,
uint32_t  batch_index,
float  extrapolation_value = 0,
Window dst_window = nullptr 
)
static

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

Note
Supported tensor rank: up to 4
Parameters
[in]srcSource tensor info. Data type supported: All. Data layouts supported: NHWC.
[in]dstDestination tensor info. Data type supported: F32
[in]startCoordinates of where to start cropping the image.
[in]endCoordinates of where to end cropping the image.
[in]batch_indexFourth dimension index of the 3D image to crop in src.
[in]extrapolation_valueValue to be used for values outside of the image. Default is 0.
[in]dst_windowOutput window to be used in case cropped image is being copied into a tensor. Default is nullptr.

Definition at line 90 of file ClCropKernel.cpp.

91 {
92  ARM_COMPUTE_UNUSED(extrapolation_value, dst_window);
96  ARM_COMPUTE_RETURN_ERROR_ON(src->tensor_shape().num_dimensions() > 4);
97  ARM_COMPUTE_RETURN_ERROR_ON(start.x < 0 || start.y < 0 || end.x < 0 || end.y < 0);
98  ARM_COMPUTE_RETURN_ERROR_ON(start.x >= static_cast<int32_t>(src->dimension(1)) || start.y >= static_cast<int32_t>(src->dimension(2))
99  || end.x >= static_cast<int32_t>(src->dimension(1)) || end.y >= static_cast<int32_t>(src->dimension(2)));
100  ARM_COMPUTE_RETURN_ERROR_ON(batch_index >= src->dimension(3));
101  if(dst_window != nullptr)
102  {
103  ARM_COMPUTE_RETURN_ERROR_ON(dst_window->x().step() != 1);
104  }
105  if(dst->total_size() > 0)
106  {
109  ARM_COMPUTE_RETURN_ERROR_ON(dst->num_dimensions() > 3);
110  }
111  return Status{};
112 }
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_LAYOUT_NOT_IN(t,...)
Definition: Validate.h:742
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(...)
Definition: Validate.h:490
#define ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(tensor)
Definition: Validate.h:108
1 channel, 1 F32 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
SimpleTensor< float > src
Definition: DFT.cpp:155
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
int x
The x coordinate.
Definition: types.h:30
Num samples, height, width, channels.
int y
The y coordinate.
Definition: types.h:31
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN(t,...)
Definition: Validate.h:690

References ARM_COMPUTE_RETURN_ERROR_ON, ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED, ARM_COMPUTE_RETURN_ERROR_ON_DATA_LAYOUT_NOT_IN, ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_NOT_IN, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT, ARM_COMPUTE_UNUSED, arm_compute::test::validation::dst, arm_compute::mlgo::parser::end(), arm_compute::F32, arm_compute::NHWC, arm_compute::test::validation::src, Window::Dimension::step(), arm_compute::UNKNOWN, Window::x(), Coordinates2D::x, and Coordinates2D::y.

Referenced by ClCropKernel::configure(), and ClCrop::validate().


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