Compute Library
 19.08
NEGatherKernel Class Reference

Kernel to perform other operation on NEON. More...

#include <NEGatherKernel.h>

Collaboration diagram for NEGatherKernel:
[legend]

Public Member Functions

 NEGatherKernel ()
 Default constructor. More...
 
 NEGatherKernel (const NEGatherKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers). More...
 
NEGatherKerneloperator= (const NEGatherKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers). More...
 
 NEGatherKernel (NEGatherKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEGatherKerneloperator= (NEGatherKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEGatherKernel ()=default
 Default detructor. More...
 
const char * name () const override
 Name of the kernel. More...
 
void configure (const ITensor *input, const ITensor *indices, ITensor *output, int axis=0)
 Initialise the kernel's inputs and outputs. 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 *input, const ITensorInfo *indices, const ITensorInfo *output, int axis)
 Static function to check if given info will lead to a valid configuration of NEGatherKernel. More...
 

Detailed Description

Kernel to perform other operation on NEON.

Definition at line 36 of file NEGatherKernel.h.

Constructor & Destructor Documentation

◆ NEGatherKernel() [1/3]

Default constructor.

Definition at line 57 of file NEGatherKernel.cpp.

58  : _input{}, _indices{}, _axis{}, _output{}, _func{}
59 {
60 }

◆ NEGatherKernel() [2/3]

NEGatherKernel ( const NEGatherKernel )
delete

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

◆ NEGatherKernel() [3/3]

NEGatherKernel ( NEGatherKernel &&  )
default

Allow instances of this class to be moved.

◆ ~NEGatherKernel()

~NEGatherKernel ( )
default

Default detructor.

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
const ITensor indices,
ITensor output,
int  axis = 0 
)

Initialise the kernel's inputs and outputs.

Parameters
[in]inputSource tensor. Supported tensor rank: up to 4. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32
[in]indicesIndices tensor. Supported tensor rank: up to 1. Must be one of the following type: U32/S32. Each value Must be in range [0, input.shape[axis])
[out]outputDestination tensor. Data type supported: Same as input
[in]axis(Optional) The axis in input to gather indices from. Negative values wrap around. Defaults to 0

Definition at line 107 of file NEGatherKernel.cpp.

108 {
109  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output, indices);
110  ARM_COMPUTE_ERROR_ON(indices->info()->num_dimensions() != 1);
113 
114  _input = input;
115  _indices = indices;
116  _output = output;
117  _axis = axis;
118 
119  if(_axis < 0)
120  {
121  _axis += input->info()->num_dimensions();
122  }
123  ARM_COMPUTE_ERROR_ON(0 > _axis || _axis >= static_cast<int32_t>(input->info()->num_dimensions()));
124 
125  if(0 == _axis)
126  {
127  switch(_indices->info()->data_type())
128  {
129  case DataType::U32:
130  _func = &NEGatherKernel::gather_0_axis<uint32_t>;
131  break;
132  case DataType::S32:
133  _func = &NEGatherKernel::gather_0_axis<int32_t>;
134  break;
135  default:
136  ARM_COMPUTE_ERROR("Not supported");
137  break;
138  }
139  }
140  else
141  {
142  switch(_indices->info()->data_type())
143  {
144  case DataType::U32:
145  _func = &NEGatherKernel::gather_n_axis<uint32_t>;
146  break;
147  case DataType::S32:
148  _func = &NEGatherKernel::gather_n_axis<int32_t>;
149  break;
150  default:
151  ARM_COMPUTE_ERROR("Not supported");
152  break;
153  }
154  }
155  // Output auto initialization if not yet initialized
156  TensorShape output_shape = arm_compute::misc::shape_calculator::compute_gather_shape(input->info()->tensor_shape(), indices->info()->tensor_shape(), _axis);
157  auto_init_if_empty(*output->info(), output_shape, 1, input->info()->data_type());
158 
159  // Create window
160  Window win = calculate_max_window(*output->info(), Steps());
161  output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
162 
163  INEKernel::configure(win);
164 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
1 channel, 1 U8 per channel
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
#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
1 channel, 1 U16 per channel
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
1 channel, 1 F16 per channel
1 channel, 1 S32 per channel
1 channel, 1 U32 per channel
quantized, asymmetric fixed-point 8-bit number
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
1 channel, 1 S16 per channel
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:789
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
signed 8-bit number
TensorShape compute_gather_shape(const TensorShape &input_shape, const TensorShape &indices_shape, uint32_t actual_axis)

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_ERROR_ON_NULLPTR, arm_compute::auto_init_if_empty(), arm_compute::test::validation::axis, arm_compute::calculate_max_window(), arm_compute::misc::shape_calculator::compute_gather_shape(), ITensorInfo::data_type(), arm_compute::F16, arm_compute::F32, ITensor::info(), ITensorInfo::num_dimensions(), arm_compute::test::validation::output_shape, arm_compute::QASYMM8, arm_compute::S16, arm_compute::S32, arm_compute::S8, ITensorInfo::set_valid_region(), ITensorInfo::tensor_shape(), arm_compute::U16, arm_compute::U32, and arm_compute::U8.

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 56 of file NEGatherKernel.h.

57  {
58  return "NEGatherKernel";
59  }

◆ operator=() [1/2]

NEGatherKernel& operator= ( const NEGatherKernel )
delete

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

◆ operator=() [2/2]

NEGatherKernel& operator= ( NEGatherKernel &&  )
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 196 of file NEGatherKernel.cpp.

197 {
200  ARM_COMPUTE_ERROR_ON(_func == nullptr);
201 
202  (this->*_func)(window, info);
203 }
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_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940

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

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo indices,
const ITensorInfo output,
int  axis 
)
static

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

