vec_and

Description

Performs bitwise AND element-wise:

Prototype

vec_and(mask, dst, src0, src1, repeat_times, dst_rep_stride, src0_rep_stride, src1_rep_stride)

Parameters

For details, see Parameters.

dst, src0, and src1 must have the same data type. Tensors of type uint16 or int16.

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()
src0_gm = tik_instance.Tensor("int16", (128,), name="src0_gm", scope=tik.scope_gm)
src1_gm = tik_instance.Tensor("int16", (128,), name="src1_gm", scope=tik.scope_gm)
dst_gm = tik_instance.Tensor("int16", (128,), name="dst_gm", scope=tik.scope_gm)
src0_ub = tik_instance.Tensor("int16", (128,), name="src0_ub", scope=tik.scope_ubuf)
src1_ub = tik_instance.Tensor("int16", (128,), name="src1_ub", scope=tik.scope_ubuf)
dst_ub = tik_instance.Tensor("int16", (128,), name="dst_ub", scope=tik.scope_ubuf)
# Move the user input from the Global Memory to the Unified Buffer.
tik_instance.data_move(src0_ub, src0_gm, 0, 1, 8, 0, 0)
tik_instance.data_move(src1_ub, src1_gm, 0, 1, 8, 0, 0)
tik_instance.vec_and(128, dst_ub, src0_ub, src1_ub, 1, 8, 8, 8)
# Move the compute result from the Unified Buffer to the destination Global Memory.
tik_instance.data_move(dst_gm, dst_ub, 0, 1, 8, 0, 0)

tik_instance.BuildCCE(kernel_name="vec_and", inputs=[src0_gm, src1_gm], outputs=[dst_gm])

Result example:

Input (src0_gm):
[-9  0 -7  7  0 -7 -3 -4  4 -8 -9  5  0  5  0 -6 -1 -9  6  1  4 -4  5  9
  6  9  4  8  3  7 -9  2 -1  5  1 -2  0 -3 -2 -3  0  4  0  4 -6  2 -8  5
 -4 -7  2 -2  0 -3  1  7 -9 -2  6 -3 -1  6 -5 -7  9  3 -3 -7  5 -4  0 -4
  7 -2  8 -9  7 -1 -2  0  2  9  0 -4  8 -8  7  0  3  4  0  5 -8 -5  3 -9
 -8 -9 -7  9  4  0  7  0 -1  0 -1  1 -1 -8 -1 -5  3  3 -7 -7 -7  2  6  6
  7  5 -2 -5 -3 -3 -6 -4]

Input (src1_gm):
[-1  8 -9  0 -7  6  5 -7 -6  7  3 -1  6  7  8  1 -6 -8 -6 -4  0  5  7 -6
 -2  5 -2 -3  0 -6 -9 -5  1  7  0 -6  8 -8  3  4  2 -7 -3  8 -3 -6  1 -8
  9 -2 -4  0 -2  6  3  5 -9  0 -1  6 -3 -7  8  4 -2 -7 -3  3 -9  6  5 -3
  8 -2  8 -5  9 -8  3 -6 -1 -7  0 -1  0  9  8 -7  4  8 -8  8 -6 -6  7 -3
  2 -8  0  0 -3  1 -2 -6 -2 -7 -9 -1  5  1  1 -8 -1  9 -2 -5  6  9  2 -5
 -4  9  9 -1 -7  6  9  5]

Output (dst_gm):
[ -9   0 -15   0   0   0   5  -8   0   0   3   5   0   5   0   0  -6 -16
   2   0   0   4   5   8   6   1   4   8   0   2  -9   2   1   5   0  -6
   0  -8   2   4   0   0   0   0  -8   2   0   0   8  -8   0   0   0   4
   1   5  -9   0   6   4  -3   0   8   0   8   1  -3   1   5   4   0  -4
   0  -2   8 -13   1  -8   2   0   2   9   0  -4   0   8   0   0   0   0
   0   0  -8  -6   3 -11   0 -16   0   0   4   0   6   0  -2   0  -9   1
   5   0   1  -8   3   1  -8  -7   0   0   2   2   4   1   8  -5  -7   4
   8   4]