Compute Library
 21.02
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...
 
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 *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 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 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 135 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::set_valid_region(), ITensorInfo::tensor_shape(), arm_compute::U32, and arm_compute::validate_arguments().

Referenced by NEGatherKernel::name().

136 {
137  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output, indices);
138  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), indices->info(), output->info(), axis));
139 
140  _input = input;
141  _indices = indices;
142  _output = output;
143  _axis = axis;
144 
145  if(_axis < 0)
146  {
147  _axis += input->info()->num_dimensions();
148  }
149  ARM_COMPUTE_ERROR_ON(0 > _axis || _axis >= static_cast<int32_t>(input->info()->num_dimensions()));
150 
151  if(0 == _axis)
152  {
153  switch(_indices->info()->data_type())
154  {
155  case DataType::U32:
156  _func = &NEGatherKernel::gather_0_axis<uint32_t>;
157  break;
158  case DataType::S32:
159  _func = &NEGatherKernel::gather_0_axis<int32_t>;
160  break;
161  default:
162  ARM_COMPUTE_ERROR("Not supported");
163  break;
164  }
165  }
166  else
167  {
168  switch(_indices->info()->data_type())
169  {
170  case DataType::U32:
171  _func = &NEGatherKernel::gather_n_axis<uint32_t>;
172  break;
173  case DataType::S32:
174  _func = &NEGatherKernel::gather_n_axis<int32_t>;
175  break;
176  default:
177  ARM_COMPUTE_ERROR("Not supported");
178  break;
179  }
180  }
181  // Output auto initialization if not yet initialized
182  TensorShape output_shape = arm_compute::misc::shape_calculator::compute_gather_shape(input->info()->tensor_shape(), indices->info()->tensor_shape(), _axis);
183  auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape));
184 
185  // Create window
186  Window win = calculate_max_window(*output->info(), Steps());
187  output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
188 
189  INEKernel::configure(win);
190 }
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
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.
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
TensorShape compute_gather_shape(const TensorShape &input_shape, const TensorShape &indices_shape, uint32_t actual_axis)

◆ 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 198 of file NEGatherKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, and ARM_COMPUTE_UNUSED.

Referenced by NEGatherKernel::name().

199 {
202  ARM_COMPUTE_ERROR_ON(_func == nullptr);
203 
204  (this->*_func)(window, info);
205 }
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)

◆ 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: All
[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 192 of file NEGatherKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, and arm_compute::validate_arguments().

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

193 {
194  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, indices, output, axis));
195  return Status{};
196 }
#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 *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)

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