Compute Library
 23.11
CLBitwiseKernel Class Reference

Interface for the bitwise operation kernel. More...

#include <CLBitwiseKernel.h>

Collaboration diagram for CLBitwiseKernel:
[legend]

Public Member Functions

 CLBitwiseKernel ()
 Default constructor. More...
 
 CLBitwiseKernel (const CLBitwiseKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLBitwiseKerneloperator= (const CLBitwiseKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLBitwiseKernel (CLBitwiseKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLBitwiseKerneloperator= (CLBitwiseKernel &&)=default
 Allow instances of this class to be moved. More...
 
void configure (const CLCompileContext &compile_context, const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output, BitwiseOperation op)
 Set the inputs 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...
 
CLKernelType type () const
 Returns the CL kernel type. 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...
 
void add_5D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 5D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_3d_tensor_nhw_argument (unsigned int &idx, const ICLTensor *tensor)
 Add the passed NHW 3D tensor's parameters to the object's kernel's arguments by passing strides, dimensions and the offset to the first valid element in bytes. More...
 
void add_4d_tensor_nhwc_argument (unsigned int &idx, const ICLTensor *tensor)
 Add the passed NHWC 4D tensor's parameters to the object's kernel's arguments by passing strides, dimensions and the offset to the first valid element in bytes. 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...
 
cl::NDRange get_cached_gws () const
 Get the cached gws used to enqueue this kernel. More...
 
void cache_gws (const cl::NDRange &gws)
 Cache the latest gws used to enqueue this kernel. 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...
 

Additional Inherited Members

- Static Public Member Functions inherited from ICLKernel
constexpr static unsigned int num_arguments_per_3d_tensor_nhw ()
 Returns the number of arguments enqueued per NHW 3D Tensor object. More...
 
constexpr static unsigned int num_arguments_per_4d_tensor_nhwc ()
 Returns the number of arguments enqueued per NHWC 4D Tensor object. More...
 
constexpr static unsigned int num_arguments_per_1D_array ()
 Returns the number of arguments enqueued per 1D array object. More...
 
constexpr static unsigned int num_arguments_per_1D_tensor ()
 Returns the number of arguments enqueued per 1D tensor object. More...
 
constexpr static unsigned int num_arguments_per_2D_tensor ()
 Returns the number of arguments enqueued per 2D tensor object. More...
 
constexpr static unsigned int num_arguments_per_3D_tensor ()
 Returns the number of arguments enqueued per 3D tensor object. More...
 
constexpr static 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, bool use_dummy_work_items)
 Get the global work size given an execution window. More...
 

Detailed Description

Interface for the bitwise operation kernel.

Result depends on the BitwiseOperation and is computed by: AND operation:

\[ output(x,y) = input1(x,y) \land input2(x,y) \]

NOT operation:

\[ output(x,y) = \lnot input1(x,y) \]

OR operation:

\[ output(x,y) = input1(x,y) \lor input2(x,y) \]

XOR operation:

\[ output(x,y) = input1(x,y) \oplus input2(x,y) \]

Definition at line 41 of file CLBitwiseKernel.h.

Constructor & Destructor Documentation

◆ CLBitwiseKernel() [1/3]

Default constructor.

Definition at line 40 of file CLBitwiseKernel.cpp.

40  : _input1(nullptr), _input2(nullptr), _output(nullptr)
41 {
43 }

References arm_compute::ELEMENTWISE.

◆ CLBitwiseKernel() [2/3]

CLBitwiseKernel ( const CLBitwiseKernel )
delete

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

◆ CLBitwiseKernel() [3/3]

CLBitwiseKernel ( CLBitwiseKernel &&  )
default

Allow instances of this class to be moved.

Member Function Documentation

◆ configure()

void configure ( const CLCompileContext compile_context,
const ICLTensor input1,
const ICLTensor input2,
ICLTensor output,
BitwiseOperation  op 
)

Set the inputs and output tensors.

Parameters
[in]compile_contextThe compile context to be used.
[in]input1Source tensor. Data types supported: U8.
[in]input2Source tensor. Data types supported: U8.
[out]outputDestination tensor. Data types supported: U8.
[in]opBitwise operation to perform. Supported: AND, OR, NOT, XOR.

Definition at line 45 of file CLBitwiseKernel.cpp.

50 {
53  if (op != BitwiseOperation::NOT)
54  {
57  }
60 
61  // Output auto inizialitation if not yet initialized
62  auto_init_if_empty(*(output->info()), *(input1->info()));
63  auto padding_info = get_padding_info({input1, input2, output});
64 
65  // Configure kernel window
66  const unsigned int vec_size_x = adjust_vec_size(16 / output->info()->element_size(), output->info()->dimension(0));
67  Window win = calculate_max_window(*output->info(), Steps(vec_size_x));
68 
69  _input1 = input1;
70  _input2 = input2;
71  _output = output;
72 
73  // Create kernel
74  std::string kernel_name = "";
75  switch (op)
76  {
78  kernel_name = "bitwise_and";
79  break;
81  kernel_name = "bitwise_not";
82  break;
84  kernel_name = "bitwise_or";
85  break;
87  kernel_name = "bitwise_xor";
88  break;
89  default:
90  ARM_COMPUTE_ERROR("Bitwise operation not supported");
91  }
92 
93  CLBuildOptions build_opts;
94  const int vec_size_x_leftovers = output->info()->dimension(0) % vec_size_x;
95  build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(vec_size_x));
96  build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(vec_size_x_leftovers));
97  _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
98 
99  ICLKernel::configure_internal(win);
101 }

