Compute Library
 22.08
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...
 
virtual void run_composite_op (ITensorPack &tensors, const Window &window, cl::CommandQueue &queue, const experimental::dynamic_fusion::ClExecutionDescriptor &exec_desc)
 The execution is carried out through run_op method. But the run_op method needs to be extended to include ClExecutionDescriptor as now LWS GWS tuning will be separated from the IKernel. 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...
 

Additional Inherited Members

- Static Public Member Functions inherited from ICLKernel
static constexpr unsigned int num_arguments_per_3d_tensor_nhw ()
 Returns the number of arguments enqueued per NHW 3D Tensor object. More...
 
static constexpr unsigned int num_arguments_per_4d_tensor_nhwc ()
 Returns the number of arguments enqueued per NHWC 4D Tensor object. More...
 
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 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 37 of file CLBitwiseKernel.cpp.

References arm_compute::ELEMENTWISE.

38  : _input1(nullptr), _input2(nullptr), _output(nullptr)
39 {
41 }
Elementwise CL kernel type.
Definition: CLTypes.h:85

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

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.

44 {
47  if(op != BitwiseOperation::NOT)
48  {
51  }
54 
55  // Output auto inizialitation if not yet initialized
56  auto_init_if_empty(*(output->info()), *(input1->info()));
57  auto padding_info = get_padding_info({ input1, input2, output });
58 
59  // Configure kernel window
60  const unsigned int vec_size_x = adjust_vec_size(16 / output->info()->element_size(), output->info()->dimension(0));
61  Window win = calculate_max_window(*output->info(), Steps(vec_size_x));
62 
63  _input1 = input1;
64  _input2 = input2;
65  _output = output;
66 
67  // Create kernel
68  std::string kernel_name = "";
69  switch(op)
70  {
72  kernel_name = "bitwise_and";
73  break;
75  kernel_name = "bitwise_not";
76  break;
78  kernel_name = "bitwise_or";
79  break;
81  kernel_name = "bitwise_xor";
82  break;
83  default:
84  ARM_COMPUTE_ERROR("Bitwise operation not supported");
85  }
86 
87  CLBuildOptions build_opts;
88  const int vec_size_x_leftovers = output->info()->dimension(0) % vec_size_x;
89  build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(vec_size_x));
90  build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(vec_size_x_leftovers));
91  _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
92 
93  ICLKernel::configure_internal(win);
95 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
1 channel, 1 U8 per channel
std::string to_string(T &&value)
Convert integer and float values to string.
#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
Bitwise NOT operation.
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:404
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...
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:601
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:786
Bitwise XOR operation.
Bitwise AND operation.
Bitwise OR operation.
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:586
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
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&#39;s first dimension, getting rounded down to its closest valid vector size.
Definition: Utils.h:1222
std::string kernel_name

◆ operator=() [1/2]

CLBitwiseKernel& operator= ( const CLBitwiseKernel )
delete

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

◆ operator=() [2/2]

CLBitwiseKernel& operator= ( CLBitwiseKernel &&  )
default

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.

Reimplemented from ICLKernel.

Definition at line 97 of file CLBitwiseKernel.cpp.

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

98 {
101 
103 
104  do
105  {
106  unsigned int idx = 0;
107  add_2D_tensor_argument(idx, _input1, slice);
108  if(_input2 != nullptr)
109  {
110  add_2D_tensor_argument(idx, _input2, slice);
111  }
112  add_2D_tensor_argument(idx, _output, slice);
113  enqueue(queue, *this, slice, lws_hint());
114  }
115  while(window.slide_window_slice_2D(slice));
116 }
Window first_slice_window_2D() const
First 2D slice of the window.
Definition: Window.h:297
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
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:384
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
Definition: Window.h:337
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
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:203
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

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