Compute Library
 21.02
CpuElementwiseUnaryKernel Class Reference

Interface for an element-wise unary operation kernel. More...

#include <CpuElementwiseUnaryKernel.h>

Collaboration diagram for CpuElementwiseUnaryKernel:
[legend]

Public Types

using ElementwiseUnaryUkernelPtr = std::add_pointer< void(const ITensor *, ITensor *, const Window &, ElementWiseUnary)>::type
 Common signature for all the specialised elementwise unary micro-kernels. More...
 

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 CpuElementwiseUnaryKernel ()
 Default constructor. More...
 
 ~CpuElementwiseUnaryKernel ()=default
 Default destructor. More...
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (CpuElementwiseUnaryKernel)
 
void configure (ElementWiseUnary op, const ITensorInfo &input, ITensorInfo &output)
 Function to configure the CpuElementwiseUnaryKernel. More...
 
void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. 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...
 

Static Public Member Functions

static Status validate (ElementWiseUnary op, const ITensorInfo &input, const ITensorInfo &output)
 Static function to check if given info will lead to a valid configuration of CpuElementwiseUnaryKernel. More...
 

Detailed Description

Interface for an element-wise unary operation kernel.

Element-wise operation is computed by:

\[ output(x) = OP(input(x))\]

Definition at line 44 of file CpuElementwiseUnaryKernel.h.

Member Typedef Documentation

◆ ElementwiseUnaryUkernelPtr

using ElementwiseUnaryUkernelPtr = std::add_pointer<void(const ITensor *, ITensor *, const Window &, ElementWiseUnary)>::type

Common signature for all the specialised elementwise unary micro-kernels.

Parameters
[in]windowRegion on which to execute the kernel.

Definition at line 82 of file CpuElementwiseUnaryKernel.h.

Constructor & Destructor Documentation

◆ CpuElementwiseUnaryKernel()

Default constructor.

Definition at line 106 of file CpuElementwiseUnaryKernel.cpp.

Referenced by CpuElementwiseUnaryKernel::name().

107  : _op()
108 {
109 }

◆ ~CpuElementwiseUnaryKernel()

Default destructor.

Referenced by CpuElementwiseUnaryKernel::name().

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( CpuElementwiseUnaryKernel  )

◆ configure()

void configure ( ElementWiseUnary  op,
const ITensorInfo input,
ITensorInfo output 
)

Function to configure the CpuElementwiseUnaryKernel.

Parameters
[in]opArithmetic operation to be executed.
[in]inputFirst tensor input. Data types supported: F16/F32, F16/F32/S32 for NEG/ABS operations.
[out]outputOutput tensor. Data types supported: Same as input.

Definition at line 111 of file CpuElementwiseUnaryKernel.cpp.

References ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), ITensorInfo::broadcast_shape_and_valid_region(), arm_compute::calculate_max_window(), ITensorInfo::data_type(), arm_compute::test::validation::valid_region, and CpuElementwiseUnaryKernel::validate().

Referenced by CpuElementwiseUnaryKernel::name().

112 {
114 
115  // Configure kernel window
116  const std::pair<TensorShape, ValidRegion> broadcast_pair = ITensorInfo::broadcast_shape_and_valid_region(input);
117  const TensorShape &out_shape = broadcast_pair.first;
118  const ValidRegion &valid_region = broadcast_pair.second;
119 
120  // Auto initialize output if not initialized
121  auto_init_if_empty(output, out_shape, 1, input.data_type());
122 
123  Window win = calculate_max_window(valid_region);
124 
125  _op = op;
126 
127  ICpuKernel::configure(win);
128 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
const ValidRegion valid_region
Definition: Scale.cpp:221
static std::pair< TensorShape, ValidRegion > broadcast_shape_and_valid_region(const Infos &... infos)
If infos are broadcast compatible tensor info&#39;s, return the broadcasted shape and the intersection of...
Definition: ITensorInfo.h:271
static Status validate(ElementWiseUnary op, const ITensorInfo &input, const ITensorInfo &output)
Static function to check if given info will lead to a valid configuration of CpuElementwiseUnaryKerne...
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...

◆ name()

◆ 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 162 of file CpuElementwiseUnaryKernel.cpp.

References arm_compute::ACL_DST, arm_compute::ACL_SRC, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::test::validation::dst, func, ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), arm_compute::test::validation::src, ukernel, and IKernel::window().

Referenced by CpuElementwiseUnaryKernel::name().

163 {
167 
168  auto src = tensors.get_const_tensor(TensorType::ACL_SRC);
169  auto dst = tensors.get_tensor(TensorType::ACL_DST);
170  auto func = get_implementation(src->info()->data_type())->ukernel;
171  ARM_COMPUTE_ERROR_ON(func == nullptr);
172  func(src, dst, window, _op);
173 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
CpuElementwiseUnaryKernel::ElementwiseUnaryUkernelPtr ukernel
#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
SimpleTensor< float > src
Definition: DFT.cpp:155
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
FloorUKernelPtr func
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

◆ validate()

Status validate ( ElementWiseUnary  op,
const ITensorInfo input,
const ITensorInfo output 
)
static

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

Parameters
[in]opArithmetic operation to be executed.
[in]inputFirst tensor input info. Data types supported: F16/F32, F16/F32/S32 for NEG/ABS operations.
[in]outputOutput tensor info. Data types supported: Same as input.
Returns
a Status

Definition at line 130 of file CpuElementwiseUnaryKernel.cpp.

References arm_compute::ABS, ARM_COMPUTE_ERROR, ARM_COMPUTE_RETURN_ERROR_ON, ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED, ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES, ITensorInfo::data_type(), arm_compute::EXP, arm_compute::F16, arm_compute::F32, arm_compute::LOG, arm_compute::NEG, arm_compute::ROUND, arm_compute::RSQRT, arm_compute::S32, arm_compute::SIN, and ITensorInfo::total_size().

Referenced by CpuElementwiseUnaryKernel::configure(), CpuElementwiseUnaryKernel::name(), and CpuElementwiseUnary::validate().

131 {
133 
134  const auto *uk = get_implementation(input.data_type());
135  ARM_COMPUTE_RETURN_ERROR_ON(uk == nullptr || uk->ukernel == nullptr);
136 
137  switch(op)
138  {
145  break;
149  break;
150  default:
151  ARM_COMPUTE_ERROR("ElementWiseUnary operation not supported");
152  }
153  // Validate in case of configured output
154  if(output.total_size() > 0)
155  {
157  }
158 
159  return Status{};
160 }
#define ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(tensor)
Definition: Validate.h:108
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
1 channel, 1 F32 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
1 channel, 1 F16 per channel
1 channel, 1 S32 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:545
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:792

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