Compute Library
 21.08
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

 CpuElementwiseUnaryKernel ()=default
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (CpuElementwiseUnaryKernel)
 
void configure (ElementWiseUnary op, const ITensorInfo &src, ITensorInfo &dst)
 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...
 
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 (ElementWiseUnary op, const ITensorInfo &src, const ITensorInfo &dst)
 Static function to check if given info will lead to a valid configuration. More...
 

Detailed Description

Interface for an element-wise unary operation kernel.

Element-wise operation is computed by:

\[ dst(x) = OP(src(x))\]

Definition at line 42 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 71 of file CpuElementwiseUnaryKernel.h.

Constructor & Destructor Documentation

◆ CpuElementwiseUnaryKernel()

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( CpuElementwiseUnaryKernel  )

◆ configure()

void configure ( ElementWiseUnary  op,
const ITensorInfo src,
ITensorInfo dst 
)

Function to configure the CpuElementwiseUnaryKernel.

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

Definition at line 113 of file CpuElementwiseUnaryKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), ITensorInfo::data_type(), ITensorInfo::is_dynamic(), ITensorInfo::tensor_shape(), and arm_compute::validate().

114 {
116  const auto uk = get_implementation(src.data_type());
117  ARM_COMPUTE_ERROR_ON(uk == nullptr || uk->ukernel == nullptr);
118 
119  _op = op;
120  _run_method = uk->ukernel;
121  _name = std::string("CpuElementwiseUnaryKernel").append("/").append(uk->name);
122 
123  // If input shape is dynamic, expect a configured window and dst at run-time.
124  if(src.is_dynamic())
125  {
126  return;
127  }
128 
129  auto shape_and_window = compute_output_shape_and_window(src.tensor_shape());
130  auto_init_if_empty(dst, shape_and_window.first, 1, src.data_type());
131  ICpuKernel::configure(shape_and_window.second);
132 }
#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_ERROR_THROW_ON(status)
Definition: Error.h:455
SimpleTensor< float > src
Definition: DFT.cpp:155
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...
static Status validate(ElementWiseUnary op, const ITensorInfo &src, const ITensorInfo &dst)
Static function to check if given info will lead to a valid configuration.

◆ name()

const char * name ( ) const
overridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 176 of file CpuElementwiseUnaryKernel.cpp.

177 {
178  return _name.c_str();
179 }

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

References arm_compute::ACL_DST, arm_compute::ACL_SRC, ARM_COMPUTE_UNUSED, arm_compute::test::validation::dst, ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), and arm_compute::test::validation::src.

167 {
169 
170  auto src = tensors.get_const_tensor(TensorType::ACL_SRC);
171  auto dst = tensors.get_tensor(TensorType::ACL_DST);
172 
173  _run_method(src, dst, window, _op);
174 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
SimpleTensor< float > src
Definition: DFT.cpp:155
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

◆ validate()

Status validate ( ElementWiseUnary  op,
const ITensorInfo src,
const ITensorInfo dst 
)
static

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

Similar to CpuElementwiseUnaryKernel::configure()

Returns
a status

Definition at line 134 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 CpuElementwiseUnary::validate().

135 {
137 
138  const auto *uk = get_implementation(src.data_type());
139  ARM_COMPUTE_RETURN_ERROR_ON(uk == nullptr || uk->ukernel == nullptr);
140 
141  switch(op)
142  {
149  break;
153  break;
154  default:
155  ARM_COMPUTE_ERROR("ElementWiseUnary operation not supported");
156  }
157  // Validate in case of configured dst
158  if(dst.total_size() > 0)
159  {
161  }
162 
163  return Status{};
164 }
#define ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(tensor)
Definition: Validate.h:115
#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
SimpleTensor< float > src
Definition: DFT.cpp:155
1 channel, 1 F16 per channel
1 channel, 1 S32 per channel
#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

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