CANN/asc-devkit SIMD API连续对齐搬入

发布时间:2026/5/20 12:55:07

CANN/asc-devkit SIMD API连续对齐搬入 连续对齐搬入【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit产品支持情况产品是否支持Ascend 950PR/Ascend 950DT√Atlas A3 训练系列产品 / Atlas A3 推理系列产品xAtlas A2 训练系列产品 / Atlas A2 推理系列产品xAtlas 200I/500 A2 推理产品xAtlas 推理系列产品 AI CorexAtlas 推理系列产品 Vector CorexAtlas 训练系列产品x功能说明Reg矢量计算数据搬运接口适用于从UB连续对齐搬入RegTensor。单搬入模式下可以将数据从UB搬运到一个目的寄存器双搬入模式下可以将数据从UB搬运到两个目的寄存器。函数原型// 单搬入模式 POST_MODE_NORMAL场景 template typename T DefaultType, LoadDist dist LoadDist::DIST_NORM, typename U __simd_callee__ inline void LoadAlign(U dstReg, __ubuf__ T* srcAddr); // 单搬入模式 POST_MODE_UPDATE场景 template typename T DefaultType, PostLiteral postMode, LoadDist dist LoadDist::DIST_NORM, typename U __simd_callee__ inline void LoadAlign(U dstReg, __ubuf__ T* srcAddr, int32_t postUpdateStride); // 单搬入模式 使用AddrReg存储偏移量 template typename T DefaultType, LoadDist dist LoadDist::DIST_NORM, typename U __simd_callee__ inline void LoadAlign(U dstReg, __ubuf__ T* srcAddr, AddrReg offset); // 双搬入模式 POST_MODE_NORMAL场景 template typename T DefaultType, LoadDist dist, typename U __simd_callee__ inline void LoadAlign(U dstReg0, U dstReg1, __ubuf__ T* srcAddr); // 双搬入模式 POST_MODE_UPDATE场景 template typename T DefaultType, PostLiteral postMode, LoadDist dist, typename U __simd_callee__ inline void LoadAlign(U dstReg0, U dstReg1, __ubuf__ T* srcAddr, int32_t postUpdateStride); // 双搬入模式使用 AddrReg存储偏移量 template typename T DefaultType, LoadDist dist, typename U __simd_callee__ inline void LoadAlign(U dstReg0, U dstReg1, __ubuf__ T* srcAddr, AddrReg offset);参数说明表 1LoadDist模板参数说明单搬入模式LoadDist取值含义搬运对齐约束ByteDIST_NORM正常模式搬运VL数据32DIST_BRC_B8搬运一个b8类型的数据并Broadcast到所有元素位置1DIST_BRC_B16搬运一个b16类型的数据并Broadcast到所有元素位置2DIST_BRC_B32搬运一个b32类型的数据并Broadcast到所有元素位置4DIST_US_B8数据2倍上采样加载VL/2个数据每个输入元素重复两次数据类型为b8min(32, VL/2)DIST_US_B16数据2倍上采样加载VL/2个数据每个输入元素重复两次数据类型为b16min(32, VL/2)DIST_DS_B8数据2倍下采样加载2倍VL的数据数据每隔一个保留数据类型为b832DIST_DS_B16数据2倍下采样加载2倍VL的数据数据每隔一个保留数据类型为b1632DIST_UNPACK_B8解压缩模式按无符号整型u8加载VL/2长度数据unpack到VL长度u16类型中间位置补0例VL256Bsrc: [0x00, 0x01, 0x02, 0x03, ..., 0xFF, ...]dst:[0x0000, 0x0001, ..., 0x0007F]min(32, VL/2)DIST_UNPACK_B16解压缩模式按无符号整型u16加载VL/2长度数据unpack到VL长度u32类型中间位置补0例VL256Bsrc: [0x0000, 0x0001, 0x0002, 0x0003, ..., 0x007F, ...]dst:[0x00000000, 0x00000001, ..., 0x000003F]min(32, VL/2)DIST_BLK读取一个DataBlock32B并广播到VL32DIST_E2B_B16加载(VL/DataBlock)B的数据并将每个元素16bit广播到一个DataBlock32B中。VL/16DIST_E2B_B32加载(VL/DataBlock)B的数据并将每个元素32bit广播到一个DataBlock32B中。VL/8DIST_UNPACK_B32解压缩模式按无符号整型u32加载VL/2长度数据unpack到VL长度u64类型中间位置补0例VL256Bsrc: [0x00000000, 0x00000001, 0x00000002, ..., 0x000003F, ...]dst:[0x0000000000000000, 0x0000000000000001, ..., 0x000000000000001F]min(32, VL/2)DIST_UNPACK4_B8解压缩模式按无符号整型u8加载VL/4长度数据unpack到VL长度u32类型中间位置补0例VL256Bsrc: [0x00, 0x01, 0x02, 0x03, ..., 0xFF, ...]dst:[0x00000000, 0x00000001, ..., 0x000003F]min(32, VL/4)表 2LoadDist模板参数说明双搬入模式LoadDist取值含义搬运对齐约束ByteDIST_DINTLV_B8双搬入模式基于元素的交错搬运从src中读取2*VL长度数据将偶数索引的元素存入dst0将奇数索引的元素存入dst1数据类型为b832DIST_DINTLV_B16双搬入模式基于元素的交错搬运从src中读取2*VL长度数据将偶数索引的元素存入dst0将奇数索引的元素存入dst1数据类型为b1632DIST_DINTLV_B32双搬入模式基于元素的交错搬运从src中读取2*VL长度数据将偶数索引的元素存入dst0将奇数索引的元素存入dst1数据类型为b3232表 3单搬入模式POST_MODE_NORMAL场景参数说明参数名输入/输出描述T输入操作数数据类型。Ascend 950PR/Ascend 950DT支持的数据类型为b8/b16/b32/b64。dist输入搬运模式LoadDist类型具体的取值请参考表1。U输入目的操作数的RegTensor类型例如RegTensorhalf由编译器自动推导用户不需要填写。dstReg输出目的操作数类型为RegTensor。srcAddr输入源操作数在UB上的起始地址。表 4单搬入模式POST_MODE_UPDATE场景参数说明参数名输入/输出描述T输入模板参数。Ascend 950PR/Ascend 950DT支持的数据类型为b8/b16/b32/b64。postMode输入用于控制是否使能post updatePostLiteral类型。dist输入搬运模式LoadDist类型具体的取值请参考表1。U输入目的操作数的RegTensor类型例如RegTensorhalf由编译器自动推导用户不需要填写。dstReg输出目的操作数类型为RegTensor。srcAddr输入/输出源操作数在UB上的起始地址。postUpdateStride输入实际搬运UB起始地址为srcAddr搬运后执行地址更新srcAddr postUpdateStride。表 5单搬入模式使用AddrReg存储偏移量场景参数说明参数名输入/输出描述T输入模板参数。Ascend 950PR/Ascend 950DT支持的数据类型为b8/b16/b32/b64。dist输入搬运模式LoadDist类型具体的取值请参考表1。U输入目的操作数的RegTensor类型例如RegTensorhalf由编译器自动推导用户不需要填写。dstReg输出目的操作数类型为RegTensor。offset输入实际搬运地址UB为srcAddr offset。srcAddr输入/输出源操作数在UB上的起始地址。表 6双搬入模式POST_MODE_NORMAL场景参数说明参数名输入/输出描述T输入模板参数支持的数据类型为b8/b16/b32。dist输入搬运模式LoadDist类型具体的取值请参考表2。U输入目的操作数的RegTensor类型例如RegTensorhalf由编译器自动推导用户不需要填写。dstReg0输出第一个目的操作数类型为RegTensor。dstReg1输出第二个目的操作数类型为RegTensor。srcAddr输入/输出源操作数在UB上的起始地址。表 7双搬入模式POST_MODE_UPDATE场景参数说明参数名输入/输出描述T输入模板参数。Ascend 950PR/Ascend 950DT支持的数据类型为b8/b16/b32/b64。postMode输入用于控制是否使能post updatePostLiteral类型。dist输入搬运模式LoadDist类型具体的取值请参考表2。U输入目的操作数的RegTensor类型例如RegTensorhalf由编译器自动推导用户不需要填写。dstReg0输出第一个目的操作数类型为RegTensor。dstReg1输出第二个目的操作数类型为RegTensor。srcAddr输入/输出源操作数在UB上的起始地址。postUpdateStride输入实际搬运UB起始地址为srcAddr搬运后执行地址更新srcAddr postUpdateStride。表 8双搬入模式使用AddrReg存储偏移量场景参数说明参数名输入/输出描述T输入模板参数支持的数据类型为b8/b16/b32。dist输入搬运模式LoadDist类型具体的取值请参考表2。U输入目的操作数的RegTensor类型例如RegTensorhalf由编译器自动推导用户不需要填写。dstReg0输出第一个目的操作数类型为RegTensor。dstReg1输出第二个目的操作数类型为RegTensor。offset输入实际搬运地址UB为srcAddr offset。srcAddr输入/输出源操作数在UB上的起始地址。返回值说明无约束说明b64数据类型只支持LoadDist中的DIST_NORM模式。调用示例// 单搬入/单搬出 POST_MODE_NORMAL 场景 __simd_vf__ inline void ComputeMode01(__ubuf__ T* dstAddr, __ubuf__ T* srcAddr, uint32_t dstSize, uint32_t oneRepeatSize, uint16_t repeatTimes) { AscendC::Reg::RegTensorT dstReg; AscendC::Reg::MaskReg mask; for (uint16_t i 0; i repeatTimes; i) { mask AscendC::Reg::UpdateMaskT(dstSize); AscendC::Reg::LoadAlign(dstReg, srcAddr i * oneRepeatSize); AscendC::Reg::StoreAlign(dstAddr i * oneRepeatSize, dstReg, mask); } } // 单搬入/单搬出 POST_MODE_UPDATE 场景 __simd_vf__ inline void ComputeMode02(__ubuf__ T* dstAddr, __ubuf__ T* srcAddr, uint32_t dstSize, uint32_t oneRepeatSize, uint16_t repeatTimes) { AscendC::Reg::RegTensorT dstReg; AscendC::Reg::MaskReg mask; for (uint16_t i 0; i repeatTimes; i) { mask AscendC::Reg::UpdateMaskT(dstSize); AscendC::Reg::LoadAlignT, AscendC::Reg::PostLiteral::POST_MODE_UPDATE(dstReg, srcAddr, oneRepeatSize); AscendC::Reg::StoreAlignT, AscendC::Reg::PostLiteral::POST_MODE_UPDATE(dstAddr, dstReg, oneRepeatSize, mask); } } // 单搬入/单搬出使用 AddrReg 存储偏移量场景 __simd_vf__ inline void ComputeMode03(__ubuf__ T* dstAddr, __ubuf__ T* srcAddr, uint32_t oneRepeatSize, uint16_t repeatTimes) { AscendC::Reg::RegTensorT dstReg; AscendC::Reg::MaskReg mask AscendC::Reg::CreateMaskT(); AscendC::Reg::AddrReg aReg; for (uint16_t i 0; i repeatTimes; i) { aReg AscendC::Reg::CreateAddrRegT(i, oneRepeatSize); AscendC::Reg::LoadAlign(dstReg, srcAddr, aReg); AscendC::Reg::StoreAlign(dstAddr, dstReg, aReg, mask); } } // 双搬入/双搬出 POST_MODE_NORMAL 场景 __simd_vf__ inline void ComputeMode04(__ubuf__ T* dstAddr, __ubuf__ T* srcAddr, uint32_t oneRepeatSize, uint16_t repeatTimes) { AscendC::Reg::RegTensorT srcReg0; AscendC::Reg::RegTensorT srcReg1; AscendC::Reg::MaskReg mask AscendC::Reg::CreateMaskuint8_t, AscendC::Reg::MaskPattern::ALL(); for (uint16_t i 0; i repeatTimes; i) { AscendC::Reg::LoadAlignT, AscendC::Reg::LoadDist::DIST_DINTLV_B8(srcReg0, srcReg1, srcAddr i * oneRepeatSize); AscendC::Reg::StoreAlignT, AscendC::Reg::StoreDist::DIST_INTLV_B8(dstAddr i * oneRepeatSize, srcReg0, srcReg1, mask); } } // 双搬入/双搬出使用 AddrReg 存储偏移量场景 __simd_vf__ inline void ComputeMode05(__ubuf__ T* dstAddr, __ubuf__ T* srcAddr, uint32_t oneRepeatSize, uint16_t repeatTimes) { AscendC::Reg::RegTensorT srcReg0; AscendC::Reg::RegTensorT srcReg1; AscendC::Reg::MaskReg mask AscendC::Reg::CreateMaskT(); AscendC::Reg::AddrReg aReg; for (uint16_t i 0; i repeatTimes; i) { aReg AscendC::Reg::CreateAddrRegT(i, oneRepeatSize); AscendC::Reg::LoadAlignT, AscendC::Reg::LoadDist::DIST_DINTLV_B8(srcReg0, srcReg1, srcAddr, aReg); AscendC::Reg::StoreAlignT, AscendC::Reg::StoreDist::DIST_INTLV_B8(dstAddr, srcReg0, srcReg1, aReg, mask); } }【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

相关新闻