Compare

The compare part of IR APIs.

tvm.aipu.script.ir.compare.vceq(x, y, mask=None)

Check if active elements of x are equal to the corresponding elements of y.

  • The inactive elements of result vector are set to False.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

   x: 1  1  3  4  5  6   7   8
   y: 1  1  3  5  5  5  99  99
mask: T  F  T  T  T  F   T   T

 out = S.vceq(x, y, mask)
 out: T  F  T  F  T  F   F   F

Parameters

x, yUnion[PrimExpr, int, float]

The operands. If either one is a scalar, it will be automatically broadcast.

maskOptional[Union[Tuple[bool], List[bool], numpy.ndarray[bool], str, PrimExpr]]

The predication mask to indicate which elements of the vector are active for the operation. None means all elements are active.

Returns

retPrimExpr

The result expression.

Supported DType

“int8/16/32”, “uint8/16/32”, “float16/32”.

Examples

mask_out = S.vceq(va, vb)
mask_out = S.vceq(va, 3)
mask_out = S.vceq(3, vb)
mask_out = S.vceq(va, vb, mask="3T5F")
mask_out = S.vceq(va, vb, mask=S.tail_mask(n, 8))

See Also

  • Zhouyi Compass OpenCL Programming Guide: __vceq, __vqeq

tvm.aipu.script.ir.compare.vcneq(x, y, mask=None)

Check if active elements of x are not equal to the corresponding elements of y.

  • The inactive elements of result vector are set to False.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

   x: 9  9  9  9  9  9  99  99
   y: 1  1  9  9  2  3  99  99
mask: T  F  T  T  T  T   T   F

 out = S.vcneq(x, y, mask)
 out: T  F  F  F  T  T   F   F

Parameters

x, yUnion[PrimExpr, int, float]

The operands. If either one is a scalar, it will be automatically broadcast.

maskOptional[Union[Tuple[bool], List[bool], numpy.ndarray[bool], str, PrimExpr]]

The predication mask to indicate which elements of the vector are active for the operation. None means all elements are active.

Returns

retPrimExpr

The result expression.

Supported DType

“int8/16/32”, “uint8/16/32”, “float16/32”.

Examples

mask_out = S.vcneq(va, vb)
mask_out = S.vcneq(va, 3)
mask_out = S.vcneq(3, vb)
mask_out = S.vcneq(va, vb, mask="3T5F")
mask_out = S.vcneq(va, vb, mask=S.tail_mask(n, 8))

See Also

  • Zhouyi Compass OpenCL Programming Guide: __vcneq, __vqne

tvm.aipu.script.ir.compare.vcge(x, y, mask=None)

Check if active elements of x are greater than or equal to the corresponding elements of y.

  • The inactive elements of result vector are set to False.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

   x: 1  1  2  3  4  5  5  6
   y: 5  5  5  5  5  5  5  5
mask: T  F  T  T  T  T  F  T

 out = S.vcge(x, y, mask)
 out: F  F  F  F  F  T  F  T

Parameters

x, yUnion[PrimExpr, int, float]

The operands. If either one is a scalar, it will be automatically broadcast.

maskOptional[Union[Tuple[bool], List[bool], numpy.ndarray[bool], str, PrimExpr]]

The predication mask to indicate which elements of the vector are active for the operation. None means all elements are active.

Returns

retPrimExpr

The result expression.

Supported DType

“int8/16/32”, “uint8/16/32”, “float16/32”.

Examples

mask_out = S.vcge(va, vb)
mask_out = S.vcge(va, 3)
mask_out = S.vcge(3, vb)
mask_out = S.vcge(va, vb, mask="3T5F")
mask_out = S.vcge(va, vb, mask=S.tail_mask(n, 8))

See Also

  • Zhouyi Compass OpenCL Programming Guide: __vcge, __vqge

tvm.aipu.script.ir.compare.vcgt(x, y, mask=None)

Check if active elements of x are greater than the corresponding elements of y.

  • The inactive elements of result vector are set to False.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

   x: 1  1  2  3  4  5  6  6
   y: 1  1  3  3  3  3  3  3
mask: T  F  T  T  T  T  T  F

 out = S.vcgt(x, y, mask)
 out: F  F  F  F  T  T  T  F

Parameters

x, yUnion[PrimExpr, int, float]

The operands. If either one is a scalar, it will be automatically broadcast.

