SliceOperation

Applicable Products

Hardware Model

Supported

Remarks

Atlas 350 accelerator cards

√

-

Atlas A3 inference products/Atlas A3 training products

√

-

Atlas A2 training products/Atlas A2 inference products

√

-

Atlas training products

√

-

Atlas inference products

√

The bf16 data type is not supported.

Atlas 200I/500 A2 inference products

√

Only the float16 data type is supported.

Description

Extracts a slice with a specified size from a start location of the input tensor.

Operator Context

Figure 1 Context of the SliceOperation operator

Definition

1
2
3
4
5
struct SliceParam {
    SVector<int64_t> offsets;
    SVector<int64_t> size;
    uint8_t rsv[8] = {0};
};

Parameters

Member

Type

Default Value

Description

offsets

SVector<int64_t>

-

Start point of each dimension slice.

offsets[i] can be positive or negative.

  • offsets[i] ≥ 0: The actual start point is offsets[i].
  • offsets[i] < 0: The actual start point is dimNum + offsets[i].
  • The actual start position must be greater than or equal to 0 and less than dimNum.

size

SVector<int64_t>

-

Size of each dimension slice.

  • The value of size[i] must be greater than 0 or equal to -1. The value 0 is not allowed.
    • If size[i] is -1, the slice extends to the end of the ith dimension.
    • If size[i] is greater than 0, the slice length is size[i].
  • For the ith dimension, the dimension size is dimNum. The actual start point and length are defined as follows:
    • Actual start point:

      If offsets[i] ≥ 0: actual_offset = offsets[i]

      If offsets[i] < 0: actual_offset = dimNum + offsets[i]

    • Actual length:

      If size[i] > 0: actual_size = size[i]

      If size[i] = -1: actual_size = dimNum - actual_offset

  • Validity check:
    • actual_offset >= 0
    • actual_offset < dimNum
    • actual_offset + actual_size <= dimNum
    • actual_size > 0

rsv[8]

uint8_t

{0}

Reserved

Input

Parameter

Dimension

Data Type

Format

Description

x

[dim_0, dim_1, ..., dim_n]

float16/float/int8/bool/int32/uint32/bf16

ND

Input tensor.

Output

Parameter

Dimension

Data Type

Format

Description

output

Same as the shape indicated by size

float16/float/int8/bool/int32/uint32/bf16

ND

Output tensor. The dimension size is the value specified by size. Same as the data type of x.

Example API Call

  • Input
    x = [[ -78.9,   78.8,  32.22,   49.7,  82.8, 24.77],
         [  72.2,  20.89,  55.16,   85.5,  72.8,  94.8],
        [ 11.36, -83.56,  65.94, -46.94, 72.44,  68.7]]
    offsets = [1, 2]
    
    size = [2, 4]

    In dimension 0, the slice length is 2 from index 1.

    In the first dimension, the slice length is 4 (2 + 4 < = 6) from index 2.

  • Output
    y.dim = [2, 4]
    y = [[ 55.1562,  85.5000,  72.8125,  94.8125],
         [ 65.9375, -46.9375,  72.4375,  68.6875]]

    If the dimension of size is -1, the output shape is automatically derived.