Duplicate

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

x

Atlas A2 training product/Atlas A2 inference product

x

Atlas 200I/500 A2 inference product

x

Atlas inference product AI Core

x

Atlas inference product Vector Core

x

Atlas training product

x

Function Usage

Supports scalar and tensor modes.

  • Scalar mode: Broadcasts scalarValue to the register and stores it in dstReg. (If mask is available, the value is stored in the position filtered by mask in dstReg.)
  • Tensor mode: Broadcasts the least significant element of srcReg to the register and stores it in the position filtered by mask in dstReg.

Prototype

  • Broadcast scalarValue to the register. mask is not supported.
    template <typename T = DefaultType, typename U, typename S>
    __simd_callee__ inline void Duplicate(S& dstReg, U scalarValue);
  • Broadcast scalarValue to the register. mask is supported.
    template <typename T = DefaultType, MaskMergeMode mode = MaskMergeMode::ZEROING, typename U, typename S>
    __simd_callee__ inline void Duplicate(S& dstReg, U scalarValue, MaskReg& mask);
  • Broadcast the least significant element of srcReg to the register.
    template <typename T = DefaultType, HighLowPart pos = HighLowPart::LOWEST, MaskMergeMode mode = MaskMergeMode::ZEROING, typename S>
    __simd_callee__ inline void Duplicate(S& dstReg, S& srcReg, MaskReg& mask)

Parameters

Table 1 Template parameters

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.

U

Data type of a scalar.

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

mode

Set it to MERGING or ZEROING.

  • MERGING: The elements that are not filtered by mask keep their original values in dst.
  • ZEROING: The elements that are not filtered by mask are set to zero in dst.

pos

The default value is LOWEST, indicating that the least significant bit in srcReg is broadcast to dstReg. (Other values are not supported currently.)

S

RegTensor type of the destination operand, for example, RegTensor<half>. It is automatically inferred by the compiler and does not need to be specified.

Table 2 Function parameters

Parameter

Input/Output

Description

dstReg

Output

Destination operand.

The type is RegTensor.

scalarValue

Input

Source operand.

The type is scalar.

srcReg

Input

Source operand.

The type is RegTensor.

mask

Input

Valid indication of the source operand element operation. For details, see MaskReg.

Table 3 Data type constraints of source and destination operands

dstReg

Scalar/srcReg

bool

bool

int8_t

int8_t

uint8_t

uint8_t

fp4x2_e2m1_t

int8_t

fp4x2_e1m2_t

int8_t

hifloat8_t

int8_t

fp8_e5m2_t

int8_t

fp8_e4m3fn_t

int8_t

fp8_e8m0_t

int8_t

int16_t

int16_t

uint16_t

uint16_t

half

half

bfloat16_t

bfloat16_t

int32_t

int32_t

uint32_t

uint32_t

float

float

complex32

complex32

int64_t

int64_t

uint64_t

uint64_t

complex64

complex64

Constraints

None

Examples

  • Example 1
    template<typename T>
    __simd_vf__ inline void DuplicateVF(__ubuf__ T* dstAddr, T scalarValue, uint32_t oneRepeatSize, uint16_t repeatTimes)
    {
        AscendC::Reg::RegTensor<T> dstReg;
        AscendC::Reg::MaskReg mask = AscendC::Reg::CreateMask<T>();    
        for (uint16_t i = 0; i < repeatTimes; i++) {
            AscendC::Reg::Duplicate(dstReg, scalarValue);
            AscendC::Reg::StoreAlign(dstAddr + i * oneRepeatSize, dstReg, mask);
        }
    }
  • Example 2
    template<typename T>
    __simd_vf__ inline void DuplicateVF(__ubuf__ T* dstAddr, T scalarValue, uint32_t count, uint32_t oneRepeatSize, uint16_t repeatTimes)
    {
        AscendC::Reg::RegTensor<T> dstReg;
        AscendC::Reg::MaskReg mask;    
        for (uint16_t i = 0; i < repeatTimes; i++) {
            mask = AscendC::Reg::UpdateMask<T>(count);
            AscendC::Reg::LoadAlign(srcReg, src0Addr + i * oneRepeatSize);
            AscendC::Reg::Duplicate(dstReg, scalarValue, mask);
            AscendC::Reg::StoreAlign(dstAddr + i * oneRepeatSize, dstReg, mask);
        }
    }
  • Example 3
    template<typename T>
    __simd_vf__ inline void DuplicateVF(__ubuf__ T* dstAddr, __ubuf__ T* srcAddr, uint32_t count, uint32_t oneRepeatSize, uint16_t repeatTimes)
    {
        AscendC::Reg::RegTensor<T> srcReg;
        AscendC::Reg::RegTensor<T> dstReg;
        AscendC::Reg::MaskReg mask;
        for (uint16_t i = 0; i < repeatTimes; i++) {
            mask = AscendC::Reg::UpdateMask<T>(count);
            AscendC::Reg::LoadAlign(srcReg, src0Addr + i * oneRepeatSize);
            AscendC::Reg::Duplicate(dstReg, srcReg, mask);
            AscendC::Reg::StoreAlign(dstAddr + i * oneRepeatSize, dstReg, mask);
        }
    }