ONE - On-device Neural Engine
Loading...
Searching...
No Matches
arm_compute::CLBinaryLogicalOpKernel Class Reference

#include <CLBinaryLogicalOpKernel.h>

Collaboration diagram for arm_compute::CLBinaryLogicalOpKernel:

Public Member Functions

 CLBinaryLogicalOpKernel ()
 
 CLBinaryLogicalOpKernel (const CLBinaryLogicalOpKernel &)=delete
 
CLBinaryLogicalOpKerneloperator= (const CLBinaryLogicalOpKernel &)=delete
 
 CLBinaryLogicalOpKernel (CLBinaryLogicalOpKernel &&)=default
 
CLBinaryLogicalOpKerneloperator= (CLBinaryLogicalOpKernel &&)=default
 
void configure (const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output, BinaryLogicalOperation op)
 
void run (const Window &window, cl::CommandQueue &queue) override
 
BorderSize border_size () const override
 

Detailed Description

OpenCL kernel to return truth values of two input tensors for Binary Logical Op

Definition at line 52 of file CLBinaryLogicalOpKernel.h.

Constructor & Destructor Documentation

◆ CLBinaryLogicalOpKernel() [1/3]

CLBinaryLogicalOpKernel::CLBinaryLogicalOpKernel ( )

Default constructor

Definition at line 80 of file CLBinaryLogicalOpKernel.cpp.

81 : _input1(nullptr), _input2(nullptr), _output(nullptr)
82{
83}

◆ CLBinaryLogicalOpKernel() [2/3]

arm_compute::CLBinaryLogicalOpKernel::CLBinaryLogicalOpKernel ( const CLBinaryLogicalOpKernel )
delete

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

◆ CLBinaryLogicalOpKernel() [3/3]

arm_compute::CLBinaryLogicalOpKernel::CLBinaryLogicalOpKernel ( CLBinaryLogicalOpKernel &&  )
default

Allow instances of this class to be moved

Member Function Documentation

◆ border_size()

BorderSize CLBinaryLogicalOpKernel::border_size ( ) const
override

Definition at line 191 of file CLBinaryLogicalOpKernel.cpp.

192{
193 const unsigned int replicateSize =
194 _output->info()->dimension(0) -
195 std::min(_input1->info()->dimension(0), _input2->info()->dimension(0));
196 const unsigned int border =
197 std::min<unsigned int>(num_elems_processed_per_iteration - 1U, replicateSize);
198 return BorderSize(0, border, 0, 0);
199}

◆ configure()

void CLBinaryLogicalOpKernel::configure ( const ICLTensor *  input1,
const ICLTensor *  input2,
ICLTensor *  output,
BinaryLogicalOperation  op 
)

Initialize the kernel's input, output.

Parameters
[in]input1Source tensor1.
[in]input2Source tensor2.
[out]outputOutput tensor.

Definition at line 85 of file CLBinaryLogicalOpKernel.cpp.

87{
88 ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input1, input2);
89 ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input1, output);
90 ARM_COMPUTE_ERROR_THROW_ON(validate_parameters(input1->info(), input2->info(), output->info()));
91
92 _input1 = input1;
93 _input2 = input2;
94 _output = output;
95
96 // Create kernel
97 std::string kernel_name = "binary_logical_op";
98 std::set<std::string> build_opts;
99 build_opts.emplace(("-DDATA_TYPE=" + get_cl_type_from_data_type(input1->info()->data_type())));
100
101 int op_code = 0;
102 switch (op)
103 {
105 op_code = 1;
106 break;
108 op_code = 2;
109 break;
110 default:
111 throw std::runtime_error("Operation not supported, yet");
112 }
113
114 build_opts.emplace(("-DOP_CODE=" + support::cpp11::to_string(op_code)));
115 build_opts.emplace(
116 ("-DVEC_SIZE=" + support::cpp11::to_string(num_elems_processed_per_iteration)));
117
118 _kernel =
119 static_cast<cl::Kernel>(CLKernelLibraryEx::get().create_kernel(kernel_name, build_opts));
120
121 const std::pair<TensorShape, ValidRegion> broadcast_pair =
122 ITensorInfo::broadcast_shape_and_valid_region(*input1->info(), *input2->info());
123
124 const ValidRegion &valid_region = broadcast_pair.second;
125
126 Window win = calculate_max_window(valid_region, Steps(num_elems_processed_per_iteration));
127 Window win_input1 = win.broadcast_if_dimension_le_one(*input1->info());
128 Window win_input2 = win.broadcast_if_dimension_le_one(*input2->info());
129
130 AccessWindowHorizontal input1_access(input1->info(), 0, num_elems_processed_per_iteration);
131 AccessWindowHorizontal input2_access(input2->info(), 0, num_elems_processed_per_iteration);
132 AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
133
134 update_window_and_padding(win_input1, input1_access) ||
135 update_window_and_padding(win_input2, input2_access) ||
136 update_window_and_padding(win, output_access);
137
138 output_access.set_valid_region(win, valid_region);
139
140 ICLKernel::configure_internal(win);
141}
static CLKernelLibraryEx & get()
Get the KernelLibrary singleton.
Kernel create_kernel(const std::string &kernel_name, const StringSet &build_options_set={}) const
Create a kernel from the kernel library.

