Compute Library
 21.02
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 ITensorInfo *input, ITensorInfo *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_op (ITensorPack &tensors, 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 (const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. 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...
 
- 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 NEStridedSliceKernel. 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 130 of file NEStridedSliceKernel.cpp.

Referenced by NEStridedSliceKernel::name().

131  : _starts_abs(), _final_strides(), _shrink_mask()
132 {
133 }

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

Referenced by NEStridedSliceKernel::name().

Member Function Documentation

◆ configure()

void configure ( const ITensorInfo input,
ITensorInfo 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 info. Data type supported: All
[out]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 135 of file NEStridedSliceKernel.cpp.

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

Referenced by NEStridedSliceKernel::name().

138 {
140  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input, output, starts, ends, strides, begin_mask, end_mask, shrink_axis_mask));
141 
142  _shrink_mask = shrink_axis_mask;
143 
144  const TensorShape &input_shape = input->tensor_shape();
145 
146  Coordinates ends_abs;
147  std::tie(_starts_abs, ends_abs, _final_strides) = arm_compute::helpers::tensor_transform::calculate_strided_slice_coords(
148  input_shape,
149  starts, ends, strides,
150  begin_mask, end_mask, shrink_axis_mask);
151 
152  // Configure kernel window
153  auto win_config = validate_and_configure_window(input, output, starts, ends, strides, begin_mask, end_mask, shrink_axis_mask);
154  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
155  INEKernel::configure(win_config.second);
156 }
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.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
TensorShape input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...
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

◆ name()

◆ operator=() [1/2]

NEStridedSliceKernel& operator= ( const NEStridedSliceKernel )
delete

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

Referenced by NEStridedSliceKernel::name().

◆ operator=() [2/2]

NEStridedSliceKernel& operator= ( NEStridedSliceKernel &&  )
default

Allow instances of this class to be moved.

◆ run_op()

void run_op ( ITensorPack tensors,
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]tensorsA vector containing the tensors to operate on.
[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 170 of file NEStridedSliceKernel.cpp.

References arm_compute::ACL_DST, arm_compute::ACL_SRC_0, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), and IKernel::window().

Referenced by NEStridedSliceKernel::name().

171 {
175 
176  // Dispatch kernel
177  strided_slice_generic(tensors.get_const_tensor(TensorType::ACL_SRC_0),
178  tensors.get_tensor(TensorType::ACL_DST),
179  _starts_abs, _final_strides, _shrink_mask, window);
180 }
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:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

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

Note
Supported tensor rank: up to 4
Parameters
[in]inputSource tensor info. Data type supported: All
[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 158 of file NEStridedSliceKernel.cpp.

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

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

161 {
162  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, starts, ends, strides, begin_mask, end_mask, shrink_axis_mask));
163  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get(),
164  starts, ends, strides, begin_mask, end_mask, shrink_axis_mask)
165  .first);
166 
167  return Status{};
168 }
#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: