Compute Library
 19.08
NEElementwiseUnaryKernel Class Reference

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

#include <NEElementwiseUnaryKernel.h>

Collaboration diagram for NEElementwiseUnaryKernel:
[legend]

Public Types

using ElementwiseUnaryFunction = void(const ITensor *input, ITensor *output, const Window &window)
 Common signature for all the specialised arithmetic functions. More...
 

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEElementwiseUnaryKernel ()
 Default constructor. More...
 
 NEElementwiseUnaryKernel (const NEElementwiseUnaryKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEElementwiseUnaryKerneloperator= (const NEElementwiseUnaryKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEElementwiseUnaryKernel (NEElementwiseUnaryKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEElementwiseUnaryKerneloperator= (NEElementwiseUnaryKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEElementwiseUnaryKernel ()=default
 Default destructor. More...
 
void configure (ElementWiseUnary op, const ITensor *input, ITensor *output)
 Static function to check if given info will lead to a valid configuration of NEElementwiseUnaryKernel. More...
 
void run (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...
 
- 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 NEElementwiseUnaryKernel. 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 40 of file NEElementwiseUnaryKernel.h.

Member Typedef Documentation

◆ ElementwiseUnaryFunction

using ElementwiseUnaryFunction = void(const ITensor *input, ITensor *output, const Window &window)

Common signature for all the specialised arithmetic functions.

Parameters
[in]inputAn input tensor. Data types supported: F16/F32.
[out]outputThe output tensor. Data types supported: F16/F32.
[in]windowRegion on which to execute the kernel.

Definition at line 87 of file NEElementwiseUnaryKernel.h.

Constructor & Destructor Documentation

◆ NEElementwiseUnaryKernel() [1/3]

Default constructor.

Definition at line 177 of file NEElementwiseUnaryKernel.cpp.

178  : _function(nullptr), _input(nullptr), _output(nullptr)
179 {
180 }

◆ NEElementwiseUnaryKernel() [2/3]

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

◆ NEElementwiseUnaryKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEElementwiseUnaryKernel()

Default destructor.

Member Function Documentation

◆ configure()

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

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

Parameters
[in]opArithmetic operation to be executed.
[in]inputFirst tensor input. Data types supported: F16/F32.
[in]outputOutput tensor. Data types supported: Same as input.

Definition at line 182 of file NEElementwiseUnaryKernel.cpp.

183 {
184  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(op, *input->info(), *output->info()));
185  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
186 
187  // Configure kernel window
188  const std::pair<TensorShape, ValidRegion> broadcast_pair = ITensorInfo::broadcast_shape_and_valid_region(*input->info());
189  const TensorShape &out_shape = broadcast_pair.first;
190  const ValidRegion &valid_region = broadcast_pair.second;
191 
192  // Auto initialize output if not initialized
193  auto_init_if_empty(*output->info(), out_shape, 1, input->info()->data_type());
194 
195  Window win = calculate_max_window(valid_region);
196 
197  _input = input;
198  _output = output;
199 
200  INEKernel::configure(win);
201 
202  switch(op)
203  {
205  _function = configure_func<ElementWiseUnary::RSQRT>(input, output);
206  break;
208  _function = configure_func<ElementWiseUnary::EXP>(input, output);
209  break;
211  _function = configure_func<ElementWiseUnary::NEG>(input, output);
212  break;
214  _function = configure_func<ElementWiseUnary::LOG>(input, output);
215  break;
217  _function = configure_func<ElementWiseUnary::ABS>(input, output);
218  break;
220  _function = configure_func<ElementWiseUnary::ROUND>(input, output);
221  break;
223  _function = configure_func<ElementWiseUnary::SIN>(input, output);
224  break;
225  default:
226  ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
227  }
228 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
static std::pair< TensorShape, ValidRegion > broadcast_shape_and_valid_region(const Infos &... infos)
If infos are broadcast compatible tensor info's, return the broadcasted shape and the intersection of...
Definition: ITensorInfo.h:247
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps=Steps(), bool skip_border=false, BorderSize border_size=BorderSize())
Calculate the maximum window for a given tensor shape and border setting.
Definition: Helpers.cpp:28
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...
Definition: Helpers.inl:201
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References arm_compute::ABS, ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, 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::EXP, ITensor::info(), arm_compute::LOG, arm_compute::NEG, arm_compute::ROUND, arm_compute::RSQRT, arm_compute::SIN, and arm_compute::test::validation::valid_region.

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 43 of file NEElementwiseUnaryKernel.h.

44  {
45  return "NEElementwiseUnaryKernel";
46  }

◆ operator=() [1/2]

NEElementwiseUnaryKernel& operator= ( const NEElementwiseUnaryKernel )
delete

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

◆ operator=() [2/2]

Allow instances of this class to be moved.

◆ run()

void run ( 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]windowRegion on which to execute the kernel. (Must be a region of the window returned by window())
[in]infoInfo about executing thread and CPU.

Implements ICPPKernel.

Definition at line 265 of file NEElementwiseUnaryKernel.cpp.

266 {
270  ARM_COMPUTE_ERROR_ON(_function == nullptr);
271  _function(_input, _output, window);
272 }
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:337
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::test::validation::info, and IKernel::window().

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

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

Definition at line 258 of file NEElementwiseUnaryKernel.cpp.

259 {
261  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(op, *input, *output));
262  return Status{};
263 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163

References ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, and ARM_COMPUTE_RETURN_ON_ERROR.

Referenced by NERsqrtLayer::validate(), NEExpLayer::validate(), NENegLayer::validate(), NELogLayer::validate(), NEAbsLayer::validate(), NERoundLayer::validate(), and NESinLayer::validate().


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