Compute Library
 19.08
NEStridedSliceKernel Class Reference

Interface for the kernel to perform tensor strided slicing. More...

#include <NEStridedSliceKernel.h>

Collaboration diagram for NEStridedSliceKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEStridedSliceKernel ()
 Default constructor. More...
 
 NEStridedSliceKernel (const NEStridedSliceKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEStridedSliceKerneloperator= (const NEStridedSliceKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEStridedSliceKernel (NEStridedSliceKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEStridedSliceKerneloperator= (NEStridedSliceKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEStridedSliceKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask)
 Configure kernel. 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 *output, const Coordinates &starts, const Coordinates &ends, const BiStrides &strides, int32_t begin_mask, int32_t end_mask, int32_t shrink_axis_mask)
 Static function to check if given info will lead to a valid configuration of CLStridedSliceKernel. More...
 

Detailed Description

Interface for the kernel to perform tensor strided slicing.

Definition at line 38 of file NEStridedSliceKernel.h.

Constructor & Destructor Documentation

◆ NEStridedSliceKernel() [1/3]

Default constructor.

Definition at line 133 of file NEStridedSliceKernel.cpp.

134  : _input(nullptr), _output(nullptr), _starts_abs(), _final_strides(), _shrink_mask()
135 {
136 }

◆ NEStridedSliceKernel() [2/3]

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

◆ NEStridedSliceKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEStridedSliceKernel()

~NEStridedSliceKernel ( )
default

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor output,
const Coordinates starts,
const Coordinates ends,
const BiStrides strides,
int32_t  begin_mask,
int32_t  end_mask,
int32_t  shrink_axis_mask 
)

Configure kernel.

Note
Supported tensor rank: up to 4
Parameters
[in]inputSource tensor. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32
[out]outputDestination tensor. Data type supported: Same as input
[in]startsThe starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
[in]endsThe ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
[in]stridesThe strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
[in]begin_maskIf the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead.
[in]end_maskIf the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead.
[in]shrink_axis_maskIf the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1. A slice of size 1 starting from starts[i] in the dimension must be preserved.

Definition at line 138 of file NEStridedSliceKernel.cpp.

141 {
142  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
143  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), starts, ends, strides, begin_mask, end_mask, shrink_axis_mask));
144 
145  _input = input;
146  _output = output;
147  _shrink_mask = shrink_axis_mask;
148 
149  const TensorShape &input_shape = input->info()->tensor_shape();
150 
151  Coordinates ends_abs;
152  std::tie(_starts_abs, ends_abs, _final_strides) = arm_compute::helpers::tensor_transform::calculate_strided_slice_coords(
153  input_shape,
154  starts, ends, strides,
155  begin_mask, end_mask, shrink_axis_mask);
156 
157  // Configure kernel window
158  auto win_config = validate_and_configure_window(input->info(), output->info(), starts, ends, strides, begin_mask, end_mask, shrink_axis_mask);
159  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
160  INEKernel::configure(win_config.second);
161 }
std::tuple< Coordinates, Coordinates, Coordinates > calculate_strided_slice_coords(TensorShape input_shape, Coordinates starts, Coordinates ends, Coordinates strides, int32_t begin_mask=0, int32_t end_mask=0, int32_t shrink_axis_mask=0)
Calculate start, end and stride coordinates for a strided slice.
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::helpers::tensor_transform::calculate_strided_slice_coords(), ITensor::info(), arm_compute::test::validation::input_shape, ITensorInfo::tensor_shape(), and arm_compute::validate_and_configure_window().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 41 of file NEStridedSliceKernel.h.

42  {
43  return "NEStridedSliceKernel";
44  }

◆ operator=() [1/2]

NEStridedSliceKernel& operator= ( const NEStridedSliceKernel )
delete

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

◆ operator=() [2/2]

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

176 {
180 
181  // Dispatch kernel
182  strided_slice_generic(_input, _output, _starts_abs, _final_strides, _shrink_mask, window);
183 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#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_INVALID_SUBWINDOW, 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 output,
const Coordinates starts,
const Coordinates ends,
const BiStrides strides,
int32_t  begin_mask,
int32_t  end_mask,
int32_t  shrink_axis_mask 
)
static

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

Note
Supported tensor rank: up to 4
Parameters
[in]inputSource tensor info. Data type supported: U8/S8/QASYMM8/U16/S16/U32/S32/F16/F32
[in]outputDestination tensor info. Data type supported: Same as input
[in]startsThe starts of the dimensions of the input tensor to be sliced. The length must be of rank(input).
[in]endsThe ends of the dimensions of the input tensor to be sliced. The length must be of rank(input).
[in]stridesThe strides of the dimensions of the input tensor to be sliced. The length must be of rank(input).
[in]begin_maskIf the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead.
[in]end_maskIf the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead.
[in]shrink_axis_maskIf the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1. A slice of size 1 starting from starts[i] in the dimension must be preserved.

Definition at line 163 of file NEStridedSliceKernel.cpp.

166 {
167  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, starts, ends, strides, begin_mask, end_mask, shrink_axis_mask));
168  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get(),
169  starts, ends, strides, begin_mask, end_mask, shrink_axis_mask)
170  .first);
171 
172  return Status{};
173 }
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193

References ARM_COMPUTE_RETURN_ON_ERROR, ICloneable< T >::clone(), and arm_compute::validate_and_configure_window().

Referenced by NESlice::validate(), and NEStridedSlice::validate().


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