Duplicate
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
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
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.
|
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. |
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. |
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); } }