CANN/asc-devkit GM到L1数据搬运函数

📅 2026/7/16 18:22:40
CANN/asc-devkit GM到L1数据搬运函数
asc_copy_gm2l1【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit产品支持情况Ascend 950PR/Ascend 950DT不支持Atlas A3 训练系列产品/Atlas A3 推理系列产品支持Atlas A2 训练系列产品/Atlas A2 推理系列产品支持Atlas 200I/500 A2 推理产品不支持Atlas 推理系列产品AI Core不支持Atlas 推理系列产品Vector Core不支持Atlas 训练系列产品不支持功能说明头文件路径c_api/cube_datamove/cube_datamove.h。将矩阵数据从Global Memory搬运到L1 Buffer中并支持不同类型的pad模式。函数原型普通搬运模式// 不进行pad操作 __aicore__ inline void asc_copy_gm2l1(__cbuf__ void* dst, __gm__ void* src, uint32_t size) // 以32B为单位每1B插入31B的pad __aicore__ inline void asc_copy_gm2l1_pad1(__cbuf__ void* dst, __gm__ void* src, uint32_t size) // 以32B为单位每1B插入15B的pad __aicore__ inline void asc_copy_gm2l1_pad2(__cbuf__ void* dst, __gm__ void* src, uint32_t size) // 以32B为单位每2B插入14B的pad __aicore__ inline void asc_copy_gm2l1_pad3(__cbuf__ void* dst, __gm__ void* src, uint32_t size) // 以32B为单位每4B插入12B的pad __aicore__ inline void asc_copy_gm2l1_pad4(__cbuf__ void* dst, __gm__ void* src, uint32_t size) // 以32B为单位每8B插入8B的pad __aicore__ inline void asc_copy_gm2l1_pad5(__cbuf__ void* dst, __gm__ void* src, uint32_t size) // 每32B删除最高位的28B,最低位的4B连续存储 __aicore__ inline void asc_copy_gm2l1_pad6(__cbuf__ void* dst, __gm__ void* src, uint32_t size) // 每32B删除最高位的24B,最低位的8B连续存储 __aicore__ inline void asc_copy_gm2l1_pad7(__cbuf__ void* dst, __gm__ void* src, uint32_t size) // 每32B删除最高位的16B,最低位的16B连续存储 __aicore__ inline void asc_copy_gm2l1_pad8(__cbuf__ void* dst, __gm__ void* src, uint32_t size)普通搬运模式高维切分// 不进行pad操作 __aicore__ inline void asc_copy_gm2l1(__cbuf__ void* dst, __gm__ void* src, uint16_t n_burst, uint16_t len_burst, uint16_t src_gap, uint16_t dst_gap) // 以32B为单位每1B插入31B的pad __aicore__ inline void asc_copy_gm2l1_pad1(__cbuf__ void* dst, __gm__ void* src, uint16_t n_burst, uint16_t len_burst, uint16_t src_gap, uint16_t dst_gap) // 以32B为单位每1B插入15B的pad __aicore__ inline void asc_copy_gm2l1_pad2(__cbuf__ void* dst, __gm__ void* src, uint16_t n_burst, uint16_t len_burst, uint16_t src_gap, uint16_t dst_gap) // 以32B为单位每2B插入14B的pad __aicore__ inline void asc_copy_gm2l1_pad3(__cbuf__ void* dst, __gm__ void* src, uint16_t n_burst, uint16_t len_burst, uint16_t src_gap, uint16_t dst_gap) // 以32B为单位每4B插入12B的pad __aicore__ inline void asc_copy_gm2l1_pad4(__cbuf__ void* dst, __gm__ void* src, uint16_t n_burst, uint16_t len_burst, uint16_t src_gap, uint16_t dst_gap) // 以32B为单位每8B插入8B的pad __aicore__ inline void asc_copy_gm2l1_pad5(__cbuf__ void* dst, __gm__ void* src, uint16_t n_burst, uint16_t len_burst, uint16_t src_gap, uint16_t dst_gap) // 每32B删除最高位的28B,最低位的4B连续存储 __aicore__ inline void asc_copy_gm2l1_pad6(__cbuf__ void* dst, __gm__ void* src, uint16_t n_burst, uint16_t len_burst, uint16_t src_gap, uint16_t dst_gap) // 每32B删除最高位的24B,最低位的8B连续存储 __aicore__ inline void asc_copy_gm2l1_pad7(__cbuf__ void* dst, __gm__ void* src, uint16_t n_burst, uint16_t len_burst, uint16_t src_gap, uint16_t dst_gap) // 每32B删除最高位的16B,最低位的16B连续存储 __aicore__ inline void asc_copy_gm2l1_pad8(__cbuf__ void* dst, __gm__ void* src, uint16_t n_burst, uint16_t len_burst, uint16_t src_gap, uint16_t dst_gap)普通搬运模式同步// 不进行pad操作 __aicore__ inline void asc_copy_gm2l1_sync(__cbuf__ void* dst, __gm__ void* src, uint32_t size) // 以32B为单位每1B插入31B的pad __aicore__ inline void asc_copy_gm2l1_pad1_sync(__cbuf__ void* dst, __gm__ void* src, uint32_t size) // 以32B为单位每1B插入15B的pad __aicore__ inline void asc_copy_gm2l1_pad2_sync(__cbuf__ void* dst, __gm__ void* src, uint32_t size) // 以32B为单位每2B插入14B的pad __aicore__ inline void asc_copy_gm2l1_pad3_sync(__cbuf__ void* dst, __gm__ void* src, uint32_t size) // 以32B为单位每4B插入12B的pad __aicore__ inline void asc_copy_gm2l1_pad4_sync(__cbuf__ void* dst, __gm__ void* src, uint32_t size) // 以32B为单位每8B插入8B的pad __aicore__ inline void asc_copy_gm2l1_pad5_sync(__cbuf__ void* dst, __gm__ void* src, uint32_t size) // 每32B删除最高位的28B,最低位的4B连续存储 __aicore__ inline void asc_copy_gm2l1_pad6_sync(__cbuf__ void* dst, __gm__ void* src, uint32_t size) // 每32B删除最高位的24B,最低位的8B连续存储 __aicore__ inline void asc_copy_gm2l1_pad7_sync(__cbuf__ void* dst, __gm__ void* src, uint32_t size) // 每32B删除最高位的16B,最低位的16B连续存储 __aicore__ inline void asc_copy_gm2l1_pad8_sync(__cbuf__ void* dst, __gm__ void* src, uint32_t size)2D搬运模式// 2D搬运bfloat16_t类型矩阵数据 __aicore__ inline void asc_copy_gm2l1(__cbuf__ bfloat16_t* dst, __gm__ bfloat16_t* src, uint16_t base_idx, uint8_t repeat, uint16_t src_stride, uint16_t dst_gap) // 2D搬运half类型矩阵数据 __aicore__ inline void asc_copy_gm2l1(__cbuf__ half* dst, __gm__ half* src, uint16_t base_idx, uint8_t repeat, uint16_t src_stride, uint16_t dst_gap) // 2D搬运float类型矩阵数据 __aicore__ inline void asc_copy_gm2l1(__cbuf__ float* dst, __gm__ float* src, uint16_t base_idx, uint8_t repeat, uint16_t src_stride, uint16_t dst_gap) // 2D搬运int32_t类型矩阵数据 __aicore__ inline void asc_copy_gm2l1(__cbuf__ int32_t* dst, __gm__ int32_t* src, uint16_t base_idx, uint8_t repeat, uint16_t src_stride, uint16_t dst_gap) // 2D搬运int8_t类型矩阵数据 __aicore__ inline void asc_copy_gm2l1(__cbuf__ int8_t* dst, __gm__ int8_t* src, uint16_t base_idx, uint8_t repeat, uint16_t src_stride, uint16_t dst_gap) // 2D搬运uint32_t类型矩阵数据 __aicore__ inline void asc_copy_gm2l1(__cbuf__ uint32_t* dst, __gm__ uint32_t* src, uint16_t base_idx, uint8_t repeat, uint16_t src_stride, uint16_t dst_gap) // 2D搬运uint8_t类型矩阵数据 __aicore__ inline void asc_copy_gm2l1(__cbuf__ uint8_t* dst, __gm__ uint8_t* src, uint16_t base_idx, uint8_t repeat, uint16_t src_stride, uint16_t dst_gap)2D搬运模式同步// 2D搬运bfloat16_t类型矩阵数据同步 __aicore__ inline void asc_copy_gm2l1_sync(__cbuf__ bfloat16_t* dst, __gm__ bfloat16_t* src, uint16_t base_idx, uint8_t repeat, uint16_t src_stride, uint16_t dst_gap) // 2D搬运half类型矩阵数据同步 __aicore__ inline void asc_copy_gm2l1_sync(__cbuf__ half* dst, __gm__ half* src, uint16_t base_idx, uint8_t repeat, uint16_t src_stride, uint16_t dst_gap) // 2D搬运float类型矩阵数据同步 __aicore__ inline void asc_copy_gm2l1_sync(__cbuf__ float* dst, __gm__ float* src, uint16_t base_idx, uint8_t repeat, uint16_t src_stride, uint16_t dst_gap) // 2D搬运int32_t类型矩阵数据同步 __aicore__ inline void asc_copy_gm2l1_sync(__cbuf__ int32_t* dst, __gm__ int32_t* src, uint16_t base_idx, uint8_t repeat, uint16_t src_stride, uint16_t dst_gap) // 2D搬运int8_t类型矩阵数据同步 __aicore__ inline void asc_copy_gm2l1_sync(__cbuf__ int8_t* dst, __gm__ int8_t* src, uint16_t base_idx, uint8_t repeat, uint16_t src_stride, uint16_t dst_gap) // 2D搬运uint32_t类型矩阵数据同步 __aicore__ inline void asc_copy_gm2l1_sync(__cbuf__ uint32_t* dst, __gm__ uint32_t* src, uint16_t base_idx, uint8_t repeat, uint16_t src_stride, uint16_t dst_gap) // 2D搬运uint8_t类型矩阵数据同步 __aicore__ inline void asc_copy_gm2l1_sync(__cbuf__ uint8_t* dst, __gm__ uint8_t* src, uint16_t base_idx, uint8_t repeat, uint16_t src_stride, uint16_t dst_gap)参数说明普通搬运模式参数参数名输入/输出描述dst输出目的操作数矢量的起始地址。src输入源操作数的起始地址。size输入搬运数据大小字节。n_burst输入待搬运的连续传输数据块个数。取值范围[1, 4095]。len_burst输入待搬运的每个连续传输数据块的长度单位为DataBlock32字节。取值范围[1, 65535]。src_gap输入源操作数相邻连续数据块的间隔前面一个数据块的尾与后面一个数据块的头的间隔。单位为DataBlock32字节。dst_gap输入目的操作数相邻连续数据块的间隔前面一个数据块的尾与后面一个数据块的头的间隔。单位为DataBlock32字节。2D搬运模式参数参数名输入/输出描述dst输出目的操作数矢量的起始地址。src输入源操作数矢量的起始地址。base_idx输入分形矩阵ID说明搬运起始位置为源操作数中的第几个分形0为源操作数中的第一个分形矩阵。取值范围[0, 65535]。单位512B。默认为0。repeat输入迭代次数。src_stride输入相邻迭代间源操作数前一个分形与后一个分形起始地址的间隔单位512B。取值范围[0, 65535]。默认为0。dst_gap输入相邻迭代间目的操作数前一个分形结束地址与后一个分形起始地址的间隔单位512B。取值范围[0, 65536]。默认为0。返回值说明无流水类型PIPE_MTE2约束说明src的起始地址要求按照对应数据类型所占字节数对齐。dst的起始地址要求32字节对齐。如果需要执行多条asc_copy_gm2l1指令且asc_copy_gm2l1指令的目的地址存在重叠需要插入同步指令保证多个asc_copy_gm2l1指令的串行化防止出现异常数据。调用示例// 普通数据搬运模式 //total_length指参与搬运的数据总长度。 constexpr uint64_t total_length 128; __cbuf__ half dst[total_length]; __gm__ half src[total_length]; // 连续搬运的数据块数量 constexpr uint16_t n_burst 1; // 连续搬运的数据块长度此处为512个half元素 constexpr uint16_t len_burst 512 * sizeof(half) / 32; // 源操作数做连续搬运 constexpr uint16_t src_gap 0; // 目的操作数连续排布 constexpr uint16_t dst_gap 0; asc_copy_gm2l1((__cbuf__ void*)dst, (__gm__ void*)src, n_burst, len_burst, src_gap, dst_gap); // 2D数据搬运模式 //搬运的起始分块为1 constexpr uint16_t base_idx 1; //搬运的迭代次数为2 constexpr uint8_t repeat 2; //输入的搬运步长为0字节输出的搬运步长为1024字节 constexpr uint16_t src_stride 0; constexpr uint16_t dst_gap 1; __gm__ half src[256]; __cbuf__ half dst[256]; asc_copy_gm2l1(dst, src, base_idx, repeat, src_stride, dst_gap);【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考