Compute Library
 21.02
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...
 
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...
 

Additional Inherited Members

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

38  : _input1(nullptr), _input2(nullptr), _output(nullptr)
39 {
40 }

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

43 {
46  if(op != BitwiseOperation::NOT)
47  {
50  }
53 
54  // Output auto inizialitation if not yet initialized
55  auto_init_if_empty(*(output->info()), *(input1->info()));
56  auto padding_info = get_padding_info({ input1, input2, output });
57 
58  // Configure kernel window
59  const unsigned int vec_size_x = adjust_vec_size(16 / output->info()->element_size(), output->info()->dimension(0));
60  Window win = calculate_max_window(*output->info(), Steps(vec_size_x));
61 
62  _input1 = input1;
63  _input2 = input2;
64  _output = output;
65 
66  // Create kernel
67  std::string kernel_name = "";
68  switch(op)
69  {
71  kernel_name = "bitwise_and";
72  break;
74  kernel_name = "bitwise_not";
75  break;
77  kernel_name = "bitwise_or";
78  break;
80  kernel_name = "bitwise_xor";
81  break;
82  default:
83  ARM_COMPUTE_ERROR("Bitwise operation not supported");
84  }
85 
86  CLBuildOptions build_opts;
87  const int vec_size_x_leftovers = output->info()->dimension(0) % vec_size_x;
88  build_opts.add_option("-DVEC_SIZE=" + support::cpp11::to_string(vec_size_x));
89  build_opts.add_option("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(vec_size_x_leftovers));
90  _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
91 
92  ICLKernel::configure_internal(win);
94 }
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:403
std::string kernel_name
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:528
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:790
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:513
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
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:1358

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

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

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