Compute Library
 21.02
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...
 
- 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 (const ITensorInfo *c, const ITensorInfo *x, const ITensorInfo *y, const ITensorInfo *output)
 Validate the argument passed to the kernel. More...
 

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 163 of file NESelectKernel.cpp.

Referenced by NESelectKernel::name().

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

◆ 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 168 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(), arm_compute::string_from_data_type(), ITensorInfo::tensor_shape(), ITensorInfo::valid_region(), and NESelectKernel::validate().

Referenced by NESelectKernel::name().

169 {
170  ARM_COMPUTE_ERROR_ON_NULLPTR(c, x, y, output);
171 
172  // Auto initialize output if not initialized
173  auto_init_if_empty(*output->info(), x->info()->tensor_shape(), 1, x->info()->data_type());
174  ARM_COMPUTE_ERROR_THROW_ON(validate(c->info(), x->info(), y->info(), output->info()));
175 
176  _c = c;
177  _x = x;
178  _y = y;
179  _output = output;
180  _has_same_rank = (c->info()->tensor_shape().num_dimensions() == x->info()->tensor_shape().num_dimensions());
181 
182  std::string function_to_call("op_");
183  function_to_call += string_from_data_type(x->info()->data_type());
184 
185  static std::map<std::string, SelectFunction *> map_function;
186 
187  if(_has_same_rank)
188  {
189  map_function =
190  {
191  { "op_S8", &select_op_8<int8_t, uint8x16_t> },
192  { "op_S16", &select_op_16<int16_t, uint16x8_t> },
193  { "op_S32", &select_op_32<int32_t, uint32x4_t> },
194  { "op_U8", &select_op_8<uint8_t, uint8x16_t> },
195  { "op_U16", &select_op_16<uint16_t, uint16x8_t> },
196  { "op_U32", &select_op_32<uint32_t, uint32x4_t> },
197  { "op_F32", &select_op_32<float, uint32x4_t> }
198  };
199 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
200  map_function["op_F16"] = &select_op_16<float16_t, uint16x8_t>;
201 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
202  }
203  else
204  {
205  map_function =
206  {
207  { "op_S8", &select_op_not_same_rank<int8_t> },
208  { "op_S16", &select_op_not_same_rank<int16_t> },
209  { "op_S32", &select_op_not_same_rank<int32_t> },
210  { "op_U8", &select_op_not_same_rank<uint8_t> },
211  { "op_U16", &select_op_not_same_rank<uint16_t> },
212  { "op_U32", &select_op_not_same_rank<uint32_t> },
213  { "op_F32", &select_op_not_same_rank<float> }
214  };
215 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
216  map_function["op_F16"] = &select_op_not_same_rank<float16_t>;
217 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
218  }
219 
220  auto it = map_function.find(function_to_call);
221 
222  if(it != map_function.end())
223  {
224  _function = it->second;
225  }
226 
227  Window win = calculate_max_window(x->info()->valid_region());
228  INEKernel::configure(win);
229 }
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 std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:135
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:161
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 253 of file NESelectKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, and IKernel::window().

Referenced by NESelectKernel::name().

254 {
258  ARM_COMPUTE_ERROR_ON(_function == nullptr);
259  _function(_c, _x, _y, _output, window);
260 }
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:941
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 ( 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 231 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(), 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().

232 {
239 
240  const bool is_same_rank = (c->tensor_shape().num_dimensions() == x->tensor_shape().num_dimensions());
241  ARM_COMPUTE_RETURN_ERROR_ON(is_same_rank && (x->tensor_shape() != c->tensor_shape()));
242  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])));
243 
244  if(output != nullptr && output->total_size() != 0)
245  {
248  }
249 
250  return Status{};
251 }
#define ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(tensor)
Definition: Validate.h:108
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
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:443
#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: