CreateVecIndex

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product / Atlas A3 inference product

Atlas A2 training product / Atlas A2 inference product

Atlas 200I/500 A2 inference product

Atlas inference product AI Core

Atlas inference product Vector Core

x

Atlas training product

x

Function Usage

Creates a vector index with a specified start value.

Prototype

  • Computation of the first n data elements of a tensor
    1
    2
    template <typename T>
    __aicore__ inline void CreateVecIndex(LocalTensor<T> dst, const T &firstValue, uint32_t count)
    
  • High-dimensional tensor sharding computation
    • Bitwise mask mode
      1
      2
      template <typename T>
      __aicore__ inline void CreateVecIndex(LocalTensor<T> &dst, const T &firstValue, uint64_t mask[], uint8_t repeatTime, uint16_t dstBlkStride, uint8_t dstRepStride)
      
    • Contiguous mask mode
      1
      2
      template <typename T>
      __aicore__ inline void CreateVecIndex(LocalTensor<T> &dst, const T &firstValue, uint64_t mask, uint8_t repeatTime, uint16_t dstBlkStride, uint8_t dstRepStride)
      

Parameters

Table 1 Parameters in the template

Parameter

Description

T

Operand data type.

For the Atlas inference product AI Core, the supported data types are int16_t, half, int32_t, and float.

For the Atlas A2 training product / Atlas A2 inference product , the supported data types are int16_t, half, int32_t, and float.

For the Atlas A3 training product / Atlas A3 inference product , the supported data types are int16_t, half, int32_t, and float.

For the Atlas 200I/500 A2 inference product , the supported data types are int16_t, half, int32_t, and float.

For the Atlas 350 Accelerator Card, the supported data types are int8_t, int16_t, half, int32_t, float, and int64_t.

Table 2 Parameters

Parameter

Input/Output

Meaning

dst

Output

Destination operand.

The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT.

The start address of LocalTensor must be 32-byte aligned.

firstValue

Input

First value of the index. The data type must be the same as that of the elements in dst.

count

Input

Number of elements involved in the computation.

mask/mask[]

Input

mask controls the elements that participate in computation in each iteration.

  • Bitwise mode: controls the elements that participate in computation by bit. If a bit is set to 1, the corresponding element participates in the computation. If a bit is set to 0, the corresponding element is masked from the computation.

    The mask value is an array. The array length and the value range of the array elements are related to the operand data type. When the operand is 16-bit, the array length is 2, with mask[0] and mask[1] each in the range [0, 264 – 1], and they cannot both be 0 at the same time. When the operand is 32-bit, the array length is 1, with mask[0] in the range (0, 264 – 1]. When the operand is 64-bit, the array length is 1, with mask[0] in the range (0, 232 – 1].

    For example, if mask = [0, 8] and 8 = 0b1000, only the fourth element participates in computation.

  • Contiguous mode: indicates the number of contiguous elements that participate in computation. The value range is related to the operand data type. The maximum number of elements that can be processed in each iteration varies according to the data type. When the operand is 16-bit, mask ∈ [1, 128]. When the operand is 32-bit, mask ∈ [1, 64]. When the operand is 64-bit, mask ∈ [1, 32].

repeatTime

Input

Number of iteration repeats. The vector compute unit reads 256 bytes of contiguous data for computation each time. To process the input data, the data needs to be read and computed over multiple repeats. repeatTime indicates the number of repeats.

For details about this parameter, see High-dimensional Sharding APIs.

dstBlkStride

Input

Address stride of the destination operand between different data blocks in a single repeat.

dstRepStride

Input

Address stride of the destination operand for the same data block between adjacent repeats.

Returns

None

Restrictions

  • For details about the operand address alignment requirements, see General Address Alignment Restrictions.
  • Ensure that the value of firstValue does not exceed the value range corresponding to the data type of elements in dst.
  • For the Atlas 350 Accelerator Card, only the APIs that compute the first n data elements of a tensor are supported for the int8_t and int64_t data types.

Examples

These examples show only part of the code used in the computation.

  • Example of high-dimensional tensor sharding computation (contiguous mask mode)
    1
    2
    3
    4
    5
    // repeatTime = 1, mask = 128, 128 elements one repeat, 128 elements total
    // The data type of firstValue is int16_t, and the data type of dstLocal is int16_t.
    // dstBlkStride = 1. Data is continuously written in a single repeat.
    // dstRepStride = 8, continuous data write between adjacent repeats.
    AscendC::CreateVecIndex(dstLocal, (int16_t)0, mask, repeatTime, dstBlkStride, dstRepStride);
    
  • Example of high-dimensional tensor sharding computation (bitwise mask mode)
    1
    2
    3
    4
    5
    6
    uint64_t mask[2] = { UINT64_MAX, UINT64_MAX };
    // repeatTime = 1, 128 elements one repeat, 128 elements total
    // The data type of firstValue is int16_t, and the data type of dstLocal is int16_t.
    // dstBlkStride = 1. Data is continuously written in a single repeat.
    // dstRepStride = 8, continuous data write between adjacent repeats.
    AscendC::CreateVecIndex(dstLocal, (int16_t)0, mask, repeatTime, dstBlkStride, dstRepStride);
    
  • Example of computing the first n data elements of a tensor
    1
    2
    uint32_t count = 128;    // Number of elements involved in computation
    AscendC::CreateVecIndex(dstLocal, (int16_t)0, count);
    
Result example:
Input (firstValue): 0
Output (dstLocal): [0 1 2... 127]