Compute Library
 21.08
NELogicalKernel Class Reference

Interface for the kernel to perform logical operations between two tensors. More...

#include <NELogicalKernel.h>

Collaboration diagram for NELogicalKernel:
[legend]

Public Member Functions

void configure (const ITensorInfo *input1, const ITensorInfo *input2, ITensorInfo *output, LogicalOperation op)
 Initialise the kernel's inputs and output. More...
 
void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
const char * name () const override
 Name of the kernel. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run (const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. More...
 
virtual void run_nd (const Window &window, const ThreadInfo &info, const Window &thread_locator)
 legacy compatibility layer for implemantions which do not support thread_locator In these cases we simply narrow the interface down the legacy version 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 *input1, const ITensorInfo *input2, const ITensorInfo *output, LogicalOperation op)
 Static function to check if given info will lead to a valid configuration of NELogicalKernel. More...
 

Detailed Description

Interface for the kernel to perform logical operations between two tensors.

Supported logical operations:

  • AND
  • OR
  • NOT

Definition at line 41 of file NELogicalKernel.h.

Member Function Documentation

◆ configure()

void configure ( const ITensorInfo input1,
const ITensorInfo input2,
ITensorInfo output,
LogicalOperation  op 
)

Initialise the kernel's inputs and output.

Parameters
[in]input1An input tensor. Data type supported: U8.
[in]input2An input tensor. Data type supported: U8
[out]outputOutput tensor. Data type supported: U8.
[out]opLogical operation to perform

Definition at line 278 of file NELogicalKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, TensorShape::broadcast_shape(), arm_compute::calculate_max_window(), ITensorInfo::data_type(), arm_compute::Not, arm_compute::set_data_type_if_unknown(), arm_compute::set_shape_if_empty(), ITensorInfo::tensor_shape(), and NELogicalKernel::validate().

279 {
280  ARM_COMPUTE_ERROR_ON_NULLPTR(input1, output);
281  ARM_COMPUTE_ERROR_THROW_ON(validate(input1, input2, output, op));
282 
283  _op = op;
284 
285  Window win = calculate_max_window(*input1, Steps());
286  TensorShape out_shape = input1->tensor_shape();
287  if(op != LogicalOperation::Not)
288  {
290  out_shape = TensorShape::broadcast_shape(input1->tensor_shape(), input2->tensor_shape());
291  win = calculate_max_window(out_shape, Steps());
292  }
293  ICPPKernel::configure(win);
294 
295  // Auto initialize if empty
296  set_shape_if_empty(*output, out_shape);
297  set_data_type_if_unknown(*output, input1->data_type());
298 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
bool set_data_type_if_unknown(ITensorInfo &info, DataType data_type)
Set the data type and number of channels to the specified value if the current data type is unknown...
static TensorShape broadcast_shape(const Shapes &... shapes)
If shapes are broadcast compatible, return the broadcasted shape.
Definition: TensorShape.h:211
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, LogicalOperation op)
Static function to check if given info will lead to a valid configuration of NELogicalKernel.
bool set_shape_if_empty(ITensorInfo &info, const TensorShape &shape)
Set the shape to the specified value if the current assignment is empty.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ name()

const char * name ( ) const
overridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 273 of file NELogicalKernel.cpp.

274 {
275  return "NELogicalKernel";
276 }

◆ run_op()

void run_op ( ITensorPack tensors,
const Window window,
const ThreadInfo info 
)
overridevirtual

Execute the kernel on the passed window.

Warning
If is_parallelisable() returns false then the passed window must be equal to window()
Note
The window has to be a region within the window returned by the window() method
The width of the window has to be a multiple of num_elems_processed_per_iteration().
Parameters
[in]tensorsA vector containing the tensors to operate on.
[in]windowRegion on which to execute the kernel. (Must be a region of the window returned by window())
[in]infoInfo about executing thread and CPU.

Reimplemented from ICPPKernel.

Definition at line 323 of file NELogicalKernel.cpp.

References arm_compute::ACL_DST, arm_compute::ACL_SRC_0, arm_compute::ACL_SRC_1, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::test::validation::dst, ITensorPack::empty(), ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), arm_compute::Not, and IKernel::window().

324 {
328  ARM_COMPUTE_ERROR_ON(tensors.empty());
329 
330  const ITensor *src0 = tensors.get_const_tensor(TensorType::ACL_SRC_0);
331  const ITensor *src1 = tensors.get_const_tensor(TensorType::ACL_SRC_1);
332  ITensor *dst = tensors.get_tensor(TensorType::ACL_DST);
333 
334  if(_op == LogicalOperation::Not)
335  {
336  run_unary(window, src0, dst);
337  }
338  else
339  {
340  run_binary(window, src0, src1, dst, _op);
341  }
342 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#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
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201

◆ validate()

Status validate ( const ITensorInfo input1,
const ITensorInfo input2,
const ITensorInfo output,
LogicalOperation  op 
)
static

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

Parameters
[in]input1An input tensor. Data type supported: U8.
[in]input2An input tensor. Data type supported: U8
[in]outputOutput tensor. Data type supported: U8.
[in]opLogical operation to perform
Returns
a status

Definition at line 300 of file NELogicalKernel.cpp.

References ARM_COMPUTE_RETURN_ERROR_ON, ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES, ARM_COMPUTE_RETURN_ERROR_ON_MSG, TensorShape::broadcast_shape(), arm_compute::detail::have_different_dimensions(), arm_compute::Not, ITensorInfo::tensor_shape(), TensorShape::total_size(), ITensorInfo::total_size(), arm_compute::U8, and arm_compute::Unknown.

Referenced by NELogicalKernel::configure(), NELogicalAnd::validate(), NELogicalOr::validate(), and NELogicalNot::validate().

301 {
304 
305  TensorShape out_shape = input1->tensor_shape();
306  if(op != LogicalOperation::Not)
307  {
308  out_shape = TensorShape::broadcast_shape(input1->tensor_shape(), input2->tensor_shape());
309  ARM_COMPUTE_RETURN_ERROR_ON_MSG(out_shape.total_size() == 0, "Inputs are not broadcast compatible");
311  }
312 
313  // Checks performed when output is configured
314  if((output != nullptr) && (output->total_size() != 0))
315  {
316  ARM_COMPUTE_RETURN_ERROR_ON(detail::have_different_dimensions(out_shape, output->tensor_shape(), 0));
318  }
319 
320  return Status{};
321 }
1 channel, 1 U8 per channel
static TensorShape broadcast_shape(const Shapes &... shapes)
If shapes are broadcast compatible, return the broadcasted shape.
Definition: TensorShape.h:211
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
bool have_different_dimensions(const Dimensions< T > &dim1, const Dimensions< T > &dim2, unsigned int upper_dim)
Definition: Validate.h:47
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:541
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:788
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Definition: Error.h:244

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