Compute Library
 19.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...
 
- 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 40 of file NESelectKernel.h.

Constructor & Destructor Documentation

◆ NESelectKernel() [1/3]

Default constructor.

Definition at line 162 of file NESelectKernel.cpp.

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.

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: U8/S8/U16/S16/U32/S32/F16/F32.
[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.

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_COMPUTE_AARCH64_V8_2 */
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_COMPUTE_AARCH64_V8_2 */
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()->valid_region());
227  INEKernel::configure(win);
228 }
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
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
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:144
#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.

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().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 43 of file NESelectKernel.h.

44  {
45  return "NESelectKernel";
46  }

◆ operator=() [1/2]

NESelectKernel& operator= ( const NESelectKernel )
delete

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

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

Implements ICPPKernel.

Definition at line 256 of file NESelectKernel.cpp.

257 {
261  ARM_COMPUTE_ERROR_ON(_function == nullptr);
262  _function(_c, _x, _y, _output, window);
263 }
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 ( 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: U8/S8/U16/S16/U32/S32/F16/F32.
[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.

231 {
234  1,
242 
243  const bool is_same_rank = (c->tensor_shape().num_dimensions() == x->tensor_shape().num_dimensions());
244  ARM_COMPUTE_RETURN_ERROR_ON(is_same_rank && (x->tensor_shape() != c->tensor_shape()));
245  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])));
246 
247  if(output != nullptr && output->total_size() != 0)
248  {
251  }
252 
253  return Status{};
254 }
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:545
1 channel, 1 U8 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:791
1 channel, 1 F32 per channel
1 channel, 1 U16 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:244
#define ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(tensor)
Definition: Validate.h:71
1 channel, 1 F16 per channel
1 channel, 1 S32 per channel
1 channel, 1 U32 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:443
1 channel, 1 S16 per channel
signed 8-bit number

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::F16, arm_compute::F32, Dimensions< T >::num_dimensions(), arm_compute::S16, arm_compute::S32, arm_compute::S8, ITensorInfo::tensor_shape(), ITensorInfo::total_size(), arm_compute::U16, arm_compute::U32, arm_compute::U8, and Dimensions< T >::x().

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


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