vec_trans_scatter

功能说明

NCHW转换成NC1HWC0格式。如果是数据类型是float32 int32,uint32, int16,unint16,float16, 则C0=16, 如果数据类型是uint8,int8,则C0=32.

函数原型

vec_trans_scatter (dst_high_half, src_high_half, dst_list, src_list, repeat_times, dst_rep_stride, src_rep_stride)

参数说明

表1 参数说明

参数名称

输入/输出

含义

dst_high_half

输入

指定 dst_list[*] 的数据存储到 block 的高半部还是低半部,该配置只支持 int8/uint8 的数据类型。

支持的数据类型为 bool,有以下两种取值:

  • True 表示存储于 block 的高半部
  • False 表示存储于 block 的低半部

src_high_half

输入

指定 src_list[*] 的数据从 block 的高半部还是低半部读取,该配置只支持int8/uint8的数据类型。

支持的数据类型为 bool,有以下两种取值:

  • True 表示存储于 block 的高半部
  • False 表示存储于 block 的低半部

dst_list

输出

矢量目的操作数序列,其中元素为每个目的操作数起始位置。

Tensor的scope为Unified Buffer

Atlas 200/300/500 推理产品,支持的数据类型为Tensor(int8/uint8/int16/uint16/float16)。

Atlas 训练系列产品,支持的数据类型为Tensor(int8/uint8/int16/uint16/float16)。

src_list

输入

矢量源操作数序列,其中元素为每个源操作数起始位置,支持的数据类型应与 dst_list 一致。

Tensor的scope为Unified Buffer

repeat_times

输入

重复迭代次数,repeat_times∈[0,255],单位:block。支持的数据类型:Scalar(int16/int32/int64/uint16/uint32/uint64)、立即数(int)、Expr(int16/int32/int64/uint16/uint32/uint64)。

注意事项:

1、当 repeat_times 为 1 时,目的操作数/源操作数的有效起始位置为 dst_list/src_list 序列输入的起始位置加上 dst_rep_stride/src_rep_stride。

2、当 repeat_times 大于 1 时,第一次 repeat 中目的操作数/源操作数的有效起始位置为 dst_list/src_list 序列输入的起始位置,第二次需要加上 dst_rep_stride/src_rep_stride, 以此类推。

dst_rep_stride

输入

相邻迭代间,目的操作数相同 block 地址 stride,dst_rep_stride∈[0,65535],单位:block。支持的数据类型:Scalar(int16/int32/int64/uint16/uint32/uint64)、立即数(int)、Expr(int16/int32/int64/uint16/uint32/uint64)

src_rep_stride

输入

相邻迭代间,源操作数相同 block 地址 stride,src_rep_stride∈[0,65535],单位:block。支持的数据类型:Scalar(int16/int32/int64/uint16/uint32/uint64)、立即数(int)、Expr(int16/int32/int64/uint16/uint32/uint64)

支持的芯片型号

Atlas 200/300/500 推理产品

Atlas 训练系列产品

注意事项

返回值

调用示例

from tbe import tik
tik_instance = tik.Tik()
src_gm = tik_instance.Tensor("float16", (256,), name="src_gm", scope=tik.scope_gm)
dst_gm = tik_instance.Tensor("float16", (256,), name="dst_gm", scope=tik.scope_gm)
src_ub = tik_instance.Tensor("float16", (256,), name="src_ub", scope=tik.scope_ubuf)
dst_ub = tik_instance.Tensor("float16", (256,), name="dst_ub", scope=tik.scope_ubuf)
# 将用户输入数据从gm搬运到ub
tik_instance.data_move(src_ub, src_gm, 0, 1, 16, 0, 0)
dst_list = [dst_ub[16 * i] for i in range(16)]
src_list = [src_ub[16 * i] for i in range(16)]
tik_instance.vec_trans_scatter(True, False, dst_list, src_list, 1, 0, 0)
# 将计算结果从ub搬运到gm
tik_instance.data_move(dst_gm, dst_ub, 0, 1, 16, 0, 0)

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

结果示例:

