Compute Library
 21.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 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...
 
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 *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 128 of file NEStridedSliceKernel.cpp.

Referenced by NEStridedSliceKernel::name().

129  : _starts_abs(), _final_strides(), _shrink_mask()
130 {
131 }

◆ 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 133 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, and ITensorInfo::tensor_shape().

Referenced by NEStridedSliceKernel::name().

136 {
138  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input, output, starts, ends, strides, begin_mask, end_mask, shrink_axis_mask));
139 
140  _shrink_mask = shrink_axis_mask;
141 
142  const TensorShape &input_shape = input->tensor_shape();
143 
144  Coordinates ends_abs;
145  std::tie(_starts_abs, ends_abs, _final_strides) = arm_compute::helpers::tensor_transform::calculate_strided_slice_coords(
146  input_shape,
147  starts, ends, strides,
148  begin_mask, end_mask, shrink_axis_mask);
149 
150  // Configure kernel window
151  auto win_config = validate_and_configure_window(input, output, starts, ends, strides, begin_mask, end_mask, shrink_axis_mask);
152  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
153  INEKernel::configure(win_config.second);
154 }
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...
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ 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 168 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().

169 {
173 
174  // Dispatch kernel
175  strided_slice_generic(tensors.get_const_tensor(TensorType::ACL_SRC_0),
176  tensors.get_tensor(TensorType::ACL_DST),
177  _starts_abs, _final_strides, _shrink_mask, window);
178 }
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:915
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201

◆ 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 156 of file NEStridedSliceKernel.cpp.

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

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

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