Skip to content

asc_copy_gm2ub_align(NPU架构版本2201)

产品支持情况​

  • Ascend 950PR&950DT系列产品:不支持
  • Atlas A3系列产品:支持
  • Atlas A2系列产品:支持
  • Atlas 200I/500 A2推理产品:不支持
  • Atlas推理系列产品AI Core:不支持
  • Atlas推理系列产品Vector Core:不支持
  • Atlas训练系列产品:不支持

功能说明​

头文件路径为:"c_api/vector_datamove/vector_datamove.h"。

将数据从Global Memory(GM)搬运到Unified Buffer(UB),支持搬运长度不是32字节整数倍的数据,并在搬运过程中进行32字节对齐补齐。该接口支持8位/16位/32位数据类型搬运,搬运数据长度仍需满足对应数据类型的字节对齐要求;源、目的起始地址的对齐要求请参见参数说明。

本接口支持以下两种数据搬运方式:

  • 前n个数据搬运

    若搬运数据长度非32字节对齐,搬运数据会补齐至32字节对齐,支持以下两种填充方式:

    • 手动填充:搬运前调用asc_set_copy_pad_val配置填充值。
    • 自动填充:不调用asc_set_copy_pad_val时,由硬件自动填充dummy假数据,dummy假数据的值为数据块的第一个元素的值。
  • 高维切分搬运

    高维切分搬运采用Normal模式。若burst_len指定的单个数据块长度非32字节对齐,则burst_count指定的每个数据块都会分别补齐至32字节对齐。非32字节对齐场景支持以下两种填充方式:

    • 手动填充:搬运前调用asc_set_copy_pad_val设置填充值。
    • 自动填充:不调用asc_set_copy_pad_val时,由硬件自动填充dummy假数据,dummy假数据的值为数据块的第一个元素的值。

    循环搬运模式相关配置接口请参考asc_set_gm2ub_loop_size、asc_set_gm2ub_loop1_stride和asc_set_gm2ub_loop2_stride。其中,asc_set_gm2ub_loop_size用于设置两层循环迭代次数,asc_set_gm2ub_loop1_stride和asc_set_gm2ub_loop2_stride分别用于设置内层循环loop1、外层循环loop2中相邻两次迭代的源操作数和目的操作数数据块起始地址偏移量。相关接口的产品支持情况以各接口文档为准。

函数原型​

  • 前n个数据搬运

    C++
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ int8_t* dst, __gm__ int8_t* src, uint32_t size)
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ uint8_t* dst, __gm__ uint8_t* src, uint32_t size)
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ int16_t* dst, __gm__ int16_t* src, uint32_t size)
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ uint16_t* dst, __gm__ uint16_t* src, uint32_t size)
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ half* dst, __gm__ half* src, uint32_t size)
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ bfloat16_t* dst, __gm__ bfloat16_t* src, uint32_t size)
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ int32_t* dst, __gm__ int32_t* src, uint32_t size)
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ uint32_t* dst, __gm__ uint32_t* src, uint32_t size)
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ float* dst, __gm__ float* src, uint32_t size)
    
  • 高维切分搬运

    C++
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ int8_t* dst, __gm__ int8_t* src, uint16_t burst_count, uint32_t burst_len, uint8_t left_padding_num, uint8_t right_padding_num, uint32_t src_gap, uint32_t dst_gap)
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ uint8_t* dst, __gm__ uint8_t* src, uint16_t burst_count, uint32_t burst_len, uint8_t left_padding_num, uint8_t right_padding_num, uint32_t src_gap, uint32_t dst_gap)
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ int16_t* dst, __gm__ int16_t* src, uint16_t burst_count, uint32_t burst_len, uint8_t left_padding_num, uint8_t right_padding_num, uint32_t src_gap, uint32_t dst_gap)
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ uint16_t* dst, __gm__ uint16_t* src, uint16_t burst_count, uint32_t burst_len, uint8_t left_padding_num, uint8_t right_padding_num, uint32_t src_gap, uint32_t dst_gap)
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ half* dst, __gm__ half* src, uint16_t burst_count, uint32_t burst_len, uint8_t left_padding_num, uint8_t right_padding_num, uint32_t src_gap, uint32_t dst_gap)
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ bfloat16_t* dst, __gm__ bfloat16_t* src, uint16_t burst_count, uint32_t burst_len, uint8_t left_padding_num, uint8_t right_padding_num, uint32_t src_gap, uint32_t dst_gap)
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ int32_t* dst, __gm__ int32_t* src, uint16_t burst_count, uint32_t burst_len, uint8_t left_padding_num, uint8_t right_padding_num, uint32_t src_gap, uint32_t dst_gap)
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ uint32_t* dst, __gm__ uint32_t* src, uint16_t burst_count, uint32_t burst_len, uint8_t left_padding_num, uint8_t right_padding_num, uint32_t src_gap, uint32_t dst_gap)
    __aicore__ inline void asc_copy_gm2ub_align(__ubuf__ float* dst, __gm__ float* src, uint16_t burst_count, uint32_t burst_len, uint8_t left_padding_num, uint8_t right_padding_num, uint32_t src_gap, uint32_t dst_gap)
    

参数说明​

表1 参数说明

参数名输入/输出描述
dst输出目的UB的起始地址。需要32字节对齐。
src输入源GM的起始地址。需要1字节对齐。
size输入搬运数据大小,单位为字节。取值范围:[0, 2097151]。
burst_count输入待搬运的连续传输数据块个数。取值范围:[0, 4095]。
burst_len输入待搬运的每个连续传输数据块的长度,单位为字节。取值范围:[0, 2097151]。
left_padding_num输入连续搬运数据块左侧需要补充的元素个数。该参数对应的填充数据大小不能超过32字节。
right_padding_num输入连续搬运数据块右侧需要补充的元素个数。该参数对应的填充数据大小不能超过32字节。
src_gap输入源操作数相邻连续数据块的距离(前面一个数据块的尾与后面一个数据块的头的间隔),单位为字节。
dst_gap输入目的操作数相邻连续数据块的距离(前面一个数据块的尾与后面一个数据块的头的间隔),单位为DataBlock(32字节)。

返回值说明​

无

流水类型​

PIPE_MTE2

约束说明​

  • 各存储单元的空间大小和对齐要求请参考存储单元说明。
  • 当burst_count、burst_len中任意一个值为0时,该接口被视为NOP(空操作)。
  • 当size值为0时,该接口被视为NOP(空操作)。
  • 如果本指令与其他指令存在数据依赖,需要插入同步指令,保证多个指令串行化,防止出现异常数据。
  • left_padding_num、right_padding_num对应的填充数据大小均不能超过32字节。

调用示例​

C++
// total_length指参与搬运的数据总长度。src是外部输入的GM内存。
constexpr uint64_t total_length = 128;
__ubuf__ uint8_t dst[total_length];
asc_copy_gm2ub_align(dst, src, total_length * sizeof(uint8_t));

免责声明:本站内容由 asc-devkit 仓 master 分支自动编译生成,属于持续开发版本,可能存在缺陷,仅供预览与参考。如需稳定及商用资料,请查阅官方 昇腾社区。