Compute Library
 22.11
NEGatherKernel Class Reference

Kernel to perform gather operation. 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...
 
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 *input, const ITensorInfo *indices, const ITensorInfo *output, int axis)
 Static function to check if given info will lead to a valid configuration. More...
 

Additional Inherited Members

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

Detailed Description

Kernel to perform gather operation.

Definition at line 37 of file NEGatherKernel.h.

Constructor & Destructor Documentation

◆ NEGatherKernel() [1/3]

◆ 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: All
[in]indicesIndices tensor. Supported tensor rank: up to 3. Must be one of the following type: U32/S32. Each value Must be in range [0, input.shape[axis])
Note
2D or 3D indices are only supported for the axis 1.
Parameters
[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 170 of file NEGatherKernel.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), arm_compute::calculate_max_window(), ICloneable< T >::clone(), arm_compute::misc::shape_calculator::compute_gather_shape(), ITensorInfo::data_type(), ITensor::info(), arm_compute::test::validation::input, ITensorInfo::num_dimensions(), arm_compute::S32, ITensorInfo::tensor_shape(), arm_compute::U32, and arm_compute::cpu::kernels::validate_arguments().

Referenced by NEGatherKernel::name().

171 {
172  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output, indices);
173  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), indices->info(), output->info(), axis));
174 
175  _input = input;
176  _indices = indices;
177  _output = output;
178  _axis = axis;
179 
180  if(_axis < 0)
181  {
182  _axis += input->info()->num_dimensions();
183  }
184  ARM_COMPUTE_ERROR_ON(0 > _axis || _axis >= static_cast<int32_t>(input->info()->num_dimensions()));
185 
186  if(indices->info()->num_dimensions() == 1u)
187  {
188  if(_axis == 0)
189  {
190  switch(_indices->info()->data_type())
191  {
192  case DataType::U32:
193  _func = &NEGatherKernel::gather_0_axis<uint32_t>;
194  break;
195  case DataType::S32:
196  _func = &NEGatherKernel::gather_0_axis<int32_t>;
197  break;
198  default:
199  ARM_COMPUTE_ERROR("Not supported");
200  break;
201  }
202  }
203  else
204  {
205  switch(_indices->info()->data_type())
206  {
207  case DataType::U32:
208  _func = &NEGatherKernel::gather_n_axis<uint32_t>;
209  break;
210  case DataType::S32:
211  _func = &NEGatherKernel::gather_n_axis<int32_t>;
212  break;
213  default:
214  ARM_COMPUTE_ERROR("Not supported");
215  break;
216  }
217  }
218  }
219  else
220  {
221  if(_axis == 1)
222  {
223  switch(_indices->info()->data_type())
224  {
225  case DataType::U32:
226  _func = &NEGatherKernel::gather_multiindices_1_axis<uint32_t>;
227  break;
228  case DataType::S32:
229  _func = &NEGatherKernel::gather_multiindices_1_axis<int32_t>;
230  break;
231  default:
232  ARM_COMPUTE_ERROR("Not supported");
233  break;
234  }
235  }
236  else
237  {
238  ARM_COMPUTE_ERROR("Not supported");
239  }
240  }
241 
242  // Output auto initialization if not yet initialized
243  const TensorShape output_shape = arm_compute::misc::shape_calculator::compute_gather_shape(input->info()->tensor_shape(), indices->info()->tensor_shape(), _axis);
244  auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape));
245 
246  // Create window
247  Window win = calculate_max_window(*output->info(), Steps());
248 
249  INEKernel::configure(win);
250 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
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_ERROR_THROW_ON(status)
Definition: Error.h:455
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
1 channel, 1 S32 per channel
1 channel, 1 U32 per channel
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...
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_NULLPTR(...)
Definition: Validate.h:157
TensorShape compute_gather_shape(const TensorShape &input_shape, const TensorShape &indices_shape, uint32_t actual_axis)
Calculate the gather output shape of a tensor.

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 57 of file NEGatherKernel.h.

References NEGatherKernel::configure(), arm_compute::test::validation::info, arm_compute::test::validation::input, NEGatherKernel::run(), NEGatherKernel::validate(), and IKernel::window().

58  {
59  return "NEGatherKernel";
60  }

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

Reimplemented from ICPPKernel.

Definition at line 258 of file NEGatherKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, and ARM_COMPUTE_UNUSED.

Referenced by NEGatherKernel::name().

259 {
262  ARM_COMPUTE_ERROR_ON(_func == nullptr);
263 
264  (this->*_func)(window, info);
265 }
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)

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

Similar to NEGatherKernel::configure()

Returns
a status

Definition at line 252 of file NEGatherKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, and arm_compute::cpu::kernels::validate_arguments().

Referenced by NEGatherKernel::name(), and NEGather::validate().

253 {
254  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, indices, output, axis));
255  return Status{};
256 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)

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