Duplicate

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

Function Usage

Copies a variable or an immediate value multiple times and fills the result into a vector.

For the Atlas 350 Accelerator Card, to facilitate development, the API for computing the first n data elements of a tensor also accepts a tensor as the direct input. In this case, the first data element of the tensor will be copied repeatedly and populated into the vector.

Prototype

  • Computation of the first n data elements of a tensor
    • When the source operand is a scalar:
      1
      2
      template <typename T>
      __aicore__ inline void Duplicate(const LocalTensor<T>& dst, const T& scalarValue, const int32_t& count)
      
    • When the source operand is a tensor:
      1
      2
      template <typename T>
      __aicore__ inline void Duplicate(const LocalTensor<T>& dst, const LocalTensor<T>& src, const int32_t& count)
      
  • High-dimensional tensor sharding computation
    • Bitwise mask mode
      1
      2
      template <typename T, bool isSetMask = true>
      __aicore__ inline void Duplicate(const LocalTensor<T>& dst, const T& scalarValue, uint64_t mask[], const uint8_t repeatTime, const uint16_t dstBlockStride, const uint8_t dstRepeatStride)
      
    • Contiguous mask mode
      1
      2
      template <typename T, bool isSetMask = true>
      __aicore__ inline void Duplicate(const LocalTensor<T>& dst, const T& scalarValue, uint64_t mask, const uint8_t repeatTime, const uint16_t dstBlockStride, const uint8_t dstRepeatStride)
      

Parameters

Table 1 Parameters in the template

Parameter

Description

T

Operand data type.

For the Atlas 350 Accelerator Card, the supported data types are bool, int8_t, uint8_t, fp4x2_e2m1_t, fp4x2_e1m2_t, hifloat8_t, fp8_e5m2_t, fp8_e4m3fn_t, fp8_e8m0_t, int16_t, uint16_t, half, bfloat16_t, int32_t, uint32_t, float, complex32, int64_t, uint64_t, and complex64.

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

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

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

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

For the Atlas training product , the supported data types are int16_t, uint16_t, half, int32_t, uint32_t, and float.

isSetMask

Indicates whether to set mask inside the API.

  • true: sets mask inside the API.
  • false: sets mask outside the API. Developers need to use the SetVectorMask API to set the mask value. In this mode, the mask value in the input parameter of this API must be set to the placeholder MASK_PLACEHOLDER.
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.

scalarValue

Input

Source operand to be copied. Its data type must match that of the elements in dst.

src

Input

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

Its data type must match that of the elements in dst.

When this parameter is passed, src[0] is copied multiple times and populated into the vector.

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

The vector compute unit reads 8 consecutive data blocks (32 bytes per block, 256 bytes in total) 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.

dstBlockStride

Input

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

dstRepeatStride

Input

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

Restrictions

  • For details about the operand address alignment requirements, see General Address Alignment Restrictions.
  • For the Atlas 350 Accelerator Card, only the APIs that compute the first n data elements of a tensor are supported for the bool, int8_t, uint8_t, fp4x2_e2m1_t, fp4x2_e1m2_t, hifloat8_t, fp8_e5m2_t, fp8_e4m3fn_t, fp8_e8m0_t, complex32, int64_t, uint64_t, and complex64 data types.

Returns

None

Examples

  • Example of high-dimensional tensor sharding computation (contiguous mask mode)
    1
    2
    3
    4
    5
    6
    uint64_t mask = 128;
    half scalar = 18.0;
    // repeatTime = 2, 128 elements one repeat, 256 elements total
    // dstBlkStride = 1, no gap between blocks in one repeat
    // dstRepStride = 8, no gap between repeats
    AscendC::Duplicate(dstLocal, scalar, mask, 2, 1, 8 );
    
  • Example of high-dimensional tensor sharding computation (bitwise mask mode)
    1
    2
    3
    4
    5
    6
    uint64_t mask[2] = { UINT64_MAX, UINT64_MAX };
    half scalar = 18.0;
    // repeatTime = 2, 128 elements one repeat, 256 elements total
    // dstBlkStride = 1, no gap between blocks in one repeat
    // dstRepStride = 8, no gap between repeats
    AscendC::Duplicate(dstLocal, scalar, mask, 2, 1, 8 );
    
  • Example of computing the first n data elements of a tensor, with the source operand being a scalar
    1
    2
    3
    half inputVal(18.0);
    int32_t srcDataSize = 256; // Number of elements involved in computation
    AscendC::Duplicate<half>(dstLocal, inputVal, srcDataSize);
    
  • Example of computing the first n data elements of a tensor, with the source operand being a tensor
    1
    AscendC::Duplicate<half>(dstLocal, srcLocal, srcDataSize);
    
Result example:
scalar: 18.0
srcLocal: [18.0 1.0 2.0 ... 254.0 255.0]
dstLocal: [18.0 18.0 18.0 ... 18.0 18.0]