Compute Library
 22.11
NESelectKernel Class Reference

Interface for the select kernel. More...

#include <NESelectKernel.h>

Collaboration diagram for NESelectKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NESelectKernel ()
 Default constructor. More...
 
 NESelectKernel (const NESelectKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NESelectKerneloperator= (const NESelectKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NESelectKernel (NESelectKernel &&)=default
 Allow instances of this class to be moved. More...
 
NESelectKerneloperator= (NESelectKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NESelectKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *c, const ITensor *x, const ITensor *y, ITensor *output)
 Common signature for all the specialised elementwise functions. 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...
 
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...
 
virtual void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. More...
 
virtual size_t get_mws (const CPUInfo &platform, size_t thread_count) const
 Return minimum workload size of the relevant kernel. 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 *c, const ITensorInfo *x, const ITensorInfo *y, const ITensorInfo *output)
 Validate the argument passed to the kernel. More...
 

Additional Inherited Members

- Static Public Attributes inherited from ICPPKernel
static constexpr size_t default_mws = 1
 

Detailed Description

Interface for the select kernel.

Select is computed by:

\[ output(i) = condition(i) ? x(i) : y(i) \]

Definition at line 41 of file NESelectKernel.h.

Constructor & Destructor Documentation

◆ NESelectKernel() [1/3]

Default constructor.

Definition at line 164 of file NESelectKernel.cpp.

Referenced by NESelectKernel::name().

165  : /*_function(nullptr), */ _c(nullptr), _x(nullptr), _y(nullptr), _output(nullptr), _has_same_rank(false)
166 {
167 }

◆ NESelectKernel() [2/3]

NESelectKernel ( const NESelectKernel )
delete

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

◆ NESelectKernel() [3/3]

NESelectKernel ( NESelectKernel &&  )
default

Allow instances of this class to be moved.

◆ ~NESelectKernel()

~NESelectKernel ( )
default

Default destructor.

Referenced by NESelectKernel::name().

Member Function Documentation

◆ configure()

void configure ( const ITensor c,
const ITensor x,
const ITensor y,
ITensor output 
)

Common signature for all the specialised elementwise functions.

Parameters
[in]cCondition input tensor. Data types supported: U8.
[in]xFirst input tensor. Data types supported: All.
[out]ySecond input tensor. Data types supported: Same as x
[in]outputOutput tensor. Data types supported: Same as x

Definition at line 169 of file NESelectKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), arm_compute::calculate_max_window(), ITensorInfo::data_type(), ITensor::info(), Dimensions< T >::num_dimensions(), ITensorInfo::tensor_shape(), and NESelectKernel::validate().

Referenced by NESelectKernel::name().

170 {
171  ARM_COMPUTE_ERROR_ON_NULLPTR(c, x, y, output);
172 
173  // Auto initialize output if not initialized
174  auto_init_if_empty(*output->info(), x->info()->tensor_shape(), 1, x->info()->data_type());
175  ARM_COMPUTE_ERROR_THROW_ON(validate(c->info(), x->info(), y->info(), output->info()));
176 
177  _c = c;
178  _x = x;
179  _y = y;
180  _output = output;
181  _has_same_rank = (c->info()->tensor_shape().num_dimensions() == x->info()->tensor_shape().num_dimensions());
182 
183  Window win = calculate_max_window(*x->info());
184  INEKernel::configure(win);
185 }
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
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...
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
static Status validate(const ITensorInfo *c, const ITensorInfo *x, const ITensorInfo *y, const ITensorInfo *output)
Validate the argument passed to the kernel.

◆ name()

const char* name ( ) const
inlineoverridevirtual

◆ operator=() [1/2]

NESelectKernel& operator= ( const NESelectKernel )
delete

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

Referenced by NESelectKernel::name().

◆ operator=() [2/2]

NESelectKernel& operator= ( NESelectKernel &&  )
default

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.

Reimplemented from ICPPKernel.

Definition at line 209 of file NESelectKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensorInfo::data_type(), ITensor::info(), and IKernel::window().

Referenced by NESelectKernel::name().

210 {
214  ARM_COMPUTE_ERROR_ON(_output == nullptr);
215  ARM_COMPUTE_ERROR_ON(_output->info() == nullptr);
216 
217  const auto *uk = get_implementation(SelectKernelSelectorData{ _output->info()->data_type(), _has_same_rank });
218  ARM_COMPUTE_ERROR_ON(uk == nullptr);
219  ARM_COMPUTE_ERROR_ON(uk->ukernel == nullptr);
220  uk->ukernel(_c, _x, _y, _output, window);
221 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#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
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
#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 c,
const ITensorInfo x,
const ITensorInfo y,
const ITensorInfo output 
)
static

Validate the argument passed to the kernel.

Parameters
[in]cCondition input tensor. Data types supported: U8.
[in]xFirst input tensor. Data types supported: All.
[in]ySecond input tensor. Data types supported: Same as x
[in]outputOutput tensor. Data types supported: Same as x.
Returns
a status

Definition at line 187 of file NESelectKernel.cpp.

References 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, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES, ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, ITensorInfo::data_type(), is_same_rank, Dimensions< T >::num_dimensions(), ITensorInfo::tensor_shape(), ITensorInfo::total_size(), arm_compute::U8, arm_compute::UNKNOWN, and Dimensions< T >::x().

Referenced by NESelectKernel::configure(), NESelectKernel::name(), and NESelect::validate().

188 {
195 
196  const bool is_same_rank = (c->tensor_shape().num_dimensions() == x->tensor_shape().num_dimensions());
197  ARM_COMPUTE_RETURN_ERROR_ON(is_same_rank && (x->tensor_shape() != c->tensor_shape()));
198  ARM_COMPUTE_RETURN_ERROR_ON(!is_same_rank && ((c->tensor_shape().num_dimensions() > 1) || (c->tensor_shape().x() != x->tensor_shape()[x->tensor_shape().num_dimensions() - 1])));
199 
200  if(output != nullptr && output->total_size() != 0)
201  {
204  }
205 
206  return Status{};
207 }
#define ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(tensor)
Definition: Validate.h:115
1 channel, 1 U8 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
bool is_same_rank
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:439
#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: