vec_abs

Description

Computes the absolute value element-wise:

Prototype

vec_abs(mask, dst, src, repeat_times, dst_rep_stride, src_rep_stride)

Parameters

For details, see Parameters.

dst and src must have the same data type.

Atlas 200/300/500 Inference Product : Tensors of type float16/float32

Atlas Training Series Product : Tensors of type float16/float32

Returns

None

Applicability

Atlas 200/300/500 Inference Product

Atlas Training Series Product

Restrictions

For details, see Restrictions.

Example

This example applies to a small amount of data that can be moved at a time, helping you understand the API functions. For more complex samples with a large amount of data, see Example.

from tbe import tik
tik_instance = tik.Tik()
src_gm = tik_instance.Tensor("float16", (128,), name="src_gm", scope=tik.scope_gm)
dst_gm = tik_instance.Tensor("float16", (128,), name="dst_gm", scope=tik.scope_gm)
src_ub = tik_instance.Tensor("float16", (128,), name="src_ub", scope=tik.scope_ubuf)
dst_ub = tik_instance.Tensor("float16", (128,), name="dst_ub", scope=tik.scope_ubuf)
# Move the user input from the Global Memory to the Unified Buffer.
tik_instance.data_move(src_ub, src_gm, 0, 1, 8, 0, 0)
tik_instance.vec_abs(128, dst_ub, src_ub, 1, 8, 8)
# Move the compute result from the Unified Buffer to the Global Memory.
tik_instance.data_move(dst_gm, dst_ub, 0, 1, 8, 0, 0)

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

Result example

Input (src_gm):
[-0.658   0.4937  3.76    4.406  -2.17    1.57    6.85    0.0899 -9.25
  8.2    -0.43   -2.898  -4.074   1.998  -7.      8.71   -2.7     4.84
 -1.128   7.766  -4.125   0.806  -6.688  -7.766   5.69   -7.504   6.195
  3.156  -0.6157  9.45    2.736  -8.5     7.324   9.44    4.766   0.203
 -2.285  -1.517   8.58   -8.93    8.51   -4.926   6.293  -6.89    4.21
  0.1958  4.24   -8.375   3.035   7.99    9.87   -5.082   1.276  -0.6094
  9.73    3.883  -5.434   0.5186 -6.855  -6.523   3.44   -6.39   -8.91
  5.562   9.125   8.09   -8.89   -9.195   3.326  -1.147   7.855   3.26
 -2.742  -4.203  -3.5     4.727   7.52   -8.25    2.809  -9.06   -5.242
 -1.373  -3.506   6.484  -7.367   3.396   2.41   -7.652   8.21   -2.707
  5.984   8.1     4.457   6.598   6.742  -7.71    3.252   0.706  -6.39
  0.9697 -1.089  -1.476  -1.011  -5.168  -8.586  -2.059  -8.22   -2.148
 -1.745   1.856  -0.292   7.188  -4.945   3.426   0.1533 -0.768   9.96
 -6.746  -8.266  -7.336  -0.3726 -2.584   3.031  -2.846  -0.3635 -1.975
  4.785  -9.83  ]

Output (dst_gm):
[0.658  0.4937 3.76   4.406  2.17   1.57   6.85   0.0899 9.25   8.2
 0.43   2.898  4.074  1.998  7.     8.71   2.7    4.84   1.128  7.766
 4.125  0.806  6.688  7.766  5.69   7.504  6.195  3.156  0.6157 9.45
 2.736  8.5    7.324  9.44   4.766  0.203  2.285  1.517  8.58   8.93
 8.51   4.926  6.293  6.89   4.21   0.1958 4.24   8.375  3.035  7.99
 9.87   5.082  1.276  0.6094 9.73   3.883  5.434  0.5186 6.855  6.523
 3.44   6.39   8.91   5.562  9.125  8.09   8.89   9.195  3.326  1.147
 7.855  3.26   2.742  4.203  3.5    4.727  7.52   8.25   2.809  9.06
 5.242  1.373  3.506  6.484  7.367  3.396  2.41   7.652  8.21   2.707
 5.984  8.1    4.457  6.598  6.742  7.71   3.252  0.706  6.39   0.9697
 1.089  1.476  1.011  5.168  8.586  2.059  8.22   2.148  1.745  1.856
 0.292  7.188  4.945  3.426  0.1533 0.768  9.96   6.746  8.266  7.336
 0.3726 2.584  3.031  2.846  0.3635 1.975  4.785  9.83  ]