maskOptional[Union[Tuple[bool], List[bool], numpy.ndarray[bool], str, PrimExpr]]

The predication mask to indicate which elements of the vector are active for the operation. None means all elements are active.

Returns

retPrimExpr

The result expression.

Supported DType

“int8/16/32”, “uint8/16/32”, “float16/32”.

Examples

mask_out = S.vcgt(va, vb)
mask_out = S.vcgt(va, 3)
mask_out = S.vcgt(3, vb)
mask_out = S.vcgt(va, vb, mask="3T5F")
mask_out = S.vcgt(va, vb, mask=S.tail_mask(n, 8))

See Also

  • Zhouyi Compass OpenCL Programming Guide: __vcgt, __vqgt

tvm.aipu.script.ir.compare.vcle(x, y, mask=None)

Check if active elements of x are less than or equal to the corresponding elements of y.

  • The inactive elements of result vector are set to False.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

   x: 1  1  2  3  4  5  6  6
   y: 1  1  3  3  3  3  3  3
mask: T  F  T  T  T  T  T  F

 out = S.vcle(x, y, mask)
 out: T  F  T  T  F  F  F  F

Parameters

x, yUnion[PrimExpr, int, float]

The operands. If either one is a scalar, it will be automatically broadcast.

maskOptional[Union[Tuple[bool], List[bool], numpy.ndarray[bool], str, PrimExpr]]

The predication mask to indicate which elements of the vector are active for the operation. None means all elements are active.

Returns

retPrimExpr

The result expression.

Supported DType

“int8/16/32”, “uint8/16/32”, “float16/32”.

Examples

mask_out = S.vcle(va, vb)
mask_out = S.vcle(va, 3)
mask_out = S.vcle(3, vb)
mask_out = S.vcle(va, vb, mask="3T5F")
mask_out = S.vcle(va, vb, mask=S.tail_mask(n, 8))

See Also

  • Zhouyi Compass OpenCL Programming Guide: __vcle, __vqle

tvm.aipu.script.ir.compare.vclt(x, y, mask=None)

Check if active elements of x are less than the corresponding elements of y.

  • The inactive elements of result vector are set to False.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

   x: 1  1  2  3  4  5  6  3
   y: 1  1  4  4  4  4  4  4
mask: T  F  T  T  T  T  T  F

 out = S.vclt(x, y, mask)
 out: F  F  T  T  F  F  F  F

Parameters

x, yUnion[PrimExpr, int, float]

The operands. If either one is a scalar, it will be automatically broadcast.

maskOptional[Union[Tuple[bool], List[bool], numpy.ndarray[bool], str, PrimExpr]]

The predication mask to indicate which elements of the vector are active for the operation. None means all elements are active.

Returns

retPrimExpr

The result expression.

Supported DType

“int8/16/32”, “uint8/16/32”, “float16/32”.

Examples

mask_out = S.vclt(va, vb)
mask_out = S.vclt(va, 3)
mask_out = S.vclt(3, vb)
mask_out = S.vclt(va, vb, mask="3T5F")
mask_out = S.vclt(va, vb, mask=S.tail_mask(n, 8))

See Also

  • Zhouyi Compass OpenCL Programming Guide: __vclt, __vqlt

tvm.aipu.script.ir.compare.isnan(x, mask=None)

Check if active elements of x are NaN.

  • The scalar situation where x is a scalar is also supported.

  • The inactive elements of result vector are set to False.

   x: nan  1.0  nan  3.6  nan  5.0  6.7  3.1
mask:  T    T    F    T    T    T    F    T

 out = S.isnan(x, mask)
 out:  T    F    F    F    T    F    F    F

Parameters

xUnion[PrimExpr, float]

The operand.

maskOptional[Union[Tuple[bool], List[bool], numpy.ndarray[bool], str, PrimExpr]]

The predication mask to indicate which elements of the vector are active for the operation. None means all elements are active.

Returns

retPrimExpr

The result expression.

Supported DType

“float16/32”.

Examples

bool_out = S.isnan(scalar_a)
mask_out = S.isnan(vector_b, mask)

See Also

  • Zhouyi Compass OpenCL Programming Guide: __class, __vclass, __vqne, __vand, isnan

tvm.aipu.script.ir.compare.isinf(x, mask=None)