References CLBuildOptions::add_option(), arm_compute::adjust_vec_size(), arm_compute::AND, ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_ERROR_ON_NULLPTR, arm_compute::auto_init_if_empty(), arm_compute::calculate_max_window(), arm_compute::create_kernel(), ITensorInfo::dimension(), ITensorInfo::element_size(), arm_compute::get_padding_info(), arm_compute::has_padding_changed(), ITensor::info(), kernel_name, arm_compute::NOT, CLBuildOptions::options(), arm_compute::OR, arm_compute::support::cpp11::to_string(), arm_compute::U8, and arm_compute::XOR.

◆ operator=() [1/2]

CLBitwiseKernel& operator= ( CLBitwiseKernel &&  )
default

Allow instances of this class to be moved.

◆ operator=() [2/2]

CLBitwiseKernel& operator= ( const CLBitwiseKernel )
delete

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

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

104 {
107 
109 
110  do
111  {
112  unsigned int idx = 0;
113  add_2D_tensor_argument(idx, _input1, slice);
114  if (_input2 != nullptr)
115  {
116  add_2D_tensor_argument(idx, _input2, slice);
117  }
118  add_2D_tensor_argument(idx, _output, slice);
119  enqueue(queue, *this, slice, lws_hint());
121 }

References ICLKernel::add_2D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, arm_compute::enqueue(), Window::first_slice_window_2D(), ICLKernel::lws_hint(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_2D(), and IKernel::window().


The documentation for this class was generated from the following files:
arm_compute::support::cpp11::to_string
std::string to_string(T &&value)
Convert integer and float values to string.
Definition: StringSupport.h:168
ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:949
arm_compute::calculate_max_window
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
Definition: WindowHelpers.cpp:29
ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:1079
ARM_COMPUTE_ERROR
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:354
arm_compute::Window::slide_window_slice_2D
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
Definition: Window.h:338
arm_compute::ICLKernel::add_2D_tensor_argument
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:210
ARM_COMPUTE_ERROR_ON_NULLPTR
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
ARM_COMPUTE_ERROR_ON
#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
arm_compute::BitwiseOperation::AND
@ AND
Bitwise AND operation.
arm_compute::auto_init_if_empty
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: AutoConfiguration.h:43
arm_compute::DataType::U8
@ U8
unsigned 8-bit number
arm_compute::create_kernel
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:409
ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:203
arm_compute::BitwiseOperation::XOR
@ XOR
Bitwise XOR operation
arm_compute::IKernel::window
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
arm_compute::ELEMENTWISE
@ ELEMENTWISE
Elementwise CL kernel type.
Definition: CLTypes.h:83
arm_compute::adjust_vec_size
unsigned int adjust_vec_size(unsigned int vec_size, size_t dim0)
Returns the adjusted vector size in case it is less than the input's first dimension,...
Definition: AdjustVecSize.h:38
arm_compute::has_padding_changed
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:491
arm_compute::ICLKernel::lws_hint
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:383
arm_compute::BitwiseOperation::NOT
@ NOT
Bitwise NOT operation.
arm_compute::BitwiseOperation::OR
@ OR
Bitwise OR operation
arm_compute::get_padding_info
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:476
arm_compute::test::validation::reference::slice
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
Definition: SliceOperations.cpp:38
arm_compute::Window::first_slice_window_2D
Window first_slice_window_2D() const
First 2D slice of the window.
Definition: Window.h:298
kernel_name
std::string kernel_name
Definition: ClIm2ColKernel.cpp:58
arm_compute::enqueue
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:33