产品 |
是否支持 Global Memory -> Local Memory |
是否支持 Local Memory -> Local Memory |
|---|---|---|
Ascend 950PR/Ascend 950DT |
√ |
√ |
√ |
√ |
|
√ |
√ |
|
x |
x |
|
√ |
x |
|
x |
x |
|
x |
x |
支持在数据搬运时进行ND到NZ格式的转换。
1 2 | template <typename T> __aicore__ inline void DataCopy(const LocalTensor<T>& dst, const GlobalTensor<T>& src, const Nd2NzParams& intriParams) |
1 2 3 | // 该函数原型仅支持Ascend 950PR/Ascend 950DT template <typename T, bool enableSmallC0 = false> __aicore__ inline void DataCopy(const LocalTensor<T>& dst, const GlobalTensor<T>& src, const Nd2NzParams& intriParams) |
1 2 | template <typename T> __aicore__ inline void DataCopy(const LocalTensor<T>& dst, const LocalTensor<T>& src, const Nd2NzParams& intriParams) |
参数名 |
描述 |
|---|---|
T |
源操作数或者目的操作数的数据类型。支持的数据类型请参考支持的通路和数据类型。 |
enableSmallC0 |
SmallC0模式开关:当dValue小于等于4的时候,C0_SIZE会补齐到4 * sizeof(T) Bytes。 默认不开启。 |
参数名称 |
输入/输出 |
含义 |
|---|---|---|
dst |
输出 |
目的操作数,类型为LocalTensor。 |
src |
输入 |
源操作数,类型为LocalTensor或GlobalTensor。 |
intriParams |
输入 |
搬运参数,类型为Nd2NzParams。 具体定义请参考${INSTALL_DIR}/include/ascendc/basic_api/interface/kernel_struct_data_copy.h,${INSTALL_DIR}请替换为CANN软件安装后文件存储路径。 |
参数名称 |
含义 |
|---|---|
ndNum |
传输ND矩阵的数目,取值范围:ndNum∈[0, 4095]。 |
nValue |
ND矩阵的行数,取值范围:nValue∈[0, 16384]。 |
dValue |
ND矩阵的列数,取值范围:dValue∈[0, 65535]。 |
srcNdMatrixStride |
源操作数相邻ND矩阵起始地址间的偏移,取值范围:srcNdMatrixStride∈[0, 65535],单位为元素。 |
srcDValue |
源操作数同一ND矩阵的相邻行起始地址间的偏移,取值范围:srcDValue∈[1, 65535],单位为元素。 |
dstNzC0Stride |
ND转换到NZ格式后,源操作数中的一行会转换为目的操作数的多行。dstNzC0Stride表示,目的NZ矩阵中,来自源操作数同一行的多行数据相邻行起始地址间的偏移,取值范围:dstNzC0Stride∈[1, 16384],单位:C0_SIZE(32B)。 |
dstNzNStride |
目的NZ矩阵中,Z型矩阵相邻行起始地址之间的偏移。取值范围:dstNzNStride∈[1, 16384],单位:C0_SIZE(32B)。 |
dstNzMatrixStride |
目的NZ矩阵中,相邻NZ矩阵起始地址间的偏移,取值范围:dstNzMatrixStride∈[1, 65535],单位为元素。 |
ND2NZ转换示意图如下,样例中参数设置值和解释说明如下:
enableSmallC0开启模式下的ND2NZ转换示意图如下:

无
针对
下文的数据通路均通过逻辑位置TPosition来表达,并注明了对应的物理通路。TPosition与物理内存的映射关系见表1。
产品型号 |
数据通路 |
源操作数和目的操作数的数据类型 (两者保持一致) |
|---|---|---|
Ascend 950PR/Ascend 950DT |
|
bool、int8_t、uint8_t、hifloat8_t、fp8_e5m2_t、fp8_e4m3fn_t、fp8_e8m0_t、int16_t、uint16_t、half、bfloat16_t、int32_t、uint32_t、float、complex32 |
|
bool、int8_t、uint8_t、fp4x2_e2m1_t、fp4x2_e1m2_t、hifloat8_t、fp8_e5m2_t、fp8_e4m3fn_t、fp8_e8m0_t、int16_t、uint16_t、half、bfloat16_t、int32_t、uint32_t、float、complex32 |
|
|
int8_t、uint8_t、int16_t、uint16_t、int32_t、uint32_t、half、float |
|
|
int16_t、uint16_t、int32_t、uint32_t、half、float |
|
|
int8_t、uint8_t、int16_t、uint16_t、int32_t、uint32_t、half、bfloat16_t、float |
|
|
int8_t、uint8_t、int16_t、uint16_t、int32_t、uint32_t、half、bfloat16_t、float |
产品型号 |
数据通路 |
源操作数和目的操作数的数据类型 (两者保持一致) |
|---|---|---|
Ascend 950PR/Ascend 950DT |
VECIN、VECCALC、VECOUT -> TSCM(UB -> L1 Buffer) |
bool、int8_t、uint8_t、hifloat8_t、fp8_e5m2_t、fp8_e4m3fn_t、fp8_e8m0_t、int16_t、uint16_t、half、bfloat16_t、int32_t、uint32_t、float、complex32 |
VECIN、VECCALC、VECOUT -> TSCM(UB -> L1 Buffer) |
int8_t、uint8_t、int16_t、uint16_t、int32_t、uint32_t、half、bfloat16_t、float |
|
VECIN、VECCALC、VECOUT -> TSCM(UB -> L1 Buffer) |
int8_t、uint8_t、int16_t、uint16_t、int32_t、uint32_t、half、bfloat16_t、float |
intriParams参数解析请参考图1。
// srcLocal为half类型的L1 Buffer空间上的LocalTensor,workLocal为half类型的UB空间上的LocalTensor,srcGlobal为half类型的GlobalTensor
AscendC::Nd2NzParams intriParams{1, 32, 32, 0, 32, 32, 1, 0};
// Global Memory -> Local Memory
AscendC::DataCopy(srcLocal, srcGlobal, intriParams);
// Local Memory -> Local Memory
AscendC::DataCopy(srcLocal, workLocal, intriParams);
结果示例:
输入数据(srcGlobal): [1 2 3 ... 1024] 输出数据(dstGlobal):[1 2 ... 15 16 33 34 ... 47 48 65 66 ... 79 80 97 98 ... 111 112 ... 1009 1010... 1023 1024]