IndexAddOperation

Applicable Products

Hardware Model

Supported

Atlas 350 accelerator cards

x

Atlas A3 inference products/Atlas A3 training products

√

Atlas A2 training products/Atlas A2 inference products

√

Atlas training products

x

Atlas inference products

x

Atlas 200I/500 A2 inference products

x

Description

Adds a value to a specified index of a fixed dimension.

Figure 1 IndexAddOperation

Definition

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
struct IndexAddParam {
    enum IndexType {
        INDEX_UNDEFINED = 0,
        INDEX_ADD,
        INDEX_ADD_VALID 
    };
    IndexType indexType = INDEX_UNDEFINED;
    int64_t axis = 0;
    uint8_t rsv[16] = {0};
};

Parameters

Member

Type

Default Value

Value Range

Mandatory

Description

indexType

IndexType

INDEX_UNDEFINED

0, 1, 2

Yes

Operation type.

  • INDEX_UNDEFINED: undefined.
  • INDEX_ADD: addition.

    Deterministic computation is involved. You can call aclrtCtxSetSysParamOpt(AclSysParamOptTypes.ACL_OPT_DETERMINISTIC, 1) to enable it.

  • INDEX_ADD_VALID: addition within the valid length. Not supported by Atlas inference products.

axis

int64_t

0

  • indexType = 1: [-intensor[0].dimNum, intensor[0].dimNum - 1]
  • indexType = 2: 0

No

Axis of the input tensor plus the updates value.

  • When indexType is set to INDEX_ADD, the value can be a negative number. The value range is [-varDimNum, varDimNum - 1]. varDimNum is the number of dimensions of input tensor 0.
  • When indexType is set to INDEX_ADD_VALID, the value can only be 0.

rsv[16]

uint8_t

{0}

[0]

No

Reserved

Input and Output (INDEX_ADD)

Parameter

Dimension

Data Type

Format

Description

var

[dim_0, ..., dim_n]

float16/bf16

ND

Input tensor. Augend. The input is zero to which addened is added in place as the output.

indices

[dim_x]

int32

ND

Input tensor. Specified index of a fixed dimension. dim_min = min(dim_x, dim_axis) (dim_axis of var). The value range is [0, dim_min). The first dim_min values must be unique.

updates

[dim_0, ..., dim_n]

float16/bf16

ND

Input tensor. Addend, which is added to var based on the value of indices. The number of dimensions is the same as that of var. The dimension with the index axis is dim_x, that is, dim_axis = dim_x (dim_axis of updates, which may be different from that of var).

alpha

[1]

float16/bf16

ND

Input tensor. Accumulation times.

output

[dim_0, ..., dim_n]

float16/bf16

ND

Output tensor. It is the same as var. That is, they have the same attributes, such as the data type, data format, and address.

min(x, y) indicates that the smaller value between x and y is used.

dim_axis indicates the size of var, updates, and output in the dimension whose index is axis. That is, if axis is 0, dim_axis corresponds to the size d_0 of the 0th dimension.

Input and Output (INDEX_ADD_VALID)

Parameter

Dimension

Data Type

Format

Description

var

[dim_1, dim_2]

float16/bf16

ND

Input tensor. Augend. The input is zero to which addened is added in place as the output.

indices

[dim_0]

int32

ND

Input tensor. Specified index of a fixed dimension. The value range is [0, dim_1).

updates

[dim_0, dim_2]

float16/bf16

ND

Input tensor. Addend, which is added to var based on the value of indices.

validIndicesNum

[1]

int32

ND

Input tensor. Valid length of indices. The value range is [0, dim_0].

output

[dim_1, dim_2]

float16/bf16

ND

Output tensor. It is the same as var. That is, they have the same attributes, such as the data type, data format, and address.

The value range of dim_2 is (0, 8192].

API Calling Example

  • indexType = INDEX_ADD
    • Input

      indexType = 0

      axis = 0

      var =
      [[ 1, 1, 1 ],
       [ 1, 1, 1],
       [ 1, 1, 1],
       [ 1, 1, 1],
       [ 1, 1, 1]]

      indices = torch.tensor[0, 4, 2]

      updates =

      [[ 1, 2, 3 ],
       [ 4, 5, 6],
       [ 7, 8, 9]]

      alpha = 1

    • Output
      output =
      [[  2, 3, 4],
       [  1, 1, 1],
       [  8, 9, 10],
       [  1, 1, 1],
       [  5, 6, 7]]
  • indexType = INDEX_ADD_VALID
    • Input

      indexType = 1

      axis = 0

      var =

      [[ 0, 0, 0 ],
       [ 0, 0, 0],
       [ 0, 0, 0],
       [ 0, 0, 0],
       [ 0, 0, 0]]

      indices = {[0, 2, 2, -1, -1]}

      updates =

      [[ 0, 1, 2 ],
       [ 1, 2, 3],
       [ 2, 3, 4],
       [ 5, 6, 7],
       [ 6, 7, 8]]

      validIndicesNum = {[3]}

    • Output
      output =
      [[  0, 1, 2],
       [  0, 0, 0],
       [  3, 5, 7],
       [  0, 0, 0],
       [  0, 0, 0]]