输入数据(src_gm):
[ 2.678    9.33    -3.406    8.35    -0.2708   5.73    -5.562   -9.445
 -4.387   -2.959    9.875    7.062   -7.652    2.914   -6.78     4.277
 -2.373    7.086   -7.777    3.846    9.73     2.725    6.867   -6.97
 -6.74     1.559   -3.348    3.78     3.459    7.113   -0.826   -1.306
 -2.008   -8.56     3.55     1.716    7.348    6.05     9.57     4.133
 -2.629    1.766   -9.59    -7.08    -3.045   -8.47     4.023    4.117
 -5.       4.44    -0.7505   1.9375  -0.02312  2.521    3.154    4.4
  1.726    7.984    8.32    -2.715    9.73    -8.875    1.201   -2.582
 -3.16    -0.1744   5.44    -9.83     1.03    -3.535    5.26     2.852
  6.77     7.66     4.668    6.367   -1.134    6.074   -6.887   -8.45
 -8.484   -2.256    8.04     4.586   -6.25     7.457    0.3906   2.299
  4.023    2.389    5.938   -1.715    2.162   -8.79    -7.99    -2.768
 -5.258    4.684   -9.195    4.52    -0.6104   9.23     1.059   -3.293
  4.13     7.67    -4.37     2.953   -1.045   -6.01     3.2     -9.805
 -0.744    0.286   -3.682   -4.355   -0.1448  -2.19    -6.49     9.31
 -2.967   -6.254   -8.27    -0.507   -0.2869   2.22    -0.729    7.58
 -0.5576   0.5894   4.684   -7.03     8.234    7.68    -5.4      0.981
  3.535    0.09344  1.268   -1.304   -5.684   -0.4846  -6.05     8.49
 -2.79    -5.48     0.12317 -7.4     -0.689   -1.389    2.855   -0.2129
 -5.805    6.598    7.117   -7.05     2.176    5.195   -7.688    0.433
  6.625    2.875    3.756   -0.03467  9.305   -9.52     4.676   -9.234
 -2.443   -1.82    -1.768    4.082    6.77     5.805   -2.83     7.67
  0.3452   5.34    -6.35    -9.945    3.943    8.46    -7.57     9.89
  8.04     7.395   -8.82     6.96    -3.662   -5.89     0.2135   2.324
  9.59    -2.607    6.457   -4.59     1.585   -3.146   -9.54    -9.41
 -7.86    -2.256   -2.53     5.695    4.742   -9.77     8.77     5.027
  6.387   -5.016    2.244   -8.53     8.83     9.68     4.703    9.93
 -6.797    9.15     5.625   -3.648    2.355    2.459    7.605   -8.85
  0.2162  -9.69     1.497    8.11    -1.618    9.48    -1.033    8.6
  7.266   -6.582    0.3564  -4.953    4.2     -3.436    3.61    -6.28
  5.938   -4.734    8.445   -5.39     7.582   -2.62     0.9937  -8.46
  9.21    -6.906   -0.3364   1.008   -0.2114   7.01    -3.066   -2.021  ]

输出数据(dst_gm):
[ 2.678   -2.373   -2.008   -5.      -3.16    -8.484   -5.258   -0.744
 -0.5576  -2.79     6.625    0.3452   9.59     6.387    0.2162   5.938
  9.33     7.086   -8.56     4.44    -0.1744  -2.256    4.684    0.286
  0.5894  -5.48     2.875    5.34    -2.607   -5.016   -9.69    -4.734
 -3.406   -7.777    3.55    -0.7505   5.44     8.04    -9.195   -3.682
  4.684    0.12317  3.756   -6.35     6.457    2.244    1.497    8.445
  8.35     3.846    1.716    1.9375  -9.83     4.586    4.52    -4.355
 -7.03    -7.4     -0.03467 -9.945   -4.59    -8.53     8.11    -5.39
 -0.2708   9.73     7.348   -0.02312  1.03    -6.25    -0.6104  -0.1448
  8.234   -0.689    9.305    3.943    1.585    8.83    -1.618    7.582
  5.73     2.725    6.05     2.521   -3.535    7.457    9.23    -2.19
  7.68    -1.389   -9.52     8.46    -3.146    9.68     9.48    -2.62
 -5.562    6.867    9.57     3.154    5.26     0.3906   1.059   -6.49
 -5.4      2.855    4.676   -7.57    -9.54     4.703   -1.033    0.9937
 -9.445   -6.97     4.133    4.4      2.852    2.299   -3.293    9.31
  0.981   -0.2129  -9.234    9.89    -9.41     9.93     8.6     -8.46
 -4.387   -6.74    -2.629    1.726    6.77     4.023    4.13    -2.967
  3.535   -5.805   -2.443    8.04    -7.86    -6.797    7.266    9.21
 -2.959    1.559    1.766    7.984    7.66     2.389    7.67    -6.254
  0.09344  6.598   -1.82     7.395   -2.256    9.15    -6.582   -6.906
  9.875   -3.348   -9.59     8.32     4.668    5.938   -4.37    -8.27
  1.268    7.117   -1.768   -8.82    -2.53     5.625    0.3564  -0.3364
  7.062    3.78    -7.08    -2.715    6.367   -1.715    2.953   -0.507
 -1.304   -7.05     4.082    6.96     5.695   -3.648   -4.953    1.008
 -7.652    3.459   -3.045    9.73    -1.134    2.162   -1.045   -0.2869
 -5.684    2.176    6.77    -3.662    4.742    2.355    4.2     -0.2114
  2.914    7.113   -8.47    -8.875    6.074   -8.79    -6.01     2.22
 -0.4846   5.195    5.805   -5.89    -9.77     2.459   -3.436    7.01
 -6.78    -0.826    4.023    1.201   -6.887   -7.99     3.2     -0.729
 -6.05    -7.688   -2.83     0.2135   8.77     7.605    3.61    -3.066
  4.277   -1.306    4.117   -2.582   -8.45    -2.768   -9.805    7.58
  8.49     0.433    7.67     2.324    5.027   -8.85    -6.28    -2.021  ]