Check if active elements of x are positive or negative infinity.

  • The scalar situation where x is a scalar is also supported.

  • The inactive elements of result vector are set to False.

   x: inf  1.0  -inf  3.1  inf  5.0  6.3  -inf
mask:  T    T     F    T    T    T    F     T

 out = S.isinf(x, mask)
 out:  T    F     F    F    T    F    F     T

Parameters

xUnion[PrimExpr, float]

The operand.

maskOptional[Union[Tuple[bool], List[bool], numpy.ndarray[bool], str, PrimExpr]]

The predication mask to indicate which elements of the vector are active for the operation. None means all elements are active.

Returns

retPrimExpr

The result expression.

Supported DType

“float16/32”.

Examples

bool_out = S.isinf(scalar_a)
mask_out = S.isinf(vector_b, mask)

See Also

  • Zhouyi Compass OpenCL Programming Guide: __class, __vclass, __vqne, __vand, isinf

tvm.aipu.script.ir.compare.max(x, y, mask=None, r=None)

Computes the maximum on active elements of x with the corresponding elements of y.

  • The scalar situation where both x and y are scalar is also supported.

  • The inactive elements of result vector are determined by r.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

   x: 1  2  3  4  5  6  7  8
   y: 5  5  5  5  5  5  5  5
mask: T  T  T  T  F  F  T  T
   z: 9  8  7  6  4  3  2  1

 out = S.max(x, y, mask, r=z)
 out: 5  5  5  5  4  3  7  8

Parameters

x, yUnion[PrimExpr, int, float]

The operands. If either one is a scalar, it will be automatically broadcast.

maskOptional[Union[Tuple[bool], List[bool], numpy.ndarray[bool], str, PrimExpr]]

The predication mask to indicate which elements of the vector are active for the operation. None means all elements are active.

rOptional[PrimExpr, int, float]

Provide the value of the inactive elements in result vector. If it is a scalar, it will be automatically broadcast. None means the inactive elements of result vector are undefined.

Returns

retPrimExpr

The result expression.

Supported DType

“int8/16/32”, “uint8/16/32”, “float16/32”.

Examples

 c = S.max(3, 4)
vc = S.max(va, vb)
vc = S.max(va, 3)
vc = S.max(3, vb)
vc = S.max(va, vb, mask="3T5F")
vc = S.max(va, vb, mask=S.tail_mask(n, 8))
vc = S.max(va, vb, mask="T7F", r=vb)

See Also

  • Zhouyi Compass OpenCL Programming Guide: __vmax

tvm.aipu.script.ir.compare.min(x, y, mask=None, r=None)

Computes the minimum on active elements of x with the corresponding elements of y.

  • The scalar situation where both x and y are scalar is also supported.

  • The inactive elements of result vector are determined by r.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

   x: 1  2  3  4  5  6  7  8
   y: 5  5  5  5  5  5  5  5
mask: T  T  T  T  F  F  T  T
   z: 9  8  7  6  4  3  2  1

 out = S.min(x, y, mask, r=z)
 out: 1  2  3  4  4  3  5  5

Parameters

x, yUnion[PrimExpr, int, float]

The operands. If either one is a scalar, it will be automatically broadcast.

maskOptional[Union[Tuple[bool], List[bool], numpy.ndarray[bool], str, PrimExpr]]

The predication mask to indicate which elements of the vector are active for the operation. None means all elements are active.

rOptional[PrimExpr, int, float]

Provide the value of the inactive elements in result vector. If it is a scalar, it will be automatically broadcast. None means the inactive elements of result vector are undefined.

Returns

retPrimExpr

The result expression.

Supported DType

“int8/16/32”, “uint8/16/32”, “float16/32”.

Examples

 c = S.min(3, 4)
vc = S.min(va, vb)
vc = S.min(va, 3)
vc = S.min(3, vb)
vc = S.min(va, vb, mask="3T5F")
vc = S.min(va, vb, mask=S.tail_mask(n, 8))
vc = S.min(va, vb, mask="T7F", r=vb)

See Also

  • Zhouyi Compass OpenCL Programming Guide: __vmin

tvm.aipu.script.ir.compare.vmaxh(x, y)

Computes the maximum of two adjacent elements, the results of x are placed to the low half part of result vector, and that of y are placed to the high half part.

  • The feature Multiple Width Vector is supported.

  x: 9  1  8  2  7  3  6  4
  y: 5  4  4  3  3  2  2  1

