开发者
资源

Gather(支持寄存器为源操作数)

产品支持情况

产品

是否支持

Atlas 350 加速卡

Atlas A3 训练系列产品/Atlas A3 推理系列产品

x

Atlas A2 训练系列产品/Atlas A2 推理系列产品

x

Atlas 200I/500 A2 推理产品

x

Atlas 推理系列产品AI Core

x

Atlas 推理系列产品Vector Core

x

Atlas 训练系列产品

x

功能说明

根据索引位置indexReg将源操作数srcReg按元素收集到结果dstReg中。收集过程如下图所示:

图1 Gather功能说明

定义原型

1
2
template <typename T = DefaultType, typename U = DefaultType, typename S, typename V>
__simd_callee__ inline void Gather(S& dstReg, S& srcReg, V& indexReg)

参数说明

表1 模板参数说明

参数名

描述

T

目的操作数和源操作数的数据类型。

Atlas 350 加速卡,支持的数据类型为:b8/b16/b32

U

索引值的数据类型。

Atlas 350 加速卡,支持的数据类型为:uint8_t/uint16_t/uint32_t

S

目的操作数的RegTensor类型,例如RegTensor<half>,由编译器自动推导,用户不需要填写。

V

索引值的RegTensor类型,例如RegTensor<uint16_t>,由编译器自动推导,用户不需要填写。

表2 函数参数说明

参数名

输入/输出

描述

dstReg

输出

目的操作数。

类型为RegTensor

srcReg

输入

源操作数。

类型为RegTensor

数据类型需要与目的操作数保持一致。

indexReg

输入

数据索引。

类型为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);
    }
}