Parameters
[in]inputSource tensor info. Supported tensor rank: up to 4. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32
[in]indicesIndices tensor info. Supported tensor rank: up to 1. Must be one of the following type: U32/S32. Each value Must be in range [0, input.shape[axis])
[in]outputDestination tensor info. Data type supported: Same as input
[in]axis(Optional) The axis in input to gather indices from. Negative values wrap around. Defaults to 0
Returns
a status

Definition at line 166 of file NEGatherKernel.cpp.

167 {
168  ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, indices, output);
169  ARM_COMPUTE_RETURN_ERROR_ON(indices->num_dimensions() > 1);
170  ARM_COMPUTE_RETURN_ERROR_ON(input->num_dimensions() > 4);
171 
172  if(axis < 0)
173  {
174  axis += input->num_dimensions();
175  }
176 
177  ARM_COMPUTE_RETURN_ERROR_ON(0 > axis || axis >= static_cast<int32_t>(input->num_dimensions()));
182 
183  if(output->total_size() != 0)
184  {
187  TensorShape output_shape = arm_compute::misc::shape_calculator::compute_gather_shape(input->tensor_shape(), indices->tensor_shape(), axis);
188  ARM_COMPUTE_RETURN_ERROR_ON(output_shape.total_size() != output->tensor_shape().total_size());
189  }
190 
192 
193  return Status{};
194 }
#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
quantized, asymmetric fixed-point 8-bit number
1 channel, 1 S16 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(...)
Definition: Validate.h:610
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
signed 8-bit number
TensorShape compute_gather_shape(const TensorShape &input_shape, const TensorShape &indices_shape, uint32_t actual_axis)

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_QUANTIZATION_INFO, ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, arm_compute::test::validation::axis, arm_compute::misc::shape_calculator::compute_gather_shape(), arm_compute::F16, arm_compute::F32, ITensorInfo::num_dimensions(), arm_compute::test::validation::output_shape, arm_compute::QASYMM8, arm_compute::S16, arm_compute::S32, arm_compute::S8, ITensorInfo::tensor_shape(), TensorShape::total_size(), ITensorInfo::total_size(), arm_compute::U16, arm_compute::U32, and arm_compute::U8.

Referenced by NEGather::validate().


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