data_move

功能说明

在src与dst间进行数据传输。支持src与dst的类型同时为Tensor。

Atlas 200/300/500 推理产品,支持UB->UB/UB->OUT/OUT->UB/OUT->L1

Atlas 训练系列产品,支持UB->UB/UB->OUT/OUT->UB/OUT->L1

函数原型

data_move (dst, src, sid, nburst, burst, src_stride, dst_stride, *args, **argv)

参数说明

表1 参数说明

参数名称

输入/输出

含义

dst

输出

目的操作数,支持数据类型参考表2

若dst的scope为L1或UB, 则要求地址偏移32Byte对齐。

src

输入

源操作数,支持数据类型参考表2

若src的scope为L1或UB, 则要求地址偏移32Byte对齐。

sid

输入

SMMU ID,为硬件保留接口,输入0即可,取值范围:sid∈[0, 15],支持数据类型:Scalar(int32)、立即数(int32)、Expr(int32)。

nburst

输入

传输数据片段数目,取值范围:nburst∈[1, 4095],支持的数据类型为:Scalar(int32)、立即数(int32)、Expr(int32)。

burst

输入

连续传输数据片段长度,取值范围:burst∈[1, 65535],单位:32B。

支持的数据类型为:Scalar(int16/int32/int64/uint16/uint32/uint64)、立即数(int)、Expr(int16/int32/int64/uint16/uint32/uint64)。

src_stride

输入

源tensor相邻连续数据片段间隔(前 burst 尾与后 burst 头),取值范围:src_stride∈[0, 65535]。支持的数据类型为:Scalar(int16/int32/int64/uint16/uint32/uint64)、立即数(int)、Expr(int16/int32/int64/uint16/uint32/uint64)。

dst_stride

输入

目的tensor相邻连续数据片段间隔(前 burst 尾与后 burst 头),取值范围:dst_stride∈[0, 65535]。支持的数据类型为:Scalar(int16/int32/int64/uint16/uint32/uint64)、立即数(int)、Expr(int16/int32/int64/uint16/uint32/uint64)。

*args

输入

扩展参数个数。

**argv

输入

扩展参数。

表2 data_move相关数据类型、scope及参数单位

src.scope

dst.scope

dtype

(src需与dst保持一致)

burst

单位

src_stride

单位

dst_stride

单位

OUT

L1

uint8, int8, float16, uint16, int16, float32, int32, uint32, uint64, int64

32B

32B

32B

L1

OUT

uint8, int8, float16, uint16, int16, float32, int32, uint32, uint64, int64

32B

32B

32B

OUT

UB

uint8, int8, float16, uint16, int16, float32, int32, uint32, uint64, int64

32B

32B

32B

UB

OUT

uint8, int8, float16, uint16, int16, float32, int32, uint32, uint64, int64

32B

32B

32B

UB

UB

uint8, int8, float16, uint16, int16, float32, int32, uint32, uint64, int64

32B

32B

32B

支持的芯片型号

Atlas 200/300/500 推理产品

Atlas 训练系列产品

注意事项

返回值

调用示例

from tbe import tik
tik_instance = tik.Tik()
src_gm = tik_instance.Tensor("float16", (512,), name="src_gm", scope=tik.scope_gm)
dst_gm = tik_instance.Tensor("float16", (512,), name="dst_gm", scope=tik.scope_gm)
tensor_ub = tik_instance.Tensor("float16", (512,), name="tensor_ub", scope=tik.scope_ubuf)
# 将用户输入数据从gm搬运到ub
# nburst表示传输片段数目,相当于传输次数;burst表示单次传输所传输的数据片段长度,单位是32B;src_stride/dst_stride表示每次传输之间的间隔
# 为提高运行性能,建议尽量减少传输次数、加大单次传输的片段长度,即nburst尽量小、burst尽量大
# 本例中,nburst为1,即一次完成所有数据传输;burst=512*2//32=32,即每次传输片段长度为32;src_stride/dst_stride都为0,表示连续传输
tik_instance.data_move(tensor_ub, src_gm, 0, 1, 32, 0, 0)
# 将计算结果拷贝到目标gm
tik_instance.data_move(dst_gm, tensor_ub, 0, 1, 32, 0, 0)

tik_instance.BuildCCE(kernel_name="data_move", inputs=[src_gm], outputs=[dst_gm])

结果示例:

输入数据(src_gm):
[-1.539    1.418   -6.418   -9.55    -9.336   -6.484    4.117    7.914
 -2.012    3.201   -5.375    7.32     4.       9.99     3.502    8.27
 -8.125   -9.33    -6.812   -8.695    9.87    -4.914   -5.992    1.233
 -3.662    3.477   -4.9     -3.924    6.438    8.266    7.31     8.97
  6.06    -3.646    9.695    0.623    9.84    -5.234    4.715   -8.07
  ...
  2.19     3.709   -3.611   -6.97    -0.772   -0.5938   2.953    7.043
  6.63     8.55     1.873    0.1703  -0.715   -5.35    -4.52     7.31
  4.336   -7.113   -5.875    9.44    -2.812   -6.5     -0.742   -6.703
  3.297   -7.605    0.3582  -1.62     2.578   -6.35    -2.166    9.95
  4.57     2.746    9.88    -3.354    5.645   -6.434   -2.32     2.59   ]

输出数据(dst_gm):
[-1.539    1.418   -6.418   -9.55    -9.336   -6.484    4.117    7.914
 -2.012    3.201   -5.375    7.32     4.       9.99     3.502    8.27
 -8.125   -9.33    -6.812   -8.695    9.87    -4.914   -5.992    1.233
 -3.662    3.477   -4.9     -3.924    6.438    8.266    7.31     8.97
  6.06    -3.646    9.695    0.623    9.84    -5.234    4.715   -8.07
  ...
  2.19     3.709   -3.611   -6.97    -0.772   -0.5938   2.953    7.043
  6.63     8.55     1.873    0.1703  -0.715   -5.35    -4.52     7.31
  4.336   -7.113   -5.875    9.44    -2.812   -6.5     -0.742   -6.703
  3.297   -7.605    0.3582  -1.62     2.578   -6.35    -2.166    9.95
  4.57     2.746    9.88    -3.354    5.645   -6.434   -2.32     2.59   ]