References arm_compute::AND, arm_compute::CLKernelLibraryEx::create_kernel(), arm_compute::CLKernelLibraryEx::get(), and arm_compute::OR.

◆ operator=() [1/2]

CLBinaryLogicalOpKernel & arm_compute::CLBinaryLogicalOpKernel::operator= ( CLBinaryLogicalOpKernel &&  )
default

Allow instances of this class to be moved

◆ operator=() [2/2]

CLBinaryLogicalOpKernel & arm_compute::CLBinaryLogicalOpKernel::operator= ( const CLBinaryLogicalOpKernel )
delete

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

◆ run()

void CLBinaryLogicalOpKernel::run ( const Window &  window,
cl::CommandQueue &  queue 
)
override

Definition at line 143 of file CLBinaryLogicalOpKernel.cpp.

144{
145 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
146 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICLKernel::window(), window);
147
148 const TensorShape &in_shape1 = _input1->info()->tensor_shape();
149 const TensorShape &in_shape2 = _input2->info()->tensor_shape();
150 const TensorShape &out_shape = _output->info()->tensor_shape();
151
152 bool can_collapse = true;
153 if (std::min(in_shape1.total_size(), in_shape2.total_size()) > 1)
154 {
155 can_collapse =
156 (std::min(in_shape1.num_dimensions(), in_shape2.num_dimensions()) > Window::DimZ);
157 for (size_t d = Window::DimZ; can_collapse && (d < out_shape.num_dimensions()); d++)
158 {
159 can_collapse = (in_shape1[d] == in_shape2[d]);
160 }
161 }
162
163 bool has_collapsed = false;
164 Window collapsed =
165 can_collapse ? window.collapse_if_possible(ICLKernel::window(), Window::DimZ, &has_collapsed)
166 : window;
167
168 const TensorShape &in_shape1_collapsed =
169 has_collapsed ? in_shape1.collapsed_from(Window::DimZ) : in_shape1;
170 const TensorShape &in_shape2_collapsed =
171 has_collapsed ? in_shape2.collapsed_from(Window::DimZ) : in_shape2;
172
173 Window slice = collapsed.first_slice_window_3D();
174 Window slice_input1 = slice.broadcast_if_dimension_le_one(in_shape1_collapsed);
175 Window slice_input2 = slice.broadcast_if_dimension_le_one(in_shape2_collapsed);
176
177 do
178 {
179 unsigned int idx = 0;
180 add_3D_tensor_argument(idx, _input1, slice_input1);
181 add_3D_tensor_argument(idx, _input2, slice_input2);
182 add_3D_tensor_argument(idx, _output, slice);
183
184 enqueue(queue, *this, slice);
185
186 collapsed.slide_window_slice_3D(slice_input1);
187 collapsed.slide_window_slice_3D(slice_input2);
188 } while (collapsed.slide_window_slice_3D(slice));
189}
::nncc::core::ADT::tensor::Shape TensorShape
Definition TensorShape.h:25

Referenced by package.infer.session::inference().


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