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

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 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 134 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(), and arm_compute::U32.

Referenced by NEGatherKernel::name().

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

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

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, and ARM_COMPUTE_UNUSED.

Referenced by NEGatherKernel::name().

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: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 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 190 of file NEGatherKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR.

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

191 {
192  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, indices, output, axis));
193  return Status{};
194 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204

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