CANN/asc-devkit Gather寄存器操作API
·
Gather(支持寄存器为源操作数)
产品支持情况
功能说明
根据索引位置indexReg将源操作数srcReg按元素收集到结果dstReg中。收集过程如下图所示:
图 1 Gather功能说明

定义原型
template <typename T = DefaultType, typename U = DefaultType, typename S, typename V>
__simd_callee__ inline void Gather(S& dstReg, S& srcReg, V& indexReg)
参数说明
表 1 模板参数说明
|
Ascend 950PR/Ascend 950DT,支持的数据类型为:uint8_t/uint16_t/uint32_t |
|
表 2 函数参数说明
|
类型为RegTensor。 |
||
|
类型为RegTensor。 |
||
|
类型为RegTensor。 srcReg为RegTensor类型,位宽是固定的VL,存储的元素个数固定。如果indexReg中索引值超出当前RegTensor中能存储的最大数据元素个数时,按照如下方式处理:设定当前RegTensor所能存储的最大数据元素个数为vlLength,indexReg中索引值为i,索引值更新为i % vlLength。 |
约束说明
无
调用示例
template<typename T, typename U>
__simd_vf__ inline void GatherVF(__ubuf__ T* dstAddr, __ubuf__ T* src0Addr, __ubuf__ U* src1Addr, uint32_t count, uint32_t oneRepeatSize, uint16_t repeatTimes)
{
AscendC::Reg::RegTensor<T> srcReg0, dstReg;
AscendC::Reg::RegTensor<U> srcReg1;
AscendC::Reg::MaskReg mask;
AscendC::Reg::LoadAlign(srcReg1, src1Addr);
for (uint16_t i = 0; i < repeatTimes; i++) {
mask = AscendC::Reg::UpdateMask<T>(count);
AscendC::Reg::LoadAlign(srcReg0, src0Addr + i * oneRepeatSize);
AscendC::Reg::Gather(dstReg, srcReg0, srcReg1);
AscendC::Reg::StoreAlign(dstAddr + i * oneRepeatSize, dstReg, mask);
}
}
更多推荐



所有评论(0)