out = S.vmaxh(x, y)
out: 9  8  7  6  5  4  3  2

Parameters

x, yUnion[PrimExpr, int]

The operands. If either one is a scalar, it will be automatically broadcast.

Returns

retPrimExpr

The result expression.

Supported DType

“int8/16/32”, “uint8/16/32”.

Examples

vc = S.vmaxh(va, vb)
vc = S.vmaxh(va, 3)
vc = S.vmaxh(3, vb)
vc = S.vmaxh(va, vb, mask="3T5F")
vc = S.vmaxh(va, vb, mask=S.tail_mask(n, 8))

See Also

  • Zhouyi Compass OpenCL Programming Guide: __vmaxh

tvm.aipu.script.ir.compare.vminh(x, y)

Computes the minimum of two adjacent elements, the results of x are placed to the low half part of result vector, and that of y are placed to the high half part.

  • The feature Multiple Width Vector is supported.

  x: 9  1  8  2  7  3  6  4
  y: 5  4  4  3  3  2  2  1

out = S.vminh(x, y)
out: 1  2  3  4  4  3  2  1

Parameters

x, yUnion[PrimExpr, int]

The operands. If either one is a scalar, it will be automatically broadcast.

Returns

retPrimExpr

The result expression.

Supported DType

“int8/16/32”, “uint8/16/32”.

Examples

vc = S.vminh(va, vb)
vc = S.vminh(va, 3)
vc = S.vminh(3, vb)
vc = S.vminh(va, vb, mask="3T5F")
vc = S.vminh(va, vb, mask=S.tail_mask(n, 8))

See Also

  • Zhouyi Compass OpenCL Programming Guide: __vminh

tvm.aipu.script.ir.compare.vrpmax(x, mask=None, return_idx=False)

Computes the reduction maximum of all active elements of x, and places the result as the lowest elements of result vector.

  • The remaining upper elements of result vector are undefined.

   x: 7  9  3  4  5  6  7  8
mask: T  F  T  T  T  T  T  T

 out = S.vrpmax(x, mask)
 out: 8  ?  ?  ?  ?  ?  ?  ?

 out = S.vrpmax(x, mask, return_idx=True)
 out: 8  7  ?  ?  ?  ?  ?  ?

Parameters

xPrimExpr

The operands.

maskOptional[Union[Tuple[bool], List[bool], numpy.ndarray[bool], str, PrimExpr]]

The predication mask to indicate which elements of the vector are active for the operation. None means all elements are active.

return_idxOptional[bool]

If True, it will record the index of the maximum value and put it in the second element of result vector. If there are more than one maximum value, the index will be the lowest one. This argument is only supported by the V3 architecture.

Returns

retPrimExpr

The result expression.

Supported DType

“int8/16/32”, “uint8/16/32”, “float16/32”.

Examples

vc = S.vrpmax(va)
vc = S.vrpmax(va,  S.tail_mask(4, 8))

See Also

  • Zhouyi Compass OpenCL Programming Guide: __vrpmax

tvm.aipu.script.ir.compare.vrpmin(x, mask=None, return_idx=False)

Computes the reduction minimum of all active elements of x, and places the result as the lowest elements of result vector.

  • The remaining upper elements of result vector are undefined.

   x: 7  9  3  4  5  6  7  8
mask: T  T  F  T  T  T  T  T

 out = S.vrpmin(x, mask)
 out: 4  ?  ?  ?  ?  ?  ?  ?

 out = S.vrpmin(x, mask, return_idx=True)
 out: 4  3  ?  ?  ?  ?  ?  ?

Parameters

xPrimExpr

The operands.

maskOptional[Union[Tuple[bool], List[bool], numpy.ndarray[bool], str, PrimExpr]]

The predication mask to indicate which elements of the vector are active for the operation. None means all elements are active.

return_idxOptional[bool]

If True, it will record the index of the minimum value and put it in the second element of result vector. If there are more than one minimum value, the index will be the lowest one. This argument is only supported by the V3 architecture.

Returns

retPrimExpr

The result expression.

Supported DType

“int8/16/32”, “uint8/16/32”, “float16/32”.

Examples

vc = S.vrpmin(va)
vc = S.vrpmin(va,  S.tail_mask(4, 8))

See Also

  • Zhouyi Compass OpenCL Programming Guide: __vrpmin