Skip to content

okftype: reference.api description: "在Atlas A2与A3系列产品上将矩阵数据从Global Memory搬运到L1 Buffer,包含普通搬运、八种pad模式的普通与高维切分搬运,以及按分形迭代的2D搬运三类重载。" tag:

  • roles: [data_movement]
  • operations: [load]
  • traits: [datablock_granularity, padding] dependencies:
  • path: docs/zh/api/SIMD-API/c_api/cube_compute/cube_compute_fractal_intro/key_fractal_format_details.md kind: requires condition: "搬入前源数据需按分形格式排布"
  • path: docs/zh/api/SIMD-API/c_api/cube_datamove/cube_compute_load/cube_compute_input_move_constraint.md kind: constrained_by condition: "地址对齐与搬运粒度要求"
  • path: docs/zh/api/SIMD-API/c_api/general_description_and_constraints.md kind: constrained_by condition: "存储单元空间大小与对齐要求"
  • path: docs/zh/api/SIMD-API/c_api/sync/system_sync_overview.md kind: requires condition: "与其他指令存在数据依赖时需插入同步指令" version: ">=9.0.0" version_changes:
  • since: "9.1.0" kind: overload_added scope: "overload:asc_copy_gm2l1__PL1bf16_PGbf16_u16_u8_u16_u16" scope_basis: resolved note: "9.1.0新增2D搬运模式重载(参数 base_idx、repeat、src_stride、dst_gap,base_idx与stride单位512B),同形态同时覆盖 half、float、int32_t、int8_t、uint32_t、uint8_t 共7种dtype,仅2201架构可用。"

asc_copy_gm2l1(NPU架构版本2201)

产品支持情况​

  • Ascend 950PR&950DT系列产品:不支持
  • Atlas A3系列产品:支持
  • 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模式。

搬入前的数据排布参见关键分形格式详解;地址对齐与搬运粒度要求参见矩阵计算输入搬运约束,并结合本接口的参数和约束说明使用。

函数原型​

  • 普通搬运模式

    C++
    // 不进行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)
    
  • 普通搬运模式(高维切分)

    C++
    // 不进行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)
    
  • 2D搬运模式

    C++
    // 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)
    

参数说明​

普通搬运模式参数​

表1 普通搬运模式参数

参数名输入/输出描述
dst输出目的操作数(矢量)的起始地址。
src输入源操作数的起始地址。
size输入搬运数据大小(字节)。
n_burst输入待搬运的连续传输数据块个数。取值范围:[1, 4095]。
len_burst输入待搬运的每个连续传输数据块的长度,单位为DataBlock(32字节)。取值范围:[1, 65535]。
src_gap输入源操作数相邻连续数据块的间隔(前面一个数据块的尾与后面一个数据块的头的间隔)。
单位为DataBlock(32字节)。
dst_gap输入目的操作数相邻连续数据块的间隔(前面一个数据块的尾与后面一个数据块的头的间隔)。
单位为DataBlock(32字节)。

2D搬运模式参数​

表2 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

约束说明​

  • 各存储单元的空间大小和对齐要求请参考存储单元说明。
  • 如果本指令与其他指令存在数据依赖,需要插入同步指令,保证多个指令串行化,防止出现异常数据。

调用示例​

C++
// 普通数据搬运模式
//total_length指参与搬运的数据总长度。
constexpr uint64_t total_length = 128;
__cbuf__ half dst[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;
// src表示源操作数的起始地址
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;
// src表示源操作数的输入地址。
__cbuf__ half dst[256];
asc_copy_gm2l1(dst, src, base_idx, repeat, src_stride, dst_gap);

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