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

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

Referenced by NESelectKernel::name().

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

◆ 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 167 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(), and NESelectKernel::validate().

Referenced by NESelectKernel::name().

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

253 {
257  ARM_COMPUTE_ERROR_ON(_function == nullptr);
258  _function(_c, _x, _y, _output, window);
259 }
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: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 230 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().

231 {
238 
239  const bool is_same_rank = (c->tensor_shape().num_dimensions() == x->tensor_shape().num_dimensions());
240  ARM_COMPUTE_RETURN_ERROR_ON(is_same_rank && (x->tensor_shape() != c->tensor_shape()));
241  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])));
242 
243  if(output != nullptr && output->total_size() != 0)
244  {
247  }
248 
249  return Status{};
250 }
#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
#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: