Add(支持进位)
产品支持情况
产品 |
是否支持 |
|---|---|
Atlas 350 加速卡 |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
功能说明
根据mask对输入数据srcReg0、srcReg1进行按元素相加操作,将结果写入dstReg。如果srcReg0, srcReg1输入转换为uint32类型相加时超出uint32_t最大值,在carry(存放进位的MaskReg寄存器)中对应位置每4bit设置1,否则写0。
计算公式如下:

函数原型
template <typename T = DefaultType, typename U> __simd_callee__ inline void Add(MaskReg& carry, U& dstReg, U& srcReg0, U& srcReg1, MaskReg& mask)
参数说明
参数名 |
描述 |
|---|---|
T |
操作数数据类型。 Atlas 350 加速卡,支持的数据类型为:uint32_t/int32_t |
U |
srcReg0/srcReg1/dstReg RegTensor类型, 例如RegTensor<uint32_t>,由编译器自动推导,用户不需要填写。 |
返回值说明
无
约束说明
无
调用示例
template <typename T>
static __simd_vf__ inline void AddVF(__ubuf__ T* dst0Addr, __ubuf__ T* dst1Addr, __ubuf__ T* src0Addr, __ubuf__ T* src1Addr, uint32_t count, uint16_t repeatTimes, uint32_t oneRepeatSize){
AscendC::Reg::RegTensor<T> srcReg0;
AscendC::Reg::RegTensor<T> srcReg1;
AscendC::Reg::RegTensor<T> dstReg0;
AscendC::Reg::RegTensor<T> dstReg1;
AscendC::Reg::MaskReg mask;
AscendC::Reg::MaskReg carry = AscendC::Reg::CreateMask<uint8_t>();
for (uint16_t i = 0; i < repeatTimes; i++) {
mask = AscendC::Reg::UpdateMask<T>(count);
AscendC::Reg::LoadAlign(srcReg0, src0Addr + i * oneRepeatSize);
AscendC::Reg::LoadAlign(srcReg1, src1Addr + i * oneRepeatSize);
AscendC::Reg::Add(carry, dstReg0, srcReg0, srcReg1, mask);
// 8*4B=32B align
AscendC::Reg::StoreAlign<uint32_t, AscendC::Reg::MaskDist::DIST_NORM>(dst1Addr + i * 8, carry);
AscendC::Reg::StoreAlign(dst0Addr + i * oneRepeatSize, dstReg0, mask);
}
}
父主题